Repository navigation
[WS1][CUDA][MiniMax-H3] generation gate: 50-block generation compare and resume check (RFC #420 stack 10c/10) #588
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fusheng-ji
wants to merge
69
commits into
RL-Align:test-h3
Choose a base branch
from
fusheng-ji:feat/h3-generation-gate
base: test-h3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+13,433
−89
Open
Changes from all commits
Commits
Show all changes
69 commits
Select commit
Hold shift + click to select a range
193f079
[WS1][CUDA][MiniMax-H3] ws1_one_h3_block: block 0 node-by-node replay…
fusheng-ji 5ecb92d
[WS1][CUDA][MiniMax-H3] full-model qualification: thresholds, ensembl…
fusheng-ji 6fe346d
[WS1][CUDA][MiniMax-H3] generation gate: 50-block generation compare …
fusheng-ji 08983f5
Merge local/h3merge/h3-sp-norm-adaln into feat/h3-one-block-replay
fusheng-ji 272aacc
Merge local/h3merge/h3-one-block-replay into feat/h3-full-model-quali…
fusheng-ji 68471df
Merge local/h3merge/h3-full-model-qualification into feat/h3-generati…
fusheng-ji d3c8df2
Merge #494 into feat/h3-one-block-replay (sync with test-h3 after #48…
fusheng-ji 74cc553
ci: run the pipeline for pull requests and pushes to test-h3 (lost in…
fusheng-ji d5fe5ec
Merge 10a (#586) sync into feat/h3-full-model-qualification; keep the…
fusheng-ji 2dcbb15
Merge 10b (#587) sync into feat/h3-generation-gate
fusheng-ji 07a77a0
style: end the sigma-schedule benchmark JSON with a newline and forma…
fusheng-ji 830996f
Merge PR #586 lint fix into PR #587
fusheng-ji ad2ac1c
Merge PR #587 lint fix into PR #588
fusheng-ji add6aad
Merge #494 review fixes into #586
fusheng-ji 743e67a
Merge #586 review fixes into #587
fusheng-ji 69fb31e
Merge #587 review fixes into #588
fusheng-ji 0d8f6e4
Merge branch 'test-h3' into feat/h3-one-block-replay
maxiaosong1124 fccbb06
Merge branch 'test-h3' into feat/h3-generation-gate
maxiaosong1124 dd9bf28
Merge branch 'test-h3' into feat/h3-full-model-qualification
maxiaosong1124 7aa29b8
fix(h3): address the review findings on the block-0 replay
fusheng-ji 82089a1
Merge PR #586 review fixes into PR #587
fusheng-ji 242517f
Merge PR #587 review fixes into PR #588
fusheng-ji 3fa9d6d
Merge local h3sync/587 (#494 and #493 review fixes, WS2 layout move, …
fusheng-ji 30d465d
Merge local h3sync/588 (#494 and #493 review fixes, WS2 layout move, …
fusheng-ji a19cec2
Merge PR #587 branch into PR #588
fusheng-ji 94b1f57
Merge local h3sync/586 (#494 and #493 review fixes, WS2 layout move, …
fusheng-ji 7347afb
Merge PR #586 branch into PR #587
fusheng-ji 5892a7e
Merge PR #587 branch into PR #588
fusheng-ji fed5eb6
Merge PR #494 (rstd and SP-plot fixes, TP alignment doc) into PR #586
fusheng-ji 2820bb9
style(h3): format test_h3_native_validation.py with the pinned black …
fusheng-ji d2cbffd
Merge PR #586 branch (with #494) into PR #587
fusheng-ji 8a6c955
Merge PR #587 branch into PR #588
fusheng-ji 0364aef
fix(h3): address the second round of automated review findings
fusheng-ji 860fd3a
perf(h3): pad the row gather only above the measured crossover
fusheng-ji 1129249
Merge PR #586 branch (second review round) into PR #587
fusheng-ji 61924a4
Merge PR #587 branch into PR #588
fusheng-ji 95d69d3
docs(h3): state that the golden backward skips the AdaLN input cast, …
fusheng-ji 8b0be25
Merge branch 'local/h3-586-review' into local/h3-587-sync
fusheng-ji 5ae933c
Merge branch 'local/h3-586-review' into local/h3-588-sync
fusheng-ji 4699a01
Merge branch 'test-h3' into feat/h3-one-block-replay
maxiaosong1124 d00322f
Merge branch 'local/h3sync/586' into local/h3sync/587
fusheng-ji 6aaac3e
Merge branch 'local/h3sync/587' into local/h3sync/588
fusheng-ji dd20e94
Merge branch 'local/h3-586-review' into local/h3-587-sync
fusheng-ji eb3bdc9
fix(h3): copy overlapping SP tables, make the block diagnostic runnab…
fusheng-ji 4a996a1
fix(h3): keep provider and candidate comparisons apart in the ensembl…
fusheng-ji 78f0287
Merge branch 'local/h3-587-sync' into local/h3-588-sync
fusheng-ji 802b7dd
fix(h3): refuse to continue saved steps whose run.json is missing
fusheng-ji 6ff40e5
style(h3): sort the ensemble rule module with the pinned isort
fusheng-ji 2270c5e
Merge branch 'local/h3-587-sync' into local/h3-588-sync
fusheng-ji 429d1a2
fix(h3): build the block context on the weights' device, state the ga…
fusheng-ji da7f1f4
Merge branch 'local/h3-586-review' into local/h3-587-sync
fusheng-ji b82db14
Merge branch 'local/h3-587-sync' into local/h3-588-sync
fusheng-ji 4bbe82c
fix(h3): draw zero errors in the block plot, finish placing the block…
fusheng-ji b3a0ae0
Merge branch 'local/h3-586-review' into local/h3-587-sync
fusheng-ji 0dea148
fix(h3): require time_proj in the full-model trace, forward only
fusheng-ji b2cdb87
Merge branch 'local/h3-587-sync' into local/h3-588-sync
fusheng-ji 148d76f
refactor(h3): leave the generation commands to the generation PR
fusheng-ji 0c8c928
feat(h3): reject zeroed gradients in the ensemble acceptance check
fusheng-ji a31cdcb
Merge branch 'local/h3-587-sync' into local/h3-588-sync
fusheng-ji 75d1b65
feat(h3): add the generation commands to the reference and candidate …
fusheng-ji 0f21456
refactor(h3): move QueryChunkAttention and the provider variant conte…
fusheng-ji 1e2a51e
fix(h3): check the saved run identity before --resume skips a finishe…
fusheng-ji 2a7ff18
fix(h3): address the third round of review on the full-model qualific…
fusheng-ji 9cf34ea
Merge branch 'local/h3-587-sync' into local/h3-588-sync
fusheng-ji 302f0b0
fix(h3): bind the compared reference to the verified inventory, tight…
fusheng-ji cbe383c
Merge branch 'local/h3-587-sync' into local/h3-588-sync
fusheng-ji 64bd640
ci(h3): run the resumable-generation tests in the CPU job
fusheng-ji bb709d0
fix(h3): put the BLAS library back when the cuBLASLt provider variant…
fusheng-ji 6736573
test(h3): skip the real-library BLAS test where torch lacks cuBLASLt
fusheng-ji File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| # MiniMax-H3 One Block, Forward and Backward | ||
|
|
||
| ## Summary | ||
|
|
||
| `ws1_one_h3_block` (RFC #420, WS1 closeout) runs **block 0 of the pinned MiniMax-H3 checkpoint** | ||
| node by node, forward and backward, and reports where it first departs from diffusers. The block | ||
| is a fixed graph of 17 nodes, from the AdaLN projection to the second gated residual. It runs on | ||
| packed FL2VA layouts that are **bitwise equal to the pinned diffusers pipeline's** `position_ids` | ||
| and modality tags. | ||
|
|
||
| On one B200, at S = 264, 925 and 3160: | ||
|
|
||
| - **Determinism.** Every node, every gradient reaching a node, and all 14 leaf gradients are | ||
| bitwise repeatable. | ||
| - **Batch invariance.** Batch row 0 of a two-row batch has the single-row bytes at every node, | ||
| forward and backward. | ||
| - **Agreement with diffusers.** Every node that promises it is bitwise equal to diffusers on | ||
| diffusers' inputs. The first drift from diffusers is `adaln_projection`, the first reduction | ||
| whose tree differs from cuBLAS. | ||
| - **Accuracy.** The block output is exactly as close to the FP32 golden as diffusers' (relative | ||
| error 5.2e-3 / 7.9e-3 / 9.0e-3). | ||
|
|
||
| Five of the 17 nodes are bound to this stack's three row operators (AdaLN projection, modulated | ||
| RMSNorm for `norm1` / `norm2`, gate residual for the two residual nodes). The other twelve use **interim** | ||
| deterministic operators until their own rows land, or the provider replay where no kernel exists | ||
| yet (see Bindings). The block-level promises above hold with whatever a node is bound to. Speed | ||
| and the exact rounding of interim nodes belong to those operators, not to this row. | ||
|
|
||
| ## Entry Point | ||
|
|
||
| ```python | ||
| from rl_engine.validation.models.h3_block import CandidateOps, run_block_backward, run_block_case | ||
| from rl_engine.validation.models.h3_weights import load_h3_block_weights | ||
|
|
||
| weights = load_h3_block_weights("cuda") # conditioning + block-0 tensors, sha256-checked | ||
| ops = CandidateOps() | ||
| forward = run_block_case(weights, layout="small", ops=ops) # per node, first_*_drift | ||
| backward = run_block_backward(weights, layout="small", ops=ops) | ||
| ``` | ||
|
|
||
| The CLI writes the JSON evidence and the plot script renders it: | ||
|
|
||
| ```bash | ||
| python tools/weights/prepare_h3_weights.py --out <dir> --block # shard 1 of 14, ~4.8 GB | ||
| export RL_KERNEL_H3_WEIGHTS=<dir> | ||
| python tools/validation/models/h3_block_replay.py --layouts tiny,small,medium --out report.json | ||
| python tools/validation/models/plot_h3_block.py report.json | ||
| ``` | ||
|
|
||
| ## Graph and Bindings | ||
|
|
||
| `rl_engine/validation/models/h3_block.py` `NODES` (graph order): | ||
|
|
||
| | Node | Owning RFC row | Binding today | | ||
| |---|---|---| | ||
| | `adaln_projection` | `adaln_projection_3mod` | **row**: `H3AdaLNProjectionCudaOp` (registry) | | ||
| | `norm1`, `norm2` | `h3_rmsnorm` | **row**: `H3RMSNormCudaOp.forward_modulated` (registry) | | ||
| | `q_proj`, `k_proj`, `v_proj` | `h3_qkv_gemm` | interim: Triton FP32-accumulate GEMM, one BF16 rounding | | ||
| | `q_norm`, `k_norm` | `h3_qk_rmsnorm_d128` | interim: `H3RMSNormCudaOp.forward` on the 128-wide heads | | ||
| | `rope_q`, `rope_k` | `h3_mm_rope_3axis_partial` | reference: the provider replay (no kernel exists yet) | | ||
| | `attention` | `h3_full_attention` | interim: `DeterministicAttentionOp(causal=False)` | | ||
| | `o_proj` | `h3_attention_o_gemm` | interim: Triton FP32-accumulate GEMM | | ||
| | `residual_attn`, `residual_mlp` | `adaln_gate_residual` | **row**: `H3GateResidualCudaOp` (registry) | | ||
| | `ffn_gate_up` | `h3_ffn_gate_up_gemm` | interim: Triton FP32-accumulate GEMM | | ||
| | `swiglu` | `h3_swiglu` | interim: `SwiGLUCudaOp` (FP32 math, one rounding) | | ||
| | `ffn_down` | `h3_ffn_down_gemm` | interim: Triton FP32-accumulate GEMM | | ||
|
|
||
| When a row lands, replacing its node's `candidate` callable is the whole integration. The node's | ||
| report entries then become that operator's block-level evidence. | ||
|
|
||
| The interim GEMMs use `_triton_gemm_fp32`, one fixed-order FP32 K loop with no split-K, and round | ||
| to BF16 once. They do not use `TritonDetGemmOp.__call__`, whose K tree has BF16 nodes. Measured on | ||
| B200: | ||
|
|
||
| | Shape | Tree path err | FP32 K loop → BF16 | cuBLAS | Tree | FP32 K loop | | ||
| |---|---|---|---|---|---| | ||
| | 264 × 5376 → 7168 | 7.0e-3 | 2.4e-3 | 2.4e-3 | 10.4 ms | 1.2 ms | | ||
| | 925 × 14336 → 5376 | 7.5e-3 | 2.6e-3 | 2.6e-3 | 47 ms | 2.7 ms | | ||
|
|
||
| Both paths are bitwise repeatable and row-invariant. Error is max|err| / max|ref| against FP64. | ||
|
|
||
| ## What Each Node Reports | ||
|
|
||
| Every node runs three ways: the provider replay (`h3_provider`, diffusers@f53d552 op for op), the | ||
| candidate (chained, and *isolated* on the provider's inputs), and the FP32 golden | ||
| (`rl_engine/reference/minimax_h3/block.py`: FP32 math, TF32 off, no BF16 storage between nodes). | ||
|
|
||
| - **Forward:** `repeat_bitwise_equal` and `batch_row_bitwise_equal` (row 0 of a B = 2 batch whose | ||
| row 1 has a different input). Also chained and isolated agreement with the provider (bitwise, | ||
| max abs, first differing packed row), the candidate's and provider's `max|err| / max|golden|`, | ||
| and the sha256 of the node's output. | ||
| - **Backward:** for the block input, `temb` and the 12 block parameters: repeat bitwise, and the | ||
| candidate's and provider's error against the golden. For the gradient reaching each node's | ||
| output, in reverse graph order: repeat bitwise and batch-row bitwise. Parameter gradients sum | ||
| over the batch, so only activation gradients take part in the batch check. | ||
| - **First drift:** `first_drift`, `first_isolated_drift`, `first_repeat_drift`, | ||
| `first_batch_drift`, `first_grad_repeat_drift` and `first_grad_batch_drift` each name the first | ||
| node where that comparison stops being bitwise. | ||
| - **Permutation probe (control H-C3, reported, not promised):** permute the packed rows together | ||
| with positions and AdaLN indices, and compare the output to the permuted original. | ||
|
|
||
| Inputs: `temb` comes from the provider's conditioning path (the conditioning rows are checked by | ||
| `h3_chain`). The block input is a seeded BF16 stand-in, because the packed input projections are | ||
| other rows. Text rows use AdaLN table row 0 and media rows use row 1. | ||
|
|
||
| ## Evidence | ||
|
|
||
| [`report.json`](https://github.com/fusheng-ji/RL-Kernel/blob/6d6193d94a83266d5f5f62bb9d90fb3215716ee3/pr539/reports/experiments/h3-one-block-b200/report.json) was generated from a clean tree | ||
| at `41e4293` on an otherwise idle B200 (torch 2.13.0+cu130): | ||
|
|
||
|  | ||
|
|
||
| | Layout | S | First drift / first isolated drift | Repeat / batch drift (fwd, grad) | Output err: RL-Kernel / diffusers | Fwd ms: RL-Kernel / diffusers | Fwd+bwd ms | | ||
| |---|---|---|---|---|---|---| | ||
| | tiny | 264 | `adaln_projection` / `adaln_projection` | none | 5.21e-3 / 5.21e-3 | 7.4 / 0.61 | 22.7 / 2.8 | | ||
| | small | 925 | `adaln_projection` / `adaln_projection` | none | 7.87e-3 / 7.87e-3 | 30.1 / 1.12 | 81.7 / 5.0 | | ||
| | medium | 3160 | `adaln_projection` / `adaln_projection` | none | 8.97e-3 / 8.97e-3 | 225 / 3.8 | 577 / 11.5 | | ||
|
|
||
| - **Forward accuracy.** Per node, the candidate's error is within 0.93–1.20× diffusers'. The | ||
| largest is `attention` at S = 3160, which is the interim attention operator's. | ||
| - **Gradient accuracy.** The candidate is better than diffusers on `adaln_proj.weight`, | ||
| `adaln_proj.bias` and `temb`, by up to 7×: diffusers' `index_select` backward accumulates the | ||
| table gradient in BF16 atomics, while the row operators use FP32 segment sums. The candidate is | ||
| within 1.16× on the other leaves, except `attn.norm_q.weight` at S = 3160 (9.5e-3 vs 5.5e-3). | ||
| At S = 925 the same leaf is 2× *more* accurate than diffusers (1.3e-2 vs 2.4e-2), so this | ||
| 128-element gradient's error moves with BF16 rounding rather than favouring one side. | ||
| - **Permutation probe (H-C3).** The output changes in 79 / 450 / 2199 of the rows, by at most 8. | ||
| Attention sums over keys in packed order, so a consistent permutation is not byte-preserving with | ||
| the interim attention operator. This is for `h3_full_attention` to settle. | ||
| - **Speed.** The candidate is 12–60× slower than diffusers forward. Almost all of it is the | ||
| interim GEMMs and attention (FP32 scores materialised). The three row operators are each | ||
| faster than or equal to diffusers in their own evidence. | ||
|
|
||
| ## Existing implementations (RFC #420 reuse rule) | ||
|
|
||
| - **Is there an existing block-level harness?** diffusers' `MiniMaxH3TransformerBlock` is the | ||
| executable reference. It is replayed op for op as the provider, so diffusers is not imported and | ||
| the replay pins the reference's dtypes and ordering. The Qwen3-8B chain gate from #315 | ||
| (`rl_engine/validation/models/chain_gate.py`) has per-node token digests and first-drift | ||
| localisation, but its graph, shapes and acceptance are Qwen3-specific (causal attention, no | ||
| AdaLN). This row reuses its method (per-node digests, graph-ordered first drift) on the H3 | ||
| `h3_chain` stage pattern. | ||
| - **Interim operators.** These are reused from RL-Kernel and are not new code. The only choice | ||
| made here is the FP32-accumulate entry of the Triton GEMM instead of its BF16 tree, for the | ||
| accuracy and speed measured above. | ||
|
|
||
| ## Tests | ||
|
|
||
| `tests/models/minimax_h3/test_h3_one_block.py`: | ||
|
|
||
| - **CPU:** | ||
| - the three layouts hash to the pinned diffusers `build_packed_sequence` output; | ||
| - the graph is well formed; | ||
| - the partial MM-RoPE leaves channels 96–127 unchanged. | ||
| - **GPU, `tiny` and `small` forward:** | ||
| - every node repeats and is batch-row bitwise; | ||
| - promised nodes are isolated-bitwise to diffusers; | ||
| - node and output errors are at most 1.25 × diffusers' + 1e-3. | ||
| - **GPU, `tiny` backward:** | ||
| - every leaf repeats; | ||
| - dX is batch-row bitwise; | ||
| - no gradient drift; | ||
| - leaf errors are at most 1.5 × diffusers' + 5e-3, or, for a BF16 leaf, at most 6 ulps | ||
| (of its largest golden element) above diffusers'. A stored gradient's worst element moves | ||
| in whole ulps, so the relative rule alone is seed- and torch-version-sensitive; | ||
| `tools/validation/models/h3_block_ulp_sweep.py` measured at most +4.15 ulps over | ||
| tiny/small × 10 seeds on torch 2.13 and 2.9.1, and +5.15 ulps over 34 single-node | ||
| candidate/provider swaps (reports: `reports/experiments/h3-one-block-b200/ulp-sweep-torch*.json`). | ||
|
|
||
| ```bash | ||
| RL_KERNEL_H3_WEIGHTS=<dir> CUDA_VISIBLE_DEVICES=0,1 python -m pytest tests/models/minimax_h3 -q | ||
| ``` | ||
|
|
||
| ## Known Limitations | ||
|
|
||
| - **Single platform.** CUDA only. `DeterministicAttentionOp` and the Triton GEMM also build for | ||
| ROCm, but the block has not been run there. | ||
| - **Interim nodes.** Twelve of the 17 nodes (ten interim, two reference) are not bound to a row operator. Their speed and | ||
| rounding are not the owning rows' final ones, and the MM-RoPE nodes are the provider replay | ||
| itself, so they carry no RL-Kernel evidence until `h3_mm_rope_3axis_partial` lands. | ||
| - **Stand-in inputs.** The block input is a seeded stand-in and `temb` is the provider's. | ||
| Real packed projections arrive with the input-projection rows. | ||
| - **Not covered here.** Block 0 only (`ws1_full_h3_transformer` covers 50 blocks and the refiner), | ||
| and one sequence per batch row (H3's batch is a replication axis). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Qualify the 8 KiB performance rationale.
ws2_comm.gather_rowsleaves outputs at or below 8 KiB unpadded, but the B200 measurement shows that padding is already faster at 8 KiB for 8 ranks. Therefore, “because the single-block loop is faster there” is not true for every rank count. Describe 8 KiB as the selected cutoff, or qualify the reason by rank count. (raw.githubusercontent.com)