llama : load MTP tensors only if they are really used - #26296
Conversation
|
Just throwing in a suggestion here to make this generic behavior across all models and not just GLM. This is an issue across any model with integrated MTP support. The tensors are loaded indiscriminately, regardless of speculative settings. Which can be quite annoying for users with hardware which dose not benefit from MTP anyways. The 1-3GB of extra RAM use can actually start to matter if you are running hardware at its very limit. (The only current solution to this problem is to strip the MTP tensors from a GGUF entirely.) |
|
@Sciguy429 Added remaining models that support MTP. Change not tested yet as I don't have GGUFs at hand. |
|
Tested this with MTP enabledVRAM usage: 22594MiB MTP disabledVRAM usage: 21032MiB IMO looks good. |
| llama_model_loader ml(/*metadata*/ nullptr, /*set_tensor_data*/ nullptr, /*set_tensor_data_ud*/ nullptr, | ||
| fname_inp, splits, /*file*/ nullptr, /*load_mode*/ load_mode, /*check_tensors*/ true, /*no_alloc*/ false, kv_overrides, nullptr); | ||
| fname_inp, splits, /*file*/ nullptr, /*load_mode*/ load_mode, /*check_tensors*/ true, /*no_alloc*/ false, /*load_mtp*/ true, kv_overrides, nullptr); |
There was a problem hiding this comment.
for next PRs: we should refactor these params in a helper struct
am17an
left a comment
There was a problem hiding this comment.
When was this behavior introduced? I remember the layers were not loaded in case mtp was not used.
@am17an Tried to test how it worked in your old mtp-clean branch, but Edit: removed HF download from CMakeLists.txt and the build finished. MTP not enabled: VRAM usage 22526MiB OK that's weird, why so much more than in current master? |
|
@fairydreaming wrong context calculation, it was fixed a while later. |
|
@fairydreaming sorry, had to redownload a quant to do some testing because most of mine are stripped at this point. I tested Step3.7 Flash and got similar results to you, notable drop in memory allocation between mainline and this PR. Everything seems to be working. |
|
OK I did some more tests with Qwen3.6-27B-Q4_K_M.gguf to make sure this PR works as expected. An old build from 1st June:MTP: 22530MiB Current master:MTP: 22534MiB This PR:MTP: 22534MiB So VRAM without MTP usage is 276 MiB less than in master/old build from 1st June. One layer of Qwen3.6-27B-Q4_K_M is approximately 16.8 GiB / 64 = 262MiB so close enough. @am17an Still having doubts? |
|
This was always there then, let's merge it and fix the issue |
* llama : load MTP tensors only if they are really used * llama : skip loading MTP (if not used) in remaining models that support MTP --------- Co-authored-by: Stanisław Szymczyk <sszymczy@gmail.com>
* llama : load MTP tensors only if they are really used * llama : skip loading MTP (if not used) in remaining models that support MTP --------- Co-authored-by: Stanisław Szymczyk <sszymczy@gmail.com>
* llama : load MTP tensors only if they are really used * llama : skip loading MTP (if not used) in remaining models that support MTP --------- Co-authored-by: Stanisław Szymczyk <sszymczy@gmail.com>
* llama : load MTP tensors only if they are really used * llama : skip loading MTP (if not used) in remaining models that support MTP --------- Co-authored-by: Stanisław Szymczyk <sszymczy@gmail.com>
* llama : load MTP tensors only if they are really used * llama : skip loading MTP (if not used) in remaining models that support MTP --------- Co-authored-by: Stanisław Szymczyk <sszymczy@gmail.com>
Overview
This PR skips loading of MTP tensors in
GLM_DSA archmodels that support MTP if no--spec-type draft-mtpwas used.Fixes #26290
Additional information
I added new
load_mtpboolean flag to llama model params and model loader. Let me know if there's a better way.Requirements