Skip to content

feat(attention): add strict bitwise ROCm path - #319

Open
inaniloquentee wants to merge 94 commits into
mainfrom
codex/ws2-rocm-strict-attention
Open

feat(attention): add strict bitwise ROCm path#319
inaniloquentee wants to merge 94 commits into
mainfrom
codex/ws2-rocm-strict-attention

Conversation

@inaniloquentee

@inaniloquentee inaniloquentee commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR adds the ROCm strict Attention path for #235. It reuses qualified high-performance vendor operators where their reduction behavior is controllable, and keeps RL-Kernel implementations where vendor paths did not pass the expanded bitwise probes.

Area Production path Strict-consistency control
Attention core AITER/CK dense MHA via aiter.ops.mha.mha_fwd/mha_bwd Same core on training and rollout; deterministic backward; dense non-Split-K API; num_splits=1 provenance
Q/K RMSNorm Transformer Engine through #230 Same TE functional forward/backward on both sides; bitwise admission probe; fail closed
RoPE rlkernel.rocm.deterministic_rope Same post-RoPE boundary and position semantics
QKV / O projection RL-Kernel deterministic GEMM TE GEMM is not selected because expanded batch-composition probes drifted
CP communication Self-owned rccl_ag_rs Q/K/V/positions AG, platform core, Out/LSE RS; autograd enabled
CP schedule rlkernel.attention.strict_ring_state.v1 Fixed logical order; communication/compute decoupled; overlap disabled
Fallback None Missing or mismatched vendor controls fail closed

The self-owned deterministic Attention core remains a reference/debug oracle, not the ROCm production arithmetic path. Strict equality is defined within the same ROCm hardware and runtime stack; this PR makes no cross-vendor bitwise claim.

ROCm Validation

Arithmetic validation is bound to 9ff0e6dc5a82d348d755f155c5ccc7790840343b. Current head 1bc4177 only narrows the test-injected AITER callable types for mypy; the platform tests remain unchanged.

Environment Value
GPU 8 x AMD Instinct MI300X (gfx942)
PyTorch / HIP 2.12.0+rocm7.14.0a20260608 / 7.14.60850
RCCL API 2.28.9
AITER source aiter.ops.mha, source fingerprint recorded in every report
TE 2.14.0.dev0+e6ede467
Workload BF16, Qwen3-8B TP-local heads, D=128
Gate Coverage Result
Unit + platform contracts tests/test_attention_correctness.py + tests/test_flashinfer_pr7_attention.py 156 passed, 41 skipped
Q/K RMSNorm reuse TE Out/dX/dW; batch row vs composed batch All bitwise, max abs 0; no fallback
Decode matrix B=1/2; KV=16/128/1024; page=4/16 3/3 passed; Out/LSE/dlogp 0; batch/page-layout invariant
Prefill matrix B=1/2; S=16/64/256; page=4/16 3/3 passed; Out/LSE/dlogp 0; batch/page-layout invariant
Strict RCCL AG+RS 2 ranks: TP=1, CP=2 2/2 ranks; Out/LSE/dQ/dK/dV max abs 0
Strict RCCL AG+RS 4 ranks: TP=2, CP=2 4/4 ranks; Out/LSE/dQ/dK/dV max abs 0
Strict RCCL AG+RS 8 ranks: TP=2, CP=2, 2 replicas 8/8 ranks; Out/LSE/dQ/dK/dV max abs 0

Every strict report records fallback=false, native_attention_arithmetic=true, actual_backend=aiter.rocm.ck_dense_mha, deterministic backward, disabled Split-KV, and communication_backend=rccl_ag_rs.

Reproduce

python -m pytest -q   tests/test_attention_correctness.py   tests/test_flashinfer_pr7_attention.py

python scripts/ws2_pr7_flashinfer_attention_check.py   --strict --device cuda --no-dry-run   --mode decode --batch-size 2 --query-len 1   --kv-seq-len 128 --page-size 16   --output results/rocm-attention/strict-decode-b2-kv128.json

python scripts/ws2_p2p_nccl_attention_reference_check.py   --run-rocm-matrix   --output-dir results/rocm-attention

Related to #235 and #294. Q/K RMSNorm wrapper integration is in #230.

inaniloquentee and others added 30 commits July 20, 2026 23:14
Signed-off-by: inaniloquentee <3051000145@qq.com>
Signed-off-by: inaniloquentee <3051000145@qq.com>
Signed-off-by: inaniloquentee <3051000145@qq.com>
Signed-off-by: inaniloquentee <3051000145@qq.com>
Signed-off-by: inaniloquentee <3051000145@qq.com>
Signed-off-by: JLiu4Coding <lzwgre@126.com>
Signed-off-by: JLiu4Coding <lzwgre@126.com>
Signed-off-by: inaniloquentee <3051000145@qq.com>
Freeze the WS1 numerical SSOT for issue #267: four-judgment tolerance rows,
dtype/TF32/FP8 policy, comparison roles, chain logprob aggregates, shared
resolver, and op_checks wiring so forward and gradient accuracy no longer
share one threshold path. Add schema tests, usage docs, and a migration
checklist for remaining private-atol call sites (C3/C4/C8).

Closes #267
Record acceptance-criteria mapping, verification commands, and residual
scope so issue #267 can close without implying full #266 exit.
Freeze the full Qwen3-8B Dense logical workload SSOT for WS1 closeout C2:
manifest pins (config fingerprint, weight content hash, 2x2 Batch/Chunk
matrix, varlen fixtures, packing, dual backend profiles, representative
case_ids), logical identity restore after pad/pack/chunk, singleton_aggregate
vs BN multiset plan, registry-resolved candidate binding, and a single
reference command. Document registry-vs-runtime actual boundary and Triton
missing_required reds without silent fallback.

Closes #268
Add the shared forward accuracy/invariance API, C2 config matrix,
backend provenance fail-closed checks, selected-logprob smoke, GPU
gate CLI, CPU tests, and closeout evidence for WS1 C3.
Shared training-style gradient comparison across the C2 Batch/Chunk matrix:
accuracy (vs FP32 VJP) and invariance (cross-config) are separate C1
judgments, thresholds come only from the contract resolver, and the report
schema is what C8/C10 must reuse.

Adapters execute on config.physical_layout — packed runs one batched call,
chunked splits per chunk, padded uses the real pad grid, permuted keeps the
permuted sample order — and return physical tensors that the harness restores
through C2's map. Seeding autograd.grad with an upstream that is a pure
function of logical identity keeps the comparison free of physical summation
order, so a failure means the operator's own backward moved.

TestPhysicalLayout locks the matrix down: a layout-sensitive synthetic op must
be judged red, a logical-identity-only op green, B=N must be one batched call,
chunking must split it, and padding must reach the operator. Without those
guards a layout-blind adapter makes every bitwise verdict a tautology.

A required differentiable node with no backward now raises MissingBackwardError
and is reported as a categorised red rather than an autograd stack trace.

scripts/sweep_gradient_invariance.py runs every adapter x required profile and
classifies each cell. Current tally on sm89: green=8, red_verdict=6,
red_no_backward=1, blocked_hardware=4, blocked_c2=3, skipped=4.

Two open findings are recorded in the closeout evidence as Blocker candidates,
not fixed here (C4 audits declared candidates, it does not rewrite kernels):
RMSNorm/QK-Norm dweight and det_gemm dW re-associate when the token stream is
split across launches, and the CUDA plain-logp candidates are not wired through
torch.autograd so dlogits cannot be produced at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GNxzCbwwa2BbZYrEXokt1a
Port remaining WS1 ops onto the shared C3/C4 runners, add the C5
inventory and C8 four-judgment sweep, and record sm86 reds in-repo.
Land remaining gtest registrations (qk_norm, pack), Triton attention VJP,
fail-closed SM90 candidates, C8 execute sweep provenance, and C5/C2 scope
docs. linear_logp stays optional_fused; pack stays N/A with CPU C3/C4
evidence. SM90 logp tests now match the no-fallback contract.
C3 reports backend_family (cuda/triton). C8 actual_backend_id should
match the declared candidate (cuda, cuda-sm90, or triton).
Regenerate the four-judgment matrix with invariance provenance,
environment, and the source commit SHA. Counts remain green=176,
N/A=16, red=0.
@coderabbitai

coderabbitai Bot commented Aug 19, 2026

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 133 files, which is 33 over the limit of 100.

To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bd81487d-907f-46f1-8114-3cff2cdc92f2

📥 Commits

Reviewing files that changed from the base of the PR and between 027c809 and 1bc4177.

📒 Files selected for processing (133)
  • .github/workflows/ci.yml
  • .github/workflows/gpu-ci.yml
  • .github/workflows/ws1-chain-gpu.yml
  • .github/workflows/ws1-gtest-gpu.yml
  • .gitignore
  • benchmarks/benchmark_sampling.py
  • ci/run_gpu_ci.sh
  • ci/run_ws1_chain_gate.sh
  • ci/run_ws1_gtest.sh
  • csrc/cuda/attention/deterministic_attention.cu
  • csrc/cuda/distributed/deterministic_collective.cu
  • csrc/cuda/embedding_lm_head_sm90.cu
  • csrc/cuda/gemm/det_gemm_kernel.cu
  • csrc/ops.cpp
  • docker/Dockerfile.cuda
  • docs/contributing/gtest-usage.md
  • docs/contributing/testing.md
  • docs/design/ws1-blockers.md
  • docs/design/ws1-c2-268-closeout-evidence.md
  • docs/design/ws1-c2-268-workload-plan.md
  • docs/design/ws1-c3-269-closeout-evidence.md
  • docs/design/ws1-c4-270-closeout-evidence.md
  • docs/design/ws1-c4-270-gradient-plan.md
  • docs/design/ws1-c5-271-inventory.md
  • docs/design/ws1-c6-c11-closeout-evidence.md
  • docs/design/ws1-c6-c11-closeout-plan.md
  • docs/design/ws1-c8-274-closeout-evidence.md
  • docs/design/ws1-c8-274-matrix-plan.md
  • docs/design/ws1-c8-execute.json
  • docs/design/ws2-attention-decode-replay.md
  • docs/design/ws2-attention-pr7-flashinfer-rope-splitk.md
  • docs/design/ws2-attention-single-gpu-harness.md
  • docs/design/ws2-attention-transformer-engine-reuse-plan.md
  • pyproject.toml
  • rl_engine/_C.pyi
  • rl_engine/alignment/qwen3_dense.py
  • rl_engine/distributed/__init__.py
  • rl_engine/distributed/collectives.py
  • rl_engine/kernels/attention_contract.py
  • rl_engine/kernels/gtest/__init__.py
  • rl_engine/kernels/gtest/chain_gate.py
  • rl_engine/kernels/gtest/chain_gradients.py
  • rl_engine/kernels/gtest/elementwise_inventory.py
  • rl_engine/kernels/gtest/forward_invariance.py
  • rl_engine/kernels/gtest/four_judgment_matrix.py
  • rl_engine/kernels/gtest/gradient_adapters.py
  • rl_engine/kernels/gtest/gradient_invariance.py
  • rl_engine/kernels/gtest/kv_consistency.py
  • rl_engine/kernels/gtest/op_checks.py
  • rl_engine/kernels/gtest/operator_inputs.py
  • rl_engine/kernels/gtest/operator_specs.py
  • rl_engine/kernels/gtest/tolerance.py
  • rl_engine/kernels/gtest/tolerance_contract.json
  • rl_engine/kernels/ops/backward_runtime.py
  • rl_engine/kernels/ops/canonical_backward.py
  • rl_engine/kernels/ops/canonical_linear.py
  • rl_engine/kernels/ops/canonical_lm_head.py
  • rl_engine/kernels/ops/canonical_rmsnorm.py
  • rl_engine/kernels/ops/cuda/attention/__init__.py
  • rl_engine/kernels/ops/cuda/attention/cp_comm.py
  • rl_engine/kernels/ops/cuda/attention/deterministic_attn.py
  • rl_engine/kernels/ops/cuda/attention/flash_attn.py
  • rl_engine/kernels/ops/cuda/attention/flashinfer_paged_attention.py
  • rl_engine/kernels/ops/cuda/linear/embedding.py
  • rl_engine/kernels/ops/cuda/linear/lm_head.py
  • rl_engine/kernels/ops/cuda/loss/batch_invariant_logp.py
  • rl_engine/kernels/ops/cuda/loss/logp.py
  • rl_engine/kernels/ops/cuda/matmul/det_gemm.py
  • rl_engine/kernels/ops/cuda/norm/rmsnorm.py
  • rl_engine/kernels/ops/cuda/rotary_embedding/rope.py
  • rl_engine/kernels/ops/pytorch/attention/cp_attention.py
  • rl_engine/kernels/ops/pytorch/attention/stateful_kv.py
  • rl_engine/kernels/ops/rocm/attention/__init__.py
  • rl_engine/kernels/ops/rocm/attention/flash_attn.py
  • rl_engine/kernels/ops/triton/attention/standard_attn.py
  • rl_engine/kernels/ops/triton/linear/__init__.py
  • rl_engine/kernels/ops/triton/linear/embedding.py
  • rl_engine/kernels/ops/triton/linear/lm_head.py
  • rl_engine/kernels/ops/triton/loss/logp.py
  • rl_engine/kernels/ops/triton/matmul/det_gemm.py
  • rl_engine/kernels/ops/triton/rmsnorm_triton.py
  • rl_engine/kernels/ops/triton/rotary_embedding/rope.py
  • rl_engine/kernels/ops/vjp_fp32.py
  • rl_engine/kernels/registry.py
  • rl_engine/testing/__init__.py
  • rl_engine/testing/attention_comparison.py
  • rl_engine/testing/ws1_manifest.json
  • rl_engine/testing/ws1_workload.py
  • rl_engine/utils/logger.py
  • scripts/check_decode_prefill.py
  • scripts/check_forward_invariance.py
  • scripts/check_gradient_invariance.py
  • scripts/check_operator.py
  • scripts/check_stateful_kv.py
  • scripts/prepare_ws1_weights.py
  • scripts/sweep_gradient_invariance.py
  • scripts/sweep_ws1_four_judgments.py
  • scripts/ws1_candidate_evidence.py
  • scripts/ws1_chain_fwd_bwd.py
  • scripts/ws1_chain_gate.py
  • scripts/ws1_reference.py
  • scripts/ws2_p2p_nccl_attention_reference_check.py
  • scripts/ws2_pr7_flashinfer_attention_check.py
  • setup.py
  • tests/distributed/__init__.py
  • tests/distributed/test_deterministic_all_gather.py
  • tests/distributed/test_deterministic_all_reduce.py
  • tests/distributed/test_deterministic_reduce_scatter.py
  • tests/test_attention_comparison.py
  • tests/test_attention_correctness.py
  • tests/test_batch_invariant_logp.py
  • tests/test_cp_attention.py
  • tests/test_cp_attention_transformer_engine.py
  • tests/test_det_gemm.py
  • tests/test_deterministic_attention_cuda.py
  • tests/test_elementwise_inventory.py
  • tests/test_flashinfer_pr7_attention.py
  • tests/test_forward_invariance.py
  • tests/test_four_judgment_matrix.py
  • tests/test_gradient_invariance.py
  • tests/test_kv_cache_attention.py
  • tests/test_kv_consistency.py
  • tests/test_op_checks.py
  • tests/test_operator_inputs.py
  • tests/test_rope.py
  • tests/test_sm90_linear_wrappers.py
  • tests/test_tolerance_contract.py
  • tests/test_triton_batch_invariant_attention.py
  • tests/test_ws1_candidate_evidence.py
  • tests/test_ws1_chain_integration.py
  • tests/test_ws1_gtest_gpu.py
  • tests/test_ws1_qwen3_dense.py
  • tests/test_ws1_workload.py

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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

Comment @coderabbitai help to get the list of available commands.

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.

5 participants