Skip to content

make rmsnorm quant fusion support gemma - #2858

Closed
ganyi1996ppo wants to merge 1 commit into
mainfrom
ganyi/gemma_rmsnorm_quant_hip
Closed

ganyi1996ppo wants to merge 1 commit into
mainfrom
ganyi/gemma_rmsnorm_quant_hip

Conversation

@ganyi1996ppo

Copy link
Copy Markdown
Contributor

Motivation

Technical Details

Test Plan

Test Result

Submission Checklist

@ganyi1996ppo
ganyi1996ppo requested review from a team and Copilot April 22, 2026 10:03
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:triton-355 Run Triton tests on MI355 in addition to MI325
ci:sglang SGLang integration tests
ci:atom ATOM benchmark (DeepSeek-R1 + GPT-OSS)
ci:vllm vLLM benchmark
ci:all All of the above

Add labels via the sidebar or gh pr edit 2858 --add-label <label>

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

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_norm flag through Python wrappers for fused RMSNorm FP8 quant ops.
  • Updates Triton kernels to conditionally apply Gemma-style RMSNorm when GEMMA_NORM is enabled.
  • Adds a new unit test validating gemma_norm=True for fused_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_norm parameter is part of the public Python API but is not described in this function’s docstring (unlike fused_rms_fp8_group_quant). Please document what gemma_norm does 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_norm is added to this function signature but the docstring doesn’t mention it. Please add a short description (same as in fused_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.

Comment on lines 24 to 37
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,
):

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines 513 to 529
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,
):

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines 13 to +22
@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

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment on lines +195 to +199
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

Copilot AI Apr 22, 2026

Copy link

Choose a reason for hiding this comment

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

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).

Suggested change
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)

Copilot uses AI. Check for mistakes.
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.

2 participants