Skip to content

perf(glm): price measured restore time in complete-checkpoint ready receipts - #1590

Closed
jonathan308 wants to merge 1 commit into
masterfrom
perf/glm-ready-stage-estimate
Closed

jonathan308 wants to merge 1 commit into
masterfrom
perf/glm-ready-stage-estimate

Conversation

@jonathan308

@jonathan308 jonathan308 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A complete-checkpoint ready receipt (prefix_cache_ready_v2.stage_ms) priced a future restore as the file's bytes at the 1.5 GB/s planning rate. A GLM-5.3-Flash restore takes about 0.9 s more than that on an M5 Ultra, so the receipt said a third to a half of the measured stage (qualification F3). The coordinator scores a holder with this value until a hit's measured lookup replaces it (Holder.StageCostAt), so it overstated the saving of short cached GLM prompts.

SSDCheckpointStageCost adds to the byte price an exponentially weighted average (newest weight 0.25) of how much longer this store's first-attempt restores took than their byte price. The first measured restore replaces the layout's prior: 935 ms for GLM5-Next (median of the nine qualification restores beyond their byte price), 0 for other layouts. A retried (shorter-endpoint) restore also paid for its refused first attempt and is not recorded.

Before

flowchart LR
    subgraph Before["Before: ready receipt for an 8,192-token GLM checkpoint (300.5 MB)"]
        direction LR
        b1(["durable write"]):::req --> b2["stage_ms = bytes ÷ 1.5 GB/s<br/>= 201 ms"]:::bad
        b2 --> b3["coordinator credit:<br/>prefill saved − 201 ms"]:::flow
        b4(["actual restore"]):::req --> b5["1.0–1.2 s"]:::check
    end
    classDef req fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
    classDef flow fill:#f3f4f6,stroke:#4b5563,color:#111827
    classDef check fill:#fef3c7,stroke:#b45309,color:#78350f
    classDef bad fill:#fee2e2,stroke:#b91c1c,color:#7f1d1d
Loading

After

flowchart LR
    subgraph After["After: SSDCheckpointStageCost per store"]
        direction LR
        a1(["durable write"]):::req --> a2["stage_ms = bytes ÷ 1.5 GB/s<br/>+ measured overhead"]:::good
        a3(["first-attempt restore<br/>(stage)"]):::req --> a4["overhead = elapsed − byte price<br/>first replaces the prior, then EWMA 0.25"]:::flow
        a4 --> a2
        a5["prior: GLM5-Next 935 ms,<br/>other layouts 0"]:::flow --> a2
        a2 --> a6["8,192-token GLM receipt ≈ 1.1 s<br/>(measured 0.9–1.2 s)"]:::good
    end
    classDef req fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
    classDef flow fill:#f3f4f6,stroke:#4b5563,color:#111827
    classDef good fill:#dcfce7,stroke:#15803d,color:#14532d
Loading

Linked issue

None; follow-up from the GLM-5.3-Flash cache qualification (finding F3).

Stacking: none. It targets master (9034a5a0f) and changes no SDK pin; it touches only the SSD store, not #1587's or #1589's files, so it merges independently of that stack (tested on top of #1589 as well). The GLM prior was measured on #1587's BF16 files; on 0.10.1's FP32 files the overhead was 1.0–1.3 s, and the first restore replaces the prior either way.

Evidence

M5 Ultra #1, real GLM-5.3-Flash, BF16 checkpoint files.

Qualification restores (old estimate vs measured, all 3 hits each):

File Old stage_ms New stage_ms (prior 935) Measured stage
2,048 tokens, 187.1 MB 125 1,060 1,043 / 960 / 1,130
8,192 tokens, 300.5 MB 201 1,136 1,136 / 1,147 / 1,170
30,720 tokens, 716.4 MB 478 1,413 1,095 / 1,383 / 1,431

Live, this commit's code (prior 935 ms) in a dev build with #1589 (M5 Ultra #1, 8,192-token files):

Receipt stage_ms sent Later measured restores
before any restore (prior) 1,136 first six hits: 885 / 1,006 / 1,016 / 1,018 / 1,011 / 1,022 (median 1,013)
after those six (learned) 985 14 later hits after ≥1 s idle: 750–1,020, median 995; 5 hits right after other GPU work: 92–96

Earlier dev builds of the same estimator with a 900 ms prior:

Receipt stage_ms sent Later measured restores of that file
8,192 tokens, before any restore (prior) 1,101 16 hits in sequence: 882–1,229 ms, median 1,088
8,192 tokens, after the first restore (870 ms) replaced the prior 871 1,043 / 1,044 / 1,056 / 1,054 / 1,215
32,512 tokens, learned 1,450 1,265 / 1,179 / 1,454
2,048 tokens, learned 1,000 1,127 / 1,175

What the fixed part is (stage phase timing, experiment build, 8,192-token file): manifest 2 ms, plan 0.7 ms, page allocation 0.9 s, stream/decrypt/copy 72–86 ms, finish 0.3 ms. Almost all of the allocation is the device zero-fill waiting on the GPU, and only when the GPU has idled: the same hit stages in 92–96 ms when it starts within about 0.6 s of other GPU work, 0.75–1.0 s after 1 s or more of idle, and 2.8 s while another request's 32k prefill holds the engine. The wake is not restore work: on the same build a novel 2k prompt's cold TTFT is 2.10–2.15 s after 16 s idle and 1.18 s right after a 49-token request, which itself takes 1.1 s after idle. The estimate cannot know which case the next restore lands in; the EWMA follows the provider's recent restores.

Test plan

  • New SSDCheckpointStageCostTests: layout priors and the exact GLM estimate (201 + 935 ms for the 8,192-token file); the first sample replaces the prior and later ones average in at 0.25; a stage faster than its byte price counts as no overhead; zero bytes, NaN and negative samples are ignored; the protocol ceiling holds. A store's ready receipt prices a first-attempt restore of 600 ms on an injected stage clock at 600 ms, and ignores a retried restore (both arguments).
  • Provider debug test build (M3 Ultra, staged metallib, isolated state files), this commit applied on top of perf(glm): capture GLM prefix checkpoints beside decoding requests #1589: swift test --skip-build --no-parallel --filter 'SSD|PrefixCache|Checkpoint|GLM5Next|Demanded|EngineV2Factory' (runner-isolated suites and the fixture-dependent MiMoV26DiscoveryLoadFootprintTests skipped): Swift Testing 753 tests in 151 suites passed; XCTest 4 executed, 1 skipped, 0 failures.
  • ./scripts/docs-check.sh (196 OK), python3 scripts/docs-impact-check.py --base origin/master (OK), python3 scripts/changelog.py check.

Components touched

  • provider-swift (Swift CLI)
  • native runtime / MLX
  • landing (Next.js)
  • enclave (Swift)
  • CI / provider release
  • docs

Protocol / interface changes

  • No protocol/interface changes. stage_ms keeps its unit, range and clamp (PrefixCacheReadyResult.maxStageMs); only its value is closer to the measured restore.

Documentation impact

  • Canonical documentation updated: docs/reference/ssd-kv-cache.md (ready stage estimate row), changelog.d/glm-ready-stage-estimate.md.

Merge Danger

Door: two-way. No persisted state; a restart starts again from the prior.

Blast Radius: SSD-complete-checkpoint receipts. Other layouts start from a zero prior, so their receipts are unchanged until the store stages a file; after that they also include measured overhead. Attention-block SSD receipts (SSDPrefixCache) are untouched.

Limitations

  • One store-wide average: a provider that alternates between idle and busy restores gets an estimate between the two (0.1 s warm vs 1.1 s idle vs 2.8 s under another request's prefill).
  • The byte part still uses the 1.5 GB/s planning rate; a warm GLM restore streams at about 3 GB/s, so very large files stay overestimated.
  • The fixed second is the GPU's first work after idling, not restore work, and is not cut here (see Evidence). A cold prefill on an idle provider pays it too, so pricing it into stage_ms matches what the coordinator measures after a hit, but understates the cache's advantage over a cold prefill on the same idle provider.

Refactor pass

Done: no change was needed, and the head stays 3260db104.

Reviewed and kept:

  • SSDCheckpointStageCost is one small, lock-guarded type with one job: the byte price plus the moving average of measured overhead. The prior, and the rule that the first sample replaces it (observed), are explicit, and its clamp matches estimatedStageMillisDouble.
  • The store records a restore at the one place a stage succeeds (stage), and only on the first attempt. publishReady is the only reader, and no other receipt path changes.
  • priorOverheadMilliseconds(backendLayout:) has the same kind of layout switch as perf(glm): capture GLM prefix checkpoints beside decoding requests #1589's write-queue depth. This PR targets master independently, so the two cannot share a helper without stacking.
  • The test file's import MLX matches the sibling SSDShorter* suites, whose fixtures it reuses.

Validation on 3260db104 itself, with master's SDK pin 6148b6da. The earlier evidence above ran it on top of #1589.

  • Setup: M3 Ultra, debug test build with the staged source-matched metallib. State was isolated, and CFFIXED_USER_HOME pointed at a temp dir. ~/.darkbloom/usage-history.json was byte-identical before and after.
  • swift test --skip-build --no-parallel --filter 'SSD|PrefixCache|Checkpoint|GLM5Next|Demanded|EngineV2Factory|Receipt', skipping the runner's fresh-process suites and the MiMo XCTests that need fixtures:
    • Swift Testing: 771 tests in 157 suites passed, including SSDCheckpointStageCostTests.
    • XCTest: 8 executed, 5 opt-in skips, 0 failures.
  • Fresh processes: SSDShorterNativeBlockRestoreTests, SSDNativeCheckpointOracleTests and stageDelta passed.
  • With DARKBLOOM_TEST_GLM5_PROTECTED_FACTORY=1, GLM5NextProtectedFactoryTests|GLM5NextEncryptedCheckpointTests|GLM5NextProviderLoopTests: 14 tests in 3 suites passed.
  • ./scripts/docs-check.sh (196 OK), python3 scripts/docs-impact-check.py --base origin/master (OK), python3 scripts/changelog.py check (2 valid) and python3 scripts/test-docs-impact-check.py (OK).
  • No real-model run, because nothing changed.

…eceipts

A complete-checkpoint ready receipt priced a future restore as its file
bytes at the 1.5 GB/s planning rate. GLM-5.3-Flash restores take about
0.9 s more than that on an M5 Ultra, mostly the device's first work
after idling, so the receipt said 478 ms for a 716 MB checkpoint that
restored in 1.1-1.4 s and 125 ms for a 187 MB one that took 1.0-1.1 s.
The coordinator scores a holder with this value until a hit's measured
lookup replaces it, so it overstated the saving of short cached GLM
prompts.

SSDCheckpointStageCost adds to the byte price an exponentially weighted
average (newest weight 0.25) of how much longer this store's first-attempt
restores took than their byte price; a retried restore also paid for its
refused first attempt and is not recorded. The first restore replaces
the layout's prior: 935 ms for GLM5-Next, the median of the nine
qualification restores beyond their byte price; 0 for other layouts, so
their receipts are unchanged until they stage a file.

With this estimator (prior 900 ms in that build), 8,192-token GLM ready
receipts said 1,101 ms against 16 measured restores of 882-1,229 ms
(median 1,088 ms) on the M5 Ultra.

Tests: SSDCheckpointStageCostTests (layout priors and the exact GLM
estimate, replace-then-average updates, invalid samples, the protocol
ceiling, and a store's ready receipt after a first-attempt and a retried
restore on an injected stage clock).
@vercel

vercel Bot commented Oct 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
d-inference Ready Ready Preview Oct 24, 2026 10:03am UTC
d-inference-console-ui-dev Ready Ready Preview Oct 24, 2026 10:03am UTC
d-inference-landing Ready Ready Preview Oct 24, 2026 10:03am UTC
darkbloom-status Ready Ready Preview Oct 24, 2026 10:03am UTC
eigen-homepages-darkbloom Ready Ready Preview Oct 24, 2026 10:03am UTC

Request Review

jonathan308 added a commit that referenced this pull request Oct 24, 2026
…features

Queue up to six SSD prefix-cache writes (SSDPrefixCachePolicy.
writeQueueMaxJobs = 6, was 2) for both writers: attention blocks
(SSDWriteBehind) and complete checkpoints (SSDHybridCheckpointStore,
whose gate and writer buffer now both use the constant). Approved head
78c904a.

Owner decision: one shared write-queue depth for every model. #1589's
GLM-only depth is folded into #1584's constant:
- SSDHybridCheckpointStore+Write.swift (conflict): the prepareWriteJob
  gate is #1584's writing.count < writeQueueMaxJobs (six unsettled jobs,
  the one being written included), not #1589's per-store
  writing.count <= config.writeQueueJobs.
- SSDHybridCheckpointStore.swift (conflict): #1590's stage-cost
  initializer, then #1584's comment and writer buffer
  (capacity: writeQueueMaxJobs). #1589's Config.writeQueueJobs is removed.
- SSDHybridCheckpointStoreFactory.swift / SSDPrefixCachePolicy.swift:
  #1589's GLM override (glm5NextCompleteCheckpointWriteQueueJobs = 8,
  completeCheckpointWriteQueueJobs(backendLayout:)) and its MLXLMCommon
  import are removed.
- docs/reference/ssd-kv-cache.md (conflict): #1584's attention and
  complete-checkpoint queue rows; #1589's GLM-only row is dropped.
- changelog.d/glm-capture-under-load.md: the eight-deep GLM queue bullet
  is dropped (ssd-write-queue-six-jobs.md states the shared depth).
- Tests: #1589's SSDCheckpointWriteQueueTests (GLM 8 / others 1 and a
  three-deep store) is removed; #1584's fleet-priority and
  writer-buffer tests cover the shared bound. The fixture loses #1589's
  writeQueueJobs parameter, and GLM5NextProtectedFactoryTests now checks
  that the GLM store's writer buffer is the shared writeQueueMaxJobs.

#1589's capture-boundary partition and GLM adopters' ordinary chunking
are unchanged.
@jonathan308

Copy link
Copy Markdown
Collaborator Author

Superseded by #1592; consolidated per owner request

@jonathan308 jonathan308 mentioned this pull request Oct 24, 2026
6 of 10 tasks
jonathan308 added a commit that referenced this pull request Oct 25, 2026
Set ProviderCore.version to 0.10.2 and render the v0.10.2 changelog
entry from the 27 fragments added since v0.10.1, ordered by theme behind
an upgrade and rollout section: Nemotron 3.5 Super prefix caching
(#1586, #1588); GLM-5.3-Flash prefix caching (#1587, #1589, #1590);
4-bit SSD checkpoints and the SSD prefix cache on every model (#1592
(mlx-swift-lm#363), #1584, #1592); Logprobs on Nemotron 3.5 Super and
GLM-5.3-Flash (#1564); OpenRouter compatibility: GLM-5.3-Flash and
MiMo-V2.6-Flash requests no longer refused (#1585, #1592); Speed: MTP
and throughput (#1592 (mlx-swift-lm#360), #1593 (mlx-swift-lm#357),
#1595 (mlx-swift-lm#359), #1594, #1595, #1598 (mlx-swift-lm#362),
#1594); Provider diagnostics: refusal reasons and load memory (#1592,
#1603); MLX stack (#1596); Desktop release workflow (#1580). Apply 12
corrections reviewed against the code. #1580 is already in the v0.10.1
tag but merged after the 0.10.1 preparation, so its fragment is rendered
here.

Mark v0.10.1 as published on 2026-10-24. Record in the provider release
runbook the SDK pin check, the enablement order (darkbloom-platform#464
before any catalog logprobs change, the GLM allowlist tuple, then both
models' logprobs after the rollout and Super's tuple after a signed
restart check), the platform evidence and the published history. No tag,
registration, upload, deployment or enablement is performed.
jonathan308 added a commit that referenced this pull request Oct 25, 2026
Set ProviderCore.version to 0.10.2 and render the v0.10.2 changelog
entry from the 27 fragments added since v0.10.1, ordered by theme behind
an upgrade and rollout section: Nemotron 3.5 Super prefix caching
(#1586, #1588); GLM-5.3-Flash prefix caching (#1587, #1589, #1590);
4-bit SSD checkpoints and the SSD prefix cache on every model (#1592
(mlx-swift-lm#363), #1584, #1592); Logprobs on Nemotron 3.5 Super and
GLM-5.3-Flash (#1564); OpenRouter compatibility: GLM-5.3-Flash and
MiMo-V2.6-Flash requests no longer refused (#1585, #1592); Speed: MTP
and throughput (#1592 (mlx-swift-lm#360), #1593 (mlx-swift-lm#357),
#1595 (mlx-swift-lm#359), #1594, #1595, #1598 (mlx-swift-lm#362),
#1594); Provider diagnostics: refusal reasons and load memory (#1592,
#1603); MLX stack (#1596); Desktop release workflow (#1580). Apply 14
corrections reviewed against the code. #1580 is already in the v0.10.1
tag but merged after the 0.10.1 preparation, so its fragment is rendered
here.

Mark v0.10.1 as published on 2026-10-24. Record in the provider release
runbook the SDK pin check, the enablement order (darkbloom-platform#464
before any catalog logprobs change, the GLM allowlist tuple, then both
models' logprobs after the rollout and Super's tuple after a signed
restart check), the platform evidence and the published history. No tag,
registration, upload, deployment or enablement is performed.
Gajesh2007 pushed a commit that referenced this pull request Oct 25, 2026
Set ProviderCore.version to 0.10.2 and render the v0.10.2 changelog
entry from the 20 fragments added since v0.10.1, ordered by theme behind
an upgrade and rollout section: Nemotron 3.5 Super prefix caching
(#1586, #1588); GLM-5.3-Flash prefix caching (#1587, #1589, #1590);
4-bit SSD checkpoints and the SSD prefix cache on every model (#1592
(mlx-swift-lm#363), #1584, #1592); Logprobs on Nemotron 3.5 Super and
GLM-5.3-Flash (#1564); GLM-5.3-Flash OpenRouter request controls (#1585,
#1592); Speed: MTP and throughput (#1592 (mlx-swift-lm#360), #1593 (mlx-
swift-lm#357), #1595 (mlx-swift-lm#359), #1594, #1595, #1598 (mlx-swift-
lm#362), #1594); Provider diagnostics (#1592); MLX stack (#1596);
Desktop release workflow (#1580). Apply 12 corrections reviewed against
the code. #1580 is already in the v0.10.1 tag but merged after the
0.10.1 preparation, so its fragment is rendered here.

Mark v0.10.1 as published on 2026-10-24. Record in the provider release
runbook the SDK pin check, the enablement order (darkbloom-platform#464
before any catalog logprobs change, the GLM allowlist tuple, then both
models' logprobs after the rollout and Super's tuple after a signed
restart check), the platform evidence and the published history. No tag,
registration, upload, deployment or enablement is performed.

Co-authored-by: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com>

This branch was successfully deployed

5 active deployments
Preview – d-inference — 3260db10 Deployed Oct 24, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — 3260db10 Deployed Oct 24, 2026 by vercel[bot]
Preview – d-inference-landing — 3260db10 Deployed Oct 24, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — 3260db10 Deployed Oct 24, 2026 by vercel[bot]
Preview – darkbloom-status — 3260db10 Deployed Oct 24, 2026 by vercel[bot]
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