feat: Enable multi-token drafting for GLM-4.5 MTP#2
Conversation
|
Great work! 👍
I suspect this will wind up being even more awkward than the existing MTP KV cache management setup since KV caching is done per-layer (in the sense that you can index into each layer's KV cache). One possible solution might be to add "layers" when N draft tokens is > 1. The other solution, possibly cleaner and more consistent with existing llama.cpp behavior, would be to revert to storing an explicit draft context as in the current speculative module. I don't love either solution right now, the former because it's hacky, the latter because IIRC the current speculative draft KV cache isn't really maintained that well. I agree that it's best to deliver the simplified version first before reverting here, it would add a good deal of complexity. |
For now, this is just a proof of concept I had in mind. I tried to replicate the workflow from SGLang because even with a proper implementation in vLLM, they are not drafting more than one token, as stated in this comment on their PR.
The drafting process must be an autoregressive loop to accommodate the CPU-side sampling required between each token generation. In case you are curious, the loop in SGLang looks like this:
With that in mind, I implemented a loop for
mtp_speculative_gen_draftbased on how many draft tokens you want at once, which gives us a similar idea.The major problem is a significant limitation regarding KV cache management; the KV cache is not persisted between draft steps, leading to a degradation in draft quality as more tokens are generated.
Here are some preliminary results showing the drop in acceptance rate (It's hardcoded for now to run 5 drafts at once in the line const int n_mtp_draft_target = 5):
If my concept is correct, then we "just" need to fix the KV cache, and here is the nightmare that you probably walked before. A proper solution would likely involve creating a persistent KV cache context for the duration of the draft loop.
I can see two options to follow:
server: implement GLM-style MTPPR is merged).