Skip to content

perf(b12x/norm): fuse 4-stream hyperconnection PackedCombineNorm - #173

Open
avifenesh wants to merge 1 commit into
local-inference-lab:mainfrom
avifenesh:perf/b12x-hc-fused4-combine-norm
Open

avifenesh wants to merge 1 commit into
local-inference-lab:mainfrom
avifenesh:perf/b12x-hc-fused4-combine-norm

Conversation

@avifenesh

Copy link
Copy Markdown

Summary

Add _Fused4StreamPackedCombineNorm in b12x.norm.hyperconnection._cute and select it in _compile_hyperconnection for role == "combine_norm" when streams == 4, hidden_size % 8 == 0, and query.max_tokens >= 64.

Previously, _PackedCombineNorm launched grid=(tokens, streams, 1), so each token's block_output[token] row was read 4 separate times from global memory by 4 distinct blocks. In _Fused4StreamPackedCombineNorm:

  • One CTA per token loads block_output[token] once into registers and reuses it across all 4 residual streams.
  • Arithmetic matches _PackedCombineNorm bit for bit (scale = 2.0 * sigmoid(logit / streams), BF16 rounding before RMS sum-of-squares, identical FP32/BF16 weight handling and zero_centered mode, with a block barrier after each stream's _block_sum before reusing shared reduction memory).
  • Small-token decode plans (max_tokens < 64) continue using _PackedCombineNorm so low-M batches retain 4x block-level SM occupancy.
  • Bumps the norm.hyperconnection.cute compile spec version from 11 to 12.

Benchmark (NVIDIA GB10 / DGX Spark, SM 12.1, streams=4, H=2560)

End-to-end Nsight Systems profile of a 32,768-token Qwen3.8 Flash-Next prefill on GB10:

  • PackedCombineNorm total GPU time:
    • 1,182.1 ms -> 942.0 ms (-240.2 ms, -20.3%) at 8,192-token prefill chunks.
    • 1,182.1 ms -> 966.0 ms (-216.2 ms, -18.3%) at 16,384-token prefill chunks.

Testing

  • Added test_fused4_combine_norm_bit_exact_with_packed in tests/experimental/b12x/norm/test_prepared_hyperconnection.py verifying rtol=0, atol=0 parity against _PackedCombineNorm across tokens in (128, 1024), (bf16/zero_centered=True, bf16/zero_centered=False, fp32/zero_centered=False), non-contiguous logit strides (stride=336), and num_warps in (8, 10, 16).
  • Existing test_combine_norm_preserves_affine_precision_and_replays also covers tokens=4096 (fused path) and tokens in (1, 7) (packed path) with CUDA graph capture/replay and in-place aliasing (out=(state, normalized)).
  • Ran on GB10 (SM 12.1):
    pytest --confcutdir=tests/experimental/b12x tests/experimental/b12x/norm/test_prepared_hyperconnection.py -> 124 passed.

Add _Fused4StreamPackedCombineNorm so a single CTA per token loads block_output[token] once into registers and reuses it across all 4 residual streams when streams == 4, hidden_size % 8 == 0, and max_tokens >= 64.

Keep _PackedCombineNorm for small-token decode plans (max_tokens < 64) where 4x more blocks improve SM occupancy on low-M batches. Bump norm.hyperconnection.cute compile spec version from 11 to 12.

Bit-exact (rtol=0, atol=0) with _PackedCombineNorm across BF16/FP32 weights, zero_centered True/False, non-contiguous logit strides, and num_warps in (8, 10, 16).
@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 19 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ceb0b2e3-acb4-428f-b8e9-eb05038a3857
Commits

Reviewing files that changed from the base of the PR and between 335459b and 36d7493.

Files selected for processing: 3

  • flashinfer/experimental/b12x/norm/hyperconnection/_cute.py
  • flashinfer/experimental/b12x/norm/hyperconnection/_preparation.py
  • tests/experimental/b12x/norm/test_prepared_hyperconnection.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@avifenesh

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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