Skip to content

Commit d6275f4

Browse files
ckkuangtensorflower-gardener
authored andcommitted
Correctly set distributed variable's update_uid if initialized from a checkpoint using CheckpointInitialValueCallable.
PiperOrigin-RevId: 369679126 Change-Id: Ib5c449dfdf02a95f804ad6132359017d3b38d49e
1 parent d1cac84 commit d6275f4

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎tensorflow/python/distribute/distribute_lib.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@
192192
import collections
193193
import copy
194194
import enum # pylint: disable=g-bad-import-order
195+
import functools
195196
import threading
196197
import weakref
197198

@@ -2105,6 +2106,16 @@ def creator_with_resource_vars(next_creator, **kwargs):
21052106
trackable.CheckpointInitialValueCallable):
21062107
checkpoint_restore_uid = kwargs[
21072108
"initial_value"].checkpoint_position.restore_uid
2109+
elif (isinstance(kwargs["initial_value"], functools.partial) and
2110+
isinstance(kwargs["initial_value"].func,
2111+
trackable.CheckpointInitialValueCallable)):
2112+
# Some libraries (e.g, Keras) create partial function out of initializer
2113+
# to bind shape/dtype, for example:
2114+
# initial_val = functools.partial(initializer, shape, dtype=dtype)
2115+
# Therefore to get the restore_uid we need to examine the "func" of
2116+
# the partial function.
2117+
checkpoint_restore_uid = kwargs[
2118+
"initial_value"].func.checkpoint_position.restore_uid
21082119
else:
21092120
checkpoint_restore_uid = None
21102121

0 commit comments

Comments
 (0)