Skip to content

Commit 5359b3c

Browse files
Avoid attempting variable equality checks implied by python in.
PiperOrigin-RevId: 590992962
1 parent 39ac369 commit 5359b3c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

tf_keras/optimizers/optimizer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,13 @@ def _trackable_children(self, save_type="checkpoint", **kwargs):
580580
for var in val:
581581
if hasattr(var, "_sharded_container"):
582582
sv = var._sharded_container()
583-
if sv not in sv_vals:
583+
# Use unique id to check existence. `in` would
584+
# attempt element-wise variable value
585+
# comparison.
586+
if not any(
587+
sv._unique_id == other_sv._unique_id
588+
for other_sv in sv_vals
589+
):
584590
sv_vals.append(sv)
585591
else:
586592
sv_vals.append(var)

0 commit comments

Comments
 (0)