feat(anima) - Anima Performance Improvements - #9220
Conversation
|
Just as a status update on this one, I'm not planning to finalize it until after we get torch bumped in the next release, I want to see if that accounts for the remaining speed differences or if there's still more to investigate |
torch on Windows does not ship the native flash-attention SDPA backend, so the denoiser fell back to the slower memory-efficient kernel. Opt into cuDNN attention (a priority list, not a forced kernel) for the denoise loop, scoped to Windows + CUDA. Measured ~6% faster per denoising step at 1024x1024 on an RTX 4070 Laptop (torch 2.7.1+cu128), matching ComfyUI's Windows behavior. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A full 1024x1024 Wan VAE decode reserves ~6GB of working memory. The previous FLUX-derived estimate (4.6GB) under-provisioned it, evicting the ~4GB Anima transformer from the model cache and thrashing the allocator near the VRAM ceiling - decode took 7s on an 8GB card and the next generation paid to reload the transformer. - Add estimate_vae_working_memory_anima, calibrated on measured Wan VAE peaks (~2900 bytes/output px/element byte decode, half for encode, +25% when tiled). - Tile the decode (512px tiles, 384px stride) only when the full-decode estimate exceeds 70% of total device VRAM, so small-VRAM GPUs decode in ~1s with the transformer left resident (1.38GB peak, 59dB PSNR vs full decode), while larger GPUs keep the faster exact single-pass decode. - Fall back to tiled decode once on OOM. - Set tiling state explicitly in both decode and encode since the cached VAE instance is shared across invocations. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
71cf03f to
1db8d03
Compare
|
@Pfannkuchensack Could you test on Windows? |
FindingsMedium - Test coverage: every new code path is untested, despite an existing precedent. Low/Medium - OOM fallback only catches Low - Behavior/output changes without an invocation version bump. |
# Conflicts: # invokeai/backend/util/vae_working_memory.py
|
this PR is ready for review, based on my testing on an 8gb GPU, anima now performs within a stone's throw of Comfy's performance |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…tests Review feedback on invoke-ai#9220: - The tiled-decode retry only caught torch.cuda.OutOfMemoryError, but OOMs surfaced from inside cuDNN/cuBLAS kernels arrive as plain RuntimeErrors, so the fallback was dead on exactly the small-VRAM path it targets. Match those by message as well. - Add unit tests for estimate_vae_working_memory_anima (constants, tiled fixed-size estimate, element-size scaling), the _use_tiled_decode 70%% threshold, the OOM->tiled-retry fallback (all three OOM shapes), and the encode-side disable_tiling reset, following the precedent in test_z_image_working_memory.py. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…behavior Tiled decode changes output pixels vs a full decode, and encode now always resets tiling state — per review feedback on invoke-ai#9220, signal the changed node semantics with a version bump (1.0.2->1.0.3 decode, 1.0.0->1.0.1 encode). Regenerated openapi.json accordingly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Feedback addressed |
Summary
Two small, self-contained performance fixes for Anima generation, mainly benefiting GPUs with limited VRAM
(e.g. 8 GB).
Tiled VAE decode (anima_l2i)
The Anima VAE decode now uses tiling, which keeps its memory use bounded. Previously a 1024×1024 decode could
spike close to the VRAM limit and take anywhere from 2 to 11 seconds; with tiling it's a consistent ~1–2
seconds. Images 512px and smaller are unaffected — they still decode in a single pass.
cuDNN attention (anima_denoise, Windows + CUDA only)
On Windows, PyTorch doesn't ship its fastest attention kernel, so the denoiser was defaulting to a noticeably
slower one. This opts the denoiser into cuDNN's attention kernel — roughly 1.7× faster for Anima — the same
thing ComfyUI does. It's a prioritized preference, not a hard requirement: torch falls back automatically on
any GPU where cuDNN isn't available, and it's scoped to Windows + CUDA where it's actually needed.
Anima performance analysis
Three configurations, all measured with the same per-generation instrumentation
(
setup= model load + LLM-adapter,denoise= sampling loop,VAE= decode):max_cache_ram_gb: 16Setup: RTX 4070 Laptop (8 GB VRAM) · 30 steps · Euler · CFG. Figures are
warm steady-state averages — the cold first run of each batch is excluded
(see Notes). Warm runs per cell: 4 (fixes-off) / 9 (1024²) / 4 (1280²).
1024×1024
1280×1280
Findings
1. The code fixes — clear, significant win
2.87 → 2.52 s/it (1280²).
consistently slow (6–9 s) because VRAM was under pressure — the full decode
spikes badly when memory is tight. Across all baseline runs the untiled
decode ranged 0.7–9.7 s; the tiled decode is a steady ~1.1 s / ~1.8 s.
The win is speed and, more importantly, predictability.
2. The RAM-cache bump — no measurable effect (in this test)
fixes-onvsfixes-on + cacheis a wash at both resolutions — 49.0 vs 49.3 s,77.5 vs 77.1 s, all within run-to-run noise.
setuptime is ~0.25 s either way.This is expected for this test: it runs the same model back-to-back, so the
transformer stays resident and is never re-read from disk — the RAM-cache size
never becomes the bottleneck. The cache bump targets a different scenario
(mixed-model workflows, where a too-small cache evicts and reloads models
between generations). It is not part of the code PR and, on this evidence,
is best treated as an optional tuning knob rather than a guaranteed speedup.
Notes
(
setup~2.6–4.7 s, one-time) and — because VRAM is clean — often denoisesfaster (the transformer fully loads). The first generation at a new
resolution is slightly slower (kernel autotune for the new shape). Both first
runs are excluded above to show steady state.
varying % each run, so denoise swings several seconds; the averages show the
trend. The 1280² baseline in particular varied ~82–87 s across batches, so the
cuDNN gain is better read as ~8–12 % than a single point estimate.
Total= setup is not included; it is denoise + VAE decode (matching theCSV). Text-encode is a separate node, small, and unaffected by these changes.
Related Issues / Discussions
QA Instructions
Merge Plan
Checklist
What's Newcopy (if doing a release after this PR)