Skip to content

serve: a third warm-up on speculating backends (n_predict 2) moves the last-token layout build (~5.6 GB, up to 10 s) to load - #2485

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-hrxmem/warmup-spec-last-step
Nov 15, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-hrxmem/warmup-spec-last-step

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

On a backend that speculates (--mtp, a model's own MTP head, --dflash), 1bit serve now sends a third warm-up request: the same 16-token /completion prompt with n_predict 2. It moves a one-time host layout build out of a client request and into load time. The shipped pair is unchanged, and the second request still does not sample (engine#1539).

Why

A speculating llama-server decodes the last token of a request without a draft: get_n_draft_max() is n_remaining - 1, which is 0 on that token. That one step runs the plain one-token decode program. The first time it runs, ggml-hrx builds the host layout that program reads for any weight the verify pass reads in another layout.

On Qwen3.8-27B Q4_K_M with its own MTP head, those are the mixed layers' Q6_K ffn weights. They show up as 76 HRX weight residency ... layouts={q6k-packed-k256-row64-scalerow, ggml-native} lines, about 5.6 GB. GGML_HRX_HOST_WEIGHT_TRACE=2 names the readers: ggml_mul_mat_f32_f32_wmma and ggml_mul_mat_add_f32_f32_wmma from the 994-command plain decode program.

Without a warm-up, this lands in whichever client request first ends on such a step. That depends on the request's acceptance pattern, which is deterministic under greedy decoding, so on one prompt set it hit 4 of 4 servers of one build and 2 of 6 of another. It was a large part of the run-to-run spread in tonight's DECODE-BW measurements.

The alternative was to not pack for that step (read the stored copy). That costs ~5 % in plain --no-mtp serving, where the same stored copy exists, so it was measured and parked.

Change

  • app/serve.cpp: warmup_requests(bool speculative) adds warmup_spec_body() (warmup_short_body() with n_predict 2) when the launch speculates (Launch::mtp).
    • Both warm_backend call sites and the --print-backend plan pass the flag.
    • ONEBIT_WARMUP=spec selects this request alone, for the same kind of bisect as long/short.
    • --print-backend leaves warmups out when the selection is empty, rather than printing [].
  • docs/serve.md: a "Why the 2-token request" paragraph, and spec added to ONEBIT_WARMUP.
  • tests/print_backend.sh: three new checks.
    • An own-MTP plan carries three warm-ups, the third ('/completion', 2, 16).
    • ONEBIT_WARMUP=spec on it sends only that one.
    • spec on a plan without a drafter sends none.

Evidence (strixhalo gfx1151, one gpu-hold ticket; Qwen3.8-27B Q4_K_M, its own MTP head; same llama-server for both arms, fork 1bit/hrx-vulkan-patched + llama.cpp#392, gpu-kernels 2022afb74)

1bit warm-up requests (ms) duplicate-layout lines at ready after one perf.py pass perf.py decode_tps / _2k
this branch chat 4333, /completion (0) 562, /completion (2) 2681 78 78 23.65 / 22.55
current main build chat 3117, /completion (0) 484 2 78 (made inside a perf request) 22.01 / 21.22
  • Ready time was 14 s against 9 s. In an earlier run the same 2-token request took 10.4 s and made the same 76 copies, so the load-time cost varies with the box.
  • The client-side cost it removes is that same build: one request in the server's life that would otherwise pay it.
  • A 2-token request sent by hand after the current warm-up (run33) gave the same result: 2 -> 78 at that request, then a clean perf.py pass of 23.55 tok/s.
  • tests/print_backend.sh: 42 ok on this branch. The current main 1bit fails exactly the three new checks.
  • 1bit serve --print-backend plans:
    • own MTP head: 3 warm-ups;
    • --no-mtp: 2, unchanged;
    • ONEBIT_WARMUP=spec: 1 on the MTP plan, none without a drafter.

🤖 Generated with Claude Code

…e last-token layout build to load

A speculating llama-server decodes the last token of a request without a draft, so that step runs the
plain one-token decode program, and its first run builds host layouts the verify pass does not use.
On Qwen3.8-27B Q4_K_M with its own MTP head that is 76 Q6_K ffn weights, ~5.6 GB, 10.4 s, inside
whichever client request first ends on such a step. A 16-token /completion with n_predict 2 makes
that step at load. Only plans that speculate (--mtp, own MTP head, --dflash) carry it; the shipped
pair is unchanged and the second request still does not sample (engine#1539).
ONEBIT_WARMUP=spec selects it alone. tests/print_backend.sh: three new checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bong-water-water-bong bong-water-water-bong added the hw-gate Run the HRX hardware gate on Strix Halo (docs/hw-gate.md) label Nov 15, 2026
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Warm-up selection logic

The warmup_selection function now supports a new option "spec" which enables the third speculative warm-up request. However, the logic for handling unrecognized values in warmup_requests may not correctly handle all edge cases, particularly when the environment variable ONEBIT_WARMUP is set to a value that is not explicitly handled, potentially leading to unexpected behavior.

static json warmup_requests(bool speculative) {
    // An unrecognised value is the shipped set, not "none": a typo must not quietly disable a warm-up that moves a
    // measured 2 s off the client's first request. Normalised here so a caller cannot see the two states differently.
    std::string sel = warmup_selection();
    if (sel != "long" && sel != "short" && sel != "spec" && sel != "none") sel = "both";
    const bool want_chat  = sel == "both" || sel == "long";
    const bool want_short = sel == "both" || sel == "short";
    const bool want_spec  = speculative && (sel == "both" || sel == "spec");
    json out = json::array();
    if (want_chat)  out.push_back(json{ { "path", kWarmupPath },    { "body", warmup_body() } });
    if (want_short) out.push_back(json{ { "path", "/completion" },  { "body", warmup_short_body() } });
    if (want_spec)  out.push_back(json{ { "path", "/completion" },  { "body", warmup_spec_body() } });
    return out;
Speculative warm-up request

The new speculative warm-up request (n_predict 2) is added conditionally based on the backend's speculation capability. It's important to ensure that this request is only sent when the backend actually speculates, as indicated by the l.mtp flag, to avoid unnecessary overhead or incorrect behavior.

const bool want_spec  = speculative && (sel == "both" || sel == "spec");
json out = json::array();
if (want_chat)  out.push_back(json{ { "path", kWarmupPath },    { "body", warmup_body() } });
if (want_short) out.push_back(json{ { "path", "/completion" },  { "body", warmup_short_body() } });
if (want_spec)  out.push_back(json{ { "path", "/completion" },  { "body", warmup_spec_body() } });

@bong-water-water-bong
bong-water-water-bong enabled auto-merge (squash) November 15, 2026 04:38
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT: READY 2485

A third warm-up request only where speculation is active is the right shape: the cost is paid by the configurations that benefit (a drafter whose first tokens are unrepresentative of steady state), and nothing is added to the plain path.

Two things worth confirming:

  1. the warm-up requests are distinguishable in the log from real traffic — a serve that emits three identical 16-token completions at startup should say why, or the next person reading a log will count them as user requests;
  2. n_predict 1 on the third request is enough to exercise the drafter — the claim is that the drafter's first invocation is the unrepresentative one, so the request should be the smallest that provably enters it. If that was measured, one line saying so settles it; if it is assumed, it is the kind of assumption that quietly stops being true when the drafter changes.

And a documentation point: docs/serve.md is touched, which is right — startup timing is user-visible, and a serve that takes three round trips longer to become ready should say so there rather than only in code.

@bong-water-water-bong
bong-water-water-bong merged commit be3d7f0 into main Nov 15, 2026
10 of 12 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-hrxmem/warmup-spec-last-step branch November 15, 2026 04:48

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at 12e892a: READY

The third warm-up is selected exactly when the backend speculates, it does not touch the slot cache, and the test fails without it. Checked on git merge-tree origin/main 12e892a in a host build of onebit:

ctest -R ^print_backend$                                         Passed
mutant: want_spec forced false in warmup_requests(), rebuilt:    ***Failed

So the new print_backend.sh arm sees whether the spec warm-up is selected.

What I checked in the code:

  • "Speculates" covers all three drafters. warmup_requests(l.mtp) and warm_backend(…, b.mtp) key on mtp, and l.mtp = true is set for --mtp, --dflash and a model's own MTP head, all in the same branch (serve.cpp ~1242–1245). So the "(--mtp, an own MTP head, --dflash)" claim holds; --dflash is not left out.
  • It does not reopen #1539. The new body is warmup_short_body() plus n_predict 2: temperature 0 and cache_prompt false, so it samples greedily and leaves nothing in the slot cache. The sampling warm-up was already the long chat request, and the shipped pair is byte-for-byte unchanged.
  • ONEBIT_WARMUP=spec on a non-speculating backend yields an empty list. out["warmup"] / out["warmups"] are then left unset rather than set to an empty element, and the code comment says so.

Not re-measured by me: the ~5.6 GB / 10.4 s layout build moving to load time, and the 23.55 tok/s next pass. That is a device run on the 27B, and I have no ticket for it. The mechanism, get_n_draft_max() = n_remaining - 1 = 0 on the last token, is the right reason a 2-token request reaches the plain decode step. The ci build is green, and the branch is level with main.

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

Labels

hw-gate Run the HRX hardware gate on Strix Halo (docs/hw-gate.md) Review effort 3/5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant