Repository navigation
hf: size GLM-5.3-Flash's KV cache from its latent layers only - #64
Merged
Merged
Conversation
GLM-5.3-Flash has 34 linear-attention layers, which hold a fixed-size state, and 11 latent-attention layers. layer_types named the first linear_attention, which matched "attention" and counted as full, and the latent layers counted as 64 full heads. inspect put about 380k tokens in 280 GB. A linear_attention layer now holds no cache, and a layer with kv_lora_rank holds its latent, rotary key and indexer key. Generated by Coder Agents on behalf of @bpmct.
Coder Agents generated.
There was a problem hiding this comment.
🟡 Changes recommended
Pure-linear configurations still trigger the full-attention fallback and overestimate memory, while the documented setup omits the restart needed to apply its settings.
2 open issues
What changed in this PR
This PR corrects KV-cache estimates for GLM-5.3-Flash and latent-attention models, improving memory and context sizing across inspect, new, and the web panel.
Changes:
- Excludes linear-attention layers from cache counting and sizes latent caches using their compressed dimensions.
- Adds regression tests and a trimmed GLM-5.3-Flash configuration fixture.
- Documents measured Mac Studio usage and records the sizing correction in the changelog.
| File | Description |
|---|---|
internal/hf/testdata/glm-5.3-flash-config.json |
Adds model dimensions and layer types for regression testing. |
internal/hf/kv_internal_test.go |
Tests hybrid, latent, and linear-attention cache sizing. |
internal/hf/arch.go |
Updates layer counting and latent-cache calculations. |
docs/providers.md |
Adds a Mac Studio example with settings and measured performance. |
CHANGELOG.md |
Records the user-visible cache-sizing correction. |
Review effort: Balanced
Comment on lines
+66
to
+67
| case strings.Contains(t, "linear"): | ||
| // GLM-5.3 names its Kimi Delta layers linear_attention. |
| ```sh | ||
| llm-helper new unsloth/GLM-5.3-Flash-GGUF --quant UD-Q4_K_XL | ||
| llm-helper set glm-5.3-flash-gguf-ud-q4_k_xl -- \ | ||
| EXTRA_ARGS="-c 1048576 -np 4 -ngl all --fit off -fa on -b 4096 -ub 2048 --spec-type draft-mtp --temp 1.0 --top-p 0.95 --min-p 0.0 --metrics --offline" |
DevelopmentCats
approved these changes
Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


First step toward GLM-5.3-Flash on a Mac Studio.
inspectsized its KV cache about 50 times too large, so a 256 GB Mac looked like it could hold almost no context:GLM-5.3-Flash (
glm5_next) has 45 layers. 34 are Kimi Delta linear attention, which keep a fixed-size state and no growing cache. 11 are latent attention (MLA) with a sparse-attention indexer. Two things went wrong:layer_typescalls the linear layerslinear_attention. That matched"attention", so they counted as full attention.kv_lora_rank + qk_rope_head_dim, plus the indexer key here.Now a
linear_attentionlayer holds no cache, and a layer withkv_lora_rankholdskv_lora_rank + qk_rope_head_dim + index_head_dim. For GLM-5.3-Flash that is 11 × 640 × 2 = 14,080 bytes a token, about 15 GB at 1M tokens. The indexer key is stored narrower than this counts it, so the estimate errs high, which is the safe side.This also changes DeepSeek V2/V3 and V3.2: their estimate falls about 25 times, to the 576 per layer vLLM allocates. DeepSeek V4 has no
kv_lora_rankand does not change.This PR also adds GLM-5.3-Flash on the Mac Studio to
docs/providers.md, measured. It runs Unsloth'sUD-Q4_K_XL(186 GiB) plusmmproj-F16.ggufon mainline llama.cpp 0.8.0 from Homebrew (GLM-5.3-Flash since ggml-org/llama.cpp#27773, MTP since #29928), with--spec-type draft-mtp. MLX was the other option. GLM-5.3-Flash runs only under mlx-vlm there, itsglm5_nextport is on main with no release, and a review found numeric bugs, so llama.cpp is the safer choice.On the Mac (M5 Ultra, 256 GB), idle, straight to llama-server:
Tool calls and images work. The clean numbers are from Huihui's abliterated copy of the same quant, which has the same shapes. An earlier run on Unsloth's copy shared the Mac with live traffic, so its numbers are not clean. I wrote the profile file by hand on the Mac (
sudothere asks for a password, sonewcould not restart the service). It has the samePROVIDER,MODELandEXTRA_ARGSas the doc, but I did not run the doc'snewandsetcommands myself.Tested:
gofmt -l .is empty,go vet ./...andGOOS=darwin go vet ./...pass,go test -racepasses forhf,resolveandcli, andgo test ./...passes. The new test reads a trimmed copy of the realzai-org/GLM-5.3-Flashconfig.inspect unsloth/GLM-5.3-Flash-GGUFgives the numbers above. Also merged main (no conflicts), andgo vet ./...andgo test ./...pass on the merge.Generated by Coder Agents on behalf of @bpmct.