The message
RuntimeError: CUDA error: an illegal memory access was encountered CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect. For debugging consider passing CUDA_LAUNCH_BLOCKING=1 (bei Sage Attention auch: Triton Error [CUDA]: an illegal memory access was encountered)
Affects: ComfyUI, AUTOMATIC1111 Stable Diffusion WebUI, Stable Diffusion WebUI Forge, TextGen (text-generation-webui), Python
Why is this happening?
The error is not “out of memory,” but an invalid read or write access in a GPU code path, often caused by a bug in a library or by exceeding an index boundary. A well-known example is Sage Attention with very long, high-resolution videos. Because the GPU works asynchronously, the traceback often points to the wrong place. After the error, every further CUDA operation in the same process returns the same error.
How to fix it
- Completely close the program and restart it. According to NVIDIA, the process is in an inconsistent state after this error.
- If you use Sage Attention (
--use-sage-attentionor an attention mode “sage” in a node) and the error occurs with long videos, switch tosdpaor leave out the startup parameter. Alternatively, reduce the number of images or the resolution. - Update the program and PyTorch to the current stable version. Some of these errors are in libraries and have been fixed in newer versions.
- If you want to report the error, start the program with synchronous GPU calls so the traceback shows up at the right place: in PowerShell, set
$env:CUDA_LAUNCH_BLOCKING="1"beforehand. This makes everything slower, so only use it for testing. - If the error only occurs with a specific workflow or node, test without that node and report the error with the traceback to the project.
Better not: Do not leave CUDA_LAUNCH_BLOCKING=1 set permanently; it is only for troubleshooting and slows things down a lot.
Set up from scratch again
If it still doesn’t work after that, a fresh setup step by step often helps:
- Set up and maintain ComfyUI on Windows
Desktop or Portable, where the models belong, sharing models with other programs, safely installing custom nodes, updates, startup options … - Your First Image with ComfyUI
Install Comfy Desktop, learn the interface, and create your first AI image with FLUX.2 [small] 4B or Z-Image Turbo. - Your First AI Video with LTX in ComfyUI
Use LTX-2.3 in ComfyUI to create short videos with sound from text or an image. Template, files, settings, and license.
Terms for this
Similar errors
- UserWarning: Torch was not compiled with flash attention – usually harmless on Windows
- No matching distribution found for torch (wrong Python version)
- 'python' is not recognized or opens the Microsoft Store
- ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied – pip cannot modify a file
- ImportError: DLL load failed while importing …: The specified module could not be found – a Python package is missing a Windows DLL
Sources
- https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__TYPES.html
- https://docs.pytorch.org/docs/2.14/notes/cuda.html
- https://discuss.pytorch.org/t/error-while-training-runtimeerror-cuda-error-an-illegal-memory-access-was-encountered/157005
- https://comfyui-guides.runcomfy.com/ultimate-comfyui-how-tos-a-runcomfy-guide/long-video-generation-fails-with-cuda-illegal-memory-access-sage-attention-length-limit
Checked on Oct 27, 2026. Didn't help? Ask in the forum and name the graphics card, program, and the full message.