Repository navigation
make rmsnorm quant fusion support gemma - #2858
ganyi1996ppo wants to merge 1 commit into
Conversation
Signed-off-by: ganyi <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
There was a problem hiding this comment.
Pull request overview
Adds support for Gemma-style RMSNorm (multiplying by (1 + weight) instead of weight) to the existing fused RMSNorm + FP8 quantization Triton ops, and introduces a test covering the group-quant path.
Changes:
- Plumbs a new
gemma_normflag through Python wrappers for fused RMSNorm FP8 quant ops. - Updates Triton kernels to conditionally apply Gemma-style RMSNorm when
GEMMA_NORMis enabled. - Adds a new unit test validating
gemma_norm=Trueforfused_rms_fp8_group_quant.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| op_tests/triton_tests/quant/test_fused_fp8_quant.py | Adds a Torch reference + new test for Gemma-style RMSNorm in the group-quant fused op. |
| aiter/ops/triton/quant/fused_fp8_quant.py | Exposes gemma_norm in fused RMSNorm FP8 quant Python APIs and forwards it into kernel meta-parameters. |
| aiter/ops/triton/_triton_kernels/quant/fused_fp8_quant.py | Implements Gemma-style RMSNorm in the Triton RMSNorm helper and threads GEMMA_NORM through kernels. |
Comments suppressed due to low confidence (2)
aiter/ops/triton/quant/fused_fp8_quant.py:45
- The new
gemma_normparameter is part of the public Python API but is not described in this function’s docstring (unlikefused_rms_fp8_group_quant). Please document whatgemma_normdoes and how it changes the RMSNorm formula so callers know which weight semantics to use.
def fused_rms_fp8_per_tensor_static_quant(
inp1,
inp1_weight,
inp1_epsilon,
inp1_scale,
inp2=None,
inp2_weight=None,
inp2_epsilon=None,
dtype_quant=fp8_dtype,
res1=None,
output_unquantized_inp1=False,
rmsnorm_convert_to_inp1_type=False,
gemma_norm=False,
):
"""
This op contains several steps:
1. if res1 is not None, inp1 = inp1 + res1, and store inp1 to out_res1
2. perform RMS norm along the last dimenion for inp1
3. if inp2 is not None, perform RMS norm along the last dimenion for inp2
4. perform fp8 quantization for inp1 only
Key parameters:
aiter/ops/triton/quant/fused_fp8_quant.py:541
gemma_normis added to this function signature but the docstring doesn’t mention it. Please add a short description (same as infused_rms_fp8_group_quant) so users understand the Gemma-style RMSNorm behavior and weight interpretation.
def fused_reduce_rms_fp8_group_quant(
inp1,
inp1_weight,
inp1_epsilon,
inp2=None,
inp2_weight=None,
inp2_epsilon=None,
inp3=None,
group_size=128,
dtype_quant=fp8_dtype,
dtype=None,
res1=None,
output_unquantized_inp1=False,
out3=None,
transpose_scale=False,
gemma_norm=False,
):
"""
This op contains several steps:
1. if res1 is not None, inp1 = inp1 + res1, and store inp1 to out_res1
2. perform RMS norm along the last dimenion for inp1
3. if inp2 is not None, perform RMS norm along the last dimenion for inp2
4. perform fp8 quantization for inp1 only
5. if inp3 is not None, perform sum reduction along the first dimension, in the meantime, the inp1 and inp2 has to have the identical first diemsion as inp3
Key parameters:
- x: Matrix X with shape (M, N1, N2).
Returns:
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def fused_rms_fp8_per_tensor_static_quant( | ||
| inp1, | ||
| inp1_weight, | ||
| inp1_epsilon, | ||
| inp1_scale, | ||
| inp2=None, | ||
| inp2_weight=None, | ||
| inp2_epsilon=None, | ||
| dtype_quant=fp8_dtype, | ||
| res1=None, | ||
| output_unquantized_inp1=False, | ||
| rmsnorm_convert_to_inp1_type=False, | ||
| gemma_norm=False, | ||
| ): |
There was a problem hiding this comment.
gemma_norm is now supported by fused_rms_fp8_per_tensor_static_quant, but there’s no test exercising the gemma_norm=True path for this API. Adding a reference test similar to test_fused_rms_fp8_group_quant_gemma_norm would prevent regressions in the per-tensor static quant kernel specialization.
| def fused_reduce_rms_fp8_group_quant( | ||
| inp1, | ||
| inp1_weight, | ||
| inp1_epsilon, | ||
| inp2=None, | ||
| inp2_weight=None, | ||
| inp2_epsilon=None, | ||
| inp3=None, | ||
| group_size=128, | ||
| dtype_quant=fp8_dtype, | ||
| dtype=None, | ||
| res1=None, | ||
| output_unquantized_inp1=False, | ||
| out3=None, | ||
| transpose_scale=False, | ||
| gemma_norm=False, | ||
| ): |
There was a problem hiding this comment.
gemma_norm is threaded into fused_reduce_rms_fp8_group_quant, but there’s no test validating gemma_norm=True for the reduce kernel. Please add coverage (e.g., compare against a Torch reference Gemma RMSNorm + quant + reduce) to ensure the GEMMA_NORM specialization stays correct.
| @triton.jit | ||
| def _rmsmorm_op(row, weight, n_cols, epsilon): | ||
| def _rmsmorm_op(row, weight, n_cols, epsilon, GEMMA_NORM: tl.constexpr = False): | ||
| row_norm = row * row | ||
| row_norm = tl.sum(row_norm, axis=-1) | ||
| norm_factor = tl.math.rsqrt((row_norm / n_cols) + epsilon) | ||
|
|
||
| rms_norm = row * norm_factor * weight | ||
| if GEMMA_NORM: | ||
| rms_norm = row * norm_factor * (1.0 + weight) | ||
| else: | ||
| rms_norm = row * norm_factor * weight |
There was a problem hiding this comment.
The helper name _rmsmorm_op looks like a typo of _rmsnorm_op. Since this line is being touched anyway, consider renaming it (and its call sites in this file) to improve readability/searchability.
| row_norm = input * input | ||
| row_norm = torch.sum(row_norm, dim=-1) | ||
| norm_factor = torch.rsqrt((row_norm / input.shape[1]) + eps) | ||
| rms_norm = input * norm_factor[:, None] * (1.0 + weight[None, :]) | ||
| return rms_norm |
There was a problem hiding this comment.
gemma_rmsnorm duplicates the existing rmsnorm helper with only the (1.0 + weight) difference. To reduce duplication and keep the reference implementations in sync, consider parameterizing rmsnorm with a gemma_norm flag (or reusing one helper from the other).
| row_norm = input * input | |
| row_norm = torch.sum(row_norm, dim=-1) | |
| norm_factor = torch.rsqrt((row_norm / input.shape[1]) + eps) | |
| rms_norm = input * norm_factor[:, None] * (1.0 + weight[None, :]) | |
| return rms_norm | |
| return rmsnorm(input, 1.0 + weight, eps) |
Motivation
Technical Details
Test Plan
Test Result
Submission Checklist