Repository navigation
Commit 0f1fc0c
feat(deepseek-v4): default-off native CompressedSparseAttention (HCA ratio-128) export [C1, DRAFT] (#593)
## Summary
**Slice C1** of the DeepSeek-V4-Flash CSA/HCA custom-kernel path. Adds a
**default-off, property-gated** Mobius exporter feature that emits the
already-merged frozen `pkg.nxrt::CompressedSparseAttention` v1 op
(**ratio-128 "Heavily Compressed Attention"** subset) for
property-matching layers, replacing the zero-valued *shape-anchor*
preservation with **real op dataflow** and **threaded compressed state
IO**.
This is **exporter-only**. No onnx-genai runner/KV changes; **no
PagedAttention-compatibility claim**.
Design: `deckard-deepseek-v4-csa-hca-cuda-slice.md` (§5 property ABI, §8
tiny-test spec, §10 C1 slice).
## What changed
- **`mobius.models._deepseek_v4_csa`** (new): `plan_native_csa` property
gate + `emit_hca_attention` op emission. The gate matches native-op
**properties** (compression ratio, block size, head/latent/rope dims,
dtype, carry planes), **not** a model-name/shape allowlist.
- **`ArchitectureConfig.native_csa: bool = False`** — export-time opt-in
(no HF equivalent; `config_overrides={"native_csa": True}`).
- **`DeepSeekV4Attention._forward_native_hca`** — emits the 11-input /
3-output op with pre-rotated `query`/`current_kv` (dense sliding-window
ring over the existing dense KV IO), real *unrotated* compressor
activations, f32 casts for the f32-cache-format op inputs, and threaded
`past_*`/`present_*` compressed state. The shared inverse RoPE + output
projection run unchanged on `Y`.
- **`DeepSeekV4Task`** — threads deterministic `past_compressed_kv.{i}`
/ `past_compression_carry.{i}` inputs and `present_*` outputs (explicit
shapes, since the custom op has no Python shape inference), with a
**dynamic record axis** and **fixed carry planes** so present state
chains back into past inputs for **≥16 decode steps**.
## Fail-closed (never silent dense)
Requesting native CSA for **ratio-4 CSA**, an **MTP** layer,
**quantized** compressor weights, or an **unknown ratio** raises
`NativeCsaExportError`. Ratio-0 dense layers and feature-off
legitimately return `None` (dense) — those are not a suppressed
fallback.
## Off = byte-identical
With the feature off, the exported graph is **byte-identical** to the
existing dense correctness export (verified) and emits **zero `pkg.nxrt`
ops / no compressed IO**.
## Tests (shape-faithful / structural — no weight download, no ORT run)
The frozen op has no Python shape inference and no Rust EP in the Python
env, so tests assert structure: exact op attrs + 11/3 IO, threaded
compressed-state IO names/shapes/dtypes, decode chainability, **f32
inputs under a FLOAT16 model dtype** (GLM DSA precedent), **no dead
anchor** for the HCA layer, byte-identical disabled baseline,
defaults-off + opt-in, and typed rejects (ratio-4 / quantized / MTP /
unknown-ratio). Existing DeepSeek-V4 tests unchanged.
Local validation (this env):
- `deepseek_v4_flash_test.py` + `deepseek_v4_test.py`: **30 passed**
- `_configs`/`tasks`/`glm_moe_dsa` related tests: **168 passed**
- `ruff check` + `ruff format --check`: clean
## Scope / non-goals
- ❌ No onnx-genai runner or KV/cache changes (later slice).
- ❌ No PagedAttention-compatibility claim.
- ❌ ratio-4 learned-indexer/top-k selection is a follow-up slice.
## Status
**DRAFT — stop for independent review. Do not merge.** CI is async;
local tests above are the validation of record.
---------
Co-authored-by: Copilot <[email protected]>1 parent 59a595e commit 0f1fc0c
5 files changed
Lines changed: 2045 additions & 43 deletions
File tree
- src/mobius
- _configs
- models
- tasks
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
25 | 29 | | |
26 | 30 | | |
27 | 31 | | |
| |||
494 | 498 | | |
495 | 499 | | |
496 | 500 | | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
497 | 512 | | |
498 | 513 | | |
499 | 514 | | |
| |||
626 | 641 | | |
627 | 642 | | |
628 | 643 | | |
629 | | - | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
630 | 654 | | |
631 | 655 | | |
632 | 656 | | |
| |||
969 | 993 | | |
970 | 994 | | |
971 | 995 | | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
972 | 1001 | | |
973 | 1002 | | |
974 | 1003 | | |
| |||
1197 | 1226 | | |
1198 | 1227 | | |
1199 | 1228 | | |
1200 | | - | |
1201 | | - | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
1202 | 1251 | | |
1203 | 1252 | | |
1204 | 1253 | | |
| |||
0 commit comments