Skip to content

oneAPI RNN State and Activation Quantizers #1195

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

Merged
merged 6 commits into from
Feb 19, 2025

Conversation

laurilaatu
Copy link
Contributor

Description

Adding support for QKeras state_quantizer for RNNs

Type of change

Extract state_quantizer bitwidth and set the accum_t to correspond to it. Change hidden state to be of accum_t instead of res_T.

Extract quantized activations from RNNs, with the exception of hard activations.

  • Bug fix (non-breaking change that fixes an issue)

Tests

model = Sequential()

model.add(qkeras.QLSTM(15,
                            kernel_quantizer=qkeras.quantizers.quantized_bits(8,1,0,alpha=1),
                            recurrent_quantizer=qkeras.quantizers.quantized_bits(9,1,0,alpha=1),
                            state_quantizer=qkeras.quantizers.quantized_bits(10,1,0,alpha=1),
                            bias_quantizer=qkeras.quantizers.quantized_bits(11,1,0,alpha=1),
                            activation=qkeras.utils.quantized_tanh(use_real_tanh=True),
                            recurrent_activation=qkeras.utils.quantized_sigmoid(use_real_sigmoid=True),
                            input_shape=(10,4)
                           ))

model.add(qkeras.QDense(1, activation=qkeras.utils.quantized_tanh(use_real_tanh=True)))

model.compile(optimizer='adam', loss='mse')



config = hls4ml.utils.config_from_keras_model(model, granularity='name', backend='oneAPI')

hls_model = hls4ml.converters.convert_from_keras_model(
    model, hls_config=config, backend='oneAPI', output_dir='model_1/hls4ml_prj', part='Agilex7'
)

hls_model.compile()

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.

@laurilaatu laurilaatu changed the title Oneapi rnn fix oneAPI RNN State and Activation Quantizers Feb 13, 2025
Copy link
Contributor

@vloncar vloncar left a comment

Choose a reason for hiding this comment

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

Looks good overall, minor cosmetic changes would be nice before finalizing

@vloncar vloncar added the please test Trigger testing by creating local PR branch label Feb 14, 2025
@vloncar vloncar merged commit 723195e into fastmachinelearning:main Feb 19, 2025
5 checks passed
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