mirror of
https://github.com/Comfy-Org/comfy-aimdo.git
synced 2026-11-04 23:37:21 +00:00
[GH-ISSUE #94] Krea2 Prompt Enhancement causes NaN when enabling Dynamic VRAM on a gfx1030 (RDNA2) card. #32
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Comfy-Org/comfy-aimdo#32
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @derfasthirnlosenick on GitHub (Aug 24, 2026).
Original GitHub issue: https://github.com/Comfy-Org/comfy-aimdo/issues/94
I noticed that I can enable dynamic vram on my card and it works well.
However, it creates NaN conversion errors in the model run when I had a prompt enhancement (the default krea2 workflow) on.
I tried to debug it a bit with CoPilot and apparently it happens on Block 26.
HOWEVER the same model / prompt / workflow works fine without prompt enhancement. It also works fine WITH prompt enhancement but WITHOUT dynamic VRAM - however, just once in the latter case and it OOMs for a second gen (or immediately if I try to use fp16 models).
My hunch is that something goes wrong during the offloading of the text encoder / loading of the model so that it ends up pointing to invalid data, resulting in the NaN.
I'll try to work my way through this issue, but so far no cigar. In case anyone has an idea, it'd be much appreciated.
@derfasthirnlosenick commented on GitHub (Aug 24, 2026):
Update: Claude is better :D basically adding --reserve-vram 2 fixed the issue. Might be suboptimal though, but at least it works now.
@0xDELUXA commented on GitHub (Aug 25, 2026):
Which ROCm version are you using? On ROCm 7.14+, dynamic VRAM is enabled by default. If you aren’t on a recent version, you should update.
@derfasthirnlosenick commented on GitHub (Aug 25, 2026):
7.14, so I have the choice of disabling dynamic veam and increased vram headroom. The latter gave me the NaN error as well after 10ish gens so something seems to be off still.
@0xDELUXA commented on GitHub (Aug 25, 2026):
I'm not on RDNA2, so I can't really investigate this issue. It works fine on my side on RDNA4.
@derfasthirnlosenick commented on GitHub (Aug 25, 2026):
Which his an interesting point in itself - I'll check if there's different paths for rdna2 vs 4. In any case, the reserve-vram already helps to get it to "usable", so I'll try to track it down once I have a bit of time.
@MillanSiS commented on GitHub (Aug 31, 2026):
Facing similar issue with dynamic vram enabled on gfx1031 rdna2. For me Krea2 turbo fp8 generating black images with any prompt. Klein 9b distill fp8 generates 1-2 somewhat correct images after startup then produces only garbage images. Zimage turbo fp8 somehow generates good images but haven't tested extensively. Using device specific wheels in venv from AMD (torch[device-gfx1031], ROCM 10.0.0 as dependency). same issue occurs with ROCM 7.15 as well. With --disable-dynamic-vram (since comfyui 0.34.0) all works fine
@0xDELUXA commented on GitHub (Aug 31, 2026):
Do you use any other environment variables or flags?
@MillanSiS commented on GitHub (Aug 31, 2026):
I only have export HF_HOME="$XDG_CACHE_HOME/huggingface" export TORCH_HOME="$XDG_CACHE_HOME/torch" and start with 'python main.py --fast-disk'. By default it uses quad cross attention but same thing occurs with pytorch attention as well. The --reserve-vram 2 mentioned by derfasthirnlosenick doesn't help either. Sometimes i get random artifacts on the display Only when prompt executes with dynamic vram enabled and no my gpu isnt failing. Probably a memory corruption issue
@0xDELUXA commented on GitHub (Aug 31, 2026):
RDNA2 support isn't the main focus, dynamic VRAM works better on 3 and 4.
@derfasthirnlosenick commented on GitHub (Aug 31, 2026):
Can confirm, the reserve-vram stopped helping and artifacts started appearing.
Claude suggested that there might be an issue in src/plat.h three_stooges that can cause incorrect mapping to be declared "safe", which could be fixed by adding a cuCtxSynchronize after the set access. That worked for me a few days ago but I didn't get around creating a pull request.
@MillanSiS commented on GitHub (Aug 31, 2026):
any noticeable impact on the performance advantage of dynamic vram ?
@derfasthirnlosenick commented on GitHub (Aug 31, 2026):
For me the main benefit is that I can actually run krea 2
@patientx commented on GitHub (Aug 31, 2026):
"Prompt enhancement" doesn't work any good with rdna2 at all, as far as I know it is different then using the models as clip , it treats it as an llm model which is extra slow. Personally I would just use Claude etc or if you want local prompt enhancements, try qwenvl with 4 bit setting ( needs bitsandbytes) which let's me for example use this model (in nf4 quant) :
https://huggingface.co/huihui-ai/Huihui-Qwen3-VL-8B-Instruct-abliteratedwhich does both image and video description , and prompt enhancement.I am using a modified version of the node though and I realized now they (the original) has added some memory improvements and new model support. For me quantized version of the above model works very well for all those scenarios though.
the QwenVL node : https://github.com/1038lab/ComfyUI-QwenVL
my fork : https://github.com/patientx/ComfyUI-QwenVL
My fork has saving and loading the model in nvfp4 format too, which I've actually made a quant of the above model, and just uploaded it to my huggingface account. It doesn't have automatic downloading but you can just download all the files in there to this folder (create if not present)
comfyui\models\LLM\Qwen-VL\Huihui-Qwen3-VL-8B-Instruct-abliterated-bnb-nf4which then should show up in the list of models you can use at the bottom of the loader.You can download other models and save them as nvfp4 -thus fits into memory and runs well- and get rid of the original models like this.
@derfasthirnlosenick commented on GitHub (Aug 31, 2026):
I don't have any issues at all with the enhancement part.
Sure, it's not fast (takes a few sec), but nothing is on RDNA2. The main issue is the memory problem discussed here, and that the loading/unloading takes more time and that the output ain't that great sometimes. So I've mostly switched it off now.
@0xDELUXA commented on GitHub (Aug 31, 2026):
To be honest, I don't think the Comfy devs will investigate this issue.
@MillanSiS commented on GitHub (Aug 31, 2026):
Least we could do is report this based on this explicit warning regarding --disable-dynamic-vram:
[WARNING] Dynamic vram disabled with argument. If you have any issues with dynamic vram enabled please give us a detailed reports as this argument will be removed soon. If you use gguf we recommend keeping dynamic vram enabled and using native ComfyUI model formats instead. ComfyUI native formats like fp8 will be faster even if they are larger than your memory.@0xDELUXA commented on GitHub (Aug 31, 2026):
github.com/Comfy-Org/ComfyUI@8a33128f2fchanges this line, so please pull the latest updates.@MillanSiS commented on GitHub (Aug 31, 2026):
I like to stay on release tags. master has nothing that addresses this issue anyway, so the issue persists with latest master too
@0xDELUXA commented on GitHub (Aug 31, 2026):
And it will continue to have nothing.
@crosson commented on GitHub (Oct 25, 2026):
I'm reproducing this on RDNA4 (r9700 pro) as well, so it isn't limited to RDNA2.
Setup: gfx1201 R9700 pro 32 GB, Linux, torch 2.11.0+rocm7.14, ComfyUI master, comfy-aimdo 0.5.6 (also reproduces
on 0.6.0).
Repro: Krea2 bf16 UNET + Qwen3-VL text encoder + VAE at 1024x1024, re-queued with a new seed each time. After 3–7 runs
the UNET output latent is entirely NaN (black image) and stays that way until models are unloaded.
I don't use the enhancer node at all. My WF is more basic than that. I have tested with ck and sage attention and triton backend on/off.
Corruptions: once outputs go NaN, I compared each layer's resident VBAR weight (
_v_weight) against thecheckpoint tensor. Several layers no longer match, even though
vbar_signature_comparestill reports them as resident:tproj.1.weighttmlp.2.weightblocks.9.mlp.up.weighttxtmlp.3.weightOn 0.6.0 only
tproj.1was hit, at 33,554,342 elements, which is almost exactly 64 MiB of bf16. So whole pages look likethey get reused or remapped while their signature stays valid, and resident layers then read stale data on every later
run.
Workaround:
--disable-smart-memoryfixes it (0 failures in 9 runs, including 2400x2400) while keeping dynamic VRAMand fast disk enabled.
@0xDELUXA commented on GitHub (Oct 25, 2026):
This looks Linux-specific. RDNA4 on Windows is fine for me.
The corrupted range on 0.6.0 is almost exactly two 32 MiB VBAR pages, with their signatures unchanged, so a page got overwritten while still mapped. One Linux-only difference on that path is
unmap_workaroundinsrc/plat.h, added for ROCm/ROCm#6021. ROCr has fixed that since (ROCm/rocm-systems#4363), so on 7.14 the range now gets remapped twice. Not proven harmful, but it's the first suspect.The script below checks that signature-resident chunks keep their contents under eviction pressure, no models needed. On Windows (gfx1200, aimdo 0.6.0) it passes 20 rounds with 0 corrupt chunks. Could someone on Linux run it? If it fails, try again with
unmap_workarounddefined empty.vbar_resident_integrity.py
Run with
python vbar_resident_integrity.py 20.@crosson commented on GitHub (Oct 25, 2026):
Ya. I'm looking through it with claude running alot of tests. It might not be aimdo's logic here might not even be aimdo's bug. It looks like it's below it, potentially in ROCM as you noted.
The bad data is another page's weights. Krea2 bf16 needs about 764 VBAR pages and about 740 stay resident, so the tail pages are evicted and refaulted every step. The corrupted resident pages
(0–11, 517–519 in my runs) hold byte-exact copies of weights that belong in tail pages 740–763.
Two addresses share the same physical memory. With the corruption present, writing into VBAR page 756 immediately changes page 1. A VA is still translating to physical memory that has been handed
to another live mapping.
aimdo's VMM calls look correct. I built 0.5.6 with a tracer around
hipMemCreate/Map/Unmap/Release/AddressFree. Across a failing run it found no release while mapped, no double release, nooverlapping maps, and no handle reused while live. ComfyUI's per-layer VBAR offsets are also stable across prompts and never overlap.
Driver: amdgpu-dkms 6.19.14. That driver already has the
GEM_VATLB flush whose absence causes ROCm/rocm-systems#11693. Forcingamdgpu.vm_update_mode=0(SDMA page-table updates) madeKrea2-only runs clean (10/10, versus failing by run 2–8 before). A workflow that also loads a second diffusion model still fails by run 4.
I haven't been able to reproduce it in a standalone HIP program yet (tried up to 23 GB with the same tail-churn pattern and SDMA uploads).
Worth noting that I am on linux. Ubuntu 24.04
@crosson commented on GitHub (Oct 25, 2026):
@0xDELUXA
OK Going to take a break. I used your script though to run some tests.
My Follow-up. With a Linux-adjusted version of your script, (aimdo.init() before importing torch, otherwise it OOMs here). Over 30 attempts it failed 3 times, with both H2D and device-copy writes. In every failure the VBAR chunks themselves were correct; what got clobbered was the script's long-lived
basetensor, a normal torch allocation (zeroed, or overwritten with the per-roundrandnactivation), so every chunk compared against it looked bad.On the full ComfyUI workflow (smart memory on), neither
DEBUG_HIP_MEM_POOL_VMHEAP=0(ROCm/rocm-systems#11693) nor--disable-cuda-mallocfixes it: NaN from run 3, and 1 bad run in 10, respectively.--disable-smart-memoryremains the only clean config.This seems more like a ROCm 7.14 VMM issue rather than one allocator; possibly related to ROCm/TheRock#9274
If anyone else ends up here IDK if there is anything to be done on the aimdo side. Someone on rocm 7.2 and 7.10 could report back I guess.