Skip to content

[WS1][CUDA][MiniMax-H3] runtime modes, ablation overlay, Diffusers adapter, training provider, LoRA gate (RFC #420 stack 6/7) - #574

Merged
maxiaosong1124 merged 15 commits into
RL-Align:test-h3from
fusheng-ji:feat/h3-runtime-integration
Nov 5, 2026
Merged

maxiaosong1124 merged 15 commits into
RL-Align:test-h3from
fusheng-ji:feat/h3-runtime-integration

Conversation

@fusheng-ji

@fusheng-ji fusheng-ji commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RFC #420 H3 stack 6/7 (base test-h3, merge in this order): #586 -> #587 -> #588 -> #567 -> #568 -> #569 -> #570 -> #571 -> this PR (#574) -> #575. This PR merges after #571; until then GitHub also shows the parent's commits. This PR's own diff.

What

  • h3_runtime_modes: RL_KERNEL_MODE strict / audit / auto / off decides whether the RL-Kernel graph is bound; strict raises instead of falling back, audit reports the fallback; the case id is R/R (strict, audit) or P/P (auto, off).
  • h3_ablation_overlay: AblationOverlay.parse("node:attention,boundary:token_refiner") keeps selected block nodes or boundary modules on provider arithmetic inside a strict run; the run is labelled ablation(...), never R/R; unknown names are rejected. full_model_execution gains native_boundaries for this.
  • diffusers_runtime_adapter_h3: H3DiffusersAdapter binds MiniMaxH3Transformer3DModel for the duration of a with adapter.active(): block, forward and backward (so checkpoint recomputation sees the same operators), and reports what was bound.
  • h3_training_provider: H3TrainingProvider gives the actor side a step() scope plus a per-sample transition.
  • h3_lora_gradient_gate: a LoRA over a strict projection trains bitwise repeatably, forward rows do not depend on batching, the base stays frozen, and the gradients are FP64-close.
  • transition.py (used by the training provider, not a separate RFC row): the cps, noise_level=0.8 step with layout-invariant per-sample noise.

Prior art & reuse decision

Existing Used here
rl_engine/runtime/policy.py (RL_KERNEL_MODE, #361 pattern) reused for the mode policy
AblationOverlay pattern of #230 extended with H3 node and boundary names
verl-omni FlowMatchSDEDiscreteScheduler the transition is checked bitwise against its sample_previous_step(sde_type="cps")

Results (H100 / Hopper)

Measured on NVIDIA H100 (93 GiB, sm90), CUDA 13.0, torch 2.13.0+cu130, pinned MiniMax-H3@42ed227 weights, at head af3dcaef. Runner: tools/validation/models/h3_runtime_report.py. Data and figure on the fork's pr_assets branch (report.json, figure.png, environment.json).

H3 integration rows

LoRA gradient gate (3 shapes, N x K x T up to 5120 x 5120 x 33): bitwise repeatable, forward rows independent of batching, base frozen in all three. Relative error to FP64 autograd: dA 4.3e-7 .. 1.3e-6, dB 3.9e-7 .. 1.3e-6, dX 1.7e-3 (BF16 input rounding), forward 1.7e-3.

CPS transition (B x tokens x channels: 3x257x96, 4x4096x96, 2x8192x32): prev_sample and prev_sample_mean are bitwise equal to the scheduler formula and, with the verl-omni FlowMatchSDEDiscreteScheduler (cps, noise_level=0.8), bitwise equal in the mean. Log-prob max relative difference to the scheduler's torch.mean: 5.8e-6 / 1.5e-4 / 7.5e-5 (fixed-order GEMM reduction vs torch reduction, FP32 rounding). Each sample is independent of the batch (bitwise) and scoring a stored rollout reproduces the sampling log-prob (bitwise) in all three.

Runtime modes on the 33B model (forward + backward through H3TrainingProvider, request sizes 12, 925, 4253 and 8349 tokens; relative difference to a first off (provider) run):

variant 12 tok: video / audio / input grad 925 tok 4253 tok
off, 2nd provider run 0 / 0 / 0 0 / 0 / 1.3e-2 0 / 0 / 1.7e-2
strict (R/R) 2.07e-3 / 1.77e-2 / 0.226 5.52e-3 / 2.40e-2 / 0.129 5.30e-3 / 2.06e-2 / 0.175
strict, node:attention native 2.22e-3 / 1.59e-2 / 0.164 5.24e-3 / 2.21e-2 / 0.126 5.39e-3 / 1.98e-2 / 0.162
strict, boundary:token_refiner native 2.00e-3 / 2.05e-2 / 0.151 5.38e-3 / 2.06e-2 / 0.117 5.27e-3 / 1.91e-2 / 0.159

8349 tokens (video / audio / input grad; second provider run: 0 / 0 / 1.5e-2): strict 5.29e-3 / 1.95e-2 / 0.154 with h3_full_attention (#553) on #575 (4f7c5d11); node:attention native 5.31e-3 / 1.94e-2 / 0.158 (still on interim attention on this branch).

No timing is claimed here; the speed of the underlying rows is in their own PRs.

Results (B200 / Blackwell)

Measured on NVIDIA B200 (179 GiB, sm100), driver 580.126, CUDA 13.0, torch 2.13.0+cu130, pinned MiniMax-H3@42ed227 weights, clean tree at af3dcaef. Optional dependencies for the two comparison tests are pinned to the revisions recorded for the H100 run (environment.json): vLLM-Omni 12e92800 and verl-omni efb9dc7f.

Tests: 19 passed (19 collected), none skipped, including the scheduler comparison against verl-omni (VERL_OMNI_PATH set); tests.json. Report: report.json.

  • Runtime modes strict, audit, auto, off bind and report as intended (R/R for strict and audit, P/P for auto and off).
  • LoRA gradient gate (3 shapes): repeatable, rows independent, base frozen; forward error against FP64 0.00166, gradients of A and B 3.9e-07 to 1.3e-06, of the input 0.0017 to 0.0017 (gate 5e-3).
  • CPS transition: prev_sample and mean bitwise equal, batch invariant, scoring reproduces the sampled log-prob in all 3 shapes; the mean is bitwise equal to verl-omni's and the largest log-prob relative difference to it is 5.8e-06, 1.5e-04, 7.5e-05 (shapes B3 x 257x96, B4 x 4096x96, B2 x 8192x32).
  • Full 33B model, strict (R/R) against the provider:
tokens video rel. diff audio rel. diff input-grad rel. diff (strict) input-grad rel. diff (provider vs provider, P/P) strict bitwise repeatable audit equals strict
12 2.29e-03 2.13e-02 0.200 0.000 True True
925 5.40e-03 2.34e-02 0.134 0.014 True True
4253 5.20e-03 2.04e-02 0.169 0.017 True True

The input-gradient columns moved by up to about 8% between two B200 runs of this PR (strict at 925 tokens: 0.1339 in the first run, 0.1345 here; the P/P column, which compares the provider with itself, 0.0127 and 0.0136), so part of that column is run-to-run variation of the provider's backward; this was not investigated further. The log-prob difference to the provider is 0 in every row. Ablations that put attention or the token refiner back on the native path give differences of the same size as strict (in the report).

runtime integration on B200

Not run on B200: the 8349-token strict / audit rows, which need the h3-flash-attention-v1 binding that is not in this PR (see the H100 section).

Tests

tests/models/minimax_h3/test_h3_runtime_integration.py (19 tests; the measurements above are from tools/validation/models/h3_runtime_report.py): runtime modes and the environment variable, overlay parsing and validation, adapter off / strict / audit, transition (scheduler comparison needs VERL_OMNI_PATH; skipped without it), LoRA gate and FP64 check. All 19 pass on H100 with a verl-omni checkout (18 pass and 1 skips without it). The #571 chain regression (refiner, projection rows, one block, full model) still passes.

B200: 19 passed, with VERL_OMNI_PATH set.

Scope & Known limitations

  • The noise law is the scheduler's current cps law (noise_level=0.8); if the recipe changes it, only transition.py and its test change. Maintainer: is this the law to pin?
  • Attention, rotary and AdaLN of other rows stay provider unless bound by their own rows.
  • Not in this PR: checkpoint mapper and the vLLM-Omni adapter (next PR in the stack).

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

…g provider, LoRA gate and CPS transition

RFC RL-Align#420 rows h3_runtime_modes, h3_ablation_overlay, diffusers_runtime_adapter_h3,
h3_training_provider and h3_lora_gradient_gate, plus the layout-invariant CPS transition
the training provider uses. full_model_execution gains native_boundaries so a run can keep
selected boundary modules on provider arithmetic (ablation).

Signed-off-by: Wenbo Ji <[email protected]>
(cherry picked from commit 65d7fff)
JSON and figure: runtime modes, LoRA gradients against FP64, CPS transition against the
scheduler formula and verl-omni, and the 33B model under off / strict / audit / ablations.

Signed-off-by: Wenbo Ji <[email protected]>
(cherry picked from commit 3f0bbe6)
@fusheng-ji
fusheng-ji force-pushed the feat/h3-runtime-integration branch from 58b724b to af3dcae Compare October 22, 2026 21:04
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Oct 23, 2026
…#567 RL-Align#568 RL-Align#570 RL-Align#571 RL-Align#574 RL-Align#575

Test summaries (tests.json), runner outputs and figures measured on NVIDIA B200 (sm100),
driver 580, CUDA 13.0, torch 2.13.0+cu130, MiniMax-H3@42ed227, clean trees at the PR heads
eab901b, 3cf51bf, 6de320d, eb7840b, af3dcae and 4f7c5d1. Figures use B200 axis labels.
No host names, paths or scheduler identifiers.

Signed-off-by: Wenbo Ji <[email protected]>
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Oct 23, 2026
…jectory diag summary

- h3-fingerprint-trace-trajectory-h100/tests.json (77 passed, eab901b)
- environment.json for RL-Align#574/RL-Align#575 H100 adapter reproducibility pins
- dual_trajectory_diag_summary.json (H100/B200 diag strict 0/16 on seeds 11/22/33)

Signed-off-by: Wenbo Ji <[email protected]>
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Oct 23, 2026
…with the H100-pinned vllm-omni and verl-omni

Same heads (af3dcae, 4f7c5d1), with vllm-omni 12e92800 and verl-omni efb9dc7f as recorded in the H100
environment files, replacing the first B200 run that used newer checkouts. Test summaries record the
dependency revisions.

Signed-off-by: Wenbo Ji <[email protected]>
@Flink-ddd Flink-ddd added platform: cuda Specific optimizations or bugs in NVIDIA graphics cards (such as FlashInfer, TMA optimizations) new-model MiniMax-H3 WS1 labels Oct 23, 2026
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Oct 29, 2026
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Oct 29, 2026
@fusheng-ji fusheng-ji changed the title [WS1][CUDA][MiniMax-H3] runtime modes, ablation overlay, Diffusers adapter, training provider, LoRA gate (RFC #420 stack 6/7) [WS1][CUDA][MiniMax-H3] runtime modes, ablation overlay, Diffusers adapter, training provider, LoRA gate (RFC #420 stack 16/17) Oct 30, 2026
@fusheng-ji fusheng-ji changed the title [WS1][CUDA][MiniMax-H3] runtime modes, ablation overlay, Diffusers adapter, training provider, LoRA gate (RFC #420 stack 16/17) [WS1][CUDA][MiniMax-H3] runtime modes, ablation overlay, Diffusers adapter, training provider, LoRA gate (RFC #420 stack 6/7) Oct 30, 2026
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Oct 30, 2026
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

🔍 OpenCodeReview found 7 issue(s) in this PR.

  • ✅ Successfully posted inline: 0 comment(s)
  • 📋 Routed to summary by policy: 7 comment(s)

⚠️ 3 warning(s) occurred during review.


bug · medium

📄 rl_engine/models/minimax_h3/runtime.py (L149-L153)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity medium · category bug)

policy.report_only is never read here: both branches re-raise, so audit (fail_on_fallback=False, report_only=True) behaves exactly like strict for any exception raised while the scope is active. The handler is also too broad in two ways:

  1. It wraps the whole with full_model_execution(...) body, so a RuntimeError thrown by the caller's own forward/backward inside the with block is recorded in self.fell_back and reported as an operator fallback (report() then labels the run P/P), mislabelling user errors as fallbacks.
  2. The actual candidate fallback detected in full_model_execution is raised as ValueError (require_candidate_cuda/_strict_boundaries), which this except RuntimeError does not catch, so that fallback is never recorded at all.

Narrow the handler to the binding/setup step (or catch both RuntimeError and ValueError from the setup only) and honour report_only by degrading to provider arithmetic with fell_back set instead of re-raising.


bug · medium

📄 rl_engine/models/minimax_h3/runtime.py (L262-L262)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity medium · category bug)

_StrictLoRA.backward returns None for the weight position, so the frozen-base assumption is silently enforced only by the caller. If weight ever arrives with requires_grad=True (base not frozen, e.g. a full fine-tune reusing this op), autograd accepts the returned None and the base silently receives no gradient — a wrong training signal with no error. Make the contract explicit at the boundary.

💡 Suggested Change

Before:

    return _StrictLoRA.apply(x.contiguous(), weight, a, b, scale)

After:

    if weight.requires_grad:
        raise ValueError("strict_lora_linear expects a frozen base weight (requires_grad=False)")
    return _StrictLoRA.apply(x.contiguous(), weight, a, b, scale)

test · medium

📄 rl_engine/models/minimax_h3/runtime.py (L291-L291)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity medium · category test)

The base_frozen check is tautological: weight.detach().clone() can never require grad, so w.grad is None and not w.requires_grad is always True regardless of what _StrictLoRA.backward does. The gate therefore cannot detect a regression that starts routing gradients to the base, which is the property it advertises. Exercise the op with a base that does require grad (and assert no grad lands on it), e.g. build the run through _StrictLoRA.apply with w = weight.detach().clone().requires_grad_(True) and record w.grad is None; if strict_lora_linear guards requires_grad, assert that guard instead.


bug · medium

📄 rl_engine/models/minimax_h3/runtime.py (L206-L208)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity medium · category bug)

sample_ids is never checked against the batch: if len(sample_ids) != sample.shape[0] (or the ids are reordered), a stack of length 1 broadcasts silently across every row, or a shorter/longer list either raises an opaque broadcast error later in cps_transition or assigns each sample the wrong noise. Since the whole contract is "eps depends on the sample id only", a misaligned id list produces plausible-looking but wrong prev_sample/log_prob with no signal. Validate the length (and, if the ids are meant to be positional, document/check the order) before stacking.

💡 Suggested Change

Before:

        noise = None
        if prev_sample is None:
            noise = torch.stack(

After:

        noise = None
        if prev_sample is None:
            ids = list(sample_ids)
            if len(ids) != sample.shape[0]:
                raise ValueError(
                    f"sample_ids has {len(ids)} entries but the batch has {sample.shape[0]} samples"
                )
            noise = torch.stack(

bug · medium

📄 rl_engine/validation/models/h3_full_model.py (L248-L248)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity medium · category bug)

A boundary listed in native is (correctly) not bound to its row, but the trace still records the row name for it, and FullModelTrace.validate() keeps emitting boundary_binding="strict rows + provider" whenever boundary_bindings is non-empty (h3_full_model.py:160-162). So a run with e.g. boundary:token_refiner native — the exact ablation the new native_boundaries argument enables — is still summarised as "strict rows + provider" and carries a row for a kernel that never executed. tools/validation/models/h3_full_transformer.py and h3_runtime_report.py copy boundary_bindings straight into evidence, so the ablation is indistinguishable from a full strict binding at the summary level. Report the row as absent for native boundaries (and consider deriving the summary from the statuses rather than from boundary_bindings being non-empty).

💡 Suggested Change

Before:

            n: dict(row=r, status="provider" if n in native else "row")

After:

            n: dict(
                row=None if n in native else r,
                status="provider" if n in native else "row",
            )

bug · medium

📄 tools/validation/models/h3_runtime_report.py (L238-L238)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity medium · category bug)

torch.OutOfMemoryError only exists in recent torch releases; the project pins torch>=2.4.1 and every other OOM guard in the repo uses torch.cuda.OutOfMemoryError (e.g. benchmarks/common/profiler.py:275). On an older supported torch the except clause itself raises AttributeError when a CUDA OOM propagates, so the intended "record an error row and continue" path never runs and the whole measurement aborts after the costly 33B runs. Use the CUDA-specific class that the rest of the code base uses.

💡 Suggested Change

Before:

            except torch.OutOfMemoryError:

After:

            except torch.cuda.OutOfMemoryError:

maintainability · low

📄 tools/validation/models/h3_runtime_report.py (L332-L332)

⚠️ GitHub could not post this as an inline comment: Routed to summary (severity low · category maintainability)

--sizes accepts arbitrary strings but model_rows indexes SIZES[size] (packed_inputs(...) if SIZES[size] is None), so a typo such as --sizes 12,925,425 fails with a bare KeyError only after the checkpoint has been loaded, rather than at argument parsing. Validate the values against SIZES when parsing (the help text already lists them).

💡 Suggested Change

Before:

    p.add_argument("--sizes", default="12,925,4253", help="comma list from: " + ",".join(SIZES))

After:

    p.add_argument(
        "--sizes",
        type=lambda s: [v for v in s.split(",") if v],
        default=list(SIZES)[:1],
        help="comma list from: " + ",".join(SIZES),
    )

⚠️ Warnings:

  • rl_engine/models/minimax_h3/runtime.py,rl_engine/models/minimax_h3/transition.py (review_limit_reached): reached the aggregate token budget before finishing; the grace round completed the task
  • rl_engine/models/minimax_h3/runtime.py (token_budget_reached): skipped round 2 of group "rl_engine/models/minimax_h3/runtime.py,rl_engine/models/minimax_h3/transition.py": used 584502 tokens exceeds budget 500000
  • rl_engine/validation/models/h3_full_model.py,tests/models/minimax_h3/test_h3_runtime_integration.py,tools/validation/models/h3_runtime_report.py (review_limit_reached): reached the aggregate token budget before finishing; the grace round did not complete the task

@github-actions

Copy link
Copy Markdown

@fusheng-ji The automated OCR review has completed.

Please review and address all automated review bot findings, then push your updates. Maintainers will begin manual review after the bot findings have been addressed.

@maxiaosong1124

maxiaosong1124 commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

please resolve conflicts first, thx! @fusheng-ji

…, RL-Align#588) into feat/h3-runtime-integration

Signed-off-by: Wenbo Ji <[email protected]>
proj_in and proj_out are strict boundary rows since the full-transformer harness binds the video projections, so an overlay may name them; norm_out stays on the provider and is still rejected.

Signed-off-by: Wenbo Ji <[email protected]>
@maxiaosong1124
maxiaosong1124 self-requested a review November 5, 2026 10:52
@maxiaosong1124
maxiaosong1124 merged commit cfec0d9 into RL-Align:test-h3 Nov 5, 2026
5 of 6 checks passed
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Nov 6, 2026
fusheng-ji added a commit to fusheng-ji/RL-Kernel that referenced this pull request Nov 6, 2026
Flink-ddd added a commit that referenced this pull request Nov 16, 2026
[WS1][CUDA][MiniMax-H3] Review follow-up for #568 / #570 / #571 / #574 and the strict full-model backward session (RFC #420 follow-up 1/3)
Flink-ddd pushed a commit that referenced this pull request Nov 23, 2026
LoRA on the six recipe targets of every H3 block, on the h3-parallel-v1
projections, with every cross-rank sum on the 8 canonical units, so TP
1/2/4/8, SP and CP give the canonical Grid(1, 1) bytes:

- column-parallel (Q/K/V; FFN-in, whose hidden and gate halves share one
  A): A whole on every TP rank, B cut by output rows like the base;
  z = x A^T and the forward need no collective; dz = s * sum_N dy B is
  the base dX's unit tree, all-reduced in the same tree;
- row-parallel (O, FFN-down): A cut by input columns like the base, B
  whole; z = sum_K x A^T is the base's unit tree, all-reduced (also
  under SP); dz, dB and the A shard's gradient need no collective;
- CP: dA and dB from the rows of every CP rank, gathered exactly.

A and B may be BF16 (the recipe's adapters); they are read as FP32 and
their gradients are rounded once. A column-parallel forward is bitwise
#574's strict_lora_linear; elsewhere the canonical run sums the 8 units
and is as close to FP64 as strict_lora_linear.

Harness: h3_lora draws a seeded LoRA per block (A ~ N(0, 1/r), B random
or zero) and cuts each rank's shards; run_tp_block_rows(lora=) runs the
LoRA projections and records the shards as gradient leaves;
parallel_model_execution reads them from the block (_rlk_tp_lora); the
full-model runner gains --lora-rank/--lora-alpha/--lora-seed/
--lora-b-zero and compares every LoRA shard's gradient. Also
lora_counted (each tensor counted once in a norm) and to_rollout_layout
(upstream map_lora_tensors' vLLM-Omni names and fc1 order).

Signed-off-by: Wenbo Ji <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MiniMax-H3 new-model platform: cuda Specific optimizations or bugs in NVIDIA graphics cards (such as FlashInfer, TMA optimizations) WS1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants