VRAM Hard Cap (PyTorch) by_steve_lasmin
Hard-caps PyTorch CUDA VRAM allocation in ComfyUI via torch.cuda.set_per_process_memory_fraction to keep heavy video models (like LTX-2.5) streaming smoothly under 16GB/12GB/8GB VRAM limits.
VRAM Hard Cap (PyTorch) by_steve_lasmin
A lightweight, zero-dependency ComfyUI custom node that enforces a hard ceiling on PyTorch's CUDA caching allocator via torch.cuda.set_per_process_memory_fraction() — without editing any ComfyUI core .py files.
Built and battle-tested for heavy 2-stage generative video pipelines like LTX-2.5 22B Distilled INT8 (15s @ 1280×1920) on consumer 16 GB, 12 GB, and 8 GB NVIDIA GPUs under Windows, keeping VRAM comfortably under the ceiling so Windows DWM, browsers, and other GPU apps stay responsive instead of freezing or crashing.
MUST-DO Setup Rules (Critical!)
Before running this node, follow these two mandatory rules:
- MUST launch ComfyUI with
--disable-dynamic-vramComfyUI's newer Dynamic VRAM (comfy-aimdo) stages weights directly via the CUDA driver outside PyTorch's allocator, completely bypassingtorch.cuda.set_per_process_memory_fraction. Without--disable-dynamic-vram, the cap will not restrict Stage 2 / staged model memory. - MUST NOT use
BlockSwapLTX(ComfyUI-JITBlockSwap) UsingBlockSwapLTXtogether with--disable-dynamic-vramtriggersCUDA error: invalid argument(cudaErrorInvalidValue) on Windows due to pinned-memory/mmapand sibling-clone conflicts. Once--disable-dynamic-vram+VRAM Hard Capare active, ComfyUI streams offloaded layers smoothly over PCIe on its own — bypass or deleteBlockSwapLTX.
Recommended Windows .bat Launch Flags
.\python_embeded\python.exe -s ComfyUI\main.py --windows-standalone-build --disable-dynamic-vram --disable-smart-memory --disable-xformers --cache-none
Optional tips:
- Startup cap override without editing code: add
set COMFY_VRAM_LIMIT_GB=14.4(or0to disable startup cap) right before the launch line in your.batfile. - If you ever hit a Windows
mmapaccess violationon repeated runs: add--disable-mmapor change--cache-noneto--cache-lru 1, and avoid--lowvramon 16 GB cards. - NVIDIA Control Panel (Windows): go to Manage 3D Settings → Program Settings, add your ComfyUI
python.exe, and set CUDA - Sysmem Fallback Policy to Prefer No Sysmem Fallback.
Installation
Option 1: ComfyUI Manager / Comfy Registry
Search for VRAM Hard Cap (PyTorch) by_steve_lasmin (Publisher: stevelasmin4real) in ComfyUI Manager and install.
Option 2: Manual / Git Clone
cd ComfyUI/custom_nodes
git clone https://github.com/Eklipsis/vram_hard_cap_by_steve_lasmin.git
Restart ComfyUI. No extra pip packages are required — it uses only Python's standard library and ComfyUI's built-in PyTorch.
On startup, verify you see this line in the console:
[VRAMHardCap by_steve_lasmin] GPU 0 (NVIDIA GeForce RTX 4070 Ti SUPER): PyTorch limit = 14.40 / 15.99 GiB (fraction=0.9005)
Where to Place the Node in Your Workflow
The default cap (14.4 GiB) activates automatically at startup. To control the cap directly inside your workflow UI and flush unused cache at key boundaries, wire VRAM Hard Cap (PyTorch) by_steve_lasmin (category: utils/vram) inline as a pass-through:
- Right after your Diffusion Model loader (
UNETLoader/Load Diffusion Model):UNETLoader→VRAM Hard Cap (PyTorch) by_steve_lasmin(any_input→any_output) → LoRA / Patcher / Guider - Right after your Text Encoder loader (
CLIPLoader/GPUCLIPLoader):GPUCLIPLoader→VRAM Hard Cap (PyTorch) by_steve_lasmin(any_input→any_output) →CLIPTextEncode(Positive & Negative)
Important: ComfyUI skips unconnected nodes. Always connect
any_input→any_outputinline. Click the node's?icon in ComfyUI to open the built-in Markdown Help Panel anytime.
Recommended limit_gib Values for 16 GB, 12 GB, and 8 GB GPUs
Because set_per_process_memory_fraction caps only PyTorch's tensor allocator (while Windows desktop DWM, your browser, and the CUDA/cuBLAS context take an additional ~0.8–1.8 GiB), set limit_gib slightly below your card's physical VRAM:
| GPU VRAM | Example GPUs | Recommended limit_gib | Practical Tips |
| :--- | :--- | :--- | :--- |
| 16 GB | RTX 4070 Ti SUPER, RTX 4080, RTX 5070 Ti, RTX 4060 Ti 16 GB | 14.0 – 14.4 | Tested sweet spot (14.4 GiB = 0.9005 fraction). Keeps total GPU-Z memory comfortably below 15 GB with smooth PCIe streaming. |
| 12 GB | RTX 3060 12 GB, RTX 4070, RTX 4070 SUPER, RTX 3080 12 GB | 10.2 – 10.6 | Add --reserve-vram 2 if you keep browsers or Photoshop open. Use Tiled VAE Decode for high-resolution video outputs. |
| 8 GB | RTX 3070, RTX 4060, RTX 3060 Ti, RTX 2070 SUPER | 6.4 – 6.8 | Always enable Tiled VAE Decode (e.g., LTXVSpatioTemporalTiledVAEDecode), disable browser hardware acceleration, and use quantized (INT8/FP8/GGUF-compatible) models. |
| Any | Disable Cap | 0.0 | Restores fraction = 1.0 (uncapped). |
Test Rig Specs & LTX-2.5 Runtime Benchmarks
Test Rig
- GPU: NVIDIA GeForce RTX 4070 Ti SUPER (16 GB VRAM / 16,375 MB)
- CPU: Intel Core i9-10900K
- RAM: 64 GB (65,450 MB)
- Environment: Windows 10 64-bit, ComfyUI
0.46.0, Frontend1.59.15, PyTorch2.13.0+cu130, Python3.13.12,comfy-kitchen 0.2.42 - Node Setting:
limit_gib = 14.4(fraction = 0.9005),--disable-dynamic-vram,BlockSwapLTXdisabled
Benchmark: LTX-2.5 22B Distilled INT8 ConvRot — 15s @ 1280×1920 px (2-Stage Pipeline)
Three consecutive back-to-back generations in a single session (8-step Stage 1 → x2 Latent Spatial Upscaler → 3-step Stage 2 @ 1280×1920 → Audio/Video VAE Decode → NVENC HEVC MP4):
| Run | Stage 1 Sampler | Stage 1 (8 steps) | Stage 2 (3 steps, 1280×1920) | Total Execution Time |
| :--- | :--- | :--- | :--- | :--- |
| Run 1 | Standard 1x sampler | 1m 17s (9.63s/it) | 2m 13s (44.39s/it) | 332.82 s (5m 33s) |
| Run 2 | res_2s (2nd-order, 2 evals/step) | 2m 44s (20.55s/it) | 2m 13s (44.47s/it) | 431.35 s (7m 11s) |
| Run 3 | Standard 1x sampler | 1m 17s (9.63s/it) | 2m 12s (44.19s/it) | 365.68 s (6m 06s) |
GPU-Z Telemetry Screenshot
Steady ~98% GPU utilization at 234.6 W with flat, controlled VRAM (9,584 MB active during heavy compute, well below the 15 GB ceiling) and clean system RAM utilization (35,744 MB / 64 GB):

Author, Links & Support
Created by Steve Lasmin
- GitHub: https://github.com/Eklipsis
- Comfy Registry Publisher:
stevelasmin4real - YouTube: https://www.youtube.com/stevelasmin
- Support on Boosty: https://boosty.to/stevelasmin
- Email: [email protected]
License
Released under the MIT License.