From 96b32a689502d58d8aab31b7ef80c6008b11199e Mon Sep 17 00:00:00 2001 From: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com> Date: Sat, 24 Oct 2026 00:34:58 -0700 Subject: [PATCH 1/4] perf(glm): store GLM-5.3-Flash SSD checkpoints at BF16 Bump mlx-swift-lm to 39a12e1d (Layr-Labs/mlx-swift-lm#353): GLM complete checkpoints write the latent keys, the index/gate/validity values row and the KDA convolution history at their BF16 activation dtype and widen them back to the identical FP32 bits on restore; the FP32 KDA recurrent state is unchanged and any value BF16 cannot hold refuses the donation. The layout becomes native-paged-glm5next-full-state-v2 (new namespace; v1 files expire through the whole-root TTL sweep). Measured on an M5 Ultra against the v0.10.1 build: checkpoints at 2,048 / 8,192 / 30,720 tokens shrink 18 / 33 / 42 %, bytes per token 48 %, SSD bytes for an identical workload 30 %, and restore stage 25-29 %. Document the v2 layout and sizes in the SSD reference and prefix-cache architecture pages. --- changelog.d/glm-bf16-ssd-checkpoints.md | 4 +++ docs/architecture/inference.md | 11 ++++++- docs/architecture/prefix-cache.md | 12 +++++-- docs/reference/ssd-kv-cache.md | 43 +++++++++++++++++++++---- libs/mlx-swift-lm | 2 +- 5 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 changelog.d/glm-bf16-ssd-checkpoints.md diff --git a/changelog.d/glm-bf16-ssd-checkpoints.md b/changelog.d/glm-bf16-ssd-checkpoints.md new file mode 100644 index 0000000000..e75b2dd48c --- /dev/null +++ b/changelog.d/glm-bf16-ssd-checkpoints.md @@ -0,0 +1,4 @@ +### Half-size GLM SSD checkpoints + +- GLM-5.3-Flash complete checkpoints now write the latent keys, the index/gate/validity rows and the KDA convolution history at their BF16 activation dtype instead of the FP32 copies the live pool keeps, and widen them back to the same FP32 bits on restore. The accumulated KDA recurrent state stays FP32. A 30,720-token checkpoint drops from 1.24 GB to 0.72 GB (per token 35.4 KB → 18.5 KB), so each donation queues, writes and charges the daily SSD write budget for 18-48 % fewer bytes, a restore stages about 25 % faster on an M5 Ultra, and prompts up to the full 262K context fit the large-memory staging cap. +- The export refuses any value BF16 cannot represent exactly, so a restore is never lossy. The layout is now `native-paged-glm5next-full-state-v2`; existing v1 files sit in a different namespace and expire through the normal TTL sweep. Providers lose their warm GLM checkpoints once on upgrade. diff --git a/docs/architecture/inference.md b/docs/architecture/inference.md index 789ae97bb6..a4a4376649 100644 --- a/docs/architecture/inference.md +++ b/docs/architecture/inference.md @@ -1,6 +1,6 @@ # Provider inference engine -> Last updated: 2026-10-23 +> Last updated: 2026-10-24 How a chat-completion request is served inside the `darkbloom` provider process: one in-process engine (`mlx-swift-lm` @@ -671,6 +671,15 @@ full-artifact qualification. Source lives under [in-progress integration contract](../design/glm53-flash-native.md) for the required paged, complete-prefix and trained-MTP gates. +The target also declares which complete-checkpoint roles are FP32 copies of BF16 +activations: the latent keys, the `[index keys, pool gates, validity]` values +row and the KDA convolution history (`GLM5NextTextModel.glm5NextPagedPayloadStorage`, +derived from the loaded weights' dtypes with the forward's own promotion). The +paged binding passes that to the checkpoint codec, which writes those roles at +BF16 and widens them back to the same FP32 bits on import; the FP32 recurrent +state is written as is +([SSD reference](../reference/ssd-kv-cache.md#complete-checkpoint-payload)). + An explicit [local qualification selection](../reference/configuration.md#local-glm-qualification) can admit the exact pinned local artifact into standalone discovery without changing coordinator advertisement. The local selection cannot bypass managed diff --git a/docs/architecture/prefix-cache.md b/docs/architecture/prefix-cache.md index 187463a2d8..e678d62d5d 100644 --- a/docs/architecture/prefix-cache.md +++ b/docs/architecture/prefix-cache.md @@ -1,6 +1,6 @@ # KV cache layouts and prefix caching -> Last updated: 2026-10-22 +> Last updated: 2026-10-24 How the provider lays out a request's KV cache, how it decides whether a previously computed prefix can be reused, and where reusable state lives: @@ -137,10 +137,16 @@ proof of paged execution (`libs/mlx-swift-lm/Libraries/MLXLMCommon/ContinuousBatchingV2/GLM5Next/GLM5NextPagedSparseState.swift`, `libs/mlx-swift-lm/Libraries/MLXLMCommon/ContinuousBatchingV2/Paged/PagedImmutableSnapshot.swift`). -The prototype full-state codec adds the distinct -`native-paged-glm5next-full-state-v1` layout, preserving the asymmetric payload +The full-state codec adds the distinct +`native-paged-glm5next-full-state-v2` layout, preserving the asymmetric payload and exact convolution/recurrence state (`libs/mlx-swift-lm/Libraries/MLXLMCommon/ContinuousBatchingV2/Prefix/GLM5Next/`). +The latent, index/gate/validity and convolution roles are written at the +activation dtype they were widened from (BF16 for `glm-5.3-flash`) and widened +back to the same FP32 bits on restore; the FP32 KDA recurrent state is written +as is. This roughly halves the per-token payload. The retired all-FP32 v1 files +fall outside the new layout epoch's namespace +([SSD reference](../reference/ssd-kv-cache.md#complete-checkpoint-payload)). Its existence does not add a qualified provider cache capability. Complete reuse still requires one accepted frontier across sparse pages, convolution/recurrence and trained MTP, charged import/export ownership, the protected native binding, diff --git a/docs/reference/ssd-kv-cache.md b/docs/reference/ssd-kv-cache.md index ef4899ca2f..f84475c22d 100644 --- a/docs/reference/ssd-kv-cache.md +++ b/docs/reference/ssd-kv-cache.md @@ -1,6 +1,6 @@ # SSD KV cache reference -> Last updated: 2026-10-21 +> Last updated: 2026-10-24 Exact on-disk format, paths, identity binding, environment knobs, size and eviction rules, and per-family reuse capability of the provider's encrypted SSD @@ -141,14 +141,43 @@ and MTP codec. No public header field exposes those token boundaries Layout constants and validation live in `CompleteCheckpointContract.swift` and `HistoricalAttentionLayout.swift`; provider selection is `EngineV2SlotFactory+CompletePrefixCache.swift` (`completeCheckpointStorage`). -The unregistered GLM prototype defines -`native-paged-glm5next-full-state-v1`: asymmetric latent/index/gate/validity rows -plus exact FP32 convolution and recurrent state. The provider store recognizes -that format, but the protected native binding, MTP serialization and encrypted -restore qualification remain separate gates. It is not permission to emit -durable-ready routing evidence +GLM5-Next uses `native-paged-glm5next-full-state-v2`: asymmetric +latent/index/gate/validity rows, the KDA convolution history and the exact FP32 +KDA recurrent state, plus the MTP prefix tensors at their own native dtypes. The +live pool and state keep these rows in FP32, but the latent keys, the `[index +keys, pool gates, 0/1 validity]` values row and the convolution history only +widen the model's activation dtype. The encrypted manifest's +`glm5NextState.storage` records each of those three roles' wire dtype, and the +export writes them at that dtype: BF16 for `glm-5.3-flash`, whose producing +weights, norms and pool gates are all BF16. Narrowing refuses (the donation +fails, no file is written) if any element is not exactly representable, and +import widens back to the original FP32 bits, so restore stays lossless. The +recurrent state is accumulated in FP32 and is always written in FP32. The +loaded target declares the role dtypes by the same promotion its forward pass +applies (`GLM5NextTextModel.glm5NextPagedPayloadStorage`); a target with FP32 +activations keeps every role FP32. The retired all-FP32 +`native-paged-glm5next-full-state-v1` spelling is refused, and its different +layout epoch keeps v1 files outside a v2 store's namespace until the TTL sweep +removes them. The shared narrowing/widening helper is +`CheckpointHalfPrecision.swift` (`libs/mlx-swift-lm/Libraries/MLXLMCommon/ContinuousBatchingV2/Prefix/GLM5Next/GLM5NextCompleteCheckpointLayout.swift`, +`libs/mlx-swift-lm/Libraries/MLXLMCommon/ContinuousBatchingV2/Prefix/CheckpointHalfPrecision.swift`, `provider-swift/Sources/ProviderCore/KVCacheSSD/SSDHybridCheckpointStoreFactory.swift`). + +| GLM-5.3-Flash checkpoint at | v1 (all FP32) | v2 (BF16 activation roles) | +|---|---:|---:| +| 2,048 tokens | 228.5 MB | 187.1 MB (-18 %) | +| 8,192 tokens | 445.8 MB | 300.5 MB (-33 %) | +| 30,720 tokens | 1,242.8 MB | 716.4 MB (-42 %) | +| Per token | 35.4 KB | 18.5 KB (-48 %) | +| Fixed part (mostly the FP32 KDA recurrent state) | 156.0 MB | 149.3 MB | + +Sizes are DBK3 files measured on an M5 Ultra (v1: 0.10.1; v2: the same build +with this layout). A donation also writes the 2,048-token anchor, so a 30,720-token +donation writes 1,471 MB at v1 and 904 MB at v2. Smaller files charge +proportionally less of the daily write cap. A full 262,144-token context +checkpoint is about 5.0 GB at v2, inside the 7 GiB large-memory staging cap; at +v1 it was about 9.4 GB, so prompts above about 208,000 tokens could not stage. See the [GLM integration gates](../design/glm53-flash-native.md). Historical windows capture the last `min(M, W)` tokens at boundary M and restore with base `max(0, M - W)`. Window copies finish before successor writes. Ordinary diff --git a/libs/mlx-swift-lm b/libs/mlx-swift-lm index 6148b6da7e..39a12e1d7b 160000 --- a/libs/mlx-swift-lm +++ b/libs/mlx-swift-lm @@ -1 +1 @@ -Subproject commit 6148b6da7eb8ed509ac56b74d7a69e8e73d8bf6c +Subproject commit 39a12e1d7b9098a9bd8b70c182b1d8f472570b94 From f8a270ae4460ca19bc67e0df92ad0d17902941ec Mon Sep 17 00:00:00 2001 From: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com> Date: Sat, 24 Oct 2026 00:41:42 -0700 Subject: [PATCH 2/4] perf(glm): validate GLM checkpoint validity flags by column Bump mlx-swift-lm to 9abc8090 (Layr-Labs/mlx-swift-lm#353): the restore-time validity check strides through the values row's validity column instead of testing every element (one 30,720-token checkpoint: 51.3 ms -> 0.53 ms on an M3 Ultra). --- changelog.d/glm-bf16-ssd-checkpoints.md | 1 + libs/mlx-swift-lm | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.d/glm-bf16-ssd-checkpoints.md b/changelog.d/glm-bf16-ssd-checkpoints.md index e75b2dd48c..9762eb5a5e 100644 --- a/changelog.d/glm-bf16-ssd-checkpoints.md +++ b/changelog.d/glm-bf16-ssd-checkpoints.md @@ -1,4 +1,5 @@ ### Half-size GLM SSD checkpoints - GLM-5.3-Flash complete checkpoints now write the latent keys, the index/gate/validity rows and the KDA convolution history at their BF16 activation dtype instead of the FP32 copies the live pool keeps, and widen them back to the same FP32 bits on restore. The accumulated KDA recurrent state stays FP32. A 30,720-token checkpoint drops from 1.24 GB to 0.72 GB (per token 35.4 KB → 18.5 KB), so each donation queues, writes and charges the daily SSD write budget for 18-48 % fewer bytes, a restore stages about 25 % faster on an M5 Ultra, and prompts up to the full 262K context fit the large-memory staging cap. +- Restores also validate the GLM validity flags by visiting only that column (one element in 257) instead of every element, about 50 ms less per 30,720-token restore. - The export refuses any value BF16 cannot represent exactly, so a restore is never lossy. The layout is now `native-paged-glm5next-full-state-v2`; existing v1 files sit in a different namespace and expire through the normal TTL sweep. Providers lose their warm GLM checkpoints once on upgrade. diff --git a/libs/mlx-swift-lm b/libs/mlx-swift-lm index 39a12e1d7b..9abc809071 160000 --- a/libs/mlx-swift-lm +++ b/libs/mlx-swift-lm @@ -1 +1 @@ -Subproject commit 39a12e1d7b9098a9bd8b70c182b1d8f472570b94 +Subproject commit 9abc8090712f3f947ae561ea8233e59f3aa1cf0f From 6e076fe304c828bdbd820d716ed5f7939d03729b Mon Sep 17 00:00:00 2001 From: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com> Date: Sat, 24 Oct 2026 02:09:50 -0700 Subject: [PATCH 3/4] docs(glm): state the GLM checkpoint format once, in the SSD reference Refactor pass. The SSD reference owns the GLM full-state v2 format; the prefix-cache and inference explanations now name the identifiers and link to it instead of restating its values (BF16, the payload ratio, the FP32 recurrent state). The reference cites the helper by its symbol and tabulates the current v2 checkpoint sizes; the retired v1 comparison stays in the changelog fragment and the PR evidence. --- docs/architecture/inference.md | 13 ++++++------- docs/architecture/prefix-cache.md | 10 ++++------ docs/reference/ssd-kv-cache.md | 27 ++++++++++++--------------- 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/docs/architecture/inference.md b/docs/architecture/inference.md index a4a4376649..c5f0e82a82 100644 --- a/docs/architecture/inference.md +++ b/docs/architecture/inference.md @@ -671,13 +671,12 @@ full-artifact qualification. Source lives under [in-progress integration contract](../design/glm53-flash-native.md) for the required paged, complete-prefix and trained-MTP gates. -The target also declares which complete-checkpoint roles are FP32 copies of BF16 -activations: the latent keys, the `[index keys, pool gates, validity]` values -row and the KDA convolution history (`GLM5NextTextModel.glm5NextPagedPayloadStorage`, -derived from the loaded weights' dtypes with the forward's own promotion). The -paged binding passes that to the checkpoint codec, which writes those roles at -BF16 and widens them back to the same FP32 bits on import; the FP32 recurrent -state is written as is +The target also declares the activation dtype that the latent keys, the +`[index keys, pool gates, validity]` values row and the KDA convolution history +only widen to FP32 (`GLM5NextTextModel.glm5NextPagedPayloadStorage`, derived +from the loaded weights' dtypes with the forward's own promotion). The paged +binding passes it to the complete-checkpoint codec, which stores those roles at +that dtype and widens them back exactly on import ([SSD reference](../reference/ssd-kv-cache.md#complete-checkpoint-payload)). An explicit [local qualification selection](../reference/configuration.md#local-glm-qualification) diff --git a/docs/architecture/prefix-cache.md b/docs/architecture/prefix-cache.md index e678d62d5d..21f85015f2 100644 --- a/docs/architecture/prefix-cache.md +++ b/docs/architecture/prefix-cache.md @@ -141,12 +141,10 @@ The full-state codec adds the distinct `native-paged-glm5next-full-state-v2` layout, preserving the asymmetric payload and exact convolution/recurrence state (`libs/mlx-swift-lm/Libraries/MLXLMCommon/ContinuousBatchingV2/Prefix/GLM5Next/`). -The latent, index/gate/validity and convolution roles are written at the -activation dtype they were widened from (BF16 for `glm-5.3-flash`) and widened -back to the same FP32 bits on restore; the FP32 KDA recurrent state is written -as is. This roughly halves the per-token payload. The retired all-FP32 v1 files -fall outside the new layout epoch's namespace -([SSD reference](../reference/ssd-kv-cache.md#complete-checkpoint-payload)). +Roles that only widen an activation dtype are stored at that dtype and widened +back exactly on restore; the +[SSD reference](../reference/ssd-kv-cache.md#complete-checkpoint-payload) lists +the roles, their wire dtypes and the retired v1 layout. Its existence does not add a qualified provider cache capability. Complete reuse still requires one accepted frontier across sparse pages, convolution/recurrence and trained MTP, charged import/export ownership, the protected native binding, diff --git a/docs/reference/ssd-kv-cache.md b/docs/reference/ssd-kv-cache.md index f84475c22d..eccbdbaa1c 100644 --- a/docs/reference/ssd-kv-cache.md +++ b/docs/reference/ssd-kv-cache.md @@ -159,25 +159,22 @@ activations keeps every role FP32. The retired all-FP32 `native-paged-glm5next-full-state-v1` spelling is refused, and its different layout epoch keeps v1 files outside a v2 store's namespace until the TTL sweep removes them. The shared narrowing/widening helper is -`CheckpointHalfPrecision.swift` +`CBv2CheckpointHalfPrecision` (`libs/mlx-swift-lm/Libraries/MLXLMCommon/ContinuousBatchingV2/Prefix/GLM5Next/GLM5NextCompleteCheckpointLayout.swift`, `libs/mlx-swift-lm/Libraries/MLXLMCommon/ContinuousBatchingV2/Prefix/CheckpointHalfPrecision.swift`, `provider-swift/Sources/ProviderCore/KVCacheSSD/SSDHybridCheckpointStoreFactory.swift`). -| GLM-5.3-Flash checkpoint at | v1 (all FP32) | v2 (BF16 activation roles) | -|---|---:|---:| -| 2,048 tokens | 228.5 MB | 187.1 MB (-18 %) | -| 8,192 tokens | 445.8 MB | 300.5 MB (-33 %) | -| 30,720 tokens | 1,242.8 MB | 716.4 MB (-42 %) | -| Per token | 35.4 KB | 18.5 KB (-48 %) | -| Fixed part (mostly the FP32 KDA recurrent state) | 156.0 MB | 149.3 MB | - -Sizes are DBK3 files measured on an M5 Ultra (v1: 0.10.1; v2: the same build -with this layout). A donation also writes the 2,048-token anchor, so a 30,720-token -donation writes 1,471 MB at v1 and 904 MB at v2. Smaller files charge -proportionally less of the daily write cap. A full 262,144-token context -checkpoint is about 5.0 GB at v2, inside the 7 GiB large-memory staging cap; at -v1 it was about 9.4 GB, so prompts above about 208,000 tokens could not stage. +| `glm-5.3-flash` checkpoint (DBK3 file, measured on an M5 Ultra) | Size | +|---|---:| +| 2,048 tokens | 187.1 MB | +| 8,192 tokens | 300.5 MB | +| 30,720 tokens | 716.4 MB | +| Per token | 18.5 KB | +| Fixed part (mostly the FP32 KDA recurrent state) | 149.3 MB | + +A donation also writes the 2,048-token anchor, so a 30,720-token donation +writes 904 MB. A full 262,144-token context checkpoint is about 5.0 GB, inside +the 7 GiB large-memory staging cap. See the [GLM integration gates](../design/glm53-flash-native.md). Historical windows capture the last `min(M, W)` tokens at boundary M and restore with base `max(0, M - W)`. Window copies finish before successor writes. Ordinary From b2d77d6efcf38154cbe0ab23064fa3c666b6f365 Mon Sep 17 00:00:00 2001 From: Jonathan Spangler <5055076+jonathan308@users.noreply.github.com> Date: Sat, 24 Oct 2026 02:09:50 -0700 Subject: [PATCH 4/4] refactor(glm): pin mlx-swift-lm at the refactor pass of Layr-Labs/mlx-swift-lm#353 Bumps libs/mlx-swift-lm 9abc8090 -> 184b5a93: the paged export walk is shared by the native and narrowing branches, a wire dtype equal to the page dtype is the native layout, the import sink drops its force unwraps, and the half-precision tests are split into unit and kernel suites. The checkpoint format and every GLM checkpoint byte are unchanged. --- libs/mlx-swift-lm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/mlx-swift-lm b/libs/mlx-swift-lm index 9abc809071..184b5a93f8 160000 --- a/libs/mlx-swift-lm +++ b/libs/mlx-swift-lm @@ -1 +1 @@ -Subproject commit 9abc8090712f3f947ae561ea8233e59f3aa1cf0f +Subproject commit 184b5a93f885862b282374576cbf85796cf8f5b1