Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ed05a09
feat(attention): add deterministic CP reference
inaniloquentee Jul 20, 2026
4fecd81
Merge branch 'main' into feat/ws2-cp-attention-reference-pr3
inaniloquentee Jul 20, 2026
1c8e9db
Merge origin/main into CP attention reference
inaniloquentee Jul 29, 2026
0480ce8
docs(attention): clarify rope boundary for cp reference
inaniloquentee Aug 2, 2026
9f46eff
fix(attention): harden CP reference Split-KV validation
inaniloquentee Aug 12, 2026
f982797
fix(attention): validate CP reference numeric inputs
inaniloquentee Aug 13, 2026
3c8b734
fix(attention): bind backward gradient dtype and device
inaniloquentee Aug 13, 2026
88872f3
fix(attention): enforce FP32 CP merge state
inaniloquentee Aug 13, 2026
5b567e1
style(attention): satisfy full PR lint
inaniloquentee Aug 13, 2026
19bc343
fix(attention): type split-k runtime boundaries
inaniloquentee Aug 13, 2026
da12ac1
docs(attention): link PR1 contract dependency
inaniloquentee Aug 13, 2026
c1cdfe5
docs(attention): record owner-local reference boundary
inaniloquentee Aug 16, 2026
afa00dc
feat(attention): align projection contract
inaniloquentee Aug 16, 2026
416642a
feat(attention): expose deterministic core reference contract
inaniloquentee Aug 17, 2026
05a22e6
fix(attention): keep strict reference on no-split core
inaniloquentee Aug 17, 2026
321b6ed
feat(attention): add canonical bitwise reference schedule
inaniloquentee Aug 18, 2026
5d9bc13
refactor(attention): share strict schedule identity
inaniloquentee Aug 18, 2026
7636cde
Merge remote-tracking branch 'upstream/test' into codex/review-pr238-…
inaniloquentee Aug 18, 2026
988d954
fix(attention): keep strict CP reference on canonical full KV schedule
inaniloquentee Aug 18, 2026
dcccb70
Merge origin/test into PR #238
inaniloquentee Aug 24, 2026
a673135
Merge latest test into PR #238
inaniloquentee Aug 24, 2026
ae09a1c
Merge branch 'test' into feat/ws2-cp-attention-reference-pr3
Flink-ddd Aug 24, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,9 @@ jobs:
run: |
python -m pytest tests/test_kv_cache_attention.py -v -k "not large and not gpu"

<<<<<<< HEAD
- name: Run WS2 Attention Contract Tests (CPU-safe)
run: python -m pytest tests/test_attention_contract.py -v
=======

- name: Run WS2 Logprob Contract Tests (CPU-safe)
run: python -m pytest tests/test_logprob_contract.py -v

Expand All @@ -111,7 +110,6 @@ jobs:
python -m pytest -q \
tests/test_alignment_wrapper_interfaces.py \
tests/test_qwen_ffn.py
>>>>>>> origin/test

docs:
runs-on: ubuntu-latest
Expand Down
27 changes: 27 additions & 0 deletions docs/operators/attention.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,33 @@ python benchmarks/benchmark_ws2_cp_attention_drift.py --smoke --tp-world-sizes 2
--output artifacts/ws2-cp-attention-drift.json
```

### WS2 CP-aware dispatch

WS2 distributed callers use a separate contract-aware entry point,
`kernel_registry.get_attention_op(contract)`. It validates explicit TP/CP ownership, fixed
`(out, lse)` merge semantics, causal or packed-sequence offsets, and decode KV-cache identity
before selecting a backend. Legacy `get_op("attention")` behavior remains unchanged.

Existing WS1 implementations do not yet export attention-domain LSE or implement deterministic
CP merge, so they are declared incompatible with strict WS2 requests instead of being selected as
a silent fallback. See the
[WS2 CP-aware Attention contract in PR #236](https://github.com/RL-Align/RL-Kernel/blob/feat/issue-235-attention-cp-contract/docs/design/ws2-cp-attention-contract.md).

Split-KV is part of that contract rather than a recorded backend extra. Strict runs allow
`disabled` or a fixed logical KV chunk size, and must export the actual per-CP-owner block
boundaries, FP32 `(out, lse)` merge order, final downcast point, backend, and fallback reason.
Runtime-selected `auto` plans are diagnostic only unless both training and rollout export and
validate the same actual plan.

The rank-aware drift benchmark can emit a CPU smoke artifact or a torchrun-friendly GPU report:

```bash
python benchmarks/benchmark_ws2_cp_attention_drift.py --smoke --json
python benchmarks/benchmark_ws2_cp_attention_drift.py --smoke --tp-world-sizes 2 \
--cp-world-sizes 2 --kv-chunk-sizes none,1 --include-backward \
--output artifacts/ws2-cp-attention-drift.json
```

## Accuracy

Reference semantics (`forward_fp32`, fp32 accumulation, TF32/autocast disabled):
Expand Down
22 changes: 21 additions & 1 deletion rl_engine/kernels/gtest/operator_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def make_operator_inputs(
"matmul": _make_matmul_inputs,
"det_gemm": _make_det_gemm_inputs,
"attention": _make_attention_inputs,
"cp_attention": _make_attention_inputs,
"cp_attention": _make_cp_attention_inputs,
"logp": _make_logp_inputs,
"linear_logp": _make_linear_logp_inputs,
"batch_invariant_logp": _make_batch_invariant_logp_inputs,
Expand Down Expand Up @@ -177,6 +177,26 @@ def _make_attention_inputs(
return inputs


def _make_cp_attention_inputs(
args: argparse.Namespace, dtype: torch.dtype, device: torch.device
) -> dict[str, Any]:
batch, seq = _batch_seq(args)
return {
"q": _floating_tensor(
(batch, DEFAULT_N_HEADS, seq, DEFAULT_HEAD_DIM), args, dtype, device, 0
),
"k": _floating_tensor(
(batch, DEFAULT_N_KV_HEADS, seq, DEFAULT_HEAD_DIM), args, dtype, device, 1
),
"v": _floating_tensor(
(batch, DEFAULT_N_KV_HEADS, seq, DEFAULT_HEAD_DIM), args, dtype, device, 2
),
"causal": True,
"cp_world_size": 2,
"kv_chunk_size": max(1, seq // 2),
}


def _make_logp_inputs(
args: argparse.Namespace, dtype: torch.dtype, device: torch.device
) -> dict[str, Any]:
Expand Down
Loading
Loading