Skip to content

Ensures consistent serialization for Functional model #21341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 2, 2025

Conversation

JyotinderSingh
Copy link
Collaborator

@JyotinderSingh JyotinderSingh commented Jun 2, 2025

Related issues: #21328
Previous fix: #20993

Original Bug

  • Models created with nested list inputs (e.g., inputs=[[input_a]]) would have their structure flattened after a serialization round-trip.
  • A previous fix for this issue removed an un-nesting step during deserialization. While it fixed the nested-input case, it introduced a regression where a standard single-input model (inputs=input_a) would have its model.input type change from KerasTensor to list upon loading.

The root cause was that the serialization format was ambiguous. It represented both a single tensor and a list containing one tensor identically.

Fix

This change makes the serialization format unambiguous. The logic in get_config is updated to:

  1. Serialize a single KerasTensor input/output as a direct pointer.
  2. Serialize a list, tuple, or dict input/output as a corresponding structure containing pointers.
  3. The deserializer can now perfectly reconstruct the original I/O structure without naive un-nesting logic, as the format is no longer lossy.

@codecov-commenter
Copy link

codecov-commenter commented Jun 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.68%. Comparing base (3d2db56) to head (de15418).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21341      +/-   ##
==========================================
- Coverage   82.68%   82.68%   -0.01%     
==========================================
  Files         565      565              
  Lines       54825    54819       -6     
  Branches     8515     8512       -3     
==========================================
- Hits        45333    45327       -6     
  Misses       7406     7406              
  Partials     2086     2086              
Flag Coverage Δ
keras 82.49% <ø> (-0.01%) ⬇️
keras-jax 63.63% <ø> (-0.01%) ⬇️
keras-numpy 58.78% <ø> (+<0.01%) ⬆️
keras-openvino 33.13% <ø> (-0.01%) ⬇️
keras-tensorflow 64.02% <ø> (-0.01%) ⬇️
keras-torch 63.67% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Jun 2, 2025
@hertschuh
Copy link
Collaborator

Thanks for the fix!

@hertschuh hertschuh merged commit 4d33a9a into keras-team:master Jun 2, 2025
12 checks passed
@google-ml-butler google-ml-butler bot removed awaiting review ready to pull Ready to be merged into the codebase kokoro:force-run labels Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants