[JAX] Make dot_product_attention usage configurable - #2549
Conversation
Signed-off-by: Andrzej Kotłowski <andrzej.kotlowski@intel.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a configuration knob to control whether quantized JAX attention layers may route through Keras’ fused dot_product_attention path, and wires it through quantization, serialization/deserialization, and the relevant attention layer implementations. The default behavior is now to disable dot_product_attention unless explicitly enabled in the config.
Changes:
- Adds
dot_product_attention_enabletoJaxBaseConfigand propagates it through static/dynamic quantization entrypoints. - Plumbs the flag into quantized layer
prepare(...)APIs and gates fused attention execution in quantizedMultiHeadAttentionandCachedGemma3Attention. - Ensures deserialized quantized models re-apply the flag when preparing layers after load.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
neural_compressor/jax/quantization/saving.py |
Passes dot_product_attention_enable into layer prepare(...) during deserialization. |
neural_compressor/jax/quantization/layers_static.py |
Adds flag to prepare(...) signatures; gates fused attention in static quantized attention layers. |
neural_compressor/jax/quantization/layers_dynamic.py |
Adds flag to prepare(...) signatures; gates fused attention in dynamic quantized attention layers. |
neural_compressor/jax/quantization/config.py |
Introduces dot_product_attention_enable config parameter and serializable state. |
neural_compressor/jax/algorithms/static.py |
Propagates config flag into static layer preparation. |
neural_compressor/jax/algorithms/dynamic.py |
Propagates config flag into dynamic layer preparation. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Andrzej Kotłowski <andrzej.kotlowski@intel.com>
508aff9 to
cec9aa6
Compare
for more information, see https://pre-commit.ci
|
|
||
| self._all_devices_cpu = all(d.platform == "cpu" for d in jax.devices()) | ||
|
|
||
| if self._all_devices_cpu: |
There was a problem hiding this comment.
_all_devices_cpu is a little awkward name. I woudn't know what it means without reading definition. Maybe _only_cpu_devices_are_available would be better
| const_weight, | ||
| w_quant_granularity, | ||
| *, | ||
| dot_product_attention_enable=False, |
There was a problem hiding this comment.
Why it cannot be a positional parameter?
Type of Change
feature
Description
Allows you to control whether to use dot_product_attention from the configuration.
Using dot_product_attention is disabled by default