Skip to content

Fix ideogram crash: mm: dont reset cast buffers in cleanup_models_gc()#14372

Merged
comfyanonymous merged 5 commits into
Comfy-Org:masterfrom
rattus128:prs/ideogram-low-ram-crash
Jun 9, 2026
Merged

Fix ideogram crash: mm: dont reset cast buffers in cleanup_models_gc()#14372
comfyanonymous merged 5 commits into
Comfy-Org:masterfrom
rattus128:prs/ideogram-low-ram-crash

Conversation

@rattus128

Copy link
Copy Markdown
Contributor

#14289

cleanup_models_gc can be called once per load_models_gpu via free_memory, which in turn can de-activate an active model via this reset_cast_buffers.

cleanup_models_gc() could also come via obscure garbage collector paths so limit reset_cast_buffers to the post-node callsite instead.

This was affecting low RAM users of ideogram, where the independent load calls meant one model was marked inactivate and could get cause a bad state stealing its own pins.

Example test conditions:
Windows, RTX5060, 16GB RAM
Ideogram4 fp8

scr

Before:

...
  File "C:\Users\rattus\ComfyUI_windows_portable_nvidia\ComfyUI_windows_portable\ComfyUI\comfy\ops.py", line 321, in cast_bias_weight
    offload_stream = cast_modules_with_vbar([s], dtype, device, bias_dtype, non_blocking)
  File "C:\Users\rattus\ComfyUI_windows_portable_nvidia\ComfyUI_windows_portable\ComfyUI\comfy\ops.py", line 188, in cast_modules_with_vbar
    handle_pin(s, pin, xfer_source, xfer_dest, size=dest_size)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rattus\ComfyUI_windows_portable_nvidia\ComfyUI_windows_portable\ComfyUI\comfy\ops.py", line 186, in handle_pin
    cast_maybe_lowvram_patch(source, pin, offload_stream, xfer_dest2=dest)
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rattus\ComfyUI_windows_portable_nvidia\ComfyUI_windows_portable\ComfyUI\comfy\ops.py", line 177, in cast_maybe_lowvram_patch
    comfy.model_management.cast_to_gathered(xfer_source, xfer_dest, non_blocking=non_blocking, stream=stream, r2=xfer_dest2)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\rattus\ComfyUI_windows_portable_nvidia\ComfyUI_windows_portable\ComfyUI\comfy\model_management.py", line 1431, in cast_to_gathered
    dest_views = comfy.memory_management.interpret_gathered_like(tensors, r) if r is not None else [None] * len(tensors)
                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "C:\Users\rattus\ComfyUI_windows_portable_nvidia\ComfyUI_windows_portable\ComfyUI\comfy\memory_management.py", line 162, in interpret_gathered_like
    raise ValueError(f"Buffer too small: needs {offset + size} bytes, but only has {gathered.numel()}. ")
ValueError: Buffer too small: needs 56623104 bytes, but only has 0.

[INFO] Prompt executed in 29.06 seconds

After:

[INFO] Requested to load Ideogram4
[INFO] 0 models unloaded.
[INFO] Model Ideogram4 prepared for dynamic VRAM loading. 8849MB Staged. 0 patches attached. Force pre-loaded 204 weights: 1261 KB.
[INFO] Requested to load Ideogram4
[INFO] 0 models unloaded.
[INFO] Model Ideogram4 prepared for dynamic VRAM loading. 8849MB Staged. 0 patches attached. Force pre-loaded 204 weights: 1261 KB.
100%|██████████████████████████████████████████████████████████████████████████████████| 20/20 [01:55<00:00,  5.76s/it]
[INFO] Requested to load AutoencoderKL
[INFO] 0 models unloaded.
[INFO] Model AutoencoderKL prepared for dynamic VRAM loading. 160MB Staged. 0 patches attached. Force pre-loaded 110 weights: 187 KB.
[INFO] Prompt executed in 134.77 seconds

Regression tests:

Linux, 5090, 96GB, ideogram4 ✅
Linux, 5090, 96GB, stable cascade ->Flux2 ✅
Linux, 5090, 96GB, ace step 1.5 XL ✅
Linux, 5090, 96GB, LTX2.3 ✅
Linux, 5090, 96GB, Wan 2.2 2x14B ✅
Linux, 5090, 96GB, qwen ✅
Windows, 5060, 16GB, LTX2.3 ✅

cleanup_models_gc can be called once per load_models_gpu via
free_memory, which in turn can de-activate an active model via
this reset_cast_buffers.

cleanup_models_gc() could also come via obscure garbage collector
paths so limit reset_cast_buffers to the post-node callsite instead.
@rattus128 rattus128 changed the title mm: dont reset cast buffers in cleanup_models_gc() Fix ideogram crash: mm: dont reset cast buffers in cleanup_models_gc() Jun 9, 2026
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 427e71e4-4fa7-4072-8269-ab621e96868f

📥 Commits

Reviewing files that changed from the base of the PR and between 95cb7df and 46a28f9.

📒 Files selected for processing (1)
  • comfy/model_management.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • comfy/model_management.py

📝 Walkthrough

Walkthrough

This PR removes a call to reset_cast_buffers() at the start of cleanup_models_gc in comfy/model_management.py. The function now immediately scans current_loaded_models for dead models and only calls gc.collect()/soft_empty_cache() when dead models are detected; no other logic was changed.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: removing reset_cast_buffers() call from cleanup_models_gc() to fix an Ideogram crash issue.
Description check ✅ Passed The description is directly related to the changeset, explaining the motivation behind removing the reset_cast_buffers() call and providing detailed evidence of the fix working.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@comfyanonymous comfyanonymous merged commit 6f01b24 into Comfy-Org:master Jun 9, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants