Skip to content

model.save in TF2 forces me to use saved_model.save() but then fails #32097

@kristofgiber

Description

@kristofgiber

Calling model.save("path/model") from within my training loop which is inside strategy scope. I get this error:

AssertionError: tf.saved_model.save is not supported inside a traced @tf.function. Move the call to the outer eagerly-executed context.

But I'm in TF2, I'm NOT calling it inside a @tf.function. Even running tf.executing_eagerly() returns True when I stop the execution just before the save() call.

How do I work around this?
I can't use .h5 saving (it says nested classes not supported)
I also noticed a warning earlier in the script that appeared around the same time as this error, it says:

AssertionError: Nesting violated for default stack of <class 'tensorflow.python.framework.func_graph.FuncGraph'> objects

probably related to my attempt trying to manually set_input_shape for my model (following the instructions of an error message that said I cannot otherwise save my model).

The code I am using is just the tensorflow 2 tutorial for VAE plus distribute strategy. The model class is about the same used by the tutorial: https://www.tensorflow.org/beta/tutorials/generative/cvae

Metadata

Metadata

Labels

TF 2.0Issues relating to TensorFlow 2.0comp:kerasKeras related issuesstat:awaiting responseStatus - Awaiting response from authortype:bugBug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions