Skip to content

Support gemma_norm flag for rmsnorm path - #3981

Merged
valarLip merged 7 commits into
ROCm:mainfrom
Phi-C:gemma_norm_support
Jul 1, 2026
Merged

valarLip merged 7 commits into
ROCm:mainfrom
Phi-C:gemma_norm_support

Conversation

@Phi-C

@Phi-C Phi-C commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Motivation

add gemma_norm flag support for rmsnorm path

Technical Details

Test Plan

Test Result

Submission Checklist

@Phi-C
Phi-C requested a review from a team June 29, 2026 03:37
@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 on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 3981 --add-label <label>

@zufayu
zufayu requested review from junhaha666 and zufayu June 29, 2026 08:40
@@ -4340,55 +4341,102 @@ void dispatchFusedAllReduceRMSNormQuant(hipStream_t stream,
#define DISPATCH_AR_FUSION_KERNEL(NGPUS) \

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.

The DISPATCH_AR_FUSION_KERNEL macro grew from ~59 to ~106 lines (+80%) to support the gemma_norm template branch. Each of the three launcher paths (1-stage, 2-stage, split) now duplicates its full 13-argument call site inside an if (gemma_norm) / else block.

The non-quant dispatchFusedAllReduceRMSNorm in this same file already handles the same dispatch with a cleaner double-pointer pattern — launch_fused_allreduce_rmsnorm(kernel, gemma_kernel) — where the if/else lives once in an 18-line macro and each call site is a single line. Adopting the same pattern here would keep the macro body flat and make adding future boolean template parameters much cheaper (currently a second bool would double the macro again to ~200 lines across 9 instantiation sites).

emit_bf16: bool = False,
gemma_norm: bool = False,
):
if quant_type == "per_token" and group_size == 128 and not emit_bf16:

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.

This fast-path condition compares quant_type against the raw string "per_token" before any normalization. communicator_cuda._normalize_fused_ar_rms_quant_type maps several aliases ("fp8", "fp8_per_token", "per-token", QuantType.per_Token, etc.) to "per_token", but that normalization only happens deeper in the stack. Callers using those aliases will silently miss this torch-compile-guarded fast path and fall through to the slower device_communicator route.

Suggest calling _normalize_fused_ar_rms_quant_type at the top of this method before the fast-path branch (it's already imported via the communicator layer; alternatively expose it from a shared utils module).

eps: float,
group_name: str,
prefill_support: bool = False,
gemma_norm: bool = 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.

No test covers the new gemma_norm=True path. The repo already has op_tests/multigpu_tests/test_custom_allreduce_fp8.py exercising the fused AR+RMSNorm+quant pipeline, so there is a ready template to extend.

Per the ROCm contributing guidelines: "New functionality is only merged with new unit tests." A minimal test could call tensor_model_parallel_fused_allreduce_rmsnorm_quant with gemma_norm=True and compare the output against a reference x / rms(x) * (1 + weight) computation, covering at least the per-token FP8 path across all three dispatch variants (1-stage, 2-stage, split).

@zufayu zufayu 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.

LGTM. All three review points addressed: macro refactored to eliminate duplication, quant_type normalization moved before fast-path check, and gemma_norm=True dispatch paths covered by new tests.

@valarLip
valarLip merged commit 6dc68e5 into ROCm:main Jul 1, 2026
89 of 92 checks passed
zhuyuhua-v pushed a commit that referenced this pull request Jul 3, 2026
…orm_quant (#4066)

* fix(dist): remove in-function import from traced fused_allreduce_rmsnorm_quant

The in-function import of _normalize_fused_ar_rms_quant_type inside
GroupCoordinator.fused_allreduce_rmsnorm_quant (added in #3981) causes a
TorchDynamo graph break for every input when the method is traced under
@support_torch_compile (surfaces as 'VllmBackend can only be called once'
on the ATOM-native DeepSeek path).

quant_type already arrives canonicalized to a string from the public API
(_canonical_fused_ar_rms_quant_type) and from the mxfp4 helper, so the
inline normalization is redundant; the device path re-normalizes anyway.
Removing it eliminates the graph break (0 breaks, server startup completes).

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* fix(dist): remove inline import from traced CudaCommunicator.fused_allreduce_rmsnorm_quant

Same latent graph break as the parallel_state.py fix: the in-function import
of _normalize_fused_ar_rms_quant_type inside
CudaCommunicator.fused_allreduce_rmsnorm_quant graph-breaks TorchDynamo when
the method is traced (reachable via the mxfp4 / emit_bf16 / non-128 per-token
paths from GroupCoordinator).

quant_type already arrives canonicalized to a string from the public API, and
both in-tree callers pass a canonical string (parallel_state.py:641 forwards
it; _fused_allreduce_rmsnorm_quant_out_place uses the per_token default), so
the normalization here is redundant.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

* update comment

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
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.

4 participants