Skip to content

tf_function and autograph #481

Open
Open
@mohamed-180

Description

@mohamed-180

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsImprovements to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions