Skip to content

[WS2][Cross-config][Attention] Integrate the Qwen3-8B TP=2 CP=2 BF16 Attention setting to cross-config alignment framework - #263

Open
zhangj1an wants to merge 39 commits into
RL-Align:testfrom
zhangj1an:jian/cross-config-attention-pr-4
Open

[WS2][Cross-config][Attention] Integrate the Qwen3-8B TP=2 CP=2 BF16 Attention setting to cross-config alignment framework#263
zhangj1an wants to merge 39 commits into
RL-Align:testfrom
zhangj1an:jian/cross-config-attention-pr-4

Conversation

@zhangj1an

@zhangj1an zhangj1an commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements issue #235 PR4 for the Qwen3-8B BF16 TP=2/CP=2 Megatron + vLLM attention cross-configuration target.

This PR now depends on the current heads of:

What is enforced

Area Strict rule
Semantic identity Checkpoint/model/weight/tokenizer/token/mask/position/padding/pre-update identity must match
TP/CP topology TP/CP ranks, world sizes, Qwen3 GQA head ownership, sequence ownership, and global block layout must match; topology is not a recorded free difference
Reduction Online-softmax LSE merge, FP32 accumulation, global block order, final-write downcast, exported attention-domain LSE
Split-KV request AttentionContract.split_kv is first-class and shared by training and rollout
Split-KV execution Both runtimes must provide the complete batch x TP x CP x KV-owner SplitKVRuntimePlanSet
Split-KV fail-closed cases Missing plans, topology/KV-length/request/boundary/order/dtype/downcast mismatch, unknown plan, or fallback all fail
Runtime evidence Constructed/configured contracts are UNOBSERVABLE; only post-execution runtime readback can be APPLIED
CP fallback Requested CP=2 becoming effective CP=1 cannot pass strict TP=2/CP=2 acceptance

bind_attention_runtime_readbacks(...) is the strict handoff for real Megatron/vLLM launchers after they reconstruct the actual contract, actual knob values, frozen-scope verification, and all-rank Split-KV plans.

The scenario now uses TP=2/CP=2 on both sides. The vLLM flash_attn_max_num_splits_for_cuda_graph value remains diagnostic only; it is not treated as proof of the executed logical Split-KV chunk boundaries.

Scope boundary

This PR defines and validates the binding/readback boundary. It does not launch Megatron or vLLM, initialize process groups, or claim GPU execution. A real engine integration must inject AttentionRuntimeReadback after execution. Decode logical KV replay remains in #260.

Validation

Current head: 48a4130

WSL Ubuntu, Python 3.11, PyTorch 2.4.1+cpu:

  • full rl_engine/ MyPy passed (123 source files)
  • updated adapters/tests: Black, isort, and flake8 passed
  • attention binding/runtime/contract/CP focused tests: 164 passed, 1 skipped
  • cross-config runner tests: 8 passed
  • CI-equivalent Attention tests: 24 passed, 2 deselected
  • CI-equivalent KV-cache tests: 15 passed; Attention contract tests: 42 passed
  • unsupported reduction requests invalidate every dependent knob application instead of allowing a missing contract to reach runtime readback
  • the CUDA Attention package exports only modules present in this PR; PR7-only cp_comm and FlashInfer exports are not falsely exposed

GitHub linting, unit-tests, and docs checks all pass on this head. GPU/Megatron/vLLM execution is intentionally not claimed by these CPU contract tests.

Diff audit

The PR currently shows 63 changed files against test. The original PR4 head already changed 62 of them. The only added path is rl_engine/kernels/gtest/operator_specs.py from the PR1 dependency, which registers the cp_attention test operator. The broader cross-config framework files are pre-existing PR4 scope, not newly added by the latest review fixes.

CyberSecurityErial and others added 24 commits July 19, 2026 09:13
Signed-off-by: inaniloquentee <3051000145@qq.com>
# Conflicts:
#	.gitignore
#	rl_engine/kernels/registry.py
#	tests/test_tolerance_contract.py
Signed-off-by: inaniloquentee <3051000145@qq.com>
Signed-off-by: inaniloquentee <3051000145@qq.com>
# Conflicts:
#	rl_engine/kernels/registry.py
# Conflicts:
#	docs/operators/attention.md
…ign#235 PR4)

Wire the CP attention path into the cross-configuration planner/runtime for the
Qwen3-8B TP=2 CP=2 BF16 target.

The PR4 criterion "rollout and training descriptors bind to the same semantic
attention contract" cannot hold literally: training runs full-sequence prefill
over a CP-sharded sequence while rollout runs vLLM paged-KV chunked prefill, so
the two AttentionContract instances always differ. Binding is therefore split
into three tiers -- identity must match bit for bit, reduction semantics must
match each other and the WS2 mandate, and materialization differences are
recorded and measured rather than rejected.

reduction.engine stays in the recorded tier so a Transformer Engine merge oracle
on one side does not fail the binding; reduction.order and acc_dtype stay in the
semantic tier because that is the WS2 claim.

Also adds the first two framework-shaped RuntimeMaterializer implementations.
Before this the only one was CpuSmokeMaterializer over a synthetic CPU model,
and every named scenario was planning-only. Neither adapter imports megatron or
vllm, so the binding rules run on CPU in CI.

Determinism is probed on both sides and compared, because the two frameworks
mean different things by it: Megatron asserts NCCL_ALGO and leaves TF32 and BF16
reduced-precision reduction unmanaged, while vLLM hard-sets ten NCCL variables
and disables both. Mismatches in NCCL_ALGO, NCCL_PROTO and CUBLAS_WORKSPACE_CONFIG
are blocking; the rest are recorded.

Fixes a latent break on the way: the planner normalizes dtype knobs to torch
spellings (bfloat16) while AttentionDType uses short ones (bf16), so passing a
normalized knob into the enum raised.

Stacked on RL-Align#236 (attention contract) and RL-Align#238 (deterministic CP reference), on
top of RL-Align#230 (cross-configuration framework).

Part of RL-Align#235

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q3Ar3z9fHEBFQQHddSEMaw
 PR4)

Three fields could differ between the two sides without the binding noticing.

dtype was in no tier at all, so a BF16 rollout could bind to an FP16 training
pass and produce a drift number attributable to nothing. It joins the semantic
tier, with allow_dtype_difference for the RL-Align#235 PR5 sweep that deliberately
scores BF16 against an FP32 reference.

batch_size was likewise unchecked. Batch invariance is a claim about results not
changing with batch makeup, so two sides scoring different batches are not
comparable and it belongs to identity.

split_kv_policy has no field in the RL-Align#236 contract, so it only reached
side_configs and never took part in binding. Callers now pass it through
rollout_recorded_extra / training_recorded_extra so the difference is at least
visible in provenance; it can move into the contract once RL-Align#236 grows the field.

Part of RL-Align#235

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q3Ar3z9fHEBFQQHddSEMaw
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ef21cddb-6596-42f9-850f-248ffcc709db

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

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@inaniloquentee
inaniloquentee changed the base branch from feat/cross-config-alignment to test August 12, 2026 16:13
# Conflicts:
#	docs/operators/attention.md
#	rl_engine/kernels/gtest/operator_specs.py
#	rl_engine/kernels/ops/cuda/attention/__init__.py
#	rl_engine/kernels/registry.py
Signed-off-by: lamentropetion <3051000145@qq.com>
Signed-off-by: lamentropetion <3051000145@qq.com>
Signed-off-by: lamentropetion <3051000145@qq.com>
Signed-off-by: lamentropetion <3051000145@qq.com>
Signed-off-by: lamentropetion <3051000145@qq.com>
…act' into codex/update-pr263

Signed-off-by: lamentropetion <3051000145@qq.com>

# Conflicts:
#	docs/operators/attention.md
#	rl_engine/kernels/gtest/operator_inputs.py
#	rl_engine/kernels/registry.py
…e-pr3' into codex/update-pr263

Signed-off-by: lamentropetion <3051000145@qq.com>

# Conflicts:
#	rl_engine/kernels/attention_contract.py
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.

3 participants