Added support of MTP speculative decoding on zai/glm-4.7-flash#25564
Added support of MTP speculative decoding on zai/glm-4.7-flash#25564TriDefender wants to merge 3 commits into
Conversation
Current code borrows from deepseek2 arch, which has fundamental flaws that lacks MTP support. I could've added something to deepseek2 but i decided not to bring potential breaking changes. I also added a few lines to deepseek2 that reveals the hidden state t_h_nextn for the MTP layer. This is because the graph function is imported from deepseek2 via `using graph = llama_model_deepseek2::graph` to reduce redundant code. `src/models/glm4-moe-lite.cpp` is a heavilly modified deepseek2.cpp so the MTP layer will be loaded or you'll crash getting more tensors than expected ## AI Artificial intelligence has been used to do pre research and information gathering
|
Hi @TriDefender, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
|
I know zai/glm-4.7-flash is outdated and ppl stopped adding MTP support models for it but I would like to contribute on this matter |
Edited PR to conform |
|
Will perform some individual tests later on model conversion |
The previous implementation results in `tensor read out of bounds`, This is because `t_h_nextn` being set after `inp_out_ids` reduces the tensor from n_tokens to n_outputs rows, but the speculative driver reads n_tokens * n_embd floats -> `tensor read out of bounds` Fix: Instead of importing the graph part of deepseek2, I rewrote the full graph into glm4-moe-lite.cpp with the correct inp_out_ids handling. And subsequently updated models.h.
|
This PR has been fully tested with actual model weights: And tested with llama-bench (no MTP) And llama-server inference test: Therefore, I can conclude that this PR is review ready |
|
duplicate #24868? |
I did considered the options of adding MTP to deepseek2 but I didn't want to introduce potential breaking changes. I think it's better to respect arch differences and do not affect current 4.7-flash models created under deepseek2 arch that is without MTP support. |
Overview
Incorporated MTP support for
glm4_moe_litearchitechture, currently unsupported by the temporary solution of borrowingdeepseek2architechtureAdditional information
Current code borrows functionality from deepseek2 arch, which has fundamental flaws that lacks MTP support. I could've added something to deepseek2 but i decided not to bring potential breaking changes.
I also added a few lines to deepseek2 that reveals the hidden state
t_h_nextnfor the MTP layer. This is because the graph function is imported from deepseek2 viausing graph = llama_model_deepseek2::graphto reduce redundant code. Of course, if necessary I can just copy the entire section over.src/models/glm4-moe-lite.cppis a heavilly modified version of deepseek2.cpp so the MTP layer will be loaded or you'll crash by getting more tensors than expectedRequirements
YES, Artificial intelligence has been used to do pre-research on llm arches and information gathering