Repository navigation
Studio FLUX.3 upsampler: count Vulkan VRAM on Linux ROCm before keeping the server resident - #17159
Conversation
…ng the server resident On Linux ROCm, hipMemGetInfo counts only compute (KFD) allocations. A Vulkan process (the upsampler's own llama-server and sd-server in the ROCm Docker image) and the desktop are invisible to it: on an RX 6700 XT a 2.5 GiB Vulkan llama-server left torch.cuda.mem_get_info() at 11802 MiB free while the DRM sysfs counter rose by 2.5 GiB. So after an enhanced prompt the upsampler (5.8 GiB) never read as tight and stayed resident, and FLUX.3 klein on sd.cpp then failed at once: "model manager cannot make enough memory available on Vulkan0: need 6447.72 MB device ... available 3715.92 MB". Every later run failed the same way until the keep-alive ran out or Enhance was turned off (which releases it). utils.hardware.hardware.rocm_linux_kernel_free_mib reads the card's free VRAM from DRM sysfs (found by the PCI address torch reports; only trusted when the sysfs total matches torch's within ~10%), and the upsampler's memory probe takes the lower of the two. Warm start, release_if_tight and the layer plan all read through that probe. Off Linux ROCm nothing changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@codex review |
1 similar comment
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Thanks @hMelchisedek. On Linux ROCm, FLUX.3 klein renders with Enhance prompt on failed with an out-of-memory error, because the prompt upsampler never unloaded after writing its caption.
The check now also reads the card's free VRAM from DRM sysfs, which counts every process and every API, and uses the lower figure. From the PR's measurement on an RX 6700 XT:
I pushed The MiniMax-H3-Image prompt enhancer uses the same server and gets the fix too. CUDA, Windows and macOS are unchanged. The 4 new tests fail on main and pass here, and 280 upsampler, enhancer and probe tests pass on the PR merged with main. CI is clear at
|
Summary
On Linux ROCm, the FLUX.3 prompt upsampler never unloads after writing its caption. FLUX.3 klein on stable-diffusion.cpp then fails at once with an out-of-memory error, and so does every later run until the upsampler's keep-alive runs out or Enhance prompt is turned off.
The cause is the free-memory figure. On Linux,
hipMemGetInfo(torch.cuda.mem_get_info) counts only compute (KFD) allocations, so Vulkan processes and the desktop are invisible to it. In the ROCm Docker image, both the upsampler's llama-server and sd-server are Vulkan processes. So with the upsampler holding 5.8 GiB,release_if_tightstill read the card as 11.8 GiB free and kept the upsampler loaded.The fix reads the card's free VRAM from DRM sysfs, which the kernel keeps for every process and every API. The upsampler's memory probe then takes the lower of the two figures.
The measurement
torch.cuda.mem_get_info()vs/sys/class/drm/card*/device/mem_info_vram_*, insideunsloth/unsloth-rocm:v0.1.916-beta-studioon an RX 6700 XT (12 GB). The middle line was taken while Studio's bundled Vulkanllama-serverheld a 3B Q4_K_M model with-ngl 99:Reproduction
FLUX.3 klein Q8_0 (
unsloth/flux-3-image-klein-GGUF) on the sd.cpp engine, 1024×1024, 16 steps, guidance 1, Enhance prompt on. Run with the v0.1.916-beta image plus #16815 backported, so the failure carries sd-server's output.Before: the upsampler starts with
free 11806 MiB on cudaand nounloading after the callline follows. The job then fails:The Images page shows "Image generation failed. The device ran out of memory." Calling
POST /images/prompt-upsampler/release(which turning Enhance off also does) and generating again succeeds. So sd-server itself is fine; the resident upsampler is what holds the memory.After:
Both enhanced 1024×1024 renders then complete (
prompt_enhancement: applied).Changes
utils/hardware/hardware.py: newrocm_linux_kernel_free_mib(device=None).mem_info_vram_used/total.get_device_propertiesreports, matched against_rocm_linux_amdgpu_cards()._rocm_system_wide_vram_by_indexuses, for APU carve-outs and partitioned cards. It never raises.core/inference/flux3_prompt_upsampler.py:_accelerator_memory_mibusesmin(HIP free, kernel free)on CUDA/ROCm devices.release_if_tightandplan_gpu_layersall read through it, so all three see the Vulkan users now.tests/test_rocm_kernel_free_vram.py: card selection by PCI address, scope mismatch / no match / broken props → None, Linux + HIP only.test_flux3_prompt_upsampler.py::test_accelerator_memory_counts_what_the_hip_figure_misses.Testing
pytest tests/test_rocm_kernel_free_vram.py tests/test_flux3_prompt_upsampler.py, run in the ROCm Studio venv (torch 2.11.0+rocm7.2) onmainand on v0.1.916-beta: 216 passed, 11 failed.CUDA_VISIBLE_DEVICES/ROCR_VISIBLE_DEVICESmask cases.scripts/run_ruff_format.pyandruff checkon the changed files: clean.Not changed here
diffusion_memory._cuda_memory, and sotrusted_mem_get_info, which diffusers load plans read, have the same blind spot on Linux ROCm. A chat model on Vulkan llama-server, or the desktop, isn't counted when an image model plans its offload. Fixing that there would change every diffusion budget on Linux ROCm, so it's left for a separate change if you want it.