Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tf_function and autograph #481

Open
mohamed-180 opened this issue Sep 12, 2021 · 1 comment
Open

tf_function and autograph #481

mohamed-180 opened this issue Sep 12, 2021 · 1 comment
Labels
docs Improvements to documentation

Comments

@mohamed-180
Copy link

mohamed-180 commented Sep 12, 2021

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 :

tensorflow/R/eager.R

Lines 126 to 145 in e3791c4

tf_function <- function(f,
input_signature = NULL,
autograph = TRUE,
...) {
if (!is.function(f))
stop("`f` must be an R function")
if (!(isTRUE(autograph) || isFALSE(autograph)))
stop("`autograph` must be TRUE or FALSE")
if (autograph) {
# Can't register tfautograph in Imports yet due to circular dependency
if(!requireNamespace("tfautograph", quietly=TRUE))
stop('"tfautograph" package required if autograph=TRUE. Please run install.packages("tfautograph")')
f <- tfautograph::autograph(f)
}
args <- list(py_func(f), input_signature, FALSE, ...)
do.call(tf$`function`, args)
}

and use autograph function only in case of executing eagerly.

@t-kalinowski
Copy link
Member

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.

@t-kalinowski t-kalinowski added the docs Improvements to documentation label Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements to documentation
Projects
None yet
Development

No branches or pull requests

2 participants