[2.8 backport] Resolve bug with re-saving Estimator-exported SavedModel #53676
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change description
Sort signature inputs by input key instead of tensor name when loading a TF1 model in TF2.
Signatures are saved using nest.flatten, which sorts the keys alphabetically for determinism. This can cause a mismatch between the lifted signature function's arg_keywords and structured_input_signature, resulting in users not being able to re-save the signature.
Detailed example below.
Say there is a SavedModel signature with the inputs:
When this signature is loaded using the TF2 API, it becomes a concrete function with arg keywords =
['b', 'a']
(sorted by tensor name)The
structured_input_signature
becomes([], {'b': spec_for_b, 'a': spec_for_a})
When this function is exported as a signature in a new SavedModel, the structured inputs are flattened and zipped with the arg keywords. However, the flattened
structured_input_signature
is[spec_for_a, spec_for_b]
, sincenest.flatten
sorts the keys for determinism. This results in the wrong spec being mapped to the wrong arguments.PiperOrigin-RevId: 417889747
Change-Id: Icdce72a43033027c18f5530068f2d6fd47e8e32d