Repository navigation
Commit 59a595e
Add opt-in --paged-attention export for dense MLA (LATENT PagedAttention) [Slice 3B] (#599)
## Slice 3B — Mobius opt-in `--paged-attention` export (dense MLA,
LATENT)
Emits `com.microsoft::PagedAttention` v1 in **LATENT / absorbed-MLA**
mode for property-compatible **dense MLA** (DeepSeek-V2/V3, GLM-5.2
`--glm-full-attention`). Builds on the merged onnx-genai native runtime
contract: audit/typed-validator/oracle (#1940), KV index emission
(#1955), CUDA LATENT kernel (#1978).
### Guarantees
- **Default off.** Feature-off exports are **byte-identical** to the
current dense-MLA graph (all new code is gated behind the flag/task). A
byte-identical test locks this.
- **Property-based eligibility, never model names.** Decided from
semantic geometry: latent width, `v_head_size`, partial-RoPE suffix
(`rotary_offset = kv_lora_rank`), cache dtype (fp16/bf16), and the
onnx-genai-kv page/block constraints (head_size %8, kv_lora %8,
rotary_dim %16, rotary_offset %8, block pow2 ≥16).
- **Typed reject, never silent fallback.** Active query-dependent sparse
selection (GLM **DSA/IndexShare**, DeepSeek-V4 **CSA/HCA**), **MTP**,
**quantized cache**, **head_sink**, **qk-norm**, **sliding window** all
raise a typed reason at model construction / build. Feature-on with an
incompatible geometry errors. GLM's *vestigial* indexer config (dropped
under `--glm-full-attention`) does **not** reject.
- **One cache authority.** The op consumes/mutates caller-owned page
buffers in place; Mobius **allocates no pages** and creates no second
cache manager. `onnx-genai-kv` stays the sole authority. The graph binds
caller-owned `block_table` / `slot_mapping` / cumulative + past lengths
/ per-layer LATENT `key_cache`, aliases the cache in place, and derives
token positions from the length tensors (no `position_ids` input).
### Emitted contract
- One `PagedAttention` node per layer, `_domain="com.microsoft"`, LATENT
attrs (`kv_cache_layout=LATENT`, `kv_num_heads=1`, explicit `scale`,
`v_head_size=kv_lora_rank`, `rotary_offset=kv_lora_rank`,
`do_rotary=1`); `rotary_dim` is **derived** from `cos_cache`, never
emitted.
- Model inputs: `input_ids`, `block_table` (i32), `slot_mapping` (i32),
`cumulative_sequence_length` (i32), `past_seqlens` (i32), per-layer
`key_cache.{i}` `[num_blocks, block_size, 1, head_size]`. Outputs:
`logits`, `updated_key_cache.{i}` (aliases input).
- `kv_b_proj` is absorbed into the query/output projections at
weight-apply time; numeric contract mirrors the onnx-genai equivalence
oracle.
### Tests (same commit)
- **component** (`components/_paged_mla_test.py`): eligibility rejects,
absorption, numpy **decomposed-vs-absorbed LATENT parity** (rel < 1e-6),
structural emission.
- **model-level** (`models/paged_mla_export_test.py`): feature-off
byte-identical; feature-on structural + exact op
attrs/inputs/outputs/model IO; typed rejects (DSA/CSA/HCA/MTP/window);
torch-tensor weight absorption; DeepSeek-V3 path proves eligibility is
not name-gated.
- **CLI** (`tests/cli_test.py`): `--features paged-attention` plumbing +
task resolution + mutual-exclusion errors.
- Existing GLM / DeepSeek / task / build-graph tests pass unchanged.
### Scope / gates
- **No full-size performance claim.** Tiny correctness only. Native
runtime full-size verification is separate.
- Executing the emitted graph needs **ORT ≥ 1.29 CUDA** (contrib op is
unknown to the base onnx checker, so model-level assertions are
structural).
- Avoids #578 (GGUF preflight) and #591 (BQMoE) files.
**Draft — do not merge.** Independent review required (reviewer
excluding Leon/Sapper; Gaff or Roy final approval).
Co-authored-by: Copilot <[email protected]>
---------
Co-authored-by: Copilot <[email protected]>1 parent d16cd4a commit 59a595e
11 files changed
Lines changed: 1741 additions & 8 deletions
File tree
- src/mobius
- _configs
- components
- integrations/transformers
- models
- tasks
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
269 | 270 | | |
270 | 271 | | |
271 | 272 | | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
272 | 290 | | |
273 | 291 | | |
274 | 292 | | |
| |||
358 | 376 | | |
359 | 377 | | |
360 | 378 | | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
361 | 389 | | |
362 | 390 | | |
363 | 391 | | |
| |||
406 | 434 | | |
407 | 435 | | |
408 | 436 | | |
| 437 | + | |
409 | 438 | | |
410 | 439 | | |
411 | 440 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
503 | 503 | | |
504 | 504 | | |
505 | 505 | | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
506 | 512 | | |
507 | 513 | | |
508 | 514 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
210 | 228 | | |
211 | 229 | | |
212 | 230 | | |
| |||
0 commit comments