Add support for qkeras v3#1473
Conversation
|
Thank you for this! We should update pyproject.toml to add an optional dependency qkeras-v3 which installs qkeras-v3 and a recent version of tensorflow (one matching keras-v3) from pip (the same way qkeras is now installed). In my understanding this doesn't yet cover all the layers, which is fine, but we should probably add QConv1D/QConv2D layers, as these are used in the tutorials. Once the above two are added, the PyTests could also migrate to QKeras v3 (should be as easy as updating the pyproject.toml for the testing dependencies) |
|
I did all the requested changes. For the qconv part the fallback to keras-v2 did the job. I added only a new test case in the test_qkeras.py to test for qconv layers. I also had to convert the 3layer model to "*.keras": fastmachinelearning/example-models#24. Most tests will actually fail if only keras3 is used. Since the qkeras part is now mostly converted to keras-v3 I was wondering if there should not be also an update to keras3 for the rest of the project. Certainly not in this PR. |
bo3z
left a comment
There was a problem hiding this comment.
As stated in some of the comments, the biggest change is aiming to keep support for both QKeras v2 and QKeras v3 (the same way we support Keras v2 and v3). The rest of the comments are for consistency with the rest of the code base and better understanding
@calad0i since you worked on the Keras v3 parser, could you also provide some feedback on this PR when you get the chance?
| +-----------------------+-----+-----+--------------+--------+--------+-----+ | ||
| | QKeras | ✅ | ✅ | ✅ | ✅ | N/A | N/A | | ||
| +-----------------------+-----+-----+--------------+--------+--------+-----+ | ||
| | QKeras-v3 | ✅ | ✅ | ✅ | ✅ | ✅ | N/A | |
There was a problem hiding this comment.
Isn't garnet a specific example implemented in some version of qkeras v2?
There was a problem hiding this comment.
It should also work in qkeras v3.
| ret['input_shape'] = [list(t.shape[1:]) for t in in_tensors] | ||
| ret['output_keras_tensor_names'] = [t.name for t in out_tensors] | ||
|
|
||
| activation = config.get('activation') |
There was a problem hiding this comment.
activation handling here is treated as a special case. The base class shall cover this already though...
There was a problem hiding this comment.
I have now this layer.py which is more or less a base class. I can call it also _base.py if you want.
…roject.toml to have qkerasv2 and qkerasv3
|
There seems to be one unrelated failure in HGQ. @calad0i any ideas? |
|
Looks like usual fluctuation in bit exactness tests, can run again and see what happens... |
Now all tests passed. |
These are the Handlers needed for qkerasV3 (https://pypi.org/project/qkeras-v3/). Updated tutorials: https://github.com/bo3z/hls4ml-tutorial/tree/tutorial-revamp-2026 were tested with the new qkerasV3.