ComfyUI icon indicating copy to clipboard operation
ComfyUI copied to clipboard

Dynamic VRAM fails with "VBAR allocation failed" on ROCm with Linux kernel < 6.10 (KFD < 1.15): dynamic_vram_supported() only checks the ROCm version

Open dragonone0001-debug opened this issue 1 week ago • 2 comments

Custom Node Testing

Expected Behavior

On systems where HIP virtual memory management is not available, ComfyUI should fall back to the legacy model patcher, as it already does when comfy-aimdo is not working.

Actual Behavior

On Ubuntu 24.04 with the stock 6.8 kernel, ComfyUI enables Dynamic VRAM ("DynamicVRAM support detected and enabled") and then fails on the first model load:

[DEBUG] aimdo: /project/src/model-vbar.c:249:DEBUG:vbar_allocate (start): size=79102M, device=0 [ERROR] aimdo: /project/src/model-vbar.c:269:ERROR:Could not reseve Virtual Address space for VBAR MemoryError: VBAR allocation failed

Root cause

dynamic_vram_supported() in main.py enables Dynamic VRAM on AMD when rocm_version >= (7, 14), but does not check whether the device supports virtual memory management.

ROCr only enables the virtual memory API when the KFD interface version is 1.15 or newer (Runtime::CheckVirtualMemApiSupport() in rocr-runtime). Linux 6.8 ships KFD 1.14, so on this kernel:

  • hipDeviceGetAttribute(hipDeviceAttributeVirtualMemoryManagementSupported) returns 0
  • hipMemAddressReserve() fails with hipErrorOutOfMemory even for 2 MB

Same GPU, same HIP runtime (7.15.26333), only the kernel changed:

Kernel KFD version VMM supported hipMemAddressReserve Dynamic VRAM
6.8.0-149 (Ubuntu 24.04 GA) 1.14 0 hipErrorOutOfMemory (even 2 MB) VBAR allocation failed
7.0.0-43 (Ubuntu 24.04 HWE) 1.22 1 hipSuccess (2 MB - 24000 MB) works (Qwen-Image 2512, 40 steps, 3.17 s/it)

An RX 9060 XT (gfx1200) on kernel 7.0 (KFD 1.22) also reports VMM supported = 1. So this is not specific to gfx1100; it should affect any AMD GPU on a kernel older than 6.10, including the Ubuntu 24.04 GA kernel.

Workarounds

  1. Start ComfyUI with --disable-dynamic-vram. However, the startup warning says this argument will be removed soon, which would leave no workaround inside ComfyUI.
  2. Use a kernel with KFD 1.15 or newer (Linux 6.10+). On Ubuntu 24.04, the HWE kernel (linux-generic-hwe-24.04, currently 7.0.0-43) works as shown above.

Suggested fix

In dynamic_vram_supported() (or in comfy-aimdo init_devices()), check hipDeviceAttributeVirtualMemoryManagementSupported, or try a small hipMemAddressReserve(), and fall back to the legacy model patcher if it is not supported. It would also help to log why Dynamic VRAM was disabled, since users currently only see "VBAR allocation failed".

Related: Comfy-Org/comfy-aimdo#25 (proposes falling back instead of raising when the VBAR reservation fails).

Steps to Reproduce

  1. Ubuntu 24.04 with the stock 6.8 kernel (KFD 1.14), AMD GPU, PyTorch with ROCm >= 7.14
  2. Start ComfyUI without --disable-dynamic-vram: --disable-pinned-memory --cache-none --disable-smart-memory --disable-async-offload --disable-all-custom-nodes --verbose DEBUG
  3. Run any workflow (tested with Qwen-Image 2512, fp8 text encoder + INT8 diffusion model); it fails on the first model load

How I checked:

  • KFD version: ioctl AMDKFD_IOC_GET_VERSION (0x80084b01) on /dev/kfd -> (1, 14) on 6.8, (1, 22) on 7.0
  • VMM attribute: hipDeviceGetAttribute(..., 89 /* hipDeviceAttributeVirtualMemoryManagementSupported */, 0) via ctypes on libamdhip64
  • hipMemAddressReserve(&p, size, 0, NULL, 0) via ctypes for sizes from 2 MB to 24000 MB

Debug Logs

[INFO] aimdo: /project/src/control.c:283:INFO:comfy-aimdo inited for GPU: AMD Radeon RX 7900 XTX (VRAM: 24560 MB)
[INFO] DynamicVRAM support detected and enabled
[INFO] Requested to load QwenImageTEModel_
[DEBUG] aimdo: /project/src/model-vbar.c:249:DEBUG:vbar_allocate (start): size=79102M, device=0
[ERROR] aimdo: /project/src/model-vbar.c:269:ERROR:Could not reseve Virtual Address space for VBAR
[ERROR] !!! Exception during processing !!! VBAR allocation failed
  File "/home/ubuntu/ComfyUI/comfy/model_patcher.py", line 1901, in _vbar_get
    vbar = comfy_aimdo.model_vbar.ModelVBAR(size, self.load_device.index, pageout_callback=pageout)
  File "/home/ubuntu/ComfyUI/venv-rocm10/lib/python3.12/site-packages/comfy_aimdo/model_vbar.py", line 69, in __init__
    raise MemoryError("VBAR allocation failed")
MemoryError: VBAR allocation failed

Full log (--verbose DEBUG) attached: vbar-master.log

Other

  • ComfyUI cdbb7ff5 (master, 2026-11-21), comfy-aimdo 0.6.0, comfy-kitchen 0.2.42
  • PyTorch 2.13.0+rocm10.0.0 (HIP 7.15.26333)
  • RX 7900 XTX (gfx1100), Ubuntu 24.04
  • Kernel 6.8.0-149 (fails) / 7.0.0-43 HWE (works)

vbar-master.log

dragonone0001-debug avatar Nov 22 '26 01:11 dragonone0001-debug

Independent source-level check from NH Applied: at ComfyUI main.py Git blob 7e7c1c3b75014d6405207b36bc1a4898dbdfd493, dynamic_vram_supported() enables DynamicVRAM on AMD when rocm_version >= (7, 14) without querying the device's VMM capability. The separate --enable-dynamic-vram override also needs an explicit safety decision.

AMD documents the per-device capability query as hipDeviceGetAttribute(..., hipDeviceAttributeVirtualMemoryManagementSupported, device_id): https://rocm.docs.amd.com/projects/HIP/en/latest/how-to/hip_runtime_api/memory_management/virtual_memory.html

I built and tested an isolated source-contract/capability triage on a Windows Strix Halo host: 6/6 unit tests PASS and 16/16 synthetic eligibility scenarios classified as expected, including no/unknown capability, mixed devices, version boundaries and explicit override. These tests do not reproduce the reporter's Linux KFD 1.14 failure or qualify a ComfyUI runtime fix.

Suggested path: require a successful attribute query and nonzero VMM support for every target AMD device before automatically selecting DynamicVRAM; on unsupported/unknown devices log the reason for choosing the legacy ModelPatcher; define safe behaviour for explicit override. Capability=1 does not guarantee a later VBAR reservation succeeds, so initialization failure still needs a fallback.

Would you prefer the capability gate in ComfyUI main.py or in comfy-aimdo device initialization? I can provide the isolated regression cases / a candidate patch in the preferred layer.

— Nigel Hutchinson, NH Applied | https://nhapplied.co.uk | [email protected]

nigelhutch avatar Nov 22 '26 16:11 nigelhutch

Thanks for checking the source and for the draft PR #17926. I'll leave the choice between main.py and comfy-aimdo to the maintainers.

I can test #17926 on real hardware. The same RX 7900 XTX machine has both kernels installed, so I can check both cases:

  • 6.8.0-149 (KFD 1.14, VMM not supported): should fall back to the legacy ModelPatcher instead of failing
  • 7.0.0-43 (KFD 1.22, VMM supported): Dynamic VRAM should still be enabled and work

dragonone0001-debug avatar Nov 22 '26 21:11 dragonone0001-debug