Use content hash instead of UUID for model identifier #16532
+21
−7
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.
Summary:
Previously, the CoreML backend generated model identifiers using
uuid.uuid4(), which created a random identifier every time. This meant that even if the exact same model was exported twice, it would get different identifiers, causing cache misses on the device.This change replaces the UUID with a SHA256 hash of the saved mlpackage contents (including weights). Now identical models produce identical identifiers, enabling proper cache hits.
The hash is computed by:
This change also makes it easier to bisect when code changes have altered a generated PTE file - if the identifier changes, you know the model content changed.
Note: The identifier format changes from UUID format (with hyphens, e.g.,
executorch_a1b2c3d4-e5f6-7890-abcd-ef1234567890) to a hash format (no hyphens, e.g.,executorch_a1b2c3d4e5f67890abcdef12). This has no BC impact since the runtime treats the identifier as an opaque string.Differential Revision: D90424166