Skip to content

AutoencoderKLMagvit.decode fails after enable_slicing() for a batch of 2 or more videos #15494

Backlog

Description

@javierdejesusda

Describe the bug

The reproduction below builds the VAE from the released alibaba-pai/EasyAnimateV5.1-12b-zh VAE config with random weights, in float32 on CPU. Loading the released VAE weights instead, in float32 or in the documented float16, gives the same error.

With enable_slicing(), AutoencoderKLMagvit.decode fails when the batch holds more than one video (checked with 2 and 3). In the 2-video reproduction below, decoding without slicing gives 9 frames per video. With slicing, the second video comes back with 12 frames and torch.cat raises RuntimeError: Sizes of tensors must match except in dimension 0. Expected size 9 but got size 12 for tensor number 1 in the list. Diffusers 0.43.0 fails the same way.

enable_slicing() is documented to "split the input tensor in slices to compute decoding in several steps" (vae.py), so the sliced result should match the unsliced one.

Likely cause: decode calls _decode once per slice and clears the causal conv cache only after the last slice (decode), so the second video is decoded with the cache left by the first. _encode (L834) and tiled_decode (L1023) clear the cache after each call or tile. Clearing it after each _decode call makes the sliced output match the unsliced one within the script's atol=1e-4.

EasyAnimatePipeline decodes all batch_size * num_images_per_prompt videos with one vae.decode call (L682, L762), so pipe.vae.enable_slicing() with num_images_per_prompt=2 reaches this path. I did not run the pipeline.

test_enable_disable_slicing is skipped for this model with the same error message (test). The skip was added in #12374, where the Magvit tests were skipped "for now as they need deeper inspection (doesn't have to be prioritized as it's not used)". I found no issue tracking it.

I'd be happy to open a PR that clears the cache per slice and removes the skip, if that approach looks right.

Reproduction

import diffusers, torch
from diffusers import AutoencoderKLMagvit

repo, revision = "alibaba-pai/EasyAnimateV5.1-12b-zh", "024eaaeba65e24f4223f60c11558227545f3f9b6"
print("diffusers", diffusers.__version__, "torch", torch.__version__)
print("vae config:", repo, "subfolder=vae, revision", revision, "(config only, random weights)")
torch.manual_seed(0)
config = AutoencoderKLMagvit.load_config(repo, subfolder="vae", revision=revision)
vae = AutoencoderKLMagvit.from_config(config).eval()
latents = torch.randn(2, vae.config.latent_channels, 3, 4, 4)  # 2 videos, 3 latent frames each
with torch.no_grad():
    expected = vae.decode(latents).sample
    print("decode without slicing:", tuple(expected.shape))
    vae.enable_slicing()
    try:
        actual = vae.decode(latents).sample
    except RuntimeError as e:
        raise SystemExit(f"decode with enable_slicing() raised: {e}")
print("decode with slicing:", tuple(actual.shape))
if actual.shape != expected.shape or not torch.allclose(actual, expected, atol=1e-4):
    raise SystemExit("enable_slicing() changes the decoded video")

The script exits with status 1. The Logs block holds its stdout followed by the last stderr line (the SystemExit message). Two other stderr messages are omitted: a huggingface_hub warning that local_dir_use_symlinks is deprecated, and the notice listing config attributes that AutoencoderKLMagvit ignores. The config was downloaded once; the logged run used HF_HUB_OFFLINE=1.

Context

Found while reading the VAE slicing implementations and checking that sliced and unsliced decoding agree for each exported VAE; reproduced with the script in this issue through the public API on main at ebda33e (run on 2026-12-04).

Logs

diffusers 0.44.0.dev0 torch 2.15.0+cpu
vae config: alibaba-pai/EasyAnimateV5.1-12b-zh subfolder=vae, revision 024eaaeba65e24f4223f60c11558227545f3f9b6 (config only, random weights)
decode without slicing: (2, 3, 9, 32, 32)
decode with enable_slicing() raised: Sizes of tensors must match except in dimension 0. Expected size 9 but got size 12 for tensor number 1 in the list.

System Info

  • Diffusers: 0.44.0.dev0 (main, ebda33e); 0.43.0 fails the same way
  • Python: 3.11.15
  • PyTorch: 2.15.0+cpu
  • OS: Linux x86_64
  • Using GPU in script? No

Who can help?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions