[GH-ISSUE #493] [Feature Request]: Configurable VRAM utilization #226

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

Originally created by @mcgravier on GitHub (Oct 2, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/493

As for now, Strata fills entire VRAM first, and loads reminder to RAM

There are two issues with this behavior:
One is that on Linux with AMD card, system and apps compete for VRAM causing severe system slowdowns, second, this prevents multitasking and using other VRAM heavy applications on cards with surplus memory capacity (7900XTX, 4090, 5090)

There should be a flag allowing user to specify desired VRAM utilization.

Originally created by @mcgravier on GitHub (Oct 2, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/493 As for now, Strata fills entire VRAM first, and loads reminder to RAM There are two issues with this behavior: One is that on Linux with AMD card, system and apps compete for VRAM causing severe system slowdowns, second, this prevents multitasking and using other VRAM heavy applications on cards with surplus memory capacity (7900XTX, 4090, 5090) There should be a flag allowing user to specify desired VRAM utilization.
Author
Owner

@mkultra333 commented on GitHub (Oct 2, 2026):

I ran into a similar issue except I'm on windows 11 and an RTX 5060ti 16GB. I will sometimes be using agentic coding for video games, so I want to save a bit of VRAM for the game being developed.

I was thinking maybe either a flag that sets the maximum VRAM to use, or a flag that reserves some set amount of VRAM for other programs.

At the moment I'm using a workaround. I have a python script I run before starting Strata that grabs a chunk of VRAM (default is 2GB). Then with that running, I start up Strata. It adapts to the lower available VRAM and leaves that 2GB untouched. Then I can close the python program and free that VRAM for other things.

The script I use is this (Claude wrote it), it's nvidia specific and may or may not work on Linux, I don't know:

# ZZZ_reserveVRAM.py - hold a chunk of VRAM until you press Enter.
# No dependencies: uses the NVIDIA driver (nvcuda.dll) directly.
# Usage: python ZZZ_reserveVRAM.py 1.5     (reserves 1.5 GB on GPU 0)

import ctypes
import sys

GB = 2**30
CHUNK = 256 * 2**20  # allocate in 256 MB pieces


def check(result, what):
    if result != 0:
        raise RuntimeError(f"{what} failed with CUDA error code {result}")


def main():
    gb = float(sys.argv[1]) if len(sys.argv) > 1 else 2.0
    gpu_index = int(sys.argv[2]) if len(sys.argv) > 2 else 0

    cuda = ctypes.CDLL("nvcuda.dll")

    cuda.cuMemAlloc_v2.argtypes = [ctypes.POINTER(ctypes.c_void_p), ctypes.c_size_t]
    cuda.cuMemGetInfo_v2.argtypes = [ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_size_t)]
    cuda.cuCtxCreate_v2.argtypes = [ctypes.POINTER(ctypes.c_void_p), ctypes.c_uint, ctypes.c_int]

    check(cuda.cuInit(0), "cuInit")

    dev = ctypes.c_int()
    check(cuda.cuDeviceGet(ctypes.byref(dev), gpu_index), "cuDeviceGet")

    name = ctypes.create_string_buffer(256)
    cuda.cuDeviceGetName(name, 256, dev)

    ctx = ctypes.c_void_p()
    check(cuda.cuCtxCreate_v2(ctypes.byref(ctx), 0, dev), "cuCtxCreate")

    def meminfo():
        free, total = ctypes.c_size_t(), ctypes.c_size_t()
        check(cuda.cuMemGetInfo_v2(ctypes.byref(free), ctypes.byref(total)), "cuMemGetInfo")
        return free.value, total.value

    free0, total = meminfo()
    print(f"GPU {gpu_index}: {name.value.decode()}")
    print(f"Before: {free0 / GB:.2f} GB free of {total / GB:.2f} GB")

    target = int(gb * GB)
    got = 0
    held = []
    while got < target:
        size = min(CHUNK, target - got)
        ptr = ctypes.c_void_p()
        if cuda.cuMemAlloc_v2(ctypes.byref(ptr), size) != 0:
            print("Ran out of VRAM before reaching the target.")
            break
        held.append(ptr)
        got += size

    free1, _ = meminfo()
    print(f"Reserved {got / GB:.2f} GB")
    print(f"After:  {free1 / GB:.2f} GB free (includes CUDA context overhead)")
    input("Holding VRAM. Press Enter to release and exit...")

    for ptr in held:
        cuda.cuMemFree_v2(ptr)
    cuda.cuCtxDestroy_v2(ctx)


if __name__ == "__main__":
    main()

<!-- gh-comment-id:5953842393 --> @mkultra333 commented on GitHub (Oct 2, 2026): I ran into a similar issue except I'm on windows 11 and an RTX 5060ti 16GB. I will sometimes be using agentic coding for video games, so I want to save a bit of VRAM for the game being developed. I was thinking maybe either a flag that sets the maximum VRAM to use, or a flag that reserves some set amount of VRAM for other programs. At the moment I'm using a workaround. I have a python script I run before starting Strata that grabs a chunk of VRAM (default is 2GB). Then with that running, I start up Strata. It adapts to the lower available VRAM and leaves that 2GB untouched. Then I can close the python program and free that VRAM for other things. The script I use is this (Claude wrote it), it's nvidia specific and may or may not work on Linux, I don't know: ``` # ZZZ_reserveVRAM.py - hold a chunk of VRAM until you press Enter. # No dependencies: uses the NVIDIA driver (nvcuda.dll) directly. # Usage: python ZZZ_reserveVRAM.py 1.5 (reserves 1.5 GB on GPU 0) import ctypes import sys GB = 2**30 CHUNK = 256 * 2**20 # allocate in 256 MB pieces def check(result, what): if result != 0: raise RuntimeError(f"{what} failed with CUDA error code {result}") def main(): gb = float(sys.argv[1]) if len(sys.argv) > 1 else 2.0 gpu_index = int(sys.argv[2]) if len(sys.argv) > 2 else 0 cuda = ctypes.CDLL("nvcuda.dll") cuda.cuMemAlloc_v2.argtypes = [ctypes.POINTER(ctypes.c_void_p), ctypes.c_size_t] cuda.cuMemGetInfo_v2.argtypes = [ctypes.POINTER(ctypes.c_size_t), ctypes.POINTER(ctypes.c_size_t)] cuda.cuCtxCreate_v2.argtypes = [ctypes.POINTER(ctypes.c_void_p), ctypes.c_uint, ctypes.c_int] check(cuda.cuInit(0), "cuInit") dev = ctypes.c_int() check(cuda.cuDeviceGet(ctypes.byref(dev), gpu_index), "cuDeviceGet") name = ctypes.create_string_buffer(256) cuda.cuDeviceGetName(name, 256, dev) ctx = ctypes.c_void_p() check(cuda.cuCtxCreate_v2(ctypes.byref(ctx), 0, dev), "cuCtxCreate") def meminfo(): free, total = ctypes.c_size_t(), ctypes.c_size_t() check(cuda.cuMemGetInfo_v2(ctypes.byref(free), ctypes.byref(total)), "cuMemGetInfo") return free.value, total.value free0, total = meminfo() print(f"GPU {gpu_index}: {name.value.decode()}") print(f"Before: {free0 / GB:.2f} GB free of {total / GB:.2f} GB") target = int(gb * GB) got = 0 held = [] while got < target: size = min(CHUNK, target - got) ptr = ctypes.c_void_p() if cuda.cuMemAlloc_v2(ctypes.byref(ptr), size) != 0: print("Ran out of VRAM before reaching the target.") break held.append(ptr) got += size free1, _ = meminfo() print(f"Reserved {got / GB:.2f} GB") print(f"After: {free1 / GB:.2f} GB free (includes CUDA context overhead)") input("Holding VRAM. Press Enter to release and exit...") for ptr in held: cuda.cuMemFree_v2(ptr) cuda.cuCtxDestroy_v2(ctx) if __name__ == "__main__": main() ```
Author
Owner

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

This exists already: --vram-reserve-mib N keeps N MiB of VRAM free (default 700). Add it to the args of strata-<model>.json, e.g. "--vram-reserve-mib", "2048", and restart; the expert cache then takes that much less. The next release documents it in INSTALL.md and lets setup set it (--vram-reserve-mib). Closing as answered.

<!-- gh-comment-id:5956994026 --> @Niko1221 commented on GitHub (Oct 2, 2026): This exists already: `--vram-reserve-mib N` keeps N MiB of VRAM free (default 700). Add it to the `args` of `strata-<model>.json`, e.g. `"--vram-reserve-mib", "2048"`, and restart; the expert cache then takes that much less. The next release documents it in INSTALL.md and lets setup set it (`--vram-reserve-mib`). Closing as answered.
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#226
No description provided.