Skip to content

spark-model: carry remaining DFlash2 batched-propose fixes to main - #64

Merged
AzeezIsh merged 5 commits into
mainfrom
lane/dflash2-batch-fixes
Sep 24, 2026
Merged

AzeezIsh merged 5 commits into
mainfrom
lane/dflash2-batch-fixes

Conversation

@AzeezIsh

Copy link
Copy Markdown
Contributor

Summary

Carries the five DFlash2 commits that shipped on c8b88c6 (the integration lane) but never reached main — the last code delta between the lane and main in the DFlash path:

  • 2e678d887 — spark-server respects the head's batched-propose envelope for DFlash
  • 34e427b3c — order DFlash front-region copies on the default stream
  • 14b3cabe7 — enable multi-lane batched propose for generic DFlash (ATLAS_DFLASH_PROPOSE_LANES)
  • 594422770 — cap deferred DFlash drafts + suppress lane-graph capture
  • b59d6b7e4 — admit DFlash gamma-shaped rows to batched verify

These are what make ATLAS_DFLASH_PROPOSE_LANES (already plumbed in product_policy.rs) actually do something on main, and restore the lane's batched-verify envelope after the #52/#60 subset merge.

Test plan

  • GB10 merged-main DFlash2 concurrency sweep (C1/C4/C8/C16) — thermally-valid run pending in job 233; this PR is expected to close any residual gap vs the lane's 37/48 tok/s cells
  • cargo check -p spark-model -p spark-server clean

AzeezIsh and others added 5 commits September 24, 2026 12:33
verify_dflash_batch_step consulted only mtp_propose_batch_min, so a
generic DFlash head (propose_batch_max = 1 — the Lightning Bxgamma seam
is the served-gamma=4 product contract) got called every step, errored
on the contract gate, and paid an error round-trip to reach the serial
fallback. Gate on batch_cap >= batch_min the same way
verify_k4_batch_step already does, and widen the else arm to propose
every pending sequence serially — it previously handled only
pending.first(), which would have stranded the rest once the batch call
was skipped.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
(cherry picked from commit 2e678d8)
The batched DFlash commit loop exposed a latent stream-ordering bug:
preserve/pack/restore_dflash_save_front honored the scheduler's literal
`0` stream arg, which lands on the CUDA legacy default stream, while the
capture that writes the owner regions and the commit_ctx that reads the
front both run on the model's NON_BLOCKING default stream. Stream 0 does
not serialize with a non-blocking stream, so commit_ctx could read the
front before the pack landed — handing each non-owner-0 sequence another
sequence's (or stale) hidden stack, poisoning ctx_hidden_acc. Acceptance
decayed with batch width and over time exactly as that race predicts;
owner-slot-0 rows stayed healthy because region 0 IS the front.

The path was unreachable before the envelope admitted k=gamma rows, so
the helpers were never exercised live. Fix model-side per the file's
convention (commit_ctx, save_hidden_for_mtp, stash_verify_hidden_rows all
ignore the boundary arg and use self.gpu.default_stream()): the copies
must be ordered with the capture writer and commit_ctx reader, which are
always on the default stream.

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
(cherry picked from commit 34e427b)
propose_batch ran the Lightning Bxgamma seam (owners collection,
DsparkBatchInput::validate, packed uploads, staged backbone) before every
dispatch — and its gamma == LIGHTNING_SERVED_GAMMA (4) contract rejected
generic gamma=8 heads outright, so the multi-lane tail was unreachable
for non-Lightning models even with ATLAS_DFLASH_PROPOSE_LANES > 1.

Generic DFlash never consumes the seam's staged result (the native rows
are only authoritative under native_batch_authoritative / batch_parity),
so skip the seam entirely for generic heads and dispatch straight to the
per-lane enqueue/collect path. propose_batch_max now reports
batch_capacity when lane_count() > 1, letting the scheduler's
cap >= min gate admit batched calls; the single-lane serial arm is
unchanged. propose_on_lanes is the extracted tail, verbatim.

(cherry picked from commit 14b3cab)
Two multi-lane propose fixes exposed by the lanes=4 sweep:

- forward_block(defer_readback=true) returns Vec::new(), so the draft
  cap in propose_drafts_on_lane ran on an empty vec and the deferred
  readback handed verify all γ rows uncapped — an 8-draft / 9-token
  verify window vs pools sized for K=8 (7 h / 8 conv intermediates).
  decode_verify_dflash refused every multi-lane seq. read_deferred_drafts
  now takes the scheduler-K cap; last_num_drafted is set from the
  collected drafts.
- Piecewise graph capture on a lane stream (lane 0 IS the default
  stream) leaks capture mode when any op between begin/end fails —
  every subsequent unrelated-stream op then fails CAPTURE_ISOLATED and
  every sync on the capturing stream fails 900. Suppress propose graphs
  under defer_readback; multi-lane stays eager until per-lane capture
  ownership is proven safe.

(cherry picked from commit 5944227)
can_batch_verify_dispatch self-gated on the MTP ladder shape (ks in
2..=4) and rejected DFlash outright (dflash_hidden_save.is_none()), so
every DFlash chunk silently fell back to per-sequence verify — verify
cost scaled linearly in batch width and the concurrency sweep stayed
flat (~25 tok/s at C=1/4/8/16, TPOT 35->538ms). The selector fix could
not help; the batched path was never entered.

- verify_batch_ks_ok: shared row-shape predicate for the gate and the
  dispatch ensure! — ladder 2..=4 on the non-DFlash envelope, k <=
  dflash_hidden_save_rows (gamma) with n <= dflash_hidden_save_nseq on
  the DFlash envelope. VERIFY_ROW_CAP=96 still applies, so gamma=8
  chunks cap at 12 seqs via mtp_dcut::chunk_ranges.
- decode_verify_batched_dispatch now calls try_dflash_capture_batched_at
  per capture layer, keyed on each sequence's immutable dspark owner
  slot (never batch position) so the deferred batched propose reads the
  accepted row's hiddens.
- CUDA-graph capture is vetoed on the DFlash lane: capture destinations
  are owner-slot regions, which are not a function of the (ssm_slot, k)
  graph key and survive slot reuse — a replayed graph could write a dead
  generation's regions. Eager batched forward still collapses the
  per-seq weight reads; owner-aware replay is follow-up.

WY-table upload still only spans k in 2..=4, so k=8 GDN layers take the
per-seq WY fallback inside decode_verify_multi; weight-bearing ops stay
batched. Widening the table is a measured follow-up.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
(cherry picked from commit b59d6b7)
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