Skip to content

r40-integration: dsv41 runtime + slot-sampler reuse on strix/master - #273

Closed
baraxnaxgaming-commits wants to merge 6 commits into
halo-box:masterfrom
baraxnaxgaming-commits:r40-integration
Closed

baraxnaxgaming-commits wants to merge 6 commits into
halo-box:masterfrom
baraxnaxgaming-commits:r40-integration

Conversation

@baraxnaxgaming-commits

Copy link
Copy Markdown

Summary

Rebases the 6 commits from opt/set-sampler-noreserve-strix onto current master (169 commits, tip Nov 10) — clean rebase, no conflicts.

  • DeepSeek V4.1 support (3 commits): converter (DeepseekV41ForCausalLM), runtime (engram + hyper-connections + sparse attention, from vcruz305 runtime/deepseek41), unity-build linkage fixes (shared dsv4 helpers, separate TUs for deepseek4/glm5-next, dsv4_view_2d kept out of models.h)
  • server: reuse slot samplers across requests to avoid sched_reserve rebuilds

Validation (halo-A, Nov 9)

  • HIP Release build clean (build 12344 @ 8eeb54cde)
  • gate-r40 (CAP trio -ngl 999 --parallel 1 -c 65536, graphs off, Ornith-1.5-35B-Q8_0 — Q8_0 decode is the path the merged MMVQ/gate-re-base commits touch):
    • r37 baseline: 45.44 / 45.88 t/s
    • r40-integration: 47.12 / 47.06 t/s (+2.6–3.7%)
    • greedy parity (temp 0, seed 42): byte-identical both runs
  • Smoke: 8 chat requests across varied temperature/top_p/seed; t=0.0 requests before/after varied-param requests byte-identical → no sampler state leak across slot reuse

…tention) from vcruz305 runtime/deepseek41

Ported 5210c7c..runtime/deepseek41 (16 commits, C++ only). One conflict resolved
in llama-kv-cache-dsv4.cpp: kept our GGML_TYPE_F16 forcing for the indexer KV cache
(fused indexer kernels read f16 only) while taking their V4.1 filter_lid/reuse_lid
layer-sharing wiring and ratio_kv.

(cherry picked from commit 1815db8)
…builds

- llama_context::set_sampler: re-registering the same sampler pointer is now
  a no-op (graph inputs hold the pointer; backend_init asserts !is_init)
- common_sampler_reuse(): in-place re-init when the effective sampling config
  is unchanged (params equality gate + grammar/rbudget rebuild + reset),
  keeping the chain pointer stable for graph reuse
- server load_task: try sampler reuse before rebuilding; unregister old
  sampler only on mode flips; slot release no longer unregisters (fixes the
  double-reserve trap: reset+load cost two sched_reserve passes per request)

A/B (stories260K, -bs, identical back-to-back requests): baseline reserves on
every request (7 reserve passes), patched reserves only on cold start and on
actual param changes (5 total). Identical-request latency 21.5-23.3ms -> 15.1-16.5ms.

(cherry picked from commit 81ba428488c3651a158e6a4ec938b11fd8f39013)
deepseek41.cpp relied on unity-batch ordering to see deepseek4.cpp's
dsv4_rope_attn_factor / dsv4_build_state_{restore,snapshot} and the
extern dsv4_view_2d. Adding the file shifts the batch so deepseek4.cpp
and glm5-next.cpp share a TU, where glm5-next's file-static
dsv4_view_2d collides with the extern definition (-fpermissive error).

Declare the shared helpers explicitly in deepseek41.cpp and use a local
dsv41_view_2d copy instead of declaring dsv4_view_2d extern, so the
file compiles in any unity grouping.
deepseek4.cpp's extern dsv4_view_2d and glm5-next.cpp's file-static one
collide (-fpermissive) whenever a batch shift puts them in the same TU.
Excluding both from unity build makes the grouping deterministic.
glm5-next.cpp has a file-static dsv4_view_2d and includes models.h, so
the shared extern declaration collides in every TU (extern declared,
static defined). deepseek41.cpp uses its own local copy; deepseek4.cpp
defines-before-use. No header declaration is needed.
@Nathanw1014

Copy link
Copy Markdown

Hi @baraxnaxgaming-commits, thanks for this, and welcome! DeepSeek V4.1 support and cheaper sampler setup are both things we want, so it's great to see them come in.

We'd like to land them a bit differently:

DeepSeek V4.1: let's take it from upstream. ggml-org/llama.cpp merged V4.1 support in ggml-org#31086, which superseded the vcruz305 branch this PR is ported from (ggml-org#28696). We'd rather bring that in with an upstream sync than carry a separate port, so the two versions don't drift apart. If you want to help, testing V4.1 on Strix Halo once it lands would be really useful.

One thing we hit while testing this branch: the change to the layer-reuse check in src/llama-kv-cache.cpp stops Gemma 3n / Gemma 4 from loading. Their shared-KV layers have no KV of their own, so they get skipped and never mapped. With gemma-4-E2B, context creation fails with unordered_map::at; master loads the same file fine. Taking V4.1 from upstream makes this go away.

Could you split these into their own PRs on master?

  1. Slot sampler reuse (server: reuse slot samplers across requests). Nice idea, and the reuse check is careful. Two small things before it goes in:
    • When the request asks for no probabilities (n_probs == 0) and temperature is 0, common_sampler_init builds a greedy sampler, but n_probs isn't part of the reuse check. A later request with n_probs > 0 and post_sampling_probs then reuses the greedy sampler and gets empty top_probs. Adding n_probs to the check should fix it.
    • common_sampler_reuse resets the sampler chain but doesn't reseed gsmpl->rng, the random generator speculative decoding uses to accept or reject draft tokens. With a fixed seed, two identical requests can then differ when drafting is on. Reseeding it the same way common_sampler_init does would fix it.
  2. The Q1_0 quantization recipe in src/llama-quant.cpp. It changes how every model quantizes at Q1_0, so it's easier to review and measure on its own.

On measurements: the decode numbers in the description compare two builds of your own branch. Our contributing guide asks for a comparison against the PR's merge-base on master, so for the sampler PR a before/after on master would be ideal. Running the server with backend sampling on would show the effect best, since without it the reserve this PR saves wasn't happening anyway.

Thanks again, and happy to help if anything here is unclear.

@baraxnaxgaming-commits

Copy link
Copy Markdown
Author

Thanks for the thorough review — all three points confirmed against the code on my side:

  • Gemma 3n / Gemma 4 breakage: reproduced the mechanism. The !hparams.has_kv(il) gate came in with the vcruz305 dsv41 runtime port (needed for its filter_lid/reuse_lid layer sharing). Gemma shared-KV layers have n_layer_kv_from_start-based sharing, so has_kv() is false for them and they never get mapped into map_layer_ids → .at() throws. Taking V4.1 from upstream removes the gate entirely.
  • n_probs: right — it selects greedy vs dist in common_sampler_init, so it's not runtime-only. Added to the reuse check.
  • rng: right — common_sampler::reset() only resets the chain; gsmpl->rng (the mt19937 used for spec-decode draft accept/reject) was not reseeded. Now reseeded in common_sampler_reuse exactly as common_sampler_init seeds it.

Split as requested:

DeepSeek V4.1: dropped from this PR — will come in with an upstream sync of ggml-org#31086. Happy to test V4.1 on Strix Halo (gfx1151, 128GB) once it lands on master.

Measurements: acknowledged on the merge-base comparison — #274/#275 will carry before/after against the PR merge-base on master (backend sampling on for the sampler PR), posted as comments.

Closing this in favor of #274 + #275.

@baraxnaxgaming-commits

Copy link
Copy Markdown
Author

Superseded by #274 (sampler reuse) and #275 (Q1_0 recipe); DeepSeek V4.1 will land via upstream sync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants