If a long video generation stops with the error below while Sage Attention is enabled, you have hit a known length limit in the SageAttention library — not a problem with your workflow, and not an out-of-memory error.
Triton Error [CUDA]: an illegal memory access was encountered(It is often followed by a chain of further CUDA errors — those are aftermath of the first one.)
Why does this happen?
SageAttention's GPU kernels compute memory addresses using 32-bit integers. When the attention input grows past 2,147,483,647 elements (attention heads × sequence length × head dimension), the address calculation overflows and the kernel touches invalid memory, which crashes the job instantly. Every current SageAttention version has this limit.
For Wan 2.1 / 2.2 14B models this works out to a maximum sequence of roughly 419,000 tokens.
When do I hit the limit?
Only very long, high-resolution video jobs get close to it:
Scenario (Wan 14B) | Approximate safe limit |
720p, text/image-to-video | ~460 frames |
720p with a reference video (MoCha and similar workflows) | Reference frames plus generated frames combined: ~460 frames |
480p | ~1,000 frames — effectively out of reach |
The most common way to hit the limit is a reference-video workflow: the reference frames are added to the same attention sequence as the frames you generate, so a 250-frame reference plus 240 generated frames at 720p is already over the line.
Will a bigger GPU fix it?
No. This is not an out-of-memory error, so the crash point is exactly the same on every GPU regardless of VRAM. Upgrading the machine and retrying with Sage Attention will fail at the same frame count.
How do I fix it?
Option 1 — stay under the limit. Reduce the number of frames, lower the resolution, or shorten the reference video so the combined total fits the table above.
Option 2 — switch the attention mode to sdpa. In WanVideoWrapper, set attention_mode to sdpa in the Model Loader node (if you enabled Sage Attention globally via ComfyUI's launch arguments, disable that instead). sdpa has no length limit and produces the same quality. It is somewhat slower than Sage Attention, so for very long jobs you may want a higher-tier machine to keep generation time reasonable — the bigger machine helps with speed here, not with the crash itself.
Is my finished video affected?
No. Jobs below the limit are completely unaffected, and jobs above it fail immediately rather than quietly degrading quality. If your generation completed, the output is fine.
Will this be fixed permanently?
The limit is in the upstream SageAttention library and affects all current releases. We are tracking upstream progress; until it is resolved, use the two workarounds above.