Skip to content

fix(dspark): reduce V2 working VRAM#27

Open
alexbi29 wants to merge 7 commits into
jasl:codex/ds4-sm120-min-enablefrom
alexbi29:codex/ds4-vram-kv-cleanups
Open

fix(dspark): reduce V2 working VRAM#27
alexbi29 wants to merge 7 commits into
jasl:codex/ds4-sm120-min-enablefrom
alexbi29:codex/ds4-vram-kv-cleanups

Conversation

@alexbi29

@alexbi29 alexbi29 commented Jul 3, 2026

Copy link
Copy Markdown

Summary

Reduces DeepSeek V4 / DSpark V2 working VRAM and increases usable KV cache on the 2x SM120 DSpark serving config.

Main changes:

  • Skip the target MTP hidden-state staging buffer unless the speculative method is actually mtp.
  • Reuse one C128A top-k backing buffer for decode + prefill metadata rows.
  • Let DSpark V2 skip DFlash's persistent context hidden-state staging tensor.
  • Avoid reserving the packed-cache padded-Q scratch when n_local_heads == padded_heads; in that case the fused qnorm/RoPE/KV-insert op can write Q in place.
  • For SM120 packed C128 prefill, map local top-k indices to global KV slots in place once per step and reuse the global view across layers. This removes a full-context runtime temporary/conversion launch; it does not change the KV profile line.
  • Fuse final MHC post-processing paths so DSpark/target finalization no longer materializes [T, hc, H] just to produce hc_head output and Eagle aux means.
  • Reuse the previous MHC residual buffer for large-token fused post/pre transitions when the old residual is dead, avoiding an additional [T, hc, H] allocation.
  • Reuse the dead MHC layer input as the next fused post/pre output buffer, removing one 64 MiB BF16 [T, H] profile allocation per rank without changing kernel math or launch count.
  • Keep DSpark probabilistic rejection logits in a persistent graph-written buffer. A current-step dense handoff was tested but backed out because DSpark drafting is CUDA-graph replayed; Python reassignment does not run per replay and caused lower acceptance/TPS.

Live memory result

Measured on 2x RTX PRO 6000 Blackwell / SM120, TP=2, DSpark V2, GMU 0.975, max model len 524288.

State KV memory KV tokens Max concurrency
baseline before this cleanup 10.54 GiB 1,095,149 2.09x
after MTP-buffer cleanup 10.79 GiB 1,121,196 2.14x
after in-place Q cleanup 11.05 GiB 1,147,140 2.19x
after C128 SM120 prefill in-place global indices 11.05 GiB 1,147,140 2.19x
after fused MHC final/aux captures 11.30 GiB 1,173,083 2.24x
after MHC residual-buffer reuse 11.55 GiB 1,199,131 2.29x
after MHC input-buffer reuse 11.61 GiB 1,205,591 2.30x

Net from baseline: +1.07 GiB available KV and +110,442 KV tokens.

Validation

  • git diff --check, targeted py_compile passed.
  • Prototype checkout: tests/v1/spec_decode/test_dspark_config.py, test_rejection_sampler_utils.py, test_dspark.py passed (48 passed).
  • Clean PR27 fold worktree: config + rejection sampler tests passed (30 passed).
  • Direct DSpark serve smoke: 7*8 -> 56.
  • Live reload on the PR27 head confirmed the 11.55 GiB available KV, 1,199,131 KV tokens, 2.29x concurrency profile.
  • Concurrency probe, 12 requests, temp=0, thinking=false: 5,986 output tokens in 9.30s, 643.5 tok/s aggregate, draft accept rate 0.4683, mean AL 3.341.
  • 2026-07-09 current-step draft-logits A/B: persistent graph-written draft logits restored acceptance/TPS. Warm decode run: avg 309.2 tok/s, median 310.9, range 304.7-311.4, versus current-step post-JIT baseline median 297.7.
  • Same A/B prefill run: 6106 / 8004 / 7710 / 6369 tok/s at 1K / 4K / 16K / 65K prompt sizes.
  • Coherency smoke: 17 + 25 -> 42.
  • Clean PR worktree fixup tests after restoring persistent draft logits:
    • tests/v1/spec_decode/test_dspark_config.py -> 2 passed
    • test_dense_draft_logits_index_mapping_matches_state_indexed and test_gumbel_sample_stores_processed_logits_inplace -> 2 passed
  • 2026-07-10 MHC input-reuse validation: focused CUDA gate 20 passed; deployed profile 11.61 GiB / 1,205,591 tokens / 2.30x; warm decode A/B 307.6 vs 307.5 tok/s; final deployed warm median 310.0 tok/s; coherency 17 + 25 -> 42.
  • Deployed concurrent decode (max_tokens=500, temperature=0, thinking off): c=2 275.7 aggregate tok/s (52.95% draft accept), c=4 393.2 tok/s (55.07%), c=8 577.9 tok/s (56.92%).
  • Deployed long-context decode-only TPS (2048 output tokens, temperature 1.0): 32,783-token prompt median 286.5 tok/s; 65,539-token prompt median 287.9 tok/s; both ~7% below the 310.0 tok/s short-context median with no further 64K degradation.

@alexbi29
alexbi29 force-pushed the codex/ds4-vram-kv-cleanups branch 4 times, most recently from 32fdb44 to d82b645 Compare July 7, 2026 23:53
@alexbi29
alexbi29 force-pushed the codex/ds4-vram-kv-cleanups branch 2 times, most recently from 65d2885 to 40f1d12 Compare July 14, 2026 00:56
alexbi29 added 7 commits July 17, 2026 23:01
dspark_inv_rope_bf16_layout and dspark_markov_greedy_argmax (and the two
Triton kernels backing the latter) have no production callers anywhere in
the tree; the live draft path uses the BF16 WO_A projection and the fused
probabilistic Markov sampler (dspark_markov_probs_sample). Drop the dead
wrappers, kernels, and their standalone tests.
@alexbi29
alexbi29 force-pushed the codex/ds4-vram-kv-cleanups branch from ced1c66 to 92d4c2b Compare July 17, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant