Buckets:
| # PAN 2 | |
| PAN2는 시간 기반의 행동 및 카메라 움직임 계획 하에서 장면이 어떻게 변화하는지를 시뮬레이션하는 파운데이션 월드 모델입니다. 29B 생성형 시뮬레이터는 듀얼 스트림 멀티모달 디퓨전 트랜스포머이며 여기에는 통합되어 있지만, 프롬프트를 작성하는 [추론 백본](https://huggingface.co/IFM/PAN2#reasoning-backbone)은 통합되어 있지 않습니다. | |
| PAN 2는 [Modular Diffusers](../../modular_diffusers/overview) 블록으로만 통합됩니다. [PAN2Blocks](/docs/diffusers/main/ko/api/pipelines/pan2#diffusers.PAN2Blocks)는 두 가지 워크플로를 지원합니다: | |
| | 워크플로우 | 입력 | | |
| |---|---| | |
| | `t2v` | `prompt` | | |
| | `i2v` | `prompt`, `image` | | |
| ```py | |
| 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`): | |
| ```py | |
| pipe.update_components(guider=pipe.guider.new(guidance_scale=5.0)) | |
| ``` | |
| 모든 호출은 패딩 없이 인코딩되는 단일 프롬프트를 받습니다. 따라서 Transformer는 attention mask가 필요하지 않으며, 모든 [attention backend](../../optimization/attention_backends)를 사용할 수 있습니다: | |
| ```py | |
| pipe.transformer.set_attention_backend("flash_hub") # FlashAttention-2 | |
| ``` | |
| ## 안전 검사기 | |
| PAN 2는 생성 전 프롬프트에 대해, 그리고 생성된 각 비디오에 대해 가드레일을 실행하며, 차단된 프롬프트 또는 비디오는 `ValueError`를 발생시킵니다. 이러한 체크는 기본적으로 활성화되어 있으며, `load_components()`는 [PAN 2 guardrail](https://github.com/ifm-ai/pan2-guardrail) 패키지가 필요한 가드레일을 로드합니다: | |
| ```bash | |
| pip install git+https://github.com/ifm-ai/pan2-guardrail | |
| ``` | |
| ## 컨텍스트 병렬성 | |
| [PAN2Transformer3DModel](/docs/diffusers/main/ko/api/models/pan2_transformer3d#diffusers.PAN2Transformer3DModel)은 [context parallelism](../../optimization/context_parallelism)을 지원합니다. 텍스트와 비디오의 토큰 수는 일반적으로 디바이스 수(텍스트 토큰 수는 프롬프트에 따라 달라짐)로 나누어 떨어지지 않으므로, 추론 시에는 `ulysses_anything` 또는 `ring_anything`을 사용하세요. 예를 들어 학습에 사용되는 일반 `ulysses_degree` / `ring_degree`는 두 토큰 수가 모두 context parallel size로 나누어 떨어져야 합니다. | |
| ```py | |
| # 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]] | |
| #### diffusers.PAN2ModularPipeline[[diffusers.PAN2ModularPipeline]] | |
| ```python | |
| diffusers.PAN2ModularPipeline(blocks: diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = None, pretrained_model_name_or_path: str | os.PathLike | None = None, components_manager: diffusers.modular_pipelines.components_manager.ComponentsManager | None = None, collection: str | None = None, workflow: str | None = None, modular_config_dict: dict[str, typing.Any] | None = None, config_dict: dict[str, typing.Any] | None = None, **kwargs) | |
| ``` | |
| [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/pan2/modular_pipeline.py#L42) | |
| PAN 2용 ModularPipeline: 텍스트-투-비디오, 첫 프레임 기반 이미지-투-비디오. | |
| ```py | |
| import torch | |
| from diffusers import ModularPipeline | |
| pipe = ModularPipeline.from_pretrained("IFM/PAN2") | |
| pipe.load_components(dtype=torch.bfloat16) | |
| ``` | |
| #### check_safety_checker_loaded[[diffusers.PAN2ModularPipeline.check_safety_checker_loaded]] | |
| ```python | |
| check_safety_checker_loaded() | |
| ``` | |
| [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/pan2/modular_pipeline.py#L103) | |
| checks가 활성화되어 있지만 PAN 2 가드레일이 로드되지 않은 경우 예외를 발생시킵니다. | |
| #### disable_safety_checker[[diffusers.PAN2ModularPipeline.disable_safety_checker]] | |
| ```python | |
| disable_safety_checker() | |
| ``` | |
| [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/pan2/modular_pipeline.py#L118) | |
| 및 검사를 끕니다. 이 경우 모든 책임은 사용자에게 있습니다. | |
| #### enable_safety_checker[[diffusers.PAN2ModularPipeline.enable_safety_checker]] | |
| ```python | |
| enable_safety_checker() | |
| ``` | |
| [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/pan2/modular_pipeline.py#L97) | |
| PAN 2 가드레일을 사용하여 프롬프트와 생성된 비디오를 확인합니다. | |
| ## PAN2Blocks[[diffusers.PAN2Blocks]] | |
| #### diffusers.PAN2Blocks[[diffusers.PAN2Blocks]] | |
| ```python | |
| diffusers.PAN2Blocks() | |
| ``` | |
| [소스](https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/pan2/modular_blocks_pan2.py#L255) | |
| 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) | |
| Inputs: 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`): 생성된 비디오. | |
Xet Storage Details
- Size:
- 8.53 kB
- Xet hash:
- 063467ab82864392a66d823c437774c079aa724edd93ecebe604e0e9657ed41d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.