You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Traceback (most recent call last):
File "/home/humbulani/tensorflow-env/keras-io-master/examples/structured_data/classification_with_tfdf.py", line 290, in <module>
gbt_model = create_gbt_model()
^^^^^^^^^^^^^^^^^^
File "/home/humbulani/tensorflow-env/keras-io-master/examples/structured_data/classification_with_tfdf.py", line 282, in create_gbt_model
gbt_model.compile(metrics=[keras.metrics.BinaryAccuracy(name="accuracy")])
File "/home/humbulani/tensorflow-env/env/lib/python3.11/site-packages/tensorflow_decision_forests/keras/core_inference.py", line 852, in compile
super(InferenceCoreModel, self).compile(
File "/home/humbulani/tensorflow-env/env/lib/python3.11/site-packages/tf_keras/src/utils/traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/home/humbulani/tensorflow-env/env/lib/python3.11/site-packages/tensorflow/python/distribute/distribute_lib.py", line 4029, in variable_created_in_scope
return v._distribute_strategy is None # pylint: disable=protected-access
^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Variable' object has no attribute '_distribute_strategy'
I have traced the error to the following section of code from the function tf_keras.src.engine.training._validate_compile:
strategy=self.distribute_strategyformetricintf.nest.flatten(metrics):
forvingetattr(metric, "variables", []): # ERROR IS HEREifnotstrategy.extended.variable_created_in_scope(v):
raiseValueError(
f"Metric ({metric}) passed to `model.compile` was ""created inside a different distribution strategy ""scope than the model. All metrics must be created ""in the same distribution strategy "f"scope as the model (in this case {strategy}). ""If you pass in a string identifier for a metric to ""compile, the metric will automatically be created ""in the correct distribution strategy scope."
)
and pdb has produced the following trace:
(Pdb) n
> /home/humbulani/tensorflow-env/env/lib/python3.11/site-packages/tf_keras/src/engine/training.py(3927)_validate_compile()
-> strategy = self.distribute_strategy
(Pdb) n
> /home/humbulani/tensorflow-env/env/lib/python3.11/site-packages/tf_keras/src/engine/training.py(3928)_validate_compile()
-> for metric in tf.nest.flatten(metrics):
(Pdb) p strategy
<tensorflow.python.distribute.distribute_lib._DefaultDistributionStrategy object at 0x7eda39f63750>
(Pdb) list
3923 )
3924
3925 # Model metrics must be created in the same distribution strategy scope
3926 # as the model.
3927 strategy = self.distribute_strategy
3928 -> for metric in tf.nest.flatten(metrics):
3929 for v in getattr(metric, "variables", []):
3930 if not strategy.extended.variable_created_in_scope(v):
3931 raise ValueError(
3932 f"Metric ({metric}) passed to `model.compile` was "
3933 "created inside a different distribution strategy "
(Pdb) n
> /home/humbulani/tensorflow-env/env/lib/python3.11/site-packages/tf_keras/src/engine/training.py(3929)_validate_compile()
-> for v in getattr(metric, "variables", []):
(Pdb) p metric
<BinaryAccuracy name=accuracy>
(Pdb) n
> /home/humbulani/tensorflow-env/env/lib/python3.11/site-packages/tf_keras/src/engine/training.py(3930)_validate_compile()
-> if not strategy.extended.variable_created_in_scope(v):
(Pdb) p v
<Variable path=accuracy/total, shape=(), dtype=float32, value=0.0>
(Pdb) p v._distribute_strategy
*** AttributeError: 'Variable' object has no attribute '_distribute_strategy'
(Pdb) p metric.variables
[<Variable path=accuracy/total, shape=(), dtype=float32, value=0.0>, <Variable path=accuracy/count, shape=(), dtype=float32, value=0.0>]
The text was updated successfully, but these errors were encountered:
The script has the following error:
I have traced the error to the following section of code from the function
tf_keras.src.engine.training._validate_compile
:and
pdb
has produced the following trace:The text was updated successfully, but these errors were encountered: