[WS2] Add CP-aware Attention contract and dispatch metadata #236
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR introduces a typed WS2 CP-aware attention contract, validates sharding, reduction, causal, packed-varlen, and KV-cache metadata, adds capability-aware registry dispatch with provenance, and documents and tests strict backend rejection behavior. ChangesWS2 attention contract and dispatch
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related issues
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@rl_engine/kernels/attention_contract.py`:
- Around line 403-420: Rename the loop-bound active_blocks variables in the
sequence consistency loop and the exclusive_page_owners loop to distinct names,
updating their references within each loop. Preserve the existing list-based
active_blocks binding and all validation and ownership logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: bb3bdb48-0e1e-4f2b-9707-bebdb8e47072
📒 Files selected for processing (6)
docs/design/runtime-dispatch.mddocs/design/ws2-cp-attention-contract.mddocs/operators/attention.mdrl_engine/kernels/attention_contract.pyrl_engine/kernels/registry.pytests/test_attention_contract.py
| object.__setattr__(self, "mode", _enum_value(AttentionMode, self.mode, "mode")) | ||
| object.__setattr__(self, "dtype", _enum_value(AttentionDType, self.dtype, "dtype")) | ||
| batch_size = _positive_int(self.batch_size, "batch_size") | ||
| _positive_int(self.query_sequence_length, "query_sequence_length") |
There was a problem hiding this comment.
Small contract gap: for prefill, should we reject cases where query_sequence_length doesn’t match sharding.local_sequence_length? Right now an inconsistent contract like query_sequence_length=2048 with local_sequence_length=1024 can still be constructed.
| global_token_positions = _integer_tuple( | ||
| self.global_token_positions, "global_token_positions" | ||
| ) | ||
| if not cache_positions or any(position < 0 for position in cache_positions): |
There was a problem hiding this comment.
Another small gap: cache_positions is only checked for shape/non-negativity, but not against global_token_positions. For decode identity, we probably want to reject cases like cache_positions=(999,) when the declared tokens are only 0..16.
Summary
Implements PR 1 of #235 by introducing the explicit WS2 contract and dispatch metadata for CP-aware deterministic standard softmax Attention.
This PR defines how TP/CP sharding, deterministic
(out, lse)reduction, packed sequences, and decode KV-cache identity must be described andvalidated before a backend can be selected.
Changes
AttentionContractShardingSpecReductionSpecKVCacheSpecAttentionBackendCapabilityKernelRegistry.get_attention_op()dispatch.Behavior
A valid Qwen3-8B
TP=4,CP=4, BF16 contract can now be represented and validated.Existing WS1 Attention backends are intentionally rejected for strict WS2 requests because they do not yet export attention-domain LSE or implement
deterministic CP
(out, lse)merge.Legacy
KernelRegistry.get_op()behavior is unchanged.Validation