Skip to content

perf(glm): capture GLM prefix checkpoints beside decoding requests - #1589

Closed
jonathan308 wants to merge 4 commits into
feat/glm-bf16-ssd-checkpointsfrom
perf/glm-capture-under-load
Closed

jonathan308 wants to merge 4 commits into
feat/glm-bf16-ssd-checkpointsfrom
perf/glm-capture-under-load

Conversation

@jonathan308

@jonathan308 jonathan308 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

GLM-5.3-Flash now caches a repeated prompt that is prefilled while other requests decode. Before, such a donor captured no checkpoint and nothing counted it (one of six donors in the qualification's concurrent burst). GLM captures only at prefill range ends on the 256-token grid, and its prefill chunk shares one 2,048-token step budget with the decode rows of other requests, so with company every range was 2,044–2,047 tokens and never ended on the grid.

  • Bumps libs/mlx-swift-lm 184b5a93 → 2231b8fc (perf(cbv2): capture GLM checkpoints beside decoding requests mlx-swift-lm#355): an opt-in scheduler partition ends a cacheable donor's range on its demanded boundaries, and GLM adopters resume under ordinary chunking.
  • The protected GLM engine with its GLM store turns the partition on at the store floor (EngineV2Factory.demandedCaptureBoundaryMinimumTokens).
  • A GLM store holds eight donations behind its writer instead of one (SSDPrefixCachePolicy.completeCheckpointWriteQueueJobs, set through SSDHybridCheckpointStore.Config.writeQueueJobs). Once every donor captures, donors that finish together overflowed the single slot: two donors finishing within 27 ms lost both of one donor's files as write_queue_full. Other layouts keep one.

The same cut lowers GLM's reuse granularity from 2,048 to 256 tokens (qualification F5).

Before

flowchart TB
    subgraph Before["Before: six GLM donors sent together"]
        direction TB
        b1(["6 repeated 8k prompts"]):::req --> b2["one 2,048 step budget;<br/>decode rows shorten each prefill range to 2,044–2,047"]:::flow
        b2 --> b3["5 of 6: no range end on the 256 grid<br/>no checkpoint, no counter"]:::bad
        b2 --> b4["1 of 6 prefilled alone: captured"]:::good
        b4 --> b5{"SSD store: 1 queued write"}:::check
        b5 -- "two donors finish together" --> b6["write_queue_full: files dropped"]:::bad
        b5 -- "alone" --> b7["written; next sighting hits"]:::good
    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 good fill:#dcfce7,stroke:#15803d,color:#14532d
    classDef bad fill:#fee2e2,stroke:#b91c1c,color:#7f1d1d
Loading

After

flowchart TB
    subgraph After["After: six GLM donors sent together"]
        direction TB
        a1(["6 repeated 8k prompts"]):::req --> a2["EngineV2Factory: GLM engine + GLM store →<br/>demandedCaptureBoundaryMinimumTokens = store floor"]:::flow
        a2 --> a3["each donor ends a range on 8,192<br/>(whatever chunk company left it)"]:::good
        a3 --> a4["6 of 6 captured"]:::good
        a4 --> a5{"GLM store: 8 queued writes<br/>(other layouts: 1)"}:::check
        a5 --> a6["6 of 6 written; ready receipts;<br/>every next sighting hits"]:::good
    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 good fill:#dcfce7,stroke:#15803d,color:#14532d
Loading

Linked issue

None; follow-up from the GLM-5.3-Flash cache qualification (findings F4, F5).

Stacking: based on #1587's head after its refactor pass, b2d77d6ef (git merge origin/feat/glm-bf16-ssd-checkpoints: already up to date). libs/mlx-swift-lm points at 2231b8fc = Layr-Labs/mlx-swift-lm#355, one commit on #353's refactored head 184b5a93, so the pin contains both. Merge order: #353 → #355, #1587 → this PR. No code file overlaps #1587 or #353; three docs files that #1587's refactor also edited (prefix-cache.md, inference.md, ssd-kv-cache.md) change here in different sections.

Evidence

M5 Ultra #1, real GLM-5.3-Flash weights, dev builds of this branch's code against a loopback coordinator with cache routing (isolated provider state; the signed install stayed stopped). "Before" is the qualification of #1587.

Measure Before After
Six distinct 8k donors sent together (after first sightings): captured 1/6 (A/B), 2/6 (run 1) 6/6 in three runs
… written and hit on their next sighting 1/6 6/6 with the 8-deep queue; 5/6 with one slot (2 × write_queue_full, twice)
32,682-token donor publishes 2,048 + 30,720 2,048 + 32,512
Hit TTFT for that prompt (suffix 1,962 → 170 tokens) 3.96 s median 3.1–3.7 s
10,678-token hit (restores 8,192) beside two decoding requests adopter forced to a 2,048 chunk hit, 3 ranges (max 2,046), 0 preemptions, captured its own 10,496

Correctness was judged on state, not text: per-tensor SHA-256 of the written checkpoints and per-layer diffs of their plaintext. Solo donors of one prompt write bit-identical checkpoints across runs and scopes. A donor prefilled beside decoding requests differs from the solo reference from its first partial four-token KDA group on (relative L2 ~0.1 in the deepest layers), and first-token logprobs of three partitions spread over ~0.1 nat while each partition repeats exactly. GLM's cold prefill already depends on the partition its company produces, as the MoE Qwen's does; a checkpoint is bit-exactly what its donor computed. Tables are in Layr-Labs/mlx-swift-lm#355.

The write_queue_full drops: in the single-slot runs the donor that prefilled alone (two files) and another donor finished within 27 ms; the other donor's job still sat in the one-slot buffer when the solo donor's two jobs arrived, so both were refused (prefix_cache_donation_outcomes: donated 8, write_queue_full 2). donation_drops_total does not count these, which is why the qualification saw zero drops.

Test plan

  • Provider debug test build with the bumped SDK (M3 Ultra, staged metallib 156f2624…, isolated state files): swift test --skip-build --no-parallel --filter 'SSD|PrefixCache|Checkpoint|GLM5Next|Demanded|EngineV2Factory', skipping the runner's isolated suites. Swift Testing: 750 tests in 150 suites passed. XCTest: 6 executed, 1 skipped, 1 failure in MiMoV26DiscoveryLoadFootprintTests, which needs MIMO_V26_SERIAL_LOAD_FIXTURES (MiMo fixture recipe not prepared; unrelated).
  • DARKBLOOM_TEST_GLM5_PROTECTED_FACTORY=1, GLM5NextProtectedFactoryTests|GLM5NextEncryptedCheckpointTests|SSDCheckpointWriteQueueTests: 11 tests in 3 suites passed (tiny synthetic GLM through the real protected factory with the partition on, and the encrypted GLM store).
  • New SSDCheckpointWriteQueueTests: four donations finishing together queue behind a blocked writer and a fifth settles write_queue_full; it times out against the old two-in-flight gate. The existing two-writer test (SSDCheckpointFleetWritePriorityTests) still passes for the default depth.
  • SDK: 82 XCTest cases, 0 failures (perf(cbv2): capture GLM checkpoints beside decoding requests mlx-swift-lm#355).
  • ./scripts/docs-check.sh (196 OK), python3 scripts/docs-impact-check.py --base origin/feat/glm-bf16-ssd-checkpoints (OK), python3 scripts/changelog.py check (3 valid).
  • M5 Ultra DGInf: Decentralized private AI inference platform #1 on this head's code (dev build 591f03fa… = 40a1fd544 + perf(glm): price measured restore time in complete-checkpoint ready receipts #1590's estimator; 5f326a737 only rewords a comment): six concurrent 8k donors 6/6 captured and written; prefix_cache_donation_outcomes donated 8 (six 8,192 files + two 2,048), skipped_novel 12 (first sightings), no write_queue_full; all six checks hit at 8,192 (stage 885–1,022 ms, TTFT 1.43–1.59 s). Production files on DGInf: Decentralized private AI inference platform #1 were restored and match the pre-run snapshot.

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. Receipts, usage and telemetry fields are unchanged; GLM ready receipts can now name any 256-token boundary at or above the 1,024 floor, which the v2 checkpoint mode already accepts.

Documentation impact

  • Canonical documentation updated: docs/architecture/prefix-cache.md (GLM capture partition, partition dependence), docs/architecture/inference.md (GLM scheduler), docs/reference/ssd-kv-cache.md (complete-checkpoint write queue), changelog.d/glm-capture-under-load.md.

Merge Danger

Door: two-way. Reverting restores the old geometry and queue; the checkpoint format and namespace are unchanged.

Blast Radius: GLM-SSD-cache. Only the protected GLM engine with a GLM store sets the partition, and only GLM stores get the deeper queue. A queued GLM donation keeps its donor's pages and KDA copies charged to the admission ledger until its write settles, so a burst of finishing donors can hold their KV for up to about eight writes (~0.15–0.3 s each) before the pages return; the bridge's slot gate counts only active requests, so new requests wait in engine admission for that time rather than being refused.

Limitations

  • GLM still admits one partial prefill at a time: a hit that arrives during another request's 32k cold prefill waited 15.3 s. Scheduler policy, not changed here.
  • Requests with logprobs and reasoning_effort: none were cut but never donated in these runs. Probably no MTP assistant state for the capture on those rows; not investigated.
  • The partition changes a donor's own prefill partition (see above); this follows the MoE Qwen precedent rather than proving invariance.

Refactor pass

Done, in two signed commits. The provider code, the tests and the changelog fragment are unchanged.

  • 3e0b8a08a (docs): the GLM capture paragraph of prefix-cache.md named two SDK files by bare file name, which docs-check cannot verify. It now cites them by path with their symbols: libs/mlx-swift-lm/Libraries/MLXLMCommon/ContinuousBatchingV2/Prefix/EngineV2+CompleteCheckpoint.swift (completeCheckpointLookup) and …/Prefix/DemandedShortCheckpointRange.swift, as the neighbouring paragraphs and docs rule 4 do.
  • 0c3b31d85 (pin): libs/mlx-swift-lm moves 2231b8fc → 723dbdaa, the refactor pass of perf(cbv2): capture GLM checkpoints beside decoding requests mlx-swift-lm#355. That pass moves CBv2DemandedCaptureBoundaryTests into the SDK's unit tests and adds two doc comments. No library code changes. This supersedes the 2231b8fc cited above.

Reviewed and left as is:

  • EngineV2Factory.demandedCaptureBoundaryMinimumTokens is next to the other demanded-checkpoint policies.
  • SSDHybridCheckpointStore.Config.writeQueueJobs sets both the pipeline capacity and the in-flight gate. At the default depth of 1, writing.count <= writeQueueJobs is the same check as the old < 2.
  • The layout switch in SSDPrefixCachePolicy.completeCheckpointWriteQueueJobs is the only one of its kind in this stack.

Validation on 0c3b31d85:

  • Setup: M3 Ultra, debug test build with the bumped SDK and the staged source-matched metallib. Daemon, loaded-model and verified-weights state were 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:
    • Swift Testing: 771 tests in 157 suites passed.
    • XCTest: 8 executed, 5 opt-in skips, 0 failures.
    • The Receipt term also selects two MiMo XCTest cases (MiMoV26NativeLoadTransactionTests, MiMoV26ServingLoadTests). They failed with fixtureRequired because the MiMo fixture recipe was not prepared, which is unrelated to this PR, as with MiMoV26DiscoveryLoadFootprintTests. The XCTest rerun skipped them.
  • Fresh processes: SSDShorterNativeBlockRestoreTests (2), SSDNativeCheckpointOracleTests (2) and stageDelta (1) passed.
  • With DARKBLOOM_TEST_GLM5_PROTECTED_FACTORY=1, GLM5NextProtectedFactoryTests|GLM5NextEncryptedCheckpointTests|GLM5NextProviderLoopTests|SSDCheckpointWriteQueueTests: 16 tests in 4 suites passed.
  • ./scripts/docs-check.sh (196 OK), python3 scripts/docs-impact-check.py --base origin/feat/glm-bf16-ssd-checkpoints (OK), python3 scripts/changelog.py check (3 valid) and python3 scripts/test-docs-impact-check.py (OK).
  • No real-model run, because no runtime code changed: the SDK delta is tests and comments.

GLM-5.3-Flash captures a complete checkpoint only at a prefill range end
on the 256-token grid, and its prefill chunk shares one 2,048-token step
budget with the decode rows of other requests. Beside a decoding request
every range was 2,044-2,047 tokens, so a donor served with company
captured nothing, with no counter: one of six donors in the
qualification burst was cached.

Bump libs/mlx-swift-lm 184b5a93 -> 2231b8fc (Layr-Labs/mlx-swift-lm#355):
an opt-in scheduler partition ends a cacheable donor's range on its
demanded boundaries (fork target, deepest aligned boundary below the
prompt end), and GLM adopters resume under ordinary chunking instead of
waiting for a donor-sized chunk and cold-restarting after three waits.
The protected GLM engine with its GLM store enables the partition at the
store floor (EngineV2Factory.demandedCaptureBoundaryMinimumTokens).

With every donor capturing, donors that finish together overflowed the
store's single write slot: on an M5 Ultra two donors finishing in the
same millisecond lost both of one donor's files as write_queue_full. A
GLM store now holds eight donations behind its writer
(SSDPrefixCachePolicy.completeCheckpointWriteQueueJobs, set through
SSDHybridCheckpointStore.Config.writeQueueJobs); other layouts keep one.
A queued donation pins only its donor's pages and KDA copies, which stay
charged to the admission ledger until the write settles.

M5 Ultra #1, real weights: six concurrent 8k donors 6/6 captured and
written (was 1/6); a 32,682-token prompt publishes 32,512 instead of
30,720 (hit TTFT 3.1-3.7 s, was 3.96 s); a hit beside two decoding
requests restores with no preemption.

Tests: SSDCheckpointWriteQueueTests (depth by layout; four donations
queue behind a blocked writer and a fifth settles write_queue_full), the
partition stays GLM-only (Nemotron policy suite), and the GLM protected
factory asserts the partition floor and the queue depth.
@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 11:28am UTC
d-inference-console-ui-dev Ready Ready Preview Oct 24, 2026 11:28am UTC
d-inference-landing Ready Ready Preview Oct 24, 2026 11:28am UTC
darkbloom-status Ready Ready Preview Oct 24, 2026 11:28am UTC
eigen-homepages-darkbloom Ready Ready Preview Oct 24, 2026 11:28am UTC

Request Review

The two donors whose finishing lost both of one donor's files to the
single write slot finished within 27 ms of each other, not in the same
millisecond (M5 Ultra burst, harness wire log).
The GLM capture paragraph of prefix-cache.md named two SDK files by bare
file name, which docs-check cannot verify. Cite them by repository path
with their symbols (completeCheckpointLookup, demandedCaptureBoundaryRange),
as the neighbouring paragraphs and docs rule 4 do. No content change.
…-swift-lm#355

libs/mlx-swift-lm moves 2231b8fc -> 723dbdaa. The refactor pass moves
CBv2DemandedCaptureBoundaryTests into the SDK's unit tests and documents
the capture-boundary partition's precedence and grid; no library behavior
changes.
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 — 0c3b31d8 Deployed Oct 24, 2026 by vercel[bot]
Preview – d-inference-console-ui-dev — 0c3b31d8 Deployed Oct 24, 2026 by vercel[bot]
Preview – d-inference-landing — 0c3b31d8 Deployed Oct 24, 2026 by vercel[bot]
Preview – eigen-homepages-darkbloom — 0c3b31d8 Deployed Oct 24, 2026 by vercel[bot]
Preview – darkbloom-status — 0c3b31d8 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