Skip to content

migrate da strategy provider to alkaid - #1518

Open
calad0i wants to merge 12 commits into
fastmachinelearning:mainfrom
calad0i:da_custom_layer_3
Open

migrate da strategy provider to alkaid#1518
calad0i wants to merge 12 commits into
fastmachinelearning:mainfrom
calad0i:da_custom_layer_3

Conversation

@calad0i

@calad0i calad0i commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Description

Replacing da strategy provider da4ml to alkaid. No user facing breaking changes except for installing alkaid instead of da4ml.

  • LUT packaging for CMVM ops with 1-bit inputs
    • Ternary adder fusion reducing up to 33% for add/sub heavy graphs in RTL doesn't translate to vitis HLS for some reason. Disabled for now.
  • General support of unknown layers fallback to symbolic traced implementation
    • All layers in HGQ2
    • Vivado/Vitis only for now, extensible to oneapai

Type of change

  • New feature (non-breaking change which adds functionality)
  • Breaking change (da strategy now needs alkaid instead of da4ml)

Tests

Added da fallback implementation of LUT layer and QGRU layer.

Test Configuration:

Checklist

  • all

@calad0i calad0i mentioned this pull request Aug 5, 2026
2 tasks
@calad0i
calad0i force-pushed the da_custom_layer_3 branch 2 times, most recently from 9ec0cb9 to 012cad5 Compare August 5, 2026 03:39
@calad0i calad0i added the please test Trigger testing by creating local PR branch label Aug 5, 2026
@calad0i
calad0i force-pushed the da_custom_layer_3 branch from 2939379 to d2449a3 Compare August 5, 2026 03:44
@JanFSchulte JanFSchulte added please test Trigger testing by creating local PR branch and removed please test Trigger testing by creating local PR branch labels Aug 5, 2026
@calad0i calad0i added please test Trigger testing by creating local PR branch and removed please test Trigger testing by creating local PR branch labels Aug 7, 2026
@calad0i calad0i added please test Trigger testing by creating local PR branch and removed please test Trigger testing by creating local PR branch labels Aug 15, 2026
@JanFSchulte

Copy link
Copy Markdown
Contributor

The QGRU still fails because there's no linear activation in hls4ml/templates/vivado/nnet_utils/nnet_recr_activations.h. Adding it fixes the compiliation, but I see issues with the model.predict() call like this tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: Exception encountered when calling QGRUCell.call(). coming from HGQ2 itself. Not sure if I'm running the tests in an incorrect environment offline or if there is really something wrong with QGRU in HGQ2, can you please verify @calad0i ?

@calad0i

calad0i commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Weird. Locally I didn't see the same issue. Could be keras version interacting? Checking

@calad0i
calad0i force-pushed the da_custom_layer_3 branch from 36e4e65 to a67e50b Compare August 28, 2026 15:17
@calad0i calad0i added please test Trigger testing by creating local PR branch and removed please test Trigger testing by creating local PR branch labels Aug 28, 2026
options = {'hard_dc': hard_dc, 'search_all_decompose_dc': True}
inp = FixedVariableArray.from_kif(k, i, f, HWConfig(1, -1, -1), solver_options=options)
options: solver_options_t = {'hard_dc': hard_dc, 'search_all_decompose_dc': True}
inp = FVArray.from_kif(k, i, f, solver_options=options)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here you are dropping the HWConfig argument. I see that the default in alkaid is HWConfig(1, 1, -1), so different from what was passed here before. Just checking if that is an intended change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is intended; the parameter is used for alkaid internal surrogate, and the config changed


fn_cpp = f'{namespace}::{fn_name}<{inp_t}, {out_t}>({inp_name}, {out_name});'
# When there's multiple inputs, make a wrapper doing the concatenation and rename the original fn.
if len(inp_names) > 1:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it would be good to add a test for the multi-input case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@calad0i can you comment why this case is not really reachable at the moment for the record? I'm fine with merging without the test, but would like to have it documented.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It can be reachable by any new layer implementation, like any transformer blocks. But those are already registered in hls4ml,and you need to patch to disable the current path to enable fallback. Or, some new layer is to be proposed and implemented.

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.

2 participants