Skip to content

Conversation

@Shlok-Saxena
Copy link
Contributor

This Pull request

Adds a defensive runtime guard to the TMVA SOFIE Keras parser to prevent segmentation faults when used with Keras 3 (enabled by default in TensorFlow ≥ 2.16).

The current parser is implemented against the Keras 2 API. When Keras 3 objects are encountered, undefined behavior may occur, leading to runtime crashes. This PR does not add Keras 3 support; it only detects the unsupported configuration early and fails cleanly with a clear error message.

This provides a temporary safety measure while proper Keras 3 support is being developed.

Changes or fixes:

  • Add an explicit runtime check for the Keras major version
  • Disable the old SOFIE Keras parser when Keras ≥ 3 is detected
  • Replace segmentation faults with a clear, user-facing error message
  • Do not change behavior for Keras 2 users

Checklist:

  • tested changes locally

This PR fixes #20591

@Shlok-Saxena Shlok-Saxena changed the title [tmva][sofie] Guard old Keras parser against Keras 3 [tmva][sofie] Apply clang-format to RModelParser_Keras.cxx Jan 2, 2026
@Shlok-Saxena Shlok-Saxena changed the title [tmva][sofie] Apply clang-format to RModelParser_Keras.cxx [tmva][sofie] Guard old Keras parser against Keras-3 Jan 2, 2026
Copy link
Contributor

@guitargeek guitargeek left a comment

Choose a reason for hiding this comment

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

Thank you very much for the PR! This is a good temporary solution. Just a few comments:

  • please remove the commit with the code formatting. It's not worth to format code that we plan to delete in #19692 anyway, so that's just bloating the history. You can ignore the clang-format CI errors this time.
  • I think you don't need to explicitly import keras again
  • Please drop the first commit, which comes from an unrelated development for which you have already opened a separate PR.

@Shlok-Saxena Shlok-Saxena force-pushed the sofie-keras3-guard branch 2 times, most recently from 44c1176 to 60975ed Compare January 5, 2026 14:30
@github-actions
Copy link

github-actions bot commented Jan 5, 2026

Test Results

    18 files      18 suites   3d 3h 41m 48s ⏱️
 3 792 tests  3 788 ✅ 0 💤 4 ❌
65 369 runs  65 365 ✅ 0 💤 4 ❌

For more details on these failures, see this check.

Results for commit 60975ed.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@guitargeek guitargeek left a comment

Choose a reason for hiding this comment

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

Thank you very much!

@guitargeek guitargeek merged commit 29b8e84 into root-project:master Jan 6, 2026
67 of 88 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[tmva][sofie] SOFIE Keras parser doesn't support Keras 3

2 participants