You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Parent work item: P2 — Decode context to 1M, block size 32
Summary
Enable elastic 1M-context decode for models/deepseek_v4_flash_dspark/ while preserving the existing DeepSeek-V4-Flash attention math and the deployment point defined by #905 (B=64, S=8, block size 32).
Here, 1M is a capacity ceiling, not a fixed execution shape. Runtime work must follow the actual visible context of each request. Short requests must not allocate or submit 1M-sized attention/indexer work, and 128/16K/1M must not become separate kernel profiles.
Goals
Make block size 32 the canonical decode cache ABI.
Support per-request logical positions and cache capacity up to 1,048,576 tokens.
Preserve heterogeneous and inactive requests through ragged runtime metadata.
Enable all three decode attention modes:
SWA / ratio 0
HCA / ratio 128
CSA / ratio 4 with exact Top-512
Keep production attention structure as close to the existing baseline as possible; long-context support should primarily change metadata, persistent-cache addressing, and the amount of submitted work.
Current-step KV participates causally through the overlay and is committed to the persistent ring only after attention has finished reading the old rows.
Contexts from 128 through 1M use the same 128-row attention tile and persistent capacity.
HCA (ratio 128)
A 1M request produces at most 8,192 compressed rows.
Attention uses fixed 128-row shards; the runtime submits 0–64 shards per query from exact packed work.
The ratio-128 state ring retains 128 semantic rows using sixteen 8-row state pages.
Compressed KV uses ragged 32-row pages and explicit page epochs.
Boundary compression events use event-local RoPE and explicit main/state write dependencies.
Raw SWA history plus compressed HCA history are merged with online softmax; no dense history index or topk_all tensor is allowed.
Runtime submits only ceil(valid_candidates / 2048) active leaves (0–128 per query), followed by a bounded exact merge forest.
Main KV, index cache, main state, and inner state use independent allocator-owned pools.
Index cache remains a flat-row ABI; candidate/page work is ragged and exact.
Preserve the baseline HC/QKV/compressor/sparse-value structure. If micro-chunking is required for the selector forest, confine it to the indexer work instead of repeating the full attention pipeline.
Standalone fixtures, golden functions, trace-only CLI options, and historical compatibility aliases are validation scaffolding. They should not remain in the final production attention modules after correctness and performance validation has been transferred to tests.
Acceptance criteria
Static and host checks
All public tensor ABIs have at most five dimensions.
No production ABI contains a full 1M RoPE table, dense 1M block table, or fixed max-work tensor per request.
Page/range/epoch/write-slot validation rejects stale, missing, aliased, inactive, and out-of-range metadata.
Separate 128/16K/1M kernel profiles or compatibility with the old dense 16K cache ABI.
Increasing PyPTO's maximum tensor dimension as a workaround.
Completion definition
This issue is complete when all three standalone attention paths use block-32 ragged cache metadata, execute the exact work implied by heterogeneous runtime lengths up to 1M, pass their existing numerical thresholds, and have no remaining production dependency on the old dense 16K ABI.
Parent tracking issue
Summary
Enable elastic 1M-context decode for
models/deepseek_v4_flash_dspark/while preserving the existing DeepSeek-V4-Flash attention math and the deployment point defined by #905 (B=64,S=8, block size 32).Here, 1M is a capacity ceiling, not a fixed execution shape. Runtime work must follow the actual visible context of each request. Short requests must not allocate or submit 1M-sized attention/indexer work, and 128/16K/1M must not become separate kernel profiles.
Goals
Required design
Common geometry and metadata
MAX_CONTEXT_TOKENS = 1_048_576.[1M, ...]RoPE table.SWA (ratio 0)
swa_sources[Q, 128]represents persistent rows, invalid rows, and current-step overlay rows.HCA (ratio 128)
topk_alltensor is allowed.CSA (ratio 4)
ceil(valid_candidates / 2048)active leaves (0–128 per query), followed by a bounded exact merge forest.Production code scope
Primary files:
models/deepseek_v4_flash_dspark/config.pymodels/deepseek_v4_flash_dspark/context_geometry.pymodels/deepseek_v4_flash_dspark/decode_metadata.pymodels/deepseek_v4_flash_dspark/decode_compressor_ratio128.pymodels/deepseek_v4_flash_dspark/decode_compressor_ratio4.pymodels/deepseek_v4_flash_dspark/decode_indexer_compressor.pymodels/deepseek_v4_flash_dspark/decode_indexer.pymodels/deepseek_v4_flash_dspark/decode_indexer_topk.pymodels/deepseek_v4_flash_dspark/decode_sparse_attn_swa.pymodels/deepseek_v4_flash_dspark/decode_sparse_attn_hca.pymodels/deepseek_v4_flash_dspark/decode_sparse_attn_csa.pymodels/deepseek_v4_flash_dspark/decode_swa.pymodels/deepseek_v4_flash_dspark/decode_hca.pymodels/deepseek_v4_flash_dspark/decode_csa.pyStandalone fixtures, golden functions, trace-only CLI options, and historical compatibility aliases are validation scaffolding. They should not remain in the final production attention modules after correctness and performance validation has been transferred to tests.
Acceptance criteria
Static and host checks
Device correctness
Work and trace evidence
Non-goals
Completion definition
This issue is complete when all three standalone attention paths use block-32 ragged cache metadata, execute the exact work implied by heterogeneous runtime lengths up to 1M, pass their existing numerical thresholds, and have no remaining production dependency on the old dense 16K ABI.