rstudio / tfprobability

R interface to TensorFlow Probability
https://rstudio.github.io/tfprobability/
Other
54 stars 16 forks source link

Error on Load #125

Closed dirmeier closed 4 years ago

dirmeier commented 4 years ago

Hello all,

first of all, thanks for putting tfprobability on CRAN. Makes work so much easier. When I use tfp as dependency in a package of mine, the first time I want to use it (say tfd_bernoulli) it throws the following error:

error in on_load() : 

  TensorFlow Probability has to be used with the TensorFlow Keras implementation

After this initial error, everything works fine though. This is usually ok, but it breaks CI. Do you have a clue what the issue might be? I try to find a minimal reproducible example, but in the meantime I thought this might be a common issue.

Thank you very much.

Cheers, Simon

dirmeier commented 4 years ago

This actually should suffice to reproduce:

> library(tensorflow)
> library(tfprobability)
> tf$compat$v2$enable_v2_behavior()

> d <- tfd_binomial(total_count = 7, probs = 0.3)
Error in on_load() : 
  TensorFlow Probability has to be used with the TensorFlow Keras implementation.
> d <- tfd_binomial(total_count = 7, probs = 0.3)
> d$sample()$numpy()
[1] 1
> tensorflow::tf_config()
TensorFlow v1.14.0
Python v3.6

> tfprobability::tfp_version()
[1] ‘0.7’
skeydan commented 4 years ago

Hi, thanks for using tfprobability!

Historically, this goes back to the switch of the default Keras implementation from standalone Keras to tf.keras (see https://blogs.rstudio.com/tensorflow/posts/2019-10-08-tf2-whatchanges/ for background). This check, and a related one, stem from nearly a year ago, when tfprobability was starting to be developed, and most R users were still using standalone Keras. By now, those checks are probably obsolete, and I could just remove them I guess...

To get rid of that warning though, it should probably be enough to update the keras R package to use the current version on CRAN - could you try that?

dirmeier commented 4 years ago

Hi, unfortunately that didn't solve it. But it's only a minor annoyance anyway, and I believe once I upgrade to TF2.1.0 it'll be solved. I circumvented the CI issue by just calling a tfp function as a dry run before the actual test suite:

test_that("dry run", {
    try({
   # do something with tfp
  })
})

# other tests
...