GLM 5.2 Indexer support#25407
Conversation
Just follow Deepseek 3.2 for now.
This is transformers' `apply_rotary_pos_emb_interleave`
Previous converted GGUFs like https://huggingface.co/unsloth/GLM-5.2-GGUF write indexer weights to _all_ layers, even if they are only required for "full" types. This PR relies on a new key "%s.attention.indexer.types"; if absent, it will use the default GLM 5.2 schedule as defined in https://huggingface.co/zai-org/GLM-5.2/blob/main/config.json#L26. Note that conversion is not saving this key yet.
| #include "llama-kv-cache-dsa.h" | ||
|
|
||
| // https://huggingface.co/zai-org/GLM-5.2/blob/main/config.json#L26 | ||
| const std::array<uint32_t, LLAMA_MAX_LAYERS> GLM_DSA_DEFAULT_INDEXER_TYPES = { |
There was a problem hiding this comment.
I considered the alternative to store just two numbers to represent the frequency of full indexers, and the number of prefix full indexers before the regular pattern. I decided towards the array because:
- There are also precedents in the codebase for irregular patterns.
- Deepseek 3.2 could be included in this pattern via
get_key_or_arrwith a single scalar (all DS indexers are "full").
|
|
||
| switch (hparams.n_layer()) { | ||
| case 79: type = LLM_TYPE_744B_A40B; break; | ||
| case 78: type = LLM_TYPE_744B_A40B; break; |
There was a problem hiding this comment.
I think this is a previous inoffensive bug introduced during the n_layer refactor; n_layer() excludes MTP layers so this should be 78.
| return std::make_unique<graph>(*this, params); | ||
| } | ||
|
|
||
| llama_model_glm_dsa::graph::graph(const llama_model & model, const llm_graph_params & params) : |
There was a problem hiding this comment.
Same graph as Deepseek v3.2, except for the two differences noted in the PR description.
I didn't want to touch other modules, but we can generalize these changes into Deepseek's and reuse the graph here.
|
As I understand GLM 5.2 uses the same lighting indexer as DS3.2 but the top-k is shared across 4 layers. If this is correct then #24231 should be used |
Yes, indeed, thanks for linking to it, I had missed the recent activity there. My understanding is that #24231 is about creating a new op that we can use from both the Deepseek and gml-dsa modeling files when it's merged, and when cuda / metal implementations are added. This PR (mine) is about contributing the remaining aspects of the architecture that were deferred from the initial GLM 5.2 implementation, and that are mostly available in the deepseek 3.2 one. But I'm new to the project, happy to coordinate with the team as necessary! |
|
Yes, my comment is for your awareness w.r.t. to the lightning indexer and not anything else different for GLM5.2 |
Overview
Adds indexer support to GLM 5.2. Currently, indexer tensors are loaded when present, but ignored. If accepted, this PR would in my understanding complete the implementation of GLM 5.2.
The implementation just copies the graph from Deepseek 3.2 and applies the GLM 5.2 changes:
"full"indexers compute top_k,"shared"ones reuse top_k from the previous full layer. In Deepseek 3.2, all indexers are"full".Additional information
"full"indexers are used.Requirements