[JAX] Add per-channel quantization for kernels#2494
Open
wpietka wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the JAX quantization utilities and layer wrappers to support per-channel weight quantization scales (along a specified axis) and applies it to Dense/EinsumDense/Conv2D kernels, with corresponding test expectation updates.
Changes:
- Add
axissupport toget_scale()/get_q_params()for per-tensor vs per-channel scale computation. - Update static and dynamic quantized Dense/EinsumDense/Conv2D layers to compute/store per-channel
w_scale(and infer axis for EinsumDense via equation parsing). - Update JAX accuracy test utilities to compute expected Dense weight scales per output channel.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
test/jax/test_accuracy.py |
Updates a comment (quantization → inference) in the test flow. |
test/jax/jax_test_utility.py |
Adjusts expected Dense weight-scale computation to per-channel. |
neural_compressor/jax/utils/utility.py |
Adds axis parameter support for scale/params computation (per-channel scaling). |
neural_compressor/jax/quantization/layers_static.py |
Uses per-channel w_scale for static quantized kernels; adds quant-axis declarations/inference. |
neural_compressor/jax/quantization/layers_dynamic.py |
Uses per-channel w_scale for dynamic quantized kernels; adds quant-axis declarations/inference and tweaks load detection. |
Comments suppressed due to low confidence (1)
neural_compressor/jax/utils/utility.py:226
get_scale()adds a newaxisparameter but the docstringArgs:section doesn't document it, which makes the API harder to use correctly.
def get_scale(orig_weight, dtype=ml_dtypes.float8_e4m3, compute_dtype=jnp.float32, axis=None):
"""Compute the quantization scale for a weight tensor.
Args:
orig_weight (jnp.ndarray): Weight tensor to analyze.
dtype (jnp.dtype): Target quantized dtype.
compute_dtype (jnp.dtype): dtype for scale computation.
052a31d to
f486af4
Compare
anko-intel
reviewed
Jun 23, 2026
| .astype(compute_dtype) | ||
| ) | ||
| dtype_max = jnp.finfo(dtype).max.astype(orig_weight.dtype).astype(orig_weight.dtype) | ||
| if axis is None: |
Contributor
There was a problem hiding this comment.
consider making this if to calculate axis, and shape and have max/min call the same
20456d2 to
c559000
Compare
Signed-off-by: Wojciech Piętka <wojciechx.pietka@intel.com>
Signed-off-by: Wojciech Piętka <wojciechx.pietka@intel.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
Feature
Description
Expected Behavior & Potential Risk
Increased quantization accuracy
How has this PR been tested?
Ran smoke tests
Dependency Change?
No changes