Skip to content

perf(qwen35/hip): the prompt's residual add and post-mixer norm in one launch - #2099

Merged
ashhart merged 2 commits into
ashhart:mainfrom
AbrahamCete:perf/hip-qwen-prompt-add-rms
Nov 4, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
AbrahamCete:perf/hip-qwen-prompt-add-rms

Conversation

@AbrahamCete

Copy link
Copy Markdown
Contributor

What this changes

For each layer and span of rows, Qwen 3.5's HIP prompt forward (forward.span) ran the mixer's residual add (tf_add), then the post-mixer RMS norm (tf_rms), as two launches. Nemotron's forward already takes both in one launch through reduce.residualNorm, with the same bytes as the two kernels. This PR calls reduce.residualNorm there.

  • residualRms still runs tf_add and tf_rms where tf_add_rms doesn't apply: under the reference policy, or for widths outside 1025 to 8192.
  • A tensor-parallel rank's fp32 share is still summed over the ranks first, as in reduce.residual.
  • Only the prompt path changes. Decode doesn't go through forward.span.
  • There is no new kernel symbol.

The add + rms byte test (kernel_tests/nemotron/fused.zig) now also covers Qwen 3.5's widths, 2048 (35B-A3B) and 5120 (27B). It runs 192 cases where it ran 128, and every one writes the bytes of tf_add and tf_rms.

Receipt

  • Environment: Ryzen AI Max+ 395 (gfx1151), Ubuntu 26.04, Zig 0.17.0, hipcc with HIP 7.1.52801 and Ubuntu clang 21.1.8 (rocprofv3 from ROCm 7.13). Checkpoints: Qwen3.8-27B-MLX-4bit and Qwen3.6-35B-A3B-MLX-4bit-MTP. Base: main 70ede48. Both sides were built from git archive trees.

  • Kernel time, rocprofv3 over a 2048-token tf-qwen35-test prefill run, per prefill:

    • 27B: the add and norm kernels take 114.4 ms against 152.2 ms. tf_add runs 64 times instead of 128 and tf_rms 65 instead of 129, plus 64 tf_add_rms launches.
    • 35B-A3B: 35.1 ms against 40.4 ms.
    • The kernel test times one launch at 3.98 us against 8.80 us for the two (1 row), and 4.01 against 8.26 us (4 rows).
  • tf-qwen35-test prefill, one prefill after a warm-up, alternated B C B C B C, seconds:

    model, tokens main this PR
    27B, 2048 5.280 / 5.307 / 5.283 5.275 / 5.310 / 5.275 (-0.1%)
    27B, 8192 22.162 / 22.123 / 22.184 21.992 / 22.016 / 22.147 (-0.5%)
    35B, 2048 1.005 / 1.008 / 1.007 1.004 / 1.003 / 1.001 (-0.4%)
    35B, 8192 4.646 / 4.649 / 4.659 4.636 / 4.616 / 4.634 (-0.5%)

    The 27B's 38 ms at 2048 tokens is 0.7% of the pass, which is about the spread between runs there.

  • Served, one fresh server a run, alternated B1 C1 B2 C2:

    • tools/bench_cache.py --require-cold --tokens 16, --context 34816 --parallel 1 --prompt-cache-gib 0, ttft_s:

      model, tokens main this PR
      27B, 2048 5.396 / 5.344 5.314 / 5.311 (-1.1%)
      27B, 8192 22.336 / 22.353 22.226 / 22.163 (-0.7%)
      27B, 32768 103.895 / 103.931 103.689 / 103.913 (-0.1%)
      35B, 2048 1.172 / 1.193 1.180 / 1.177 (-0.3%)
      35B, 8192 5.098 / 5.156 5.113 / 5.078 (-0.6%)
      35B, 32768 26.366 / 26.436 26.427 / 26.458 (+0.2%)

      Every cold request's token_sha is the same on both sides, with 0 cached tokens. At 32,768 tokens the difference is inside the spread between runs.

    • tools/bench_concurrent.py --levels 1,4 --tokens 256 --reps 3 --temperatures 0 --alone --serial, --parallel 4: token hashes are equal on every server (35B code 9f2923ac14d0, chat a8c28b8297b4; 27B code 2b28aa2108de, chat a06fab348fbe), 0 failed. Decode is unchanged: code at 4 streams 228.6 / 230.2 on main and 230.1 / 230.7 here on the 35B; 43.9 / 43.7 and 43.9 / 43.6 on the 27B.

  • Exactness:

    • Prompt logits (tf-qwen35-test logits, 2048 tokens) are byte-identical to main's on both checkpoints, bf16 and --f32 (27B dcc85692582d / 232dd4cf1fcd, 35B 18bee11563f1 / 84fbaeb871d7).
    • tf-qwen35-test check --only invariants: 27B 42 passed, 0 failed, 5 skipped; 35B-A3B 46 passed, 0 failed, 1 skipped, the same on both trees.
  • Tests run:

    • zig build test -Dhip=true --summary all: 546/546 steps, 7046/7103 tests passed, 57 skipped.
    • zig build hip-kernel-test --summary all: 129/130 passed, 1 skipped, 0 failed.
    • Kernel contract: SUMMARY gfx1151 82 kernels: 82 pass gates 1-4, 0 fail, 2 known findings; 7 controls: 7 red as planted, 0 missed; 145 limit problems, the same as main.
    • tools/zig/lean_check.py: 425 problems, the same as main. zig fmt --check is clean.
  • Not run, and why:

    • gfx1030, gfx1100, gfx1150 and gfx1201, because I have no card. The fused kernel is the same one Nemotron's HIP forward uses.
    • Tensor parallel, because I have one GPU. On that path residualNorm sums the ranks' fp32 shares as reduce.residual did, then takes the fp32 (wide) form of the add, which the byte test covers.

@ashhart

ashhart commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Thanks @AbrahamCete. Calling the fused add-and-norm that Nemotron already uses is a clean win: prompt logits byte-identical on both checkpoints, served tokens equal, and the byte test now covers Qwen's 2048 and 5120 widths. Ready to land.

@ashhart
ashhart force-pushed the perf/hip-qwen-prompt-add-rms branch from 79724b5 to 579d850 Compare November 4, 2026 17:06
ashhart added a commit to AbrahamCete/TensorFold that referenced this pull request Nov 4, 2026
AbrahamCete and others added 2 commits November 4, 2026 17:52
…e launch

The prompt forward ran tf_add and then tf_rms for the mixer's residual and the post-mixer norm. reduce.residualNorm takes both in tf_add_rms, as Nemotron's forward does, with the same bytes. The add + rms byte test now also covers Qwen 3.5's 2048 and 5120 widths.
@ashhart
ashhart force-pushed the perf/hip-qwen-prompt-add-rms branch from 579d850 to aa97f91 Compare November 4, 2026 17:52
@ashhart
ashhart merged commit 2bfc234 into ashhart:main Nov 4, 2026
@ashhart

ashhart commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Thank you @AbrahamCete. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

@ashhart

ashhart commented Nov 5, 2026

Copy link
Copy Markdown
Owner

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