Skip to content

[JAX] Make dot_product_attention usage configurable - #2549

Open
anko-intel wants to merge 3 commits into
mainfrom
dev/anko/disable_fused_att
Open

[JAX] Make dot_product_attention usage configurable#2549
anko-intel wants to merge 3 commits into
mainfrom
dev/anko/disable_fused_att

Conversation

@anko-intel

Copy link
Copy Markdown
Contributor

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

Signed-off-by: Andrzej Kotłowski <andrzej.kotlowski@intel.com>

Copilot AI left a comment

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.

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_enable to JaxBaseConfig and propagates it through static/dynamic quantization entrypoints.
  • Plumbs the flag into quantized layer prepare(...) APIs and gates fused attention execution in quantized MultiHeadAttention and CachedGemma3Attention.
  • 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.

Comment thread neural_compressor/jax/quantization/layers_static.py
Comment thread neural_compressor/jax/quantization/layers_dynamic.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Andrzej Kotłowski <andrzej.kotlowski@intel.com>
@anko-intel
anko-intel force-pushed the dev/anko/disable_fused_att branch from 508aff9 to cec9aa6 Compare August 7, 2026 11:15

self._all_devices_cpu = all(d.platform == "cpu" for d in jax.devices())

if self._all_devices_cpu:

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.

_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,

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.

Why it cannot be a positional parameter?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants