Skip to content

Eval bug: llama-fit-params does not include vision stack in calculations #18111

Closed as duplicate

Description

@eapache

Name and Version

ggml_cuda_init: GGML_CUDA_FORCE_MMQ: no
ggml_cuda_init: GGML_CUDA_FORCE_CUBLAS: no
ggml_cuda_init: found 1 CUDA devices:
Device 0: NVIDIA GeForce RTX 3060, compute capability 8.6, VMM: yes
version: 7437 (ec98e20)
built with GNU 13.3.0 for Linux x86_64

Operating systems

Linux

GGML backends

CUDA

Hardware

RTX 3060 (12GB)

Models

Anything that exceeds your vram and has a vision stack (I have been testing with gemma3-27B. The new GLM-4.6V also works if you need something that will still overflow vram on a more expensive GPU.)

Problem description & steps to reproduce

./build/bin/llama-server -m models/custom/gemma3/gemma-3-27B-it-qat/gemma-3-27b-it-q4_0.gguf --mmproj models/custom/gemma3/gemma-3-27B-it-qat/mmproj-model-f16-27B.gguf

The new fit algorithm fills up my vram nicely with as many layers as possible, and as much context as possible. Hitting the server with text-only requests processes fine, and about as efficiently as I have been able to tune myself manually.

However, hitting the server with an image causes a CUDA OOM crash. I assume the vision stack is loaded lazily, and cannot overflow to system ram; because the fit algorithm has otherwise filled vram already, it crashes trying to allocate memory for the vision stack.

(Also, the new llama-fit-params command doesn't even accept --mmproj so I assume it's just not including that in the calculation at all.)

First Bad Commit

No response

Relevant log output

srv  process_chun: processing image...
encoding image slice...
/home/eapache/src/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu:94: CUDA error
CUDA error: out of memory
  current device: 0, in function alloc at /home/eapache/src/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu:471
  cuMemCreate(&handle, reserve_size, &prop, 0)

...

Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x00007a9ae3710813 in __GI___wait4 (pid=20921, stat_loc=0x0, options=0, usage=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
warning: 30	../sysdeps/unix/sysv/linux/wait4.c: No such file or directory
#0  0x00007a9ae3710813 in __GI___wait4 (pid=20921, stat_loc=0x0, options=0, usage=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
30	in ../sysdeps/unix/sysv/linux/wait4.c
#1  0x00007a9ae40d96b3 in ggml_print_backtrace () from /home/eapache/src/llama.cpp/build/bin/libggml-base.so.0
#2  0x00007a9ae40d985b in ggml_abort () from /home/eapache/src/llama.cpp/build/bin/libggml-base.so.0
#3  0x00007a9adbf2ce27 in ggml_cuda_error(char const*, char const*, char const*, int, char const*) () from /home/eapache/src/llama.cpp/build/bin/libggml-cuda.so.0
#4  0x00007a9adbf448ce in ggml_cuda_pool_vmm::alloc(unsigned long, unsigned long*) () from /home/eapache/src/llama.cpp/build/bin/libggml-cuda.so.0
#5  0x00007a9adbf33160 in ggml_cuda_op_mul_mat_cublas(ggml_backend_cuda_context&, ggml_tensor const*, ggml_tensor const*, ggml_tensor*, char const*, float const*, char const*, float*, long, long, long, long, CUstream_st*) () from /home/eapache/src/llama.cpp/build/bin/libggml-cuda.so.0
#6  0x00007a9adbf39c54 in ggml_cuda_op_mul_mat(ggml_backend_cuda_context&, ggml_tensor const*, ggml_tensor const*, ggml_tensor*, void (*)(ggml_backend_cuda_context&, ggml_tensor const*, ggml_tensor const*, ggml_tensor*, char const*, float const*, char const*, float*, long, long, long, long, CUstream_st*), void (*)(float const*, int const*, void*, ggml_type, long, long, long, long, long, long, long, long, CUstream_st*)) () from /home/eapache/src/llama.cpp/build/bin/libggml-cuda.so.0
#7  0x00007a9adbf3ce0b in ggml_cuda_compute_forward(ggml_backend_cuda_context&, ggml_tensor*) () from /home/eapache/src/llama.cpp/build/bin/libggml-cuda.so.0
#8  0x00007a9adbf40803 in evaluate_and_capture_cuda_graph(ggml_backend_cuda_context*, ggml_cgraph*, bool&, bool&, bool&) [clone .constprop.0] () from /home/eapache/src/llama.cpp/build/bin/libggml-cuda.so.0
#9  0x00007a9adbf42770 in ggml_backend_cuda_graph_compute(ggml_backend*, ggml_cgraph*) () from /home/eapache/src/llama.cpp/build/bin/libggml-cuda.so.0
#10 0x00007a9ae40f59a7 in ggml_backend_sched_graph_compute_async () from /home/eapache/src/llama.cpp/build/bin/libggml-base.so.0
#11 0x00007a9ae40f5c82 in ggml_backend_sched_graph_compute () from /home/eapache/src/llama.cpp/build/bin/libggml-base.so.0
#12 0x00007a9ae4208310 in clip_image_batch_encode(clip_ctx*, int, clip_image_f32_batch const*, float*) () from /home/eapache/src/llama.cpp/build/bin/libmtmd.so.0
#13 0x00007a9ae41958a3 in mtmd_encode () from /home/eapache/src/llama.cpp/build/bin/libmtmd.so.0
#14 0x00007a9ae4202489 in mtmd_helper_eval_chunk_single () from /home/eapache/src/llama.cpp/build/bin/libmtmd.so.0
#15 0x00005dbd58a6ee43 in server_tokens::process_chunk(llama_context*, mtmd_context*, unsigned long, int, int, unsigned long&) const ()
#16 0x00005dbd58ab8f34 in server_context_impl::update_slots() ()
#17 0x00005dbd58a5e9e8 in server_queue::start_loop() ()
#18 0x00005dbd589e7dbf in main ()

Activity

  1. eapache commented on Dec 16, 2025

    @eapache
    ContributorAuthor
  2. SlavikCA commented on Dec 18, 2025

    @SlavikCA

    I'm getting same issue.

    System with 2 GPUs:

    • RTX 4090D 48GB VRAM
    • RTX 3090 24GB VRAM

    Build:
    build: 7444 (5806286) with GNU 11.4.0 for Linux x86_64

    Using this config:

    services:
      glm46:
        image: ghcr.io/ggml-org/llama.cpp:full-cuda
        container_name: glm46v
        deploy:
          resources:
            reservations:
              devices:
                - driver: nvidia
                  capabilities: [gpu]
        ports:
          - "36000:36000"
        volumes:
          - /home/slavik/.cache:/root/.cache
        entrypoint: ["./llama-server"]
        command: >
          --model  /root/.cache/llama.cpp/router/local-GLM4.6V-106b/ggml-org_GLM-4.6V-GGUF_GLM-4.6V-Q4_K_M.gguf
          --mmproj /root/.cache/llama.cpp/router/local-GLM4.6V-106b/mmproj-GLM-4.6V-Q8_0.gguf
          --host 0.0.0.0  --port 36000
          --ctx-size 65536
          --jinja
          --fit on
    

    When I start it:

    • using 47.67Gi/47.98Gi on RTX 4090D
    • using 22.88Gi/24.00Gi on RTX 3090
    • textual requests works great, no issues.
    glm46v  | common_init_result: fitting params to device memory, to report bugs during this step use -fit off (or --verbose if you can't)
    glm46v  | llama_params_fit_impl: projected memory use with initial parameters [MiB]:
    glm46v  | llama_params_fit_impl:   - CUDA0 (NVIDIA GeForce RTX 4090 D):  48508 total,  54332 used,   6181 deficit
    glm46v  | llama_params_fit_impl:   - CUDA1 (NVIDIA GeForce RTX 3090)  :  24124 total,  25698 used,   1839 deficit
    glm46v  | llama_params_fit_impl: projected to use 80030 MiB of device memory vs. 72632 MiB of free device memory
    glm46v  | llama_params_fit_impl: cannot fulfill margin of 1024 MiB on all devices, need to use 10068 MiB less in total
    glm46v  | llama_params_fit_impl: context size set by user to 65536 -> no change
    glm46v  | llama_params_fit_impl: with only dense weights in device memory there is a total surplus of 52835 MiB
    glm46v  | llama_params_fit_impl: filling dense-only layers back-to-front:
    glm46v  | llama_params_fit_impl:   - CUDA1 (NVIDIA GeForce RTX 3090)  : 46 layers,   2016 MiB used,  21842 MiB free
    glm46v  | llama_params_fit_impl:   - CUDA0 (NVIDIA GeForce RTX 4090 D):  0 layers,   1236 MiB used,  46914 MiB free
    glm46v  | llama_params_fit_impl: converting dense-only layers to full layers and filling them front-to-back with overflow to next device/system memory:
    glm46v  | llama_params_fit_impl:   - CUDA0 (NVIDIA GeForce RTX 4090 D): 28 layers ( 1 overflowing),  46879 MiB used,   1271 MiB free
    glm46v  | llama_params_fit_impl:   - CUDA1 (NVIDIA GeForce RTX 3090)  : 18 layers ( 7 overflowing),  22683 MiB used,   1175 MiB free
    glm46v  | llama_params_fit: successfully fit params to free device memory
    glm46v  | llama_params_fit: fitting params to free memory took 5.74 seconds
    glm46v  | llama_model_load_from_file_impl: using device CUDA0 (NVIDIA GeForce RTX 4090 D) (0000:00:10.0) - 48150 MiB free
    glm46v  | llama_model_load_from_file_impl: using device CUDA1 (NVIDIA GeForce RTX 3090) (0000:00:11.0) - 23859 MiB free
    

    But on the first request with image it crashed:

    glm46v  | slot launch_slot_: id  3 | task 0 | processing task
    glm46v  | slot update_slots: id  3 | task 0 | new prompt, n_ctx_slot = 65536, n_keep = 0, task.n_tokens = 1395
    glm46v  | slot update_slots: id  3 | task 0 | n_tokens = 0, memory_seq_rm [0, end)
    glm46v  | slot update_slots: id  3 | task 0 | prompt processing progress, n_tokens = 12, batch.n_tokens = 12, progress = 0.008602
    glm46v  | slot update_slots: id  3 | task 0 | n_tokens = 12, memory_seq_rm [12, end)
    glm46v  | srv  process_chun: processing image...
    glm46v  | encoding image slice...
    glm46v exited with code 139
    
  3. SlavikCA commented on Dec 26, 2025

    @SlavikCA

    duplicate to #18181 ?

  4. eapache commented on Dec 26, 2025

    @eapache
    ContributorAuthor

    Yes, duplicate, although this one was filed first that one clearly has received more attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions