Skip to content

llama: add default load-mode auto, which avoids mmap on iGPUs - #26081

Merged
ggerganov merged 9 commits into
masterfrom
0cc4m/mmap-auto
Aug 11, 2026
Merged

llama: add default load-mode auto, which avoids mmap on iGPUs#26081
ggerganov merged 9 commits into
masterfrom
0cc4m/mmap-auto

Conversation

@0cc4m

@0cc4m 0cc4m commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Overview

Follow-up to #20834 and #26023

mmap is detrimental on iGPUs that have to copy the model to device-visible, but still shared memory, as that means during loading it will have the model in RAM twice, doubling the memory requirements temporarily and slowing down the process if it overflows. This is currently the default behaviour, leading to issues for users that don't know about this.

Add load-mode auto and default to it. It keeps the current behaviour for most cases, except when a device reports that it doesn't support mmap. This is up to the backends to flag, through a new capability boolean (apologies for the mass-pinging this causes..). I only disabled it for CUDA/ROCm and Vulkan iGPUs for now, because I'm not familiar enough with the other backends.

Please let me know if this implementation is feasible or if there's a better way to handle it, and also if there are more backends I should include.

In the future further features could be added, e.g. automatic use of direct-io, if we know when it can definitely be enabled.

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES, Claude prototyped the code, I manually reviewed and tested.

@github-actions github-actions Bot added Vulkan Issues specific to the Vulkan backend ggml changes relating to the ggml tensor library for machine learning SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language Apple Metal https://en.wikipedia.org/wiki/Metal_(API) Ascend NPU issues specific to Ascend NPUs OpenCL Issues specific to the OpenCL backend IBM zDNN issues specific to IBM zDNN Accelerator Hexagon CUDA Related to the CUDA backend AMD ZenDNN Issues related to the AMD ZenDNN backend OpenVINO WebGPU labels Jul 24, 2026

@pwilkin pwilkin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is sorely needed for ROCm, where the --mmap mode is additionally bugged beyond 64GB.

@ORippler ORippler self-assigned this Jul 27, 2026
@0cc4m
0cc4m force-pushed the 0cc4m/mmap-auto branch from 6bcf37a to 36b9da0 Compare July 28, 2026 10:10
@0cc4m

0cc4m commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

I addressed the feedback and added llama-bench support.

Comment thread src/llama-model.cpp
if (ml.use_mmap && params.load_mode == LLAMA_LOAD_MODE_AUTO) {
for (const auto & dev : devices) {
ggml_backend_dev_props props;
ggml_backend_dev_get_props(dev.dev, &props);

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure the compiler figures this out no problem.

@ORippler ORippler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. AI tells me we may wish to bump APIR_PROTOCOL_MINOR as we change ggml_backend_dev_props to encode one more bool. Pinging @kpouget as I have no clue about virtgpu backend.
  2. Please run llama-gen-docs to regenerate/update docs to reflect this change

Validated this change on DGX Spark. Would love to change default to -dio on iGPU systems in future to achieve faster load times

@kpouget

kpouget commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

AI tells me we may wish to bump APIR_PROTOCOL_MINOR as we change ggml_backend_dev_props to encode one more bool. Pinging @kpouget as I have no clue about virtgpu backend.

thanks for the ping,
yes, the bump makes sense
I'll start testing the PR with the virtgpu backend 👍🏻

@0cc4m
0cc4m force-pushed the 0cc4m/mmap-auto branch from 36b9da0 to 125b6c6 Compare August 5, 2026 06:12
@0cc4m
0cc4m requested a review from a team as a code owner August 5, 2026 06:12
@github-actions github-actions Bot added documentation Improvements or additions to documentation server labels Aug 5, 2026

@ORippler ORippler left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM!

@kpouget

kpouget commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

LGTM for the virt-gpu part (@taronaeo)

@elchic00

elchic00 commented Aug 8, 2026

Copy link
Copy Markdown

Confirming this is worth automating on gfx1151 (Strix Halo APU, Framework Desktop Ryzen AI Max+ 395, ROCm/HIP). Without --direct-io, GPU-layer offload for a 35B-A3B MoE model at Q8 was capped at 45/99 layers — pushing further didn't degrade gracefully, it fell off a cliff to ~0.01 t/s (effectively hung). Looked like GTT page-fault thrashing from mmap's default region-pinning once the resident working set crossed a threshold, not an actual VRAM limit (it's an APU, so the GPU reaches system RAM through GTT). --direct-io (skips mmap entirely) gave a stable full 99-layer offload, not just a faster one. Happy to share exact config/benchmarks if useful for wiring this into auto-detection.

@0cc4m 0cc4m added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Aug 10, 2026
@ggerganov
ggerganov merged commit 153d324 into master Aug 11, 2026
53 of 61 checks passed
@ggerganov
ggerganov deleted the 0cc4m/mmap-auto branch August 11, 2026 06:20
mlogix added a commit to SynoriAI/llama.cpp that referenced this pull request Aug 11, 2026
…, multi-output backend sampling, pocket-tts

Merges 45 upstream commits (0865990..ebb546b, b10362-16-gebb546b7e) into
synori/llama-update-mtp-fit. Zero conflicts; all vendored patches carried over
untouched.

Primary motivation — new Meta architecture:
  * 62bf73d model: Muse Glimmer Support (ggml-org#26841)
    LLM_ARCH_MUSE_GLIMMER + src/models/muse-glimmer.cpp + the mtmd vision tower
    in tools/mtmd/models/muse-glimmer.cpp and conversion/muse_glimmer.py.

Other notable changes that touch our public API surface:
  * dd1ea52 llama : support multi-output backend sampling (ggml-org#25532)
    llama_context_params gains n_outputs_max_per_seq; llama_sampler_i.backend_init
    takes it as a third argument; new backend_reset / copy_state vtable slots and
    llama_sampler_copy().
  * 153d324 llama : default load-mode auto, avoids mmap on iGPUs (ggml-org#26081)
    llama_load_mode gains LLAMA_LOAD_MODE_AUTO = -1 (enum is now signed).
  * 6e62ba5 mtmd: support pocket-tts (ggml-org#26871)
    mtmd_gen_inp/mtmd_gen_out gain seed/temp/feats/is_eos; new
    mtmd_gen_inp_default(); mtmd_helper_gen_audio_step_gen() takes out_stop.
  * 157b81f model : Granite-Switch Architecture (ggml-org#25107)
  * 7a20b41 model: MTP support for Nemotron (ggml-org#26725) and
    cc078b4 Dflash support for nemotron-3.5 (ggml-org#26905)
  * e23e944 vendor : cpp-httplib 0.53.0, 4c6766f vendor : subprocess.h sync

Vendored patches preserved:
  * 919fde3 feat(rpc): thread-local last_error accessor — intact, upstream
    touched ggml-rpc.cpp by one unrelated line.
  * 3679b23 Fixes (RPC) — intact.
  * 2aa76c7 fix(metal): drop stray kernel_pad_f32 — still applies; upstream has
    since refactored pad into a templated kernel_pad_impl<T>, so the duplicate
    definition that referenced the nonexistent kargs_pad.s0..s3 is gone on both
    sides and nothing had to be re-applied.
huaxel pushed a commit to huaxel/CachyLLama that referenced this pull request Aug 12, 2026
…rg#26081)

* llama: add new default load-mode auto which picks mmap unless a non-Metal iGPU is used

* Update ggml/src/ggml-hexagon/ggml-hexagon.cpp

Co-authored-by: Max Krasnyansky <maxk@qti.qualcomm.com>

* set mmap_support to false on OpenCL backend

* fix order of load modes

* use -1 for auto

* resolve load mode auto earlier to correctly pick gpu host or cpu memory

* add load mode auto to llama-bench

* bump virtgpu api version, regenerate docs

---------

Co-authored-by: Piotr Wilkin (ilintar) <piotr.wilkin@syndatis.com>
Co-authored-by: Max Krasnyansky <maxk@qti.qualcomm.com>
Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AMD ZenDNN Issues related to the AMD ZenDNN backend Apple Metal https://en.wikipedia.org/wiki/Metal_(API) Ascend NPU issues specific to Ascend NPUs CUDA Related to the CUDA backend documentation Improvements or additions to documentation examples ggml changes relating to the ggml tensor library for machine learning Hexagon IBM zDNN issues specific to IBM zDNN Accelerator merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. OpenCL Issues specific to the OpenCL backend OpenVINO server SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language Vulkan Issues specific to the Vulkan backend WebGPU

Projects

None yet

Development

Successfully merging this pull request may close these issues.