imatrix: optionally activate MTP/NextN draft head during collection#23476
Draft
mudler wants to merge 1 commit into
Draft
imatrix: optionally activate MTP/NextN draft head during collection#23476mudler wants to merge 1 commit into
mudler wants to merge 1 commit into
Conversation
`llama-imatrix` only runs forward passes through the trunk, so MTP draft head tensors (`blk.<n_layer>.nextn.eh_proj` etc., added by ggml-org#22673) never receive activations and have no imatrix data. Low-bit i-quants for those tensors then fail at quantize-time: llama_model_quantize: failed to quantize: Missing importance matrix for tensor blk.40.nextn.eh_proj.weight in a very low-bit quantization This adds an opt-in `--mtp` flag to `llama-imatrix`. When set and the loaded model has MTP/NextN layers, a second `llama_context` is created with `ctx_type = LLAMA_CONTEXT_TYPE_MTP`. After each trunk sub-batch decode, the trunk's pre-norm hidden states are paired with the next-token ids and decoded through the MTP context, mirroring how `common_speculative_state_draft_mtp::process()` invokes the head during real spec decoding. MTP-layer tensors then land in the same imatrix collector via the existing eval callback. Default behavior unchanged. No-op (with warning) for models without MTP layers. Currently restricted to `n_seq == 1` to keep MTP-row-to- output-row mapping unambiguous; warns and disables itself otherwise. Adds a small public accessor `llama_model_n_nextn(model)` so callers outside `src/` can probe MTP presence without pulling in `llama_hparams`. Files: common/arg.cpp +9 --mtp CLI option common/common.h +1 imat_mtp on common_params include/llama.h +4 llama_model_n_nextn() decl src/llama-model.cpp +4 llama_model_n_nextn() impl tools/imatrix/imatrix.cpp +125 MTP context + per-batch MTP forward pass
Member
|
Overlapping #23258 |
Contributor
Author
ouch, didn't saw it - sorry. feel free to close anytime. I'd be ok to pick it up in case the other one doesn't land. |
Member
It seems you have differing approaches, perhaps worth looking into if something can be combined and/or improved? |
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.
Overview
llama-imatrixonly runs forward passes through the trunk, so MTP draft head tensors (blk.<n_layer>.nextn.eh_projetc., added by #22673) never receive activations and have no imatrix data. Low-bit i-quants for those tensors then fail at quantize-time:llama_model_quantize: failed to quantize: Missing importance matrix for
tensor blk.40.nextn.eh_proj.weight in a very low-bit quantization
This adds an opt-in
--mtpflag tollama-imatrix. When set and the loaded model has MTP/NextN layers, a secondllama_contextis created withctx_type = LLAMA_CONTEXT_TYPE_MTP. After each trunk sub-batch decode, the trunk's pre-norm hidden states are paired with the next-token ids and decoded through the MTP context, mirroring howcommon_speculative_state_draft_mtp::process()invokes the head during real spec decoding. MTP-layer tensors then land in the same imatrix collector via the existing eval callback.Default behavior unchanged. No-op (with warning) for models without MTP layers. Currently restricted to
n_seq == 1to keep MTP-row-to- output-row mapping unambiguous; warns and disables itself otherwise.Adds a small public accessor
llama_model_n_nextn(model)so callers outsidesrc/can probe MTP presence without pulling inllama_hparams.Requirements