Skip to content

Conversation

@calad0i
Copy link
Contributor

@calad0i calad0i commented Jan 30, 2026

Description

Allows the use of any subclass of keras.layers.Layer object that is supported in da4ml to be used in the hls4ml project, such as LUT-based layers (such as hgq.layers.DenseT/ConvT12D or keras.layers.Conv3D). Due to parser limitation, keras.operation.Operation still cannot be supported (yet), so arbitrary tensor slicing or indexing operations will not work for now.

Now, the keras v3 parser will try da parser fallback before trying v2 parser. If it falls by not finding the corresponding layer or da4ml is not present, it will proceed with the current behavior.

Type of change

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

Tests

Still no keras v3 test infra there.

Checklist

  • All.

@bo3z bo3z added this to the v1.3.0 milestone Jan 30, 2026
@bo3z bo3z added enhancement please test Trigger testing by creating local PR branch labels Jan 30, 2026
@calad0i calad0i added feature New hls4ml feature and removed enhancement labels Jan 30, 2026
@JanFSchulte
Copy link
Contributor

Looks very nice, but I do have a question about the user interface. The switches for the fallback are added to the keras_v3_to_hls function. However, the user usually just interacts with the convert_from_keras_model function, which doesn't receive these controls. So I don't see how the user would actually control this feature, which would a problem because right now there are several fail states, for example if io_stream is selected where IIUC the converter can fail in the DA fallback with the obvious for the user to turn it off.

@calad0i
Copy link
Contributor Author

calad0i commented Feb 4, 2026

**kwargs are passed through from convert_from_keras_model

@JanFSchulte
Copy link
Contributor

Yes, the point is more that they are not explained in the doc for that function. So the user has no pointers on how to configure this, except by reading the code. I guess the specific request would be to add this to the function doc string for convert_from_keras_model.

@JanFSchulte JanFSchulte merged commit 1099d65 into fastmachinelearning:main Feb 5, 2026
4 checks passed
Abubakar-rashid added a commit to Abubakar-rashid/hls4ml that referenced this pull request Feb 6, 2026
Added allow_da_fallback and allow_v2_fallback args from PR fastmachinelearning#1429
JanFSchulte pushed a commit that referenced this pull request Feb 9, 2026
* Fix Keras v3 model conversion in numerical profiling

* Address review feedback: remove unnecessary else clause and add test to LONGLIST

- Removed else clause in convert_from_config() as it's no longer needed
- Added test_keras_v3_profiling to LONGLIST in generate_ci_yaml.py for proper CI environment

* Fix line length issue in generate_ci_yaml.py

Break KERAS3_LIST into multiple lines to comply with max line length of 125 characters

* Einsum and EinsumDense for oneAPI

* Add tests

* Add tests

* Remove hgq2 from testing-keras3 dependencies and test_hgq2_mha from KERAS3_LIST

As requested by reviewers:
- Removed hgq2>=0.0.1 from testing-keras3 optional dependencies
- Removed test_hgq2_mha from KERAS3_LIST

* [pre-commit.ci] pre-commit autoupdate (#1425)

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.14.13 → v0.14.14](astral-sh/ruff-pre-commit@v0.14.13...v0.14.14)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Add LHC trigger use case context to README (#1418)

* Add LHC trigger use case context to README

* Clarify hls4ml application domains in README

---------

Co-authored-by: Siddardha Desu <siddardhadesu@Siddardhas-MacBook-Air.local>

* [pre-commit.ci] pre-commit autoupdate (#1430)

updates:
- [github.com/tox-dev/pyproject-fmt: v2.11.1 → v2.12.1](tox-dev/pyproject-fmt@v2.11.1...v2.12.1)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Fix Keras v3 profiling tests: build models and correct bar count expectations

- Call model.build() or pass sample data to initialize Keras v3 models
- Fix bar count assertions to match actual behavior (1 bar per layer, not per weight)
- Ensures models have defined inputs before profiling

* Fix qkeras import to avoid namespace conflict with hgq2

- Change 'import qkeras' to 'from qkeras import QActivation' in profiling.py
- This protects against hgq2's qkeras compatibility layer causing conflicts
- Add back hgq2>=0.0.1 to testing-keras3 dependencies
- Add back test_hgq2_mha to KERAS3_LIST

As requested by reviewers to resolve qkeras/hgq2 namespace issues.

* Fix activation and batch norm tests

- Call model with data instead of just build() for activation test
- Fix batch norm expected bar count to 3

* Add new arguments to convert_from_keras_model call

Added allow_da_fallback and allow_v2_fallback args from PR #1429

* Fix Keras v3 profiling tests - 4/5 passing

One test (hls_model comparison) is skipped because get_unoptimized_hlsmodel()
tries to recreate the model from saved config, which fails for Keras v3 due to
config format changes. This is a library issue in keras_v2_to_hls parser that
needs a separate fix.

---------

Co-authored-by: Jovan Mitrevski <jmitrevs@fnal.gov>
Co-authored-by: laurilaatu <l.laatu@imperial.ac.uk>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: siddardhadesu <153359094+siddardhadesu@users.noreply.github.com>
Co-authored-by: Siddardha Desu <siddardhadesu@Siddardhas-MacBook-Air.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New hls4ml feature please test Trigger testing by creating local PR branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants