Repository navigation
Conversation
…t leaves free available_bytes left max(4 GiB, a tenth of memory) free on both sides: the GPU's mem_get_info total (a tenth rounded up) and, where /proc/meminfo exists, MemTotal (a tenth rounded down). reserve_bytes() keeps that default exactly and takes TENSORFOLD_MEMORY_RESERVE_GIB instead when it is set: a number of GiB from 2 to the memory's size, anything else refuses at startup. On a unified-memory GPU the host side is the whole budget, so a DGX Spark (128 GB, MemTotal 121.7 GiB) always kept 12.2 GiB back; an operator who knows the machine's headroom can now give some of it to KV caches, or keep more for other work. docs/api.md names the variable next to the reserve it replaces. Tests: tests/test_memory_reserve.py (the default, rounding included; overrides; out-of-range and non-numeric values refuse; available_bytes on unified and discrete GPUs with and without /proc/meminfo). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_014wCj5zx4NuKdUNWUeJi3X1
|
This PR conflicts with #106 (the host-RAM tier for Qwen3.8-27B) in #106 moves the host term into a helper,
The resolution I'd suggest is to have def host_room() -> int | None:
memory = _meminfo()
return None if memory is None else max(0, memory["MemAvailable"] - reserve_bytes(memory["MemTotal"], host=True))
def available_bytes(torch) -> int:
free, total = map(int, torch.cuda.mem_get_info())
available = max(0, free - reserve_bytes(total))
host = host_room()
...I tried this merge locally. Your If this PR lands first, I'll rebase #106 onto it with the change above. |
|
Thanks for the knob. |
TL;DR:
TENSORFOLD_MEMORY_RESERVE_GIBsets how much memory the CUDA startup budget leaves free. Unset, the reserve is exactly what it is today: max(4 GiB, a tenth of memory). On unified-memory machines such as the DGX Spark, where the default holds back 12.2 GiB, an operator who knows the headroom can give more of it to KV caches (or keep more back for other work).The problem
cuda/capacity.available_bytessizes every CUDA engine's startup budget as free memory minusmax(4 GiB, total / 10). The reserve covers what the estimate doesn't count (CUDA context, NCCL, workspaces) and the host itself, and it can't be changed. On a unified-memory GPU the host side is the whole budget, so a DGX Spark (128 GB,MemTotal121.7 GiB) always keeps 12.2 GiB back, however much of that the machine actually needs. With large models, that decides how many streams or how long a window fits. The only way to leave more room for other work is a smaller--context/--parallel.The change
capacity.reserve_bytes(total, host=False): with the variable unset it returns today's reserve exactly, including the rounding (the GPU path'smath.ceil(total / 10)and the host path'sMemTotal // 10). WhenTENSORFOLD_MEMORY_RESERVE_GIBis set, it returns that many GiB instead, on both sides.nan, not a number) raises aValueErrornaming the variable at startup.available_bytescallsreserve_bytesin place of the two inline expressions. Nothing else changes.docs/api.md: the unified-memory paragraph names the variable, with a warning that the reserve also carries memory the estimate doesn't count and that running a unified GPU out of memory can freeze the host.Tests
tests/test_memory_reserve.py: the default is unchanged, including the rounding on each side and the 4 GiB floor; overrides (integer and fractional, surrounding spaces); out-of-range and non-numeric values refuse;available_bytesuses the reserve on a unified GPU, on a discrete GPU (bounded by both sides), and without/proc/meminfo.tensorfold-glm53:v0.5.0(NVIDIA PyTorch container, aarch64):test_memory_reserve.py,test_cuda_capacity.py,test_cuda_unified_memory.py,test_cuda_geometry.py: 81 passed. Withpytest tests --ignore=tests/cuda -k 'glm or capacity or geometry or cuda or memory': 1155 passed and 21 failed. The failures are the same 21 on unmodifiedmain(1146 passed): MLX memory tests (test_memory_window.py,test_prompt_memory.py,test_resume_memory.py, ...) that needmlx.