Skip to content

Fix mega_mhc split barriers under CUDA graph replay - #478

Merged
zheanxu merged 1 commit into
deepseek-ai:mainfrom
lightseek-bot:bot/mega-mhc-split-barrier-epoch
Oct 20, 2026
Merged

zheanxu merged 1 commit into
deepseek-ai:mainfrom
lightseek-bot:bot/mega-mhc-split-barrier-epoch

Conversation

@lightseek-bot

@lightseek-bot lightseek-bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

A CUDA graph kernel node keeps the same %gridid on every replay. The mega_mhc split barriers tag executions with %gridid, so after a replay a barrier line still holds encode_state(grid_idx, kNumSplits) — exactly what the next replay waits for. A Mix or Norm waiter whose m-block init CTA has not started yet proceeds at once and reads the previous replay's split partials (the graph-pool scratch is the same memory). wait_init only protects producers.

This tags each execution with an epoch instead of %gridid. The epoch and an exit count live in the unused tail of the first barrier line, so the host-side barrier buffer and the compiled extension are unchanged (JIT headers only). Every CTA reads the epoch after cudaGridDependencySynchronize(); the last CTA to retire resets the exit count and advances the epoch.

The MegaMoE combine readiness has the same stale-tag problem and is addressed separately in #451.

Validation on B200: one graph node is replayed while alternating two input sets, and every replay is compared bit for bit with eager results (fresh JIT cache per run). Measured on 66081d4, whose versions of these headers differ from main only by an added #include.

case before after
33 tokens, SMs contended by another stream 185/200 wrong 0/400
512 tokens, contended 27/200 0/400
8192 tokens, contended 3/200 0/400
512 tokens, idle GPU 1/200 0/400

Eager calls, and graph replays preceded by an eager launch that rewrites the tag, were 0/200 before the fix as well.

A CUDA graph kernel node keeps the same %gridid on every replay. The
mega_mhc split barriers tag each execution with %gridid, so after a replay
a barrier line still holds encode_state(grid_idx, kNumSplits), which is
exactly the state the next replay waits for. A Mix or Norm waiter whose
m-block init CTA has not started yet proceeds immediately and reads the
previous replay's split partials.

Tag executions with an epoch instead. The epoch and an exit count live in
the unused tail of the first barrier line, so the host-side buffer is
unchanged. Every CTA reads the epoch after cudaGridDependencySynchronize,
and the last CTA to retire resets the exit count and advances the epoch.

Signed-off-by: lightseek-bot <[email protected]>
@lightseek-bot

Copy link
Copy Markdown
Contributor Author

@LyricZhao PTAL Thanks!

@zheanxu
zheanxu merged commit 5081f85 into deepseek-ai:main Oct 20, 2026
zyongye added a commit to vllm-project/DeepGEMM that referenced this pull request Oct 29, 2026
…#48)

A CUDA graph kernel node keeps the same %gridid on every replay. The
mega_mhc split barriers tag each execution with %gridid, so after a replay
a barrier line still holds encode_state(grid_idx, kNumSplits), which is
exactly the state the next replay waits for. A Mix or Norm waiter whose
m-block init CTA has not started yet proceeds immediately and reads the
previous replay's split partials.

Tag executions with an epoch instead. The epoch and an exit count live in
the unused tail of the first barrier line, so the host-side buffer is
unchanged. Every CTA reads the epoch after cudaGridDependencySynchronize,
and the last CTA to retire resets the exit count and advances the epoch.


(cherry picked from commit 5081f85)

Co-authored-by: LightSeek Foundation <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
zcnrex added a commit to sgl-project/DeepGEMM that referenced this pull request Nov 2, 2026
…#131)

A CUDA graph kernel node keeps the same %gridid on every replay. The
mega_mhc split barriers tag each execution with %gridid, so after a replay
a barrier line still holds encode_state(grid_idx, kNumSplits), which is
exactly the state the next replay waits for. A Mix or Norm waiter whose
m-block init CTA has not started yet proceeds immediately and reads the
previous replay's split partials.

Tag executions with an epoch instead. The epoch and an exit count live in
the unused tail of the first barrier line, so the host-side buffer is
unchanged. Every CTA reads the epoch after cudaGridDependencySynchronize,
and the last CTA to retire resets the exit count and advances the epoch.

Signed-off-by: lightseek-bot <[email protected]>
Co-authored-by: LightSeek Foundation <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
zcnrex added a commit to sgl-project/DeepGEMM that referenced this pull request Nov 4, 2026
* Fix mega_mhc split barriers under CUDA graph replay (deepseek-ai#478)

A CUDA graph kernel node keeps the same %gridid on every replay. The
mega_mhc split barriers tag each execution with %gridid, so after a replay
a barrier line still holds encode_state(grid_idx, kNumSplits), which is
exactly the state the next replay waits for. A Mix or Norm waiter whose
m-block init CTA has not started yet proceeds immediately and reads the
previous replay's split partials.

Tag executions with an epoch instead. The epoch and an exit count live in
the unused tail of the first barrier line, so the host-side buffer is
unchanged. Every CTA reads the epoch after cudaGridDependencySynchronize,
and the last CTA to retire resets the exit count and advances the epoch.

Signed-off-by: lightseek-bot <[email protected]>

* Update instructions for deepgemm fork development

* Fix SM100 kernels to use the allocated tensor memory base

* Keep the pull request limited to the tensor memory base fix

* Make the HC-prenorm regression test require a nonzero TMEM base

* Skip the nonzero TMEM base HC-prenorm test on CC 10.7

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

---------

Signed-off-by: lightseek-bot <[email protected]>
Co-authored-by: LightSeek Foundation <[email protected]>
Co-authored-by: Baizhou Zhang <[email protected]>
Co-authored-by: Chunan Zeng <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
kevmo314 added a commit to kevmo314/DeepGEMM that referenced this pull request Nov 11, 2026
SM90 grouped 1D2D heuristics, thread-local alignment, MoE precompile, and deepseek-ai#455/deepseek-ai#478
RayWang96 pushed a commit that referenced this pull request Nov 19, 2026
* Public Release 26/09 (#432)

* Public release 26/09

* Update News

* Fix Mega MoE task info slot release ordering (#441)

* Public release 26/09/30 (#462)

Add locality-aware Mega MoE execution, GEMM epilogue classes with BF16
stochastic rounding, wider sparse MQA head support, and packed SF strides.
Improve Indexer and Mega MoE pipelines, update attention and Mega Gate
interfaces, and include runtime and correctness fixes.

Export the current source through the OSS filter while retaining public
release history and the Mega MoE task-info release-ordering fix.

Co-authored-by: Anyi Xu <[email protected]>
Co-authored-by: huahuaquq <[email protected]>
Co-authored-by: TwenTy_ <[email protected]>
Co-authored-by: xyf007 <[email protected]>
Co-authored-by: Yongqi Zhuo <[email protected]>
Co-authored-by: yukuai26 <[email protected]>
Co-authored-by: Zhean Xu <[email protected]>

* Update FP8 epilogues and paged sparse MQA alignment (#471)

Add FP8CastWithClamp with optional clamped-element counts, consolidate
GEMM epilogue conversions, and accept 128-byte paged sparse KV strides.
Keep the Mega MoE localizer alive until test teardown and bump the
package version to 2.8.2.

Co-authored-by: xyf007 <[email protected]>
Co-authored-by: yukuai26 <[email protected]>
Co-authored-by: Zhean Xu <[email protected]>

* Fix mega_mhc split barriers under CUDA graph replay (#478)

A CUDA graph kernel node keeps the same %gridid on every replay. The
mega_mhc split barriers tag each execution with %gridid, so after a replay
a barrier line still holds encode_state(grid_idx, kNumSplits), which is
exactly the state the next replay waits for. A Mix or Norm waiter whose
m-block init CTA has not started yet proceeds immediately and reads the
previous replay's split partials.

Tag executions with an epoch instead. The epoch and an exit count live in
the unused tail of the first barrier line, so the host-side buffer is
unchanged. Every CTA reads the epoch after cudaGridDependencySynchronize,
and the last CTA to retire resets the exit count and advances the epoch.

Signed-off-by: lightseek-bot <[email protected]>

* Restore FP32 weights/logits in SM100 MQA logits (port of vllm-project#46)

Upstream 26/09/30 made the SM100 dense and paged MQA logits kernels take
BF16 weights and write BF16 logits only. nv_dev callers pass FP32 weights
and read FP32 logits, so port vllm-project#46: the SM100 kernel
is templated on the weights and logits types again, and the host accepts
FP32 or BF16 weights on SM100 (MX inputs).

`logits_dtype` now defaults to the weights' precision: BF16 weights reduce
in BF16 and require (and default to) BF16 logits; FP32 and FP16 weights
default to FP32 logits. This is the same default on every architecture.

Non-MX FP8 inputs on SM100 still take the FP16-weight path only.

Tests: test_nv_attention_restoration.py checks the SM100 unified dense
kernel with MXFP8 inputs and FP32/BF16 weights, eager against scheduled,
bitwise.

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

* Pin the sparse MQA metadata layout in the SM120 kernel

The SM120 sparse MQA kernel reads `layout/sparse_mqa_logits.cuh`, which is
shared with SM100 and follows upstream. Assert the parts of it the kernel
reads (struct sizes and field offsets, slot packing, KV split flag mask), so
a future upstream format change fails to compile instead of producing wrong
logits. The device file matches DeepGEMM-sm120 v0.2.0.

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

* Drop stale clean_logits notes from the README

The MQA logits APIs no longer take `clean_logits`. Also note that the SM100
FP16-weight path is the only non-MX FP8 MQA logits path on SM100.

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

---------

Signed-off-by: lightseek-bot <[email protected]>
Co-authored-by: Zhean Xu <[email protected]>
Co-authored-by: Chenggang Zhao <[email protected]>
Co-authored-by: Anyi Xu <[email protected]>
Co-authored-by: huahuaquq <[email protected]>
Co-authored-by: TwenTy_ <[email protected]>
Co-authored-by: xyf007 <[email protected]>
Co-authored-by: Yongqi Zhuo <[email protected]>
Co-authored-by: yukuai26 <[email protected]>
Co-authored-by: LightSeek Foundation <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
lucifer1004 added a commit to lucifer1004/DeepGEMM that referenced this pull request Nov 19, 2026
…deepseek-ai#441, deepseek-ai#462, deepseek-ai#471) as merged into nv_dev

deepseek-ai#509 synced these upstream commits into nv_dev but was squash-merged, which kept
their changes and dropped their ancestry. Without it the next upstream sync
would see them as unmerged and re-apply them from an older merge base. This
merge uses the 'ours' strategy: the tree is unchanged.
RayWang96 added a commit that referenced this pull request Nov 19, 2026
RayWang96 pushed a commit that referenced this pull request Nov 19, 2026
…r CUDA graph replay) into nv_dev

Brings deepseek-ai PRs #462 (057ca59, Public release 26/09/30), #471
(1fc9c66) and #478 (5081f85) onto nv_dev (b4c138c). Merge base is 78b6900.

API follows upstream:
  * MQA logits: `clean_logits` is removed, `max_seqlen_k` is required, and
    the SM100 paged metadata is varlen-only. nv_dev keeps one extension: a
    `logits_dtype` keyword (FP32 or BF16, after `max_seqlen_k` /
    `max_context_len`). It defaults to BF16 on SM100 and FP32 on SM90/SM120.
  * The legacy `fp8_mqa_logits` / `fp8_paged_mqa_logits` wrappers and
    `fp8_gemm_nt_skip_head_mid` are removed, as upstream removed them.
  * GEMM/einsum epilogues take upstream's `EpilogueClass` objects.

Conflict resolution highlights:
  * Epilogues: the SM120 BF16 and FP8/FP4 GEMM kernels move from
    `epilogue/transform.cuh` to the `epilogue/operators.cuh` operator API
    (`EpilogueOperatorArgs`, `Identity`); `HeadSplits` and `apply_index_n`
    are gone. The device files match DeepGEMM-sm120 v0.2.0. SM120 GEMMs
    reject custom epilogue classes; the SM120 BF16 einsum takes `C` and
    accepts only a plain BF16 store on its native path, checked before `D`
    is written.
  * MQA logits: adopt upstream's dense/paged/sparse host code while keeping
    nv_dev's SM120 dense, paged and sparse paths, the SM90 block_kv=32 and
    next_n=4 multicast, and the SM100 FP16-weight path.
  * Sparse MQA logits: follow upstream's `kNumMaxHeads` layout and the
    `kPartialTailFlag` bit in the KV split header. nv_dev keeps its metadata,
    device, alignment and weight-stride checks, the 16-byte paged KV stride
    (#459) and workspace reuse under graph capture (#459).
  * Mega MoE, mega_mhc, locality domain, layout and runtime: upstream.
  * README: upstream. docs/scaling-factor-format.md describes the new API.
  * Tests: SM120 tests move to the new API (no `clean_logits`, 0x3fffffff
    KV count mask, required `max_seqlen_k`) and add coverage for the plain
    FP8 GEMM store branches and the SM120 einsum `C` input.
    test_nv_attention_restoration.py no longer imports removed helpers.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RayWang96 added a commit that referenced this pull request Nov 19, 2026
Merge of pull/509/head (72e97d7) without squashing, so that the upstream
merges 78b6900 and 5081f85 stay recorded in nv_dev's history.
Replaces the squash commit c9b569a and its revert c54abc4 (#511).

Co-Authored-By: Claude Fable 5.2 <[email protected]>
original-el8 added a commit to local-inference-lab/DeepGEMM that referenced this pull request Nov 22, 2026
zyongye added a commit to vllm-project/DeepGEMM that referenced this pull request Nov 28, 2026
* Public release 26/09/30 (deepseek-ai#462)

Add locality-aware Mega MoE execution, GEMM epilogue classes with BF16
stochastic rounding, wider sparse MQA head support, and packed SF strides.
Improve Indexer and Mega MoE pipelines, update attention and Mega Gate
interfaces, and include runtime and correctness fixes.

Export the current source through the OSS filter while retaining public
release history and the Mega MoE task-info release-ordering fix.

Co-authored-by: Anyi Xu <[email protected]>
Co-authored-by: huahuaquq <[email protected]>
Co-authored-by: TwenTy_ <[email protected]>
Co-authored-by: xyf007 <[email protected]>
Co-authored-by: Yongqi Zhuo <[email protected]>
Co-authored-by: yukuai26 <[email protected]>
Co-authored-by: Zhean Xu <[email protected]>

* Update FP8 epilogues and paged sparse MQA alignment (deepseek-ai#471)

Add FP8CastWithClamp with optional clamped-element counts, consolidate
GEMM epilogue conversions, and accept 128-byte paged sparse KV strides.
Keep the Mega MoE localizer alive until test teardown and bump the
package version to 2.8.2.

Co-authored-by: xyf007 <[email protected]>
Co-authored-by: yukuai26 <[email protected]>
Co-authored-by: Zhean Xu <[email protected]>

* Fix mega_mhc split barriers under CUDA graph replay (deepseek-ai#478)

A CUDA graph kernel node keeps the same %gridid on every replay. The
mega_mhc split barriers tag each execution with %gridid, so after a replay
a barrier line still holds encode_state(grid_idx, kNumSplits), which is
exactly the state the next replay waits for. A Mix or Norm waiter whose
m-block init CTA has not started yet proceeds immediately and reads the
previous replay's split partials.

Tag executions with an epoch instead. The epoch and an exit count live in
the unused tail of the first barrier line, so the host-side buffer is
unchanged. Every CTA reads the epoch after cudaGridDependencySynchronize,
and the last CTA to retire resets the exit count and advances the epoch.

Signed-off-by: lightseek-bot <[email protected]>

* Public release 26/11/26 (deepseek-ai#525)

* Public release 26/11/26

* Add 2026.11.26 News entry for deepseek-ai#525

---------

Signed-off-by: lightseek-bot <[email protected]>
Co-authored-by: Chenggang Zhao <[email protected]>
Co-authored-by: Anyi Xu <[email protected]>
Co-authored-by: huahuaquq <[email protected]>
Co-authored-by: TwenTy_ <[email protected]>
Co-authored-by: xyf007 <[email protected]>
Co-authored-by: Yongqi Zhuo <[email protected]>
Co-authored-by: yukuai26 <[email protected]>
Co-authored-by: Zhean Xu <[email protected]>
Co-authored-by: LightSeek Foundation <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
aryatsc added a commit to aryatsc/DeepGEMM that referenced this pull request Nov 28, 2026
Brings in sgl-project#177 (deepseek-ai public release 26/11/26, deepseek-ai#525) and deepseek-ai#478.

No textual conflicts: this branch's changes follow the renames
(csrc/apis/mega_moe.hpp -> mega_moe_inference.hpp,
impls/sm100_fp8_fp4_mega_moe.{hpp,cuh} -> ..._inference.{hpp,cuh},
scheduler/mega_moe.cuh -> scheduler/mega_moe/inference.cuh).
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