这是indexloc提供的服务,不要输入任何密码
Skip to content

Correctly apply global scale in nvfp4 quantization. #30467

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jreiffers
Copy link
Contributor

Currently, the global scale is not applied consistently to the input tensor, leading to all values being rounded to zeroes in most cases when using the global scale logic from the test.

The existing tests did not catch this because they use matrix multiplications on dequantized tensors as the reference. This ended up just comparing 0@0 to 0@0.

Instead of adjusting the matmul tests, I opted to add test coverage for quantization logic directly, since that doesn't require carefully chosen tolerances in most cases.

Currently, the global scale is not applied consistently to the input
tensor, leading to all values being rounded to zeroes in most cases
when using the global scale logic from the test.

The existing tests did not catch this because they use matrix
multiplications on dequantized tensors as the reference. This ended
up just comparing 0@0 to 0@0.

Instead of adjusting the matmul tests, I opted to add test coverage
for quantization logic directly, since that doesn't require carefully
chosen tolerances in most cases.
SCALE_MAX = dtypes.finfo(config.scale_type).max.astype(x.dtype)

scales_q = jnp.clip(scales / config.global_scale, 0, SCALE_MAX)
x /= config.global_scale
scales_q = jnp.clip(get_scales_per_block(x), 0, SCALE_MAX)
scales_q = lax.optimization_barrier(scales_q.astype(config.scale_type))
scaled_x = x / scales_q.astype(np.float32)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(This x is where we previously didn't apply the global scale)

@jreiffers jreiffers requested a review from IvyZX July 25, 2025 06:05
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.

1 participant