Running example gives: "ValueError: Tensor conversion requested dtype int64 for Tensor with dtype int32"


#1

When I run the sample code given on get started page, I get the following error,

Error in py_call_impl(callable, dots$args, dots$keywords) : 
  ValueError: Tensor conversion requested dtype int64 for Tensor with dtype int32: 'Tensor("Placeholder_14:0", dtype=int32)'

Detailed traceback: 
  File "/home/adityap/.local/lib/python3.7/site-packages/tensorflow_probability/python/mcmc/sample.py", line 216, in sample_chain
    name="num_steps_between_results")
  File "/home/adityap/.local/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 1039, in convert_to_tensor
    return convert_to_tensor_v2(value, dtype, preferred_dtype, name)
  File "/home/adityap/.local/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 1097, in convert_to_tensor_v2
    as_ref=False)
  File "/home/adityap/.local/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 1175, in internal_convert_to_tensor
    ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
  File "/home/adityap/.local/lib/python3.7/site-packages/tensorflow/python/framework/ops.py", line 977, in _TensorTensorConversi

This happens at the line

draws <- mcmc(m, n_samples = 1000)

I have tensorflow version 1.13.1 and tensorflow-probability version 0.6.0 installed.


#2

@whoami, as far as I remember, then this error happens when you are using Greta from cran, and not the ‘testing’ version from github and using tensorflow > 1.10
devtools::install_github(“greta-dev/greta”).

The testing version does work, for me, with tf-1.12 and tfp-0.5.0 and python 3.6


#3

In my experience, the best combination to use is the CRAN version of Greta (i.e. v.0.3.0) with tensorflow==1.11 and tensorflow-probability 0.4.0. The error you are getting happens when using the CRAN version of tensorflow with tensorflow-probability 0.5.0. You can get rid of this message by installing Greta from github, but I do not recommend it as tensorflow-probability 0.5.0 is giving very ugly deprecation warnings when used with the latest version of numpy (i.e. >= 1.16). All the version compatibility issues are a pain to deal with so I strongly recommend following the below recipe for success.

The best course of action is to create the r-tensorflow environment manually from the Anaconda prompt. The following recipe is currently the best in my opinion:
conda create -n r-tensorflow python=3.6 pip numpy=1.15
conda activate r-tensorflow
pip install tensorflow-probability==0.4.0 --no-dependencies
conda install tensorflow=1.11
pip install h5py pyyaml requests Pillow scipy

and then use greta from CRAN:
install.packages("greta")