diffusers
a17ab726 - [Modular] Add PAN 2 (#15202)

Commit
22 days ago
[Modular] Add PAN 2 (#15202) * Add PAN2 text-to-video and image-to-video PAN2 transformer (29B MoT, video and text streams) and a modular pipeline with t2v and i2v workflows, using a Qwen3.5 text encoder and the Wan2.2 VAE: - standard CFG, 50 steps by default - context parallelism (Ulysses) - optional safety checker on the prompt and the generated video (pan2-guardrail), following Cosmos - checkpoint conversion script, docs, model and pipeline tests on a tiny checkpoint * PAN2: address self-review and overnight test findings - return annotations on all blocks and the rotary embedding - "video" wording in block inputs and the auto docstrings - reset stateful cache hooks after each call, as Cosmos3 does - move context_type_embedding to the text device (device_map="auto") - test that latent output skips decoding and the video check - document the custom safety checker contract; dtype= in the conversion script Signed-off-by: Yi Gu <Yi.Gu@mbzuai.ac.ae> * PAN2: address review comments - Keep only the default-on safety-checker test and drop the dummy checker, since the PAN2 guardrail package tests the checker itself (test_modular_pipeline_pan2.py). - Raise a ValueError when user-provided latents do not have the expected shape (PAN2PrepareLatentsStep). - Write the full pipeline in the conversion script only with --save_pipeline, with --text_encoder_path and --vae_path defaulting to Qwen/Qwen3.5-9B and Wan-AI/Wan2.2-TI2V-5B-Diffusers, so the text encoder and VAE can no longer be given partially. * drop manual "skip decoder" pattern Co-authored-by: YiYi Xu <yixu310@gmail.com> * PAN2: drop the test of the removed output_type="latent" decoder shortcut The decoder step no longer returns the latents for output_type="latent"; to get them, pop the decode block (blocks.sub_blocks.pop("decode")). * PAN2: derive height and width from image_latents for image-to-video Add PAN2Image2VideoInputStep to the image-to-video denoise blocks, after the text input step. As Anima's image input step does, it takes `height` and `width` from the shape of `image_latents`, and raises a ValueError when they are passed and do not match it. The VAE encoder and prepare-latents steps no longer declare 704 x 1248 as input defaults and fall back to the pipeline's `default_height` / `default_width` (from `default_sample_height` / `default_sample_width`) at run time, as in Wan, so that these defaults do not override the size of `image_latents`. Test the image-to-video workflow from standalone-encoded `image_latents`. * PAN2: stop declaring the guider as a component of the text encoder step The guider belongs to the denoise step. In the full pipeline, it decides through `requires_unconditional_embeds` whether the negative prompt is encoded, with a warning when a `negative_prompt` is given but guidance does not use it. Standalone, the text encoder has no guider and still encodes the negative prompt, since the PAN2 denoise step uses classifier-free guidance by default. * use "flash_hub" instead of "flash" in PAN2 doc Co-authored-by: Sayak Paul <spsayakpaul@gmail.com> * PAN2: point the guardrail links to github.com/ifm-ai/pan2-guardrail * PAN2: describe PAN2 as a foundation world model and the guardrails without their models Describe PAN2 as a foundation world model (intro, pipeline and transformer docstrings, conversion script) instead of a video generation model. Describe the guardrails as checking the prompt and each generated video, without naming the guard models, and say that turning them off with `disable_safety_checker()` is at your own risk (docs, error messages and a new docstring). * PAN2: adapt safety checker code and doc to our policy * PAN2: use the tiny test checkpoint from hf-internal-testing * PAN2: write the model name as PAN 2 in docs, docstrings and messages * PAN2: no guidance on the given first frame of image-to-video; default CFG 2.5 and shift 9.0 * PAN2: run the timestep embedder and modulation in float32 * PAN2: drop the test_save_from_pretrained override * PAN2: default to the released negative prompt, its time ranges set to the clip * PAN2: pin the workflow defaults in the modular pipeline tests * PAN2: load the safety checker in load_components and move it with the pipeline The guardrail is loaded once by `load_components()` when the checks are on and the package is installed, and `pipe.to()` moves it with the other components. The text encoder and decoder steps no longer load it or move it between devices during a call; they only raise when the checks are on and it is not loaded. * PAN2: drop the __call__ override * PAN2: take height and width only from image_latents in the image-to-video input step * PAN2: drop the revision note from the docs * PAN2: encode the negative prompt standalone only when it is passed * PAN2: register the safety checker as a component --------- Signed-off-by: Yi Gu <Yi.Gu@mbzuai.ac.ae> Co-authored-by: YiYi Xu <yixu310@gmail.com> Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
Author
Parents
Loading