[GH-ISSUE #679] Feature Request: Load/Offload/Swap mmproj dynamically from RAM to VRAM when used #317

Closed
opened 2026-11-04 01:41:55 +07:00 by bsakaguchi · 13 comments
Owner

Originally created by @Interpause on GitHub (Oct 3, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/679

mmproj is only used when images are attached, and AFAIK all images can be encoded to image tokens first before prompt processing with the rest of the text tokens. As such, swapping mmproj from RAM to VRAM only when used is a way to reduce VRAM use and hence keep more experts in VRAM.

See discussion on llama.cpp for ideas on how this can be done optimally for max speed: https://github.com/ggml-org/llama.cpp/discussions/20246

Originally created by @Interpause on GitHub (Oct 3, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/679 mmproj is only used when images are attached, and AFAIK all images can be encoded to image tokens first before prompt processing with the rest of the text tokens. As such, swapping mmproj from RAM to VRAM only when used is a way to reduce VRAM use and hence keep more experts in VRAM. See discussion on llama.cpp for ideas on how this can be done optimally for max speed: https://github.com/ggml-org/llama.cpp/discussions/20246
Author
Owner

@ampersandru commented on GitHub (Oct 3, 2026):

Depends on your RAM and CPU but I found mmproj running on CPU already extremely fast with qwen3.8, where the latency of having it load to vram, then process it, would negate any speed differences

<!-- gh-comment-id:5973275786 --> @ampersandru commented on GitHub (Oct 3, 2026): Depends on your RAM and CPU but I found mmproj running on CPU already extremely fast with qwen3.8, where the latency of having it load to vram, then process it, would negate any speed differences
Author
Owner

@ukrolelo commented on GitHub (Oct 3, 2026):

Depends on your RAM and CPU but I found mmproj running on CPU already extremely fast with qwen3.8, where the latency of having it load to vram, then process it, would negate any speed differences

strata allows to use mmproj through CPU? please advice ^^

<!-- gh-comment-id:5973344773 --> @ukrolelo commented on GitHub (Oct 3, 2026): > Depends on your RAM and CPU but I found mmproj running on CPU already extremely fast with qwen3.8, where the latency of having it load to vram, then process it, would negate any speed differences strata allows to use mmproj through CPU? please advice ^^
Author
Owner

@ampersandru commented on GitHub (Oct 3, 2026):

Depends on your RAM and CPU but I found mmproj running on CPU already extremely fast with qwen3.8, where the latency of having it load to vram, then process it, would negate any speed differences

strata allows to use mmproj through CPU? please advice ^^

Yeah, use --vision cpu instead of true

<!-- gh-comment-id:5973363326 --> @ampersandru commented on GitHub (Oct 3, 2026): > > Depends on your RAM and CPU but I found mmproj running on CPU already extremely fast with qwen3.8, where the latency of having it load to vram, then process it, would negate any speed differences > > strata allows to use mmproj through CPU? please advice ^^ Yeah, use --vision cpu instead of true
Author
Owner

@Interpause commented on GitHub (Oct 4, 2026):

Depends on your RAM and CPU but I found mmproj running on CPU already extremely fast with qwen3.8, where the latency of having it load to vram, then process it, would negate any speed differences

would you mind sharing your timing? I assume you are using the default settings which means 1024 max image tokens... 3 months ago on mainline llama.cpp for qwen3.6 27B's mmproj encode stage, 1024 took about 3s per image for me. Is your time roughly in that ballpark?

EDIT: ill test tmrw

<!-- gh-comment-id:5977791045 --> @Interpause commented on GitHub (Oct 4, 2026): > Depends on your RAM and CPU but I found mmproj running on CPU already extremely fast with qwen3.8, where the latency of having it load to vram, then process it, would negate any speed differences would you mind sharing your timing? I assume you are using the default settings which means 1024 max image tokens... 3 months ago on mainline llama.cpp for qwen3.6 27B's mmproj encode stage, 1024 took about 3s per image for me. Is your time roughly in that ballpark? EDIT: ill test tmrw
Author
Owner

@jinkang06 commented on GitHub (Oct 4, 2026):

Brilliant idea!

<!-- gh-comment-id:5978578980 --> @jinkang06 commented on GitHub (Oct 4, 2026): Brilliant idea!
Author
Owner

@ampersandru commented on GitHub (Oct 4, 2026):

Depends on your RAM and CPU but I found mmproj running on CPU already extremely fast with qwen3.8, where the latency of having it load to vram, then process it, would negate any speed differences

would you mind sharing your timing? I assume you are using the default settings which means 1024 max image tokens... 3 months ago on mainline llama.cpp for qwen3.6 27B's mmproj encode stage, 1024 took about 3s per image for me. Is your time roughly in that ballpark?

EDIT: ill test tmrw

It's about 3 seconds on CPU (14600k with ddr4) and right under 2 seconds with mmproj on vram. Id be interested what the total time would be to have it on ram then load it into vram, but I'm assuming it's going to equal out to be very similar

<!-- gh-comment-id:5982205079 --> @ampersandru commented on GitHub (Oct 4, 2026): > > Depends on your RAM and CPU but I found mmproj running on CPU already extremely fast with qwen3.8, where the latency of having it load to vram, then process it, would negate any speed differences > > would you mind sharing your timing? I assume you are using the default settings which means 1024 max image tokens... 3 months ago on mainline llama.cpp for qwen3.6 27B's mmproj encode stage, 1024 took about 3s per image for me. Is your time roughly in that ballpark? > > EDIT: ill test tmrw It's about 3 seconds on CPU (14600k with ddr4) and right under 2 seconds with mmproj on vram. Id be interested what the total time would be to have it on ram then load it into vram, but I'm assuming it's going to equal out to be very similar
Author
Owner

@boorad64 commented on GitHub (Oct 4, 2026):

Yeah, use --vision cpu instead of true

I changed my json to have "--vision cpu", and it quit with an error: "unknown argument: --vision cpu"

Any advice? the "usage" statement doesn't show vision taking any arguments

<!-- gh-comment-id:5984011132 --> @boorad64 commented on GitHub (Oct 4, 2026): > Yeah, use --vision cpu instead of true I changed my json to have "--vision cpu", and it quit with an error: "unknown argument: --vision cpu" Any advice? the "usage" statement doesn't show vision taking any arguments
Author
Owner

@ampersandru commented on GitHub (Oct 4, 2026):

Yeah, use --vision cpu instead of true

I changed my json to have "--vision cpu", and it quit with an error: "unknown argument: --vision cpu"

Any advice? the "usage" statement doesn't show vision taking any arguments

Im using docker, so its either
VISION=cpu
VISION=yes

for docker commandline, it should be -e VISION=no\yes\cpu

https://github.com/Niko1221/Strata/blob/main/docs/INSTALL.md

<!-- gh-comment-id:5984056694 --> @ampersandru commented on GitHub (Oct 4, 2026): > > Yeah, use --vision cpu instead of true > > I changed my json to have "--vision cpu", and it quit with an error: "unknown argument: --vision cpu" > > Any advice? the "usage" statement doesn't show vision taking any arguments Im using docker, so its either VISION=cpu VISION=yes for docker commandline, it should be -e VISION=no\yes\cpu https://github.com/Niko1221/Strata/blob/main/docs/INSTALL.md
Author
Owner

@sinand99 commented on GitHub (Oct 4, 2026):

This would be very useful for low VRAM cards

<!-- gh-comment-id:5984204518 --> @sinand99 commented on GitHub (Oct 4, 2026): This would be very useful for low VRAM cards
Author
Owner

@talisp commented on GitHub (Oct 5, 2026):

Some numbers for the VRAM side of this, from a 48 GB card (NVIDIA L40S vGPU, ~42 GiB usable, 0.1.38/0.1.39, --vision gpu, the BF16 mmproj, 1024 image tokens):

  • VRAM: the GPU encoder took ~1.5 GiB. The expert cache went from 18,536 to 17,761 slots (−4%).
  • Decode on IQ3_S: no measurable change at 90–190K context. Mean 102.8 tok/s without images (309 replies) and 102.5 with images (871 replies).
  • Per image request: 3.6–8 s for a whole request with one image (encode + prompt + answer).

So on a big card the resident encoder is nearly free; the case for swapping it in and out is the small cards (12–16 GB), where 1.5 GiB is a much bigger share of the cache.

@boorad64: --vision cpu is a setup option, not an engine argument, which is why the engine said "unknown argument". Run setup again with --vision cpu (setup.py --setup --vision cpu), or in strata-<model>.json keep the bare "--vision" flag in args and set the separate section, which is what setup writes:

"vision": {"exe": ".../strata-vision", "mmproj": ".../mmproj-Qwen3.8-Flash-Next-BF16.gguf", "model": "<shard 1>", "gpu": false, "max_tokens": 300, "threads": 16}
<!-- gh-comment-id:6002043173 --> @talisp commented on GitHub (Oct 5, 2026): Some numbers for the VRAM side of this, from a 48 GB card (NVIDIA L40S vGPU, ~42 GiB usable, 0.1.38/0.1.39, `--vision gpu`, the BF16 mmproj, 1024 image tokens): - **VRAM:** the GPU encoder took ~1.5 GiB. The expert cache went from 18,536 to 17,761 slots (−4%). - **Decode on IQ3_S:** no measurable change at 90–190K context. Mean 102.8 tok/s without images (309 replies) and 102.5 with images (871 replies). - **Per image request:** 3.6–8 s for a whole request with one image (encode + prompt + answer). So on a big card the resident encoder is nearly free; the case for swapping it in and out is the small cards (12–16 GB), where 1.5 GiB is a much bigger share of the cache. @boorad64: `--vision cpu` is a **setup** option, not an engine argument, which is why the engine said "unknown argument". Run setup again with `--vision cpu` (`setup.py --setup --vision cpu`), or in `strata-<model>.json` keep the bare `"--vision"` flag in `args` and set the separate section, which is what setup writes: ```json "vision": {"exe": ".../strata-vision", "mmproj": ".../mmproj-Qwen3.8-Flash-Next-BF16.gguf", "model": "<shard 1>", "gpu": false, "max_tokens": 300, "threads": 16} ```
Author
Owner

@ampersandru commented on GitHub (Oct 7, 2026):

heres my test with vision on VRAM vs vision on CPU (14600k with 3200Mhz DDR4):
IQ3_S comparison using the same images, with K8V4 cache in VRAM:

Metric GPU vision CPU vision
Completed requests 5/5 5/5
Average reported duration 1.54 s 1.74 s
Duration range 1.2–1.7 s 1.6–2.0 s
Average decode speed 88.4 tok/s 85.2 tok/s
Average output length 76.6 tokens 86.2 tokens
Average VRAM expert hit rate 97.84% 97.88%
Reused prompt tokens 0 0

CPU vision averaged 0.20 seconds longer in the displayed request timings,
but generated approximately 12.5% more output tokens. Decode speed was
approximately 3.6% lower, with essentially unchanged expert-cache hit rate.

For these images, the displayed timings show only a small difference.
These are five-request samples, and the monitor's duration may not include
the separate image-encoding step, so this does not establish total
end-to-end image-processing latency.

Im going to keep vision on CPU so i can free up some VRAM for other things

<!-- gh-comment-id:6027856413 --> @ampersandru commented on GitHub (Oct 7, 2026): heres my test with vision on VRAM vs vision on CPU (14600k with 3200Mhz DDR4): IQ3_S comparison using the same images, with K8V4 cache in VRAM: | Metric | GPU vision | CPU vision | |---|---:|---:| | Completed requests | 5/5 | 5/5 | | Average reported duration | 1.54 s | 1.74 s | | Duration range | 1.2–1.7 s | 1.6–2.0 s | | Average decode speed | 88.4 tok/s | 85.2 tok/s | | Average output length | 76.6 tokens | 86.2 tokens | | Average VRAM expert hit rate | 97.84% | 97.88% | | Reused prompt tokens | 0 | 0 | CPU vision averaged 0.20 seconds longer in the displayed request timings, but generated approximately 12.5% more output tokens. Decode speed was approximately 3.6% lower, with essentially unchanged expert-cache hit rate. For these images, the displayed timings show only a small difference. These are five-request samples, and the monitor's duration may not include the separate image-encoding step, so this does not establish total end-to-end image-processing latency. Im going to keep vision on CPU so i can free up some VRAM for other things
Author
Owner

@Niko1221 commented on GitHub (Oct 7, 2026):

Thanks. We have no plan to swap the encoder between RAM and VRAM on demand. The choice is made at setup: --vision gpu keeps it in VRAM, --vision cpu keeps it in RAM, and as you measured, 1.5 GiB for the encoder costs about 4% of expert slots and does not change decode. Closing with that answer.

<!-- gh-comment-id:6037745171 --> @Niko1221 commented on GitHub (Oct 7, 2026): Thanks. We have no plan to swap the encoder between RAM and VRAM on demand. The choice is made at setup: --vision gpu keeps it in VRAM, --vision cpu keeps it in RAM, and as you measured, 1.5 GiB for the encoder costs about 4% of expert slots and does not change decode. Closing with that answer.
Author
Owner

@dany4ok commented on GitHub (Nov 6, 2026):

Additional exploratory measurement: CPU vision encoder resident in RAM vs elastic idle-unload, while generating text only

This is a small, single-machine observation relevant to whether keeping the mmproj/vision process resident has a measurable cost. It is not a standard Strata benchmark, and the rates below are client-observed end-to-end rates, not engine decode throughput.

Environment: Windows 11 Pro build 26200; RTX 5070 Ti (16 GiB, driver 621.01, configured 252 W power limit); Ryzen 7 7700X; 31.6 GiB installed RAM visible to Windows. Strata engine 0.1.57 (Windows x86_64 CUDA 13). Local Gyro-Gyro-S / Qwen3.8-Flash-Next-TQ1_0 model. BF16 mmproj, vision encoder on CPU, 8 threads, elastic idle timeout 30 s. While resident, strata-vision.exe used ~1,108 MiB working set (~1,349 MiB private bytes). During text-only generation the encoder was idle.

Method: same text-only chat-completions request, max_tokens=2000, four requests per state per cycle. The model naturally stopped at 759–826 completion tokens. Encoder residency/unload was checked by process; unload was the configured elastic idle-down. Reported rate = API completion_tokens divided by full HTTP request elapsed time, so it includes prompt processing and request overhead. The Strata community benchmark guide correctly says this must not be called decode tok/s; engine timing lines were not captured. Prompt/cache state and GPU clocks were not controlled, and the comparison is underpowered.

Cycle State completion tokens / elapsed seconds -> client end-to-end tok/s
A Encoder resident 784/21.65 -> 36.2*; 826/6.81 -> 121.2; 790/7.44 -> 106.2; 797/7.23 -> 110.3
A Encoder unloaded 763/6.91 -> 110.4; 767/5.86 -> 130.9; 759/6.87 -> 110.5; 780/5.63 -> 138.5
B Encoder resident 797/22.06 -> 36.1*; 759/5.34 -> 142.0; 766/5.04 -> 151.9; 780/5.66 -> 137.8
B Encoder unloaded 763/5.15 -> 148.2; 804/6.10 -> 131.9; 784/5.77 -> 135.9; 787/5.80 -> 135.8

*First request after starting the encoder; the ~22 s includes encoder-start overlap and is not a steady-state comparison.

Warm medians: cycle A 110.3 tok/s resident vs 120.7 unloaded; cycle B 142.0 resident vs 135.8 unloaded. Direction reverses between cycles; these data do not establish a consistent steady-state penalty from RAM residency. The first request overlapping startup was slower in both cycles.

Limitations / failures: encoder was triggered using an invalid 8x8 PNG; image request returned HTTP 400 (cannot read image), although the encoder process did start and remain resident. No successful image correctness check was performed. Exact Strata app/source revision, model hash, background load and engine timing logs were not recorded. Per-run observations above were transcribed from the test output; no structured results JSON was saved.

Takeaway: on this setup, leaving the CPU vision encoder resident in RAM showed no consistent steady-state text-generation penalty in this small sample. A follow-up using the engine's decode/prompt timing fields, more order-swapped trials, and saved structured results would be needed for a comparable benchmark. No configuration change is proposed.

<!-- gh-comment-id:6696125263 --> @dany4ok commented on GitHub (Nov 6, 2026): Additional exploratory measurement: CPU vision encoder resident in RAM vs elastic idle-unload, while generating text only This is a small, single-machine observation relevant to whether keeping the mmproj/vision process resident has a measurable cost. It is not a standard Strata benchmark, and the rates below are client-observed end-to-end rates, not engine decode throughput. Environment: Windows 11 Pro build 26200; RTX 5070 Ti (16 GiB, driver 621.01, configured 252 W power limit); Ryzen 7 7700X; 31.6 GiB installed RAM visible to Windows. Strata engine 0.1.57 (Windows x86_64 CUDA 13). Local Gyro-Gyro-S / Qwen3.8-Flash-Next-TQ1_0 model. BF16 mmproj, vision encoder on CPU, 8 threads, elastic idle timeout 30 s. While resident, strata-vision.exe used ~1,108 MiB working set (~1,349 MiB private bytes). During text-only generation the encoder was idle. Method: same text-only chat-completions request, max_tokens=2000, four requests per state per cycle. The model naturally stopped at 759–826 completion tokens. Encoder residency/unload was checked by process; unload was the configured elastic idle-down. Reported rate = API completion_tokens divided by full HTTP request elapsed time, so it includes prompt processing and request overhead. The Strata community benchmark guide correctly says this must not be called decode tok/s; engine timing lines were not captured. Prompt/cache state and GPU clocks were not controlled, and the comparison is underpowered. | Cycle | State | completion tokens / elapsed seconds -> client end-to-end tok/s | |---|---|---| | A | Encoder resident | 784/21.65 -> 36.2*; 826/6.81 -> 121.2; 790/7.44 -> 106.2; 797/7.23 -> 110.3 | | A | Encoder unloaded | 763/6.91 -> 110.4; 767/5.86 -> 130.9; 759/6.87 -> 110.5; 780/5.63 -> 138.5 | | B | Encoder resident | 797/22.06 -> 36.1*; 759/5.34 -> 142.0; 766/5.04 -> 151.9; 780/5.66 -> 137.8 | | B | Encoder unloaded | 763/5.15 -> 148.2; 804/6.10 -> 131.9; 784/5.77 -> 135.9; 787/5.80 -> 135.8 | *First request after starting the encoder; the ~22 s includes encoder-start overlap and is not a steady-state comparison. Warm medians: cycle A 110.3 tok/s resident vs 120.7 unloaded; cycle B 142.0 resident vs 135.8 unloaded. Direction reverses between cycles; these data do not establish a consistent steady-state penalty from RAM residency. The first request overlapping startup was slower in both cycles. Limitations / failures: encoder was triggered using an invalid 8x8 PNG; image request returned HTTP 400 (cannot read image), although the encoder process did start and remain resident. No successful image correctness check was performed. Exact Strata app/source revision, model hash, background load and engine timing logs were not recorded. Per-run observations above were transcribed from the test output; no structured results JSON was saved. Takeaway: on this setup, leaving the CPU vision encoder resident in RAM showed no consistent steady-state text-generation penalty in this small sample. A follow-up using the engine's decode/prompt timing fields, more order-swapped trials, and saved structured results would be needed for a comparable benchmark. No configuration change is proposed.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#317
No description provided.