Repository navigation
[WS1][CUDA][MiniMax-H3] Add FP32 video output projection - #646
maxiaosong1124 merged 8 commits into
Conversation
Signed-off-by: walker-ai <[email protected]>
Share canonical weight and bias row preparation while retaining stable sorting. Reuse 128x32 tiles and compute long dW reductions through the transposed product. Preserve the original full-K dX path. Validated on H20 with torch 2.4.1+cu124 and Triton 3.0.0: 80 operator cases, 5 embedding regressions, 6 framework checks, OP_SPECS, and accuracy/BI/performance across ten sizes through 629106 rows. Signed-off-by: walker-ai <[email protected]>
Merge the latest test-h3 and reuse its canonical backward and FP32 GEMM paths. Keep only wide address arithmetic in the shared kernel for large output layouts, and qualify the output-specific matrix routing. Reuse the independent input reference helper; cover projection followed by video selection, conditioned layouts, registry dispatch and OP_SPECS. Validated on one H20 with the CI installation procedure (torch 2.4.1+cu124, Triton 3.0.0): 82 output tests, 154 input tests, 27 shared Triton tests, 7 output integration tests and all 4 OP_SPECS outputs passed. Performance and source-identity evidence are retained locally. Signed-off-by: walker-ai <[email protected]>
Cover equal and variable-length requests using the merged vLLM-Omni H3 packing layout. Check independent and packed forwards, canonical session grouping, row order, and per-request padding. Guard chunked reductions against the Triton merge tensor-size limit. Signed-off-by: walker-ai <[email protected]>
Copy large CUDA multi-use inputs directly into their canonical row order. Keep small inputs and other platforms on the existing path, with bytewise copy, session, and routing coverage. Validated on H20 with the CI PyTorch 2.4.1 / Triton 3.0 environment: 310 related pytest cases, three maximum requests, and old Qwen/LM-head calls. Signed-off-by: walker-ai <[email protected]>
Separate projection block dimensions from warp count and reuse the public H3 dimension constants without changing GEMM dispatch or launch arguments. Remove the duplicate canonical bias-sharing test already covered by input projection. Cover sampled and unsampled non-finite benchmark results and strict JSON output in four CPU cases. Validation: 128 passed on H20 with PyTorch 2.4.1+cu124 and Triton 3.0.0 (output suite: 125; existing input bias-sharing regression: 3). Black, isort, flake8 and git diff --check pass. Signed-off-by: walker-ai <[email protected]>
Check every output and gradient element with the existing independent CPU FP32 reference. Tile only reference output positions to bound temporary memory while keeping complete reduction axes. Cover reference tile boundaries and full-result non-finite detection. Add default FL2VA and Ref2VA layouts alongside the existing context-limit profiles. Replace sampled layout and packed-request accuracy checks with full comparisons. Update benchmark defaults and operator documentation. Validation on H20, PyTorch 2.4.1+cu124 and Triton 3.0.0: 323 passed with no skips (output 130, input 154, shared Triton GEMM 27, embedding 5, output registry/validation 7). CI extension smoke, Black, isort, flake8, and strict MkDocs build passed. Operator and CI implementations are unchanged. Signed-off-by: walker-ai <[email protected]>
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Projection contract and reference rl_engine/ops/gemm/video_output_projection_fp32.py, rl_engine/reference/gemm/video_output_projection_fp32.py, rl_engine/validation/operators/*, tests/ops/gemm/test_video_output_projection_fp32.py, tests/validation/operators/* |
Adds input and logical-key validation, a CPU FP32 reference, and operator validation support for the 5376-to-96 projection. Tests cover the contract, reference behavior, gradients, and invalid inputs. |
Triton kernel and CUDA dispatch rl_engine/backends/shared/triton/gemm/det_gemm.py, rl_engine/backends/shared/triton/gemm/video_output_projection_fp32.py, rl_engine/runtime/registry.py, tests/ops/gemm/test_video_output_projection_fp32.py, tests/runtime/test_kernel_registry.py |
Adds the SM90 Triton backend and registers CUDA dispatch. The shared FP32 GEMM widens tile offsets and checks the supported chunk-reduction limit. Tests cover backend qualification, dispatch, accuracy, gradients, and graph capture. |
Canonical gradient row preparation rl_engine/ops/autograd/canonical_backward.py, tests/ops/gemm/test_video_output_projection_fp32.py |
Adds direct row ordering for eligible multi-input CUDA reductions of at least 256 MiB. Tests cover canonical order, fallback routing, and row-copy behavior. |
Benchmark and workload qualification benchmarks/operators/gemm/benchmark_video_output_projection_fp32.py, docs/operators/video-output-projection-fp32.md, docs/.nav.yml, tests/ops/gemm/test_video_output_projection_fp32.py |
Adds accuracy and permutation checks, timing and memory measurements, and JSON benchmark reporting. Documentation and tests cover packed requests, task layouts, and large reduction limits. |
Estimated code review effort: 4 (Complex) | ~60 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
participant Caller
participant RuntimeRegistry
participant VideoOutputProjectionFP32Op
participant TritonVideoOutputProjectionFP32Op
Caller->>RuntimeRegistry: Request video_output_projection_fp32 backend
RuntimeRegistry->>TritonVideoOutputProjectionFP32Op: Select CUDA SM90 implementation
Caller->>VideoOutputProjectionFP32Op: Submit projection inputs
VideoOutputProjectionFP32Op->>TritonVideoOutputProjectionFP32Op: Run FP32 projection GEMM
TritonVideoOutputProjectionFP32Op->>VideoOutputProjectionFP32Op: Return projection output
VideoOutputProjectionFP32Op->>Caller: Return output with width 96
Possibly related issues
- RL-Align/RL-Kernel issue 420: The issue describes the H3 video output head and its FP32 and deterministic-reduction requirements; this change adds the corresponding output projection and gradient support.
Merge Risk: 
Minimal · up to 6289e
-
This change adds an FP32 video output projection with a CUDA SM90 Triton backend, canonical gradient handling, tests, docs, and a benchmark. No actionable merge-blocking risk remains after review.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passedFull details: Docstring Coverage
-
Explanation
Docstring coverage is 27.12% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 59 functions across 13 files. (2 skipped: 2 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Signed-off-by: walker-ai <[email protected]>
9c7eb21 to
6289efc
Compare
|
🔍 OpenCodeReview found 1 issue(s) in this PR.
📄
|
|
@walker-ai 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. |
Flink-ddd
left a comment
There was a problem hiding this comment.
LGTM. The layout follows #497 and the canonical reduction order is preserved. SM90 is already checked before execution in _check_backend, so I don’t consider the bot’s registry finding blocking. also cc @maxiaosong1124 PTAL
…ness strict_boundaries now routes proj_in and proj_out through video_input_projection_fp32 and video_output_projection_fp32 (RL-Align#562, RL-Align#646) instead of leaving them on the provider's cuBLAS FP32 path, whose result depends on the row count and caused the residual single-vs-batched drift. time_embedder and norm_out stay on the provider and are reported as such. The --diag-video-projections diagnostic bound the h3_projection GEMM and is removed: with strict boundaries it would be overridden and mislabelled. The H100 numbers in the doc predate this binding and are marked as such; a rerun is still needed. Signed-off-by: Wenbo Ji <[email protected]>
Refs #420. Target:
test-h3.Summary
Add the MiniMax-H3 FP32 output projection with optional bias and gradients for X, W and bias.
The output head projects the complete video/audio/context sequence after final normalization and AdaLN. The model then selects video rows.
Tested on one H20. Supports eager forward/backward and CUDA Graph forward under
torch.no_grad().Implementation
canonical_linear_fp32, and canonical parameter-gradient session.(X.T @ G).Tto reuse the input projection's tile layout.Reuse investigation
Files changed — 6 added, 9 modified
[A]= added.[M]= modified.Call path:
get_op → registry → Triton wrapper → canonical_linear_fp32 → projection_gemm_fp32.The canonical session collects and orders the complete parameter-gradient contributions.
Tests
CI extension smoke, operator CLI with random VJP, formatting checks and the strict documentation build pass. All listed pytest cases run on the same source version, with zero skips.
Coverage includes Y/dX/dW/dbias, optional and frozen bias, row permutation, microbatches, padding, unrelated-row placement, noncontiguous gradients, video-row selection and no-grad CUDA Graph forward. Input projection and legacy BF16/Qwen calls exercise the shared implementation.
For every benchmark size, accuracy checks all elements against the independent CPU FP32 reference using
atol=rtol=1e-4. BI checks exact FP32 bits after reversing the same logical rows. The ten sizes include three video lengths and both conditioned layouts with the default context budget.Accuracy and BI figure
Left: elements outside the FP32 tolerance. Right: elements whose FP32 bits change after reversing rows. Zero is a pass. The one-row permutation is trivial. Both panels check all Y/dX/dW/dbias elements.
Performance
Compare ordinary PyTorch
F.linear+ autograd with complete calls to this PR, including validation, bias and canonical parameter-gradient handling. FP32, TF32 off, seed 420, 5 warmups and 40 CUDA-event samples. The table reports median eager forward + backward latency; a PR / PyTorch ratio above 1 means higher latency.The output head projects all mixed-sequence rows. Consequently, its row counts exceed the video-only input projection's counts in #562.
At 367,986 rows, this PR takes 93.066 ms versus 51.258 ms for PyTorch (1.82x latency). Throughput is 3.95 vs 7.18 million mixed rows/s; incremental peak allocated memory is 15.38 vs 7.52 GiB.
Incremental peak memory measures one warmed eager F+B call above the pre-call allocation, excluding inputs and persistent caches.
Left: eager forward + backward. Right: no-grad CUDA Graph forward. Each panel compares the same execution mode and uses its own linear scale.
Additional context-limit and multi-request coverage
The 371,870- and 629,106-row cases extend FL2VA/Ref2VA to the checkpoint's declared 262,144-token context limit. They supplement the default pipeline layouts above.
The large-input row-copy change also supports three maximum-default Ref2VA requests in one canonical gradient session. Each request has 367,986 active rows and is padded to 368,000. Two-request old/new results match byte-for-byte; three-request packed, reversed per-request and deterministic-mode executions also match for all active Y/dX/dW/dbias values.
The following A/B compares existing
cat + index_selectwith direct canonical copying, within the same Triton operator. Memory is total peak allocation, including independent request inputs.Two-request latency alternates old/new execution in one process. The output test suite covers full reference accuracy for two/four packed requests and mixed lengths; the maximum-capacity comparison above checks full-result BI and memory.
Reproduce
Use this PR checkout in the environment from
ci/scripts/run_gpu_ci.sh:runpod/pytorch:2.4.0-py3.11-cuda12.4.1-devel-ubuntu22.04.Recorded environment: H20, driver 535.261.03, Python 3.11.10, PyTorch 2.4.1+cu124, CUDA 12.4, Triton 3.0.0, pytest 9.2.0, NumPy 1.26.3, Transformers 5.13.1, Accelerate 1.15.0, FlashInfer 0.6.18.post1.
Install in CI order on H20
Run from the repository root. Values are generated from fixed seeds at the model's task shapes.
The JSON contains raw timing samples, memory, versions, source hashes, accuracy counts and BI mismatches. Full CPU reference checks run before timing.
Summary by CodeRabbit