Skip to content

Keras v3 Support #1116

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

Keras v3 Support #1116

wants to merge 18 commits into from

Conversation

calad0i
Copy link
Contributor

@calad0i calad0i commented Nov 8, 2024

A# Description

Add keras v3 specific object-based parser and some layer handlers (no h5 or json loading supported). The current keras parser doesn't work with v3 functional models in general.

Type of change

  • New feature (non-breaking change which adds functionality)

Tests

test/pytest/test_keras_v3_api.py

Test Configuration:

Requires keras>=3.0. Skips the whole module if this requirement is not sufficed.

Checklist

  • I have read the guidelines for contributing.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have installed and run pre-commit on the files I edited or added.
  • I have added tests that prove my fix is effective or that my feature works.

@jmitrevs jmitrevs added this to the v1.1.0 milestone Nov 8, 2024
@calad0i
Copy link
Contributor Author

calad0i commented Nov 8, 2024

This PR will be rebased after its prerequisites are merged to resolve the conflicts.

@calad0i calad0i added the please test Trigger testing by creating local PR branch label Mar 11, 2025
@vloncar vloncar self-requested a review March 11, 2025 21:40
@vloncar vloncar self-assigned this Mar 11, 2025
@bo3z bo3z modified the milestones: v1.1.0, v1.2.0 Apr 8, 2025
if keras.__version__ > '3.0':
layer_list, *_ = hls4ml.converters.parse_keras_v3_model(model)
else:
model_arch = json.loads(model.to_json())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if the case was used in practice, but the old logic allows model to be a dict, and only if it's not not a dict, only then model_arch = json.loads(model.to_json()). Does the logic here work if model is a dict?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dict is a representation of a json. we work with a dict that was a json of a model whether made by us or, in the old days, by the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model.get_config has slightly different behavior, where objects may be passed as-is (not serialized). v2 converter assumes a dict of fully serialized model config, so serialize+deserialize is used here.

@calad0i calad0i added please test Trigger testing by creating local PR branch and removed please test Trigger testing by creating local PR branch labels Apr 16, 2025
@calad0i calad0i added please test Trigger testing by creating local PR branch and removed please test Trigger testing by creating local PR branch labels Apr 18, 2025
@calad0i calad0i added please test Trigger testing by creating local PR branch and removed please test Trigger testing by creating local PR branch labels Apr 18, 2025
@calad0i calad0i added please test Trigger testing by creating local PR branch and removed please test Trigger testing by creating local PR branch labels Apr 18, 2025
@calad0i calad0i mentioned this pull request May 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
please test Trigger testing by creating local PR branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants