Repository navigation
llama: disable lazy tensor loading by default on iGPUs - #28326
Conversation
| ggml_backend_dev_props props; | ||
| ggml_backend_dev_get_props(dev.dev, &props); | ||
| if (!props.caps.mmap_support) { | ||
| ml.lazy.mode = LLAMA_LAZY_MODE_OFF; |
There was a problem hiding this comment.
For my understanding, this corresponds to --load-mode none?
There was a problem hiding this comment.
probably be useful to establish a table with one axis as --load-mode and one as --lazy-mode, to see which combination does what
edit: in the end, 2 modes stay independent, so such table is not necessary anymore
There was a problem hiding this comment.
Should we unify the two modes so that they take all the same settings / have all the same behaviours? It is a bit hard to reason about still since they are almost-but-not-always the same right now.
| } | ||
| } | ||
|
|
||
| // resolve AUTO: LARGE where mmap is supported, else OFF (e.g. iGPUs); see #28160 |
note that it's not practically possible atm, only tensors marked as and currently only PLE tensors are being marked this way, so |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
As discussed, I simplified it to only switch AUTO to mean OFF on iGPUs, no other change. |
|
@0cc4m @pwilkin |
This comment was marked as abuse.
This comment was marked as abuse.
|
A model that fits into your memory on an iGPU will now run as fast as it can. If you run a model that's larger than your available memory, you should reenable lazy-mode manually, yes. |
|
Ideally autofitting should be made capable of figuring this out. |
|
Is there a reason the 104GB Q4 GGUF isn't fitting a 124GB available memory slot (when |
* llama: add lazy mode auto, fix iGPU regression * revert changes except disabling lazy load on iGPUs in AUTO (cherry picked from commit f3f1a8f)
I figured that out after llama.cpp crashed my system with a previously working config, yes. |
* llama: add lazy mode auto, fix iGPU regression * revert changes except disabling lazy load on iGPUs in AUTO
As a general note, I really do recommend setting up a good oomkiller when dealing with local models. I can't remember how many times I crashed my system before I decided to set up one, but it really helps. |
Big +1. Some other inference engines set their oom score very high in main(), since it's common that e.g. Vulkan memory won't be accounted to the process. I've been meaning to send this as a PR honestly... |
Thanks for the advice. I will do this. |
* llama: add lazy mode auto, fix iGPU regression * revert changes except disabling lazy load on iGPUs in AUTO
* llama: add lazy mode auto, fix iGPU regression * revert changes except disabling lazy load on iGPUs in AUTO
…ing CLI, route-info - apu-cli route-info: NPU/GPU capability detection (runtime-only XRT dlopen probe, /dev/accel + amdxdna driver, /dev/kfd), four-tier .xclbin discovery, memory-estimate gate, honest route resolution with explicit fallback reasons - common: --tokenize/--prefill/--decode, --gpu-based/--cpu-based/--npu-based, --apu-xclbin, --apu-verbose; presets honor explicit -ngl; APU flags raise log threshold so NPU->GPU fallback is visible at default verbosity - llama-model: log reason when lazy loading auto-resolves OFF on iGPU/unified memory (upstream IGPU mmap_support=false mechanism, issue ggml-org#28326)
…s lookup tables from disk (unslothai#16857) On an integrated GPU, a GGUF larger than memory fails to load, while Studio's warning says the weights are memory-mapped and paged in from disk. Reported on Discord: on an RTX Spark N1X (Windows), `unsloth/DeepSeek-V4.1-Flash-1017-GGUF` `UD-IQ1_S` (216.97 GiB) failed with `unable to allocate CUDA_Host buffer` for 110,595,290,400 bytes, exactly the size of the model's Engram lookup table (`per_layer_token_embd.weight`). ## Cause llama.cpp's default `--load-mode auto` means mmap unless a device lacks mmap support, which ggml reports for CUDA, HIP and Vulkan iGPUs (ggml-org/llama.cpp#26081). On the same devices `--lazy-mode auto` turns off (ggml-org/llama.cpp#28326), so lookup tables that are streamed from disk elsewhere stay resident too. Studio already switches an oversized `none` or `mlock` load to mmap (`_page_an_oversized_unmapped_load`), but it treated an unset mode as mmap. On an iGPU nothing is set, so nothing changed. ## Fix When a load Studio already prices as oversized runs where llama.cpp's `auto` resolves to `none` (the build lists `auto`, and a model device lacks mmap support), the override now: - appends `--load-mode mmap`, including after it drops an explicit `none`, `--no-mmap` or `LLAMA_ARG_NO_MMAP`; - appends `--lazy-mode on` if no lazy mode was set and the model has a table over llama.cpp's 4 GiB auto threshold. mmap alone would still read the whole table at load, because prefetch skips only lazy ranges (`src/llama-mmap.cpp`); - on Windows, raises `--fit-target` by 15 GiB over the launch's margin, unless the fitter is off or the user set a margin. Otherwise the fitter fills the shared memory with the GPU share and the load aborts at warm-up. The load warning gains one sentence saying Unsloth turned on memory mapping, which llama.cpp leaves off by default on this integrated GPU; the lazy table and the fit headroom go to the log only. Both the first launch and the arch-crash retry apply it. Not changed: loads that fit (they keep `none`, the faster load on an iGPU), discrete GPUs, Metal, builds without `auto`, a lazy mode or fit target the user set, and "Don't reserve system RAM" on an iGPU. Limits: - The 15 GiB is empirical: on a 127 GiB Strix Halo, 8 GiB still aborted at warm-up and 16 GiB ran. - Nothing ran on a CUDA iGPU (RTX Spark, DGX Spark) or a ROCm APU build. The reporter's 217 GiB model leaves less room than the 147 GiB one tested, so it may still not fit, and will be slow if it does. ## Verification AMD DevLab Strix Halo machines (128 GB, Vulkan) loading `unsloth/Qwen3.8-Flash-Next-GGUF` `UD-Q5_K_XL` (147.4 GiB, 50.7 GiB of it lookup table) through Studio, then two chat requests: | | main | This PR | |---|---|---| | Linux | Killed by the OS (signal 9) in one API load and one chat-picker load; a third load got through in 104 s | Loads in 71 to 76 s, chats answer | | Windows | `ErrorOutOfDeviceMemory` at load | Loads on the GPU in 246 s, chats answer | Loading from the chat picker on Linux, main is killed after 80 s and this PR loads in 73 s. The "after" panel shows the warning text of the final commit, rendered locally over a mocked load status; the load itself is the DevLab run above.  llama-server run directly on the same file, which is why the override sets each flag: - Windows: without mmap the load fails at load, with or without the lazy table. mmap with the lazy table aborts at warm-up with a 1 or 8 GiB fit target, and with 16 GiB it runs at about 16 tok/s. - Linux: `--lazy-mode on` loads with or without mmap (34 and 72 s, about 23 tok/s). The 16 GiB fit target is not needed there and cut generation to 13 to 15 tok/s, so the headroom is Windows only. - A 61.8 GiB quant that fits launches identically on main and this PR. Tests in `test_llama_cpp_placement.py` and `test_llama_server_args.py` drive `load_model` on a simulated integrated CUDA SoC with the DeepSeek-V4.1 table and cover each rule and exception above; the behavior tests fail on main. The 19 related backend test files pass (4,202 tests), and every full-suite failure also fails on main or passes when rerun on its own. --------- Co-authored-by: Daniel Han <[email protected]> Co-authored-by: Daniel Han <[email protected]>
Overview
Refactor lazy mode
autoto mean "pick a probably good mode for your system", whereas the currentautobehaviour (lazy load tensors > 4GiB) moves to lazy modelarge, and lazy load all of these tensors becomes lazy modeall. This makes the meaning ofautoconsistent with how it works for load mode, and resolves the issue where we're back to mmap enabled by default on iGPUs that lose a lot of performance this way.Fixes #28160
Please let me know what you think, or if you have better ideas.
Requirements