Diffusers documentation

PAN 2

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

PAN 2

PAN2는 시간 기반의 행동 및 카메라 움직임 계획 하에서 장면이 어떻게 변화하는지를 시뮬레이션하는 파운데이션 월드 모델입니다. 29B 생성형 시뮬레이터는 듀얼 스트림 멀티모달 디퓨전 트랜스포머이며 여기에는 통합되어 있지만, 프롬프트를 작성하는 추론 백본은 통합되어 있지 않습니다.

PAN 2는 Modular Diffusers 블록으로만 통합됩니다. PAN2Blocks는 두 가지 워크플로를 지원합니다:

워크플로우입력
t2vprompt
i2vprompt, image
import torch
from diffusers import ModularPipeline
from diffusers.utils import export_to_video, load_image

pipe = ModularPipeline.from_pretrained("IFM/PAN2")
pipe.load_components(dtype=torch.bfloat16)
pipe.to("cuda")

prompt = "A red fox trots through fresh snow in a pine forest at dawn."

video = pipe(prompt=prompt, generator=torch.Generator().manual_seed(0), output="videos")[0]
export_to_video(video, "pan2_t2v.mp4", fps=24)

image = load_image("path/to/first_frame.png")
video = pipe(prompt=prompt, image=image, generator=torch.Generator().manual_seed(0), output="videos")[0]
export_to_video(video, "pan2_i2v.mp4", fps=24)

Classifier-free guidance는 guider에서 설정됩니다(기본값은 guidance_scale=2.5):

pipe.update_components(guider=pipe.guider.new(guidance_scale=5.0))

모든 호출은 패딩 없이 인코딩되는 단일 프롬프트를 받습니다. 따라서 Transformer는 attention mask가 필요하지 않으며, 모든 attention backend를 사용할 수 있습니다:

pipe.transformer.set_attention_backend("flash_hub")  # FlashAttention-2

안전 검사기

PAN 2는 생성 전 프롬프트에 대해, 그리고 생성된 각 비디오에 대해 가드레일을 실행하며, 차단된 프롬프트 또는 비디오는 ValueError를 발생시킵니다. 이러한 체크는 기본적으로 활성화되어 있으며, load_components()는 PAN 2 guardrail 패키지가 필요한 가드레일을 로드합니다:

pip install git+https://github.com/ifm-ai/pan2-guardrail

컨텍스트 병렬성

PAN2Transformer3DModel은 context parallelism을 지원합니다. 텍스트와 비디오의 토큰 수는 일반적으로 디바이스 수(텍스트 토큰 수는 프롬프트에 따라 달라짐)로 나누어 떨어지지 않으므로, 추론 시에는 ulysses_anything 또는 ring_anything을 사용하세요. 예를 들어 학습에 사용되는 일반 ulysses_degree / ring_degree는 두 토큰 수가 모두 context parallel size로 나누어 떨어져야 합니다.

# torchrun --nproc_per_node=2 pan2_context_parallel.py
import torch
import torch.distributed as dist
from diffusers import ContextParallelConfig, ModularPipeline

dist.init_process_group("nccl")
rank = dist.get_rank()
torch.cuda.set_device(rank)

pipe = ModularPipeline.from_pretrained("IFM/PAN2")
pipe.load_components(dtype=torch.bfloat16)
pipe.to(f"cuda:{rank}")
pipe.transformer.enable_parallelism(config=ContextParallelConfig(ulysses_degree=2, ulysses_anything=True))

video = pipe(prompt="A red fox trots through fresh snow.", generator=torch.Generator().manual_seed(0), output="videos")[0]
dist.destroy_process_group()

PAN2ModularPipeline

클래스 diffusers.PAN2ModularPipeline

< >

( blocks: diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = Nonepretrained_model_name_or_path: str | os.PathLike | None = Nonecomponents_manager: diffusers.modular_pipelines.components_manager.ComponentsManager | None = Nonecollection: str | None = Noneworkflow: str | None = Nonemodular_config_dict: dict[str, typing.Any] | None = Noneconfig_dict: dict[str, typing.Any] | None = None**kwargs )

PAN 2용 ModularPipeline: 텍스트-투-비디오, 첫 프레임 기반 이미지-투-비디오.

import torch
from diffusers import ModularPipeline

pipe = ModularPipeline.from_pretrained("IFM/PAN2")
pipe.load_components(dtype=torch.bfloat16)

check_safety_checker_loaded

< >

( )

checks가 활성화되어 있지만 PAN 2 가드레일이 로드되지 않은 경우 예외를 발생시킵니다.

disable_safety_checker

< >

( )

및 검사를 끕니다. 이 경우 모든 책임은 사용자에게 있습니다.

enable_safety_checker

< >

( )

PAN 2 가드레일을 사용하여 프롬프트와 생성된 비디오를 확인합니다.

PAN2Blocks

클래스 diffusers.PAN2Blocks

< >

( )

PAN 2를 활용한 텍스트-비디오 및 이미지-비디오 생성을 위한 모듈형 파이프라인 블록

지원되는 워크플로:

  • t2v: prompt 필수
  • i2v: prompt, image 필수

구성 요소: text_encoder (Qwen3_5TextModel) tokenizer (Qwen2Tokenizer) safety_checker (PAN2SafetyChecker) vae (AutoencoderKLWan) video_processor (VideoProcessor) scheduler (FlowMatchEulerDiscreteScheduler) transformer (PAN2Transformer3DModel) guider (ClassifierFreeGuidance)

설정: enable_safety_checker (기본값: True)

입력: prompt (str): 생성을 안내하는 프롬프트, 단일 문자열입니다. negative_prompt (str, 선택 사항): 생성을 안내하지 않는 프롬프트, 단일 문자열입니다. 가이던스에 프롬프트가 필요하지만 프롬프트가 전달되지 않거나(또는 빈 문자열이 전달되는 경우) PAN 2의 기본 negative prompt가 사용되며, 그 시간 범위는 클립의 길이로 설정됩니다. max_sequence_length (int, 선택 사항, 기본값 1536): 프롬프트 인코딩을 위한 최대 시퀀스 길이입니다. num_frames (int, 선택 사항, 기본값 313): 생성할 비디오 프레임 수, 4 * n + 1 형태입니다. fps (float, 선택 사항, 기본값 24.0): 비디오의 프레임 레이트로, 기본 negative prompt에서 비디오의 길이를 설정합니다. image (Image, 선택 사항): 첫 번째 프레임, 단일 이미지입니다. height (int, 선택 사항): 생성된 비디오의 픽셀 단위 높이, 기본값은 704입니다. width (int, 선택 사항): 생성된 비디오의 픽셀 단위 너비, 기본값은 1248입니다. num_videos_per_prompt (int, 선택 사항, 기본값 1): 프롬프트당 생성할 비디오 수입니다. image_latents (Tensor, 선택 사항): 정규화된 첫 번째 프레임 latents입니다. vae_encoder 단계에서 생성할 수 있습니다. num_inference_steps (int): 디노이징 단계 수입니다. sigmas (list, 선택 사항): 디노이징 프로세스를 위한 사용자 지정 sigmas입니다. latents (Tensor): 비디오 생성의 입력으로 사용할 사전 생성된 노이즈 latents입니다. generator (Generator, 선택 사항): 결정론적 생성을 위한 Torch generator입니다. attention_kwargs (dict, 선택 사항): attention 프로세서에 대한 추가 kwargs입니다. output_type (str, 선택 사항, 기본값 np): 출력 형식: ‘pil’, ‘np’, ‘pt’.

Outputs: videos (list): 생성된 비디오.

Update on GitHub