diff --git a/changelog.d/glm-bf16-ssd-checkpoints.md b/changelog.d/glm-bf16-ssd-checkpoints.md new file mode 100644 index 0000000000..9762eb5a5e --- /dev/null +++ b/changelog.d/glm-bf16-ssd-checkpoints.md @@ -0,0 +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/docs/architecture/inference.md b/docs/architecture/inference.md index 789ae97bb6..c5f0e82a82 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,14 @@ 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 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) 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..21f85015f2 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,14 @@ 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/`). +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 ef4899ca2f..eccbdbaa1c 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,40 @@ 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 +`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 (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 diff --git a/libs/mlx-swift-lm b/libs/mlx-swift-lm index 6148b6da7e..184b5a93f8 160000 --- a/libs/mlx-swift-lm +++ b/libs/mlx-swift-lm @@ -1 +1 @@ -Subproject commit 6148b6da7eb8ed509ac56b74d7a69e8e73d8bf6c +Subproject commit 184b5a93f885862b282374576cbf85796cf8f5b1