Support per-layer DSA indexer schedule (GLM-5.2) - #1412
Open
davidrhodus wants to merge 1 commit into
Open
Conversation
GLM-5.2 (glm_moe_dsa) enables the DeepSeek-V3.2-style lightning indexer on
only a subset of layers, declared via a per-layer `indexer_types` list
("full" = own indexer weights, otherwise none). The shared deepseek_v32
attention unconditionally builds an Indexer on every layer, so loading
GLM-5.2 failed with "Missing N parameters" for the indexer-less layers.
- deepseek_v32: build the Indexer only when `indexer_types[layer_idx]` is
"full" (or when the field is absent -> every layer, unchanged for
DeepSeek-V3.2); guard the indexer use in forward; give indexer-less layers
a single-slot cache in make_cache (a second, never-written KVCache crashes
CacheList.state).
- glm_moe_dsa: add the optional `indexer_types` config field.
- tests: glm_moe_dsa config with mixed "full"/"shared" indexer_types.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
GLM-5.2 (
model_type: glm_moe_dsa) reuses the DeepSeek-V3.2 backbone but enables the DSA "lightning indexer" on only a subset of layers, declared per-layer via anindexer_typeslist ("full"= that layer has its own indexer weights; otherwise it has none). The shareddeepseek_v32attention builds anIndexeron every layer unconditionally, so loading GLM-5.2 fails:(GLM-5.2 declares
"full"on layers 0,1,2 then every 4th — 22 of 78 layers.)Changes
deepseek_v32.pyDeepseekV32Attentiontakeslayer_idxand builds theIndexeronly whenindexer_types[layer_idx] == "full"— or whenindexer_typesis absent, in which case the indexer is built on every layer (DeepSeek-V3.2 behaviour is unchanged).forwardguards the indexer/sparse-mask block behindself.indexer is not None.make_cachegives indexer-less layers a single-slotCacheList(KVCache())— a second, never-writtenKVCacheotherwise crashesCacheList.stateon its emptykeys.glm_moe_dsa.py— add the optionalindexer_typesconfig field.tests/test_models.py—glm_moe_dsaconfig with mixed["full","shared",...]indexer_types, exercising both the conditional indexer build and the mixed-cache decode path.Testing
model_test_runnerchecks (fp32/fp16 forward, KV-cache decode, batch > 1, deepcopy); confirmed indexer is built only on"full"layers and the single-slot cache decodes correctly.glm_moe_dsa, 256 experts) to MLX and verified coherent generation (it failed with "Missing parameters" before this change).DeepSeek-V3.2 / other
glm_moe_dsacheckpoints withoutindexer_typesare unaffected (indexer still built on every layer, 2-slot cache).🤖 Generated with Claude Code