rstudio / tensorflow

TensorFlow for R
https://tensorflow.rstudio.com
Apache License 2.0
1.33k stars 318 forks source link

tf_function and autograph #481

Open mohamed-180 opened 3 years ago

mohamed-180 commented 3 years ago

from the advanced tutorial in Advanced Quickstart the part of :

training_loop <- tf_function(autograph(function(train_ds, test_ds) {

  for (b1 in train_ds) {
    train_step(b1$x, b1$y)
  }

  for (b2 in test_ds) {
    test_step(b2$x, b2$y)
  }

  tf$print("Acc", train_accuracy$result(), "Test Acc", test_accuracy$result())

  train_loss$reset_states()
  train_accuracy$reset_states()
  test_loss$reset_states()
  test_accuracy$reset_states()

}))

can we just use tf_function with out the autograph function based on tf_function have argument to use autograph see : https://github.com/rstudio/tensorflow/blob/e3791c4dbd685e5f8788c1bf4902c7cc70dea477/R/eager.R#L126-L145 and use autograph function only in case of executing eagerly.

t-kalinowski commented 3 years ago

Hi, Thanks for asking. Yes, as of version 2.6 tf_function() calls autograph() by default for you and there is no need to call it yourself. The example in the "Advanced Quickstart" needs to be updated. Though, it's harmless to call autograph() on a function twice, so the example should still work even if it is a little verbose.