ROCm Memory Optimizer
An empty_cache button with opinions
- MEMORY_STATUS
- OPTIMIZATION_LOG
- RECOMMENDATIONS
ROCm Memory Optimizer is a utility node that takes no model inputs, needs no wires into your graph, and does exactly two things: it cleans up GPU memory on a schedule and it tells you what it thinks your memory situation is. Think of it as a polite version of running torch.cuda.empty_cache() by hand mid-workflow, with a report card attached.
It lives in ROCm Ninodes/Memory. You drop it into the graph, wire its three STRING outputs into Show Text nodes, and it reports on every run of the queue.
How it works
Each time the node executes it increments an internal operation counter. When the counter hits cleanup_frequency (default 10), it actually does the work: runs Python garbage collection, clears the CUDA cache if clear_cache is on, and - only on the "aggressive" level - forces a device synchronize first so the HIP allocator can fully reclaim blocks. Between cleanups it just looks at allocated/reserved/free memory and prints a status string. Then it generates recommendations from current usage: over 80% allocated and it'll suggest cutting batch size or resolution; under 60% it'll tell you things look good.
The three outputs split it up: MEMORY_STATUS (allocated/reserved/free/total), OPTIMIZATION_LOG (what cleanup actually ran), and RECOMMENDATIONS (the advice).
The inputs that matter
- optimization_level - conservative/balanced/aggressive. Aggressive adds the synchronize; honestly, balanced is a fine default for most AMD boxes.
- enable_gc / clear_cache - both default on. If you're on a modern PyTorch/ROCm allocator, you can afford to dial the active cleanup down and use this node mostly as a status readout.
- cleanup_frequency - how often it acts. Lower it if you're fighting OOM in long loops; raise it (or disable cleanup) if you just want the monitoring.
Installing it
Standard pack install: ComfyUI Manager, search rocm-ninodes, or:
cd ComfyUI/custom_nodes
git clone https://github.com/iGavroche/rocm-ninodes.git
then restart. v1.x upgraders run uv run python tools/upgrade_to_v2.py once. Dependencies are the usual light set (numpy, Pillow, psutil, gguf, safetensors) on top of a ROCm PyTorch build.
The honest version
Set expectations. Forcing empty_cache() has a real downside on modern allocators: it returns memory to the OS and then pays a re-allocation cost the next time something big shows up. This pack's own checkpoint loader documents that PyTorch 2.7+ with ROCm handles its own allocator and doesn't need manual cleanup. So the genuinely useful half of this node is the monitoring - a cheap, in-graph peek at allocated/reserved/free memory at whatever point in the workflow you place it. The active cleanup half is a hammer you keep for the times you actually need a hammer: long video loops on an APU where reserved memory creeps up run after run. If you're not in that situation, wire it up, read the status, and leave the level at balanced.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| optimization_level | COMBO | balanced | Memory optimization level |
| enable_gc | BOOLEAN | true | Enable garbage collection |
| clear_cache | BOOLEAN | true | Clear CUDA cache |
| cleanup_frequency | INT | 101–100 | Cleanup frequency (operations between cleanups) |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| MEMORY_STATUS | STRING | — |
| OPTIMIZATION_LOG | STRING | — |
| RECOMMENDATIONS | STRING | — |