Buckets:

mishig's picture
|
download
raw
94.1 kB
# # Được cấp phép theo Giấy phép Apache, Phiên bản 2.0 (gọi là "Giấy phép"); # bạn có thể không sử dụng tệp này ngoại trừ tuân thủ theo Giấy phép. # Bạn có thể nhận được một bản sao của Giấy phép tại # # http://www.apache.org/licenses/LICENSE-2.0 # # Trừ khi được yêu cầu bởi luật pháp có hiệu lực hoặc được thỏa thuận bằng văn bản, phần mềm # được phân phối theo Giấy phép được phân phối trên cơ sở # KHÔNG CÓ BẢO HÀNH HOẶC ĐIỀU KIỆN DƯỚI BẤT KỲ HÌNH THỨC NÀO, dù được nêu rõ hay ngụ ý. # Xem Giấy phép để biết ngôn ngữ cụ thể điều chỉnh các quyền và # giới hạn theo Giấy phép. --> # Cosmos [Nền tảng Mô hình Nền tảng Thế giới Cosmos cho AI Vật lý](https://huggingface.co/papers/2501.03575) của NVIDIA. *Physical AI cần được huấn luyện kỹ thuật số trước. Nó cần một bản sao kỹ thuật số của chính nó, mô hình chính sách, và một bản sao kỹ thuật số của thế giới, mô hình thế giới. Trong bài báo này, chúng tôi giới thiệu Nền tảng Mô hình Nền tảng Thế giới Cosmos để hỗ trợ các nhà phát triển xây dựng các mô hình thế giới tùy chỉnh cho các hệ thống Physical AI của họ. Chúng tôi định vị một mô hình nền tảng thế giới như một mô hình thế giới đa năng, có thể được tinh chỉnh thành các mô hình thế giới tùy chỉnh cho các ứng dụng hạ nguồn. Nền tảng của chúng tôi bao gồm một quy trình tuyển chọn video, các mô hình nền tảng thế giới đã được huấn luyện trước, các ví dụ về huấn luyện sau của các mô hình nền tảng thế giới đã được huấn luyện trước, và các bộ mã hóa video. Để hỗ trợ các nhà xây dựng Physical AI giải quyết những vấn đề quan trọng nhất của xã hội, chúng tôi mã nguồn mở nền tảng của mình và cung cấp các mô hình với trọng số mở theo giấy phép cho phép, có sẵn tại https://github.com/NVIDIA/Cosmos.* > [!TIP] > Hãy chắc chắn xem qua [hướng dẫn](../../using-diffusers/schedulers) về Schedulers để tìm hiểu cách khám phá sự đánh đổi giữa tốc độ và chất lượng của scheduler, và xem phần [tái sử dụng các thành phần giữa các pipeline](../../using-diffusers/loading#reusing-models-in-multiple-pipelines) để tìm hiểu cách nạp các thành phần giống nhau vào nhiều pipeline một cách hiệu quả. ## Cách sử dụng cơ bản ```python import torch from diffusers import Cosmos2_5_PredictBasePipeline from diffusers.utils import export_to_video model_id = "nvidia/Cosmos-Predict2.5-2B" pipe = Cosmos2_5_PredictBasePipeline.from_pretrained( model_id, revision="diffusers/base/post-trained", dtype=torch.bfloat16 ) pipe.to("cuda") # or "mps", "xpu", "cpu" prompt = "As the red light shifts to green, the red bus at the intersection begins to move forward, its headlights cutting through the falling snow. The snowy tire tracks deepen as the vehicle inches ahead, casting fresh lines onto the slushy road. Around it, streetlights glow warmer, illuminating the drifting flakes and wet reflections on the asphalt. Other cars behind start to edge forward, their beams joining the scene. The stillness of the urban street transitions into motion as the quiet snowfall is punctuated by the slow advance of traffic through the frosty city corridor." negative_prompt = "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality." output = pipe( image=None, video=None, prompt=prompt, negative_prompt=negative_prompt, num_frames=93, generator=torch.Generator().manual_seed(1), ).frames[0] export_to_video(output, "text2world.mp4", fps=16) ``` ## Cosmos2_5_TransferPipeline[[diffusers.Cosmos2_5_TransferPipeline]] #### diffusers.Cosmos2_5_TransferPipeline[[diffusers.Cosmos2_5_TransferPipeline]] ```python diffusers.Cosmos2_5_TransferPipeline(text_encoder: Qwen2_5_VLForConditionalGeneration, tokenizer: AutoTokenizer, transformer: CosmosTransformer3DModel, vae: AutoencoderKLWan, scheduler: UniPCMultistepScheduler, controlnet: CosmosControlNetModel, safety_checker: typing.Optional[diffusers.pipelines.cosmos.pipeline_cosmos2_5_transfer.CosmosSafetyChecker] = None) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos2_5_transfer.py#L152) **Tham số:** text_encoder (`Qwen2_5_VLForConditionalGeneration`) : Bộ mã hóa văn bản đóng băng. Cosmos Transfer2.5 sử dụng bộ mã hóa [Qwen2.5 VL](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct). tokenizer (`AutoTokenizer`) : Tokenizer liên quan đến bộ mã hóa Qwen2.5 VL. transformer ([CosmosTransformer3DModel](/docs/diffusers/main/vi/api/models/cosmos_transformer3d#diffusers.CosmosTransformer3DModel)) : Transformer có điều kiện để khử nhiễu các latents ảnh đã mã hóa. scheduler ([UniPCMultistepScheduler](/docs/diffusers/main/vi/api/schedulers/unipc#diffusers.UniPCMultistepScheduler)) : Một trình lập lịch được sử dụng kết hợp với `transformer` để khử nhiễu các latent ảnh đã mã hóa. vae ([AutoencoderKLWan](/docs/diffusers/main/vi/api/models/autoencoder_kl_wan#diffusers.AutoencoderKLWan)) : Mô hình Variational Auto-Encoder (VAE) để mã hóa và giải mã video sang và từ các biểu diễn ẩn. controlnet (`CosmosControlNetModel`) : ControlNet được sử dụng để điều kiện hóa quá trình tạo dựa trên các đầu vào điều khiển. Pipeline cho Cosmos Transfer2.5, hỗ trợ suy luận tự hồi quy. Mô hình này kế thừa từ [DiffusionPipeline](/docs/diffusers/main/vi/api/pipelines/overview#diffusers.DiffusionPipeline). Xem tài liệu của lớp cha để biết các phương thức chung được triển khai cho tất cả các pipeline (tải xuống, lưu, chạy trên một thiết bị cụ thể, v.v.). #### __call__[[diffusers.Cosmos2_5_TransferPipeline.__call__]] ```python __call__(controls: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], typing.List[typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]]], controls_conditioning_scale: typing.Union[float, typing.List[float]] = 1.0, prompt: typing.Union[str, typing.List[str], NoneType] = None, negative_prompt: typing.Union[str, typing.List[str]] = 'The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality.', height: int = 704, width: typing.Optional[int] = None, num_frames: typing.Optional[int] = None, num_frames_per_chunk: int = 93, num_inference_steps: int = 36, guidance_scale: float = 3.0, num_videos_per_prompt: int = 1, generator: typing.Union[torch.Generator, typing.List[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: typing.Optional[str] = 'pil', return_dict: bool = True, callback_on_step_end: typing.Union[typing.Callable[[int, int, typing.Dict], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'], max_sequence_length: int = 512, conditional_frame_timestep: float = 0.1, num_ar_conditional_frames: typing.Optional[int] = 1, num_ar_latent_conditional_frames: typing.Optional[int] = None) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos2_5_transfer.py#L569) **Tham số:** controls (`PipelineImageInput`, `List[PipelineImageInput]`) : Ảnh hoặc video đầu vào điều khiển được sử dụng bởi ControlNet. controls_conditioning_scale (`float` hoặc `List[float]`, *tùy chọn*, mặc định là `1.0`) : Hệ số tỷ lệ cho các đầu ra của ControlNet. Một giá trị float đơn lẻ sẽ được phát sóng (broadcast) đến tất cả các khối điều khiển. prompt (`str` hoặc `List[str]`, *tùy chọn*) : Prompt hoặc các prompt để hướng dẫn quá trình tạo. Bắt buộc trừ khi `prompt_embeds` được cung cấp. negative_prompt (`str` hoặc `List[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `negative_prompt_embeds` thay thế. Bỏ qua khi không sử dụng guidance (tức là bị bỏ qua nếu `guidance_scale` không lớn hơn `1`). height (`int`, mặc định là `704`) : Chiều cao của hình ảnh được tạo ra, tính bằng pixel. width (`int`, *optional*) : Độ rộng của hình ảnh được tạo ra, tính bằng pixel. Nếu không được cung cấp, giá trị này sẽ được xác định dựa trên tỷ lệ khung hình của đầu vào và chiều cao được cung cấp. num_frames (`int`, *optional*) : Số lượng khung hình đầu ra. Mặc định là `None` để xuất ra cùng số lượng khung hình với đầu vào `controls`. num_frames_per_chunk (`int`, *tuỳ chọn*, mặc định là `93`) : Số lượng khung hình được tạo ra cho mỗi khối tự hồi quy. Khi tổng số khung hình vượt quá giá trị này, quá trình tạo sẽ được chia thành nhiều khối bằng cách tiếp cận cửa sổ trượt. num_inference_steps (`int`, mặc định là `36`) : Số bước khử nhiễu. Số bước khử nhiễu nhiều hơn thường dẫn đến hình ảnh có chất lượng cao hơn, với cái giá là suy luận chậm hơn. guidance_scale (`float`, mặc định là `3.0`) : Thang độ dẫn hướng như được định nghĩa trong [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598). `guidance_scale` được định nghĩa là `w` của phương trình 2. trong [Imagen Paper](https://huggingface.co/papers/2205.11487). Thang độ dẫn hướng được kích hoạt bằng cách đặt `guidance_scale > 1`. num_videos_per_prompt (`int`, *tuỳ chọn*, mặc định là 1) : Số lượng hình ảnh cần tạo cho mỗi prompt. generator (`torch.Generator` hoặc `List[torch.Generator]`, *tùy chọn*) : Một [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) để đảm bảo quá trình sinh là tất định. latents (`torch.Tensor`, *tùy chọn*) : Các latents nhiễu được tạo trước, lấy mẫu từ phân phối Gaussian, dùng làm đầu vào. Có thể dùng để tinh chỉnh cùng một quá trình sinh với các prompt khác nhau. Nếu không được cung cấp, một tensor latents sẽ được tạo bằng cách lấy mẫu sử dụng `generator` ngẫu nhiên được cung cấp. prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, các vector nhúng văn bản sẽ được tạo từ đối số đầu vào `prompt`. negative_prompt_embeds (`torch.FloatTensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã được tạo trước. Đối với PixArt-Sigma, prompt âm này nên là "". Nếu không được cung cấp, negative_prompt_embeds sẽ được tạo từ đối số đầu vào `negative_prompt`. output_type (`str`, *tùy chọn*, mặc định là `"pil"`) : Định dạng đầu ra của hình ảnh được tạo ra. Chọn giữa `PIL.Image` hoặc `np.array`. return_dict (`bool`, *tùy chọn*, mặc định là `True`) : Có nên trả về một `CosmosPipelineOutput` thay vì một tuple thông thường hay không. callback_on_step_end (`Callable`, `PipelineCallback`, `MultiPipelineCallbacks`, *optional*) : Một hàm hoặc một lớp con của `PipelineCallback` hoặc `MultiPipelineCallbacks` được gọi vào cuối mỗi bước khử nhiễu trong quá trình suy luận, với các đối số sau: `callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)`. `callback_kwargs` sẽ bao gồm một danh sách tất cả các tensor như được chỉ định bởi `callback_on_step_end_tensor_inputs`. callback_on_step_end_tensor_inputs (`List`, *tùy chọn*) : Danh sách các đầu vào tensor cho hàm `callback_on_step_end`. Các tensor được chỉ định trong danh sách sẽ được truyền dưới dạng tham số `callback_kwargs`. Bạn chỉ có thể bao gồm các biến được liệt kê trong thuộc tính `._callback_tensor_inputs` của lớp pipeline của bạn. max_sequence_length (`int`, mặc định là `512`) : Số lượng token tối đa trong prompt. Nếu prompt vượt quá độ dài này, nó sẽ bị cắt bớt. Nếu prompt ngắn hơn độ dài này, nó sẽ được đệm. conditional_frame_timestep (`float`, *optional*, mặc định là 0.1) : Giá trị bước thời gian (timestep) được sử dụng cho các khung hình điều kiện trong quá trình khử nhiễu. Phải nằm trong khoảng `[0, 1]`. num_ar_conditional_frames (`int`, *optional*, mặc định là `1`) : Số lượng khung hình để điều kiện cho các vòng lặp suy luận tiếp theo trong suy luận tự hồi quy, tức là cho chunk thứ hai trở đi. Chỉ được sử dụng nếu `num_ar_latent_conditional_frames` là `None`. Tham số này chỉ được sử dụng khi thực hiện suy luận tự hồi quy, tức là khi số lượng khung hình trong controls > num_frames_per_chunk num_ar_latent_conditional_frames (`int`, *optional*) : Số lượng khung tiềm ẩn (latent frames) để điều kiện cho các vòng lặp suy luận tiếp theo trong suy luận tự hồi quy (auto-regressive inference), tức là cho chunk thứ hai trở đi. Chỉ được sử dụng nếu `num_ar_conditional_frames` là `None`. Tham số này chỉ được dùng khi thực hiện suy luận tự hồi quy, tức là khi số lượng khung trong controls > num_frames_per_chunk **Trả về:** `~CosmosPipelineOutput` hoặc `tuple` Nếu `return_dict` là `True`, `CosmosPipelineOutput` sẽ được trả về, ngược lại một `tuple` sẽ được trả về trong đó phần tử đầu tiên là một danh sách chứa các hình ảnh đã tạo và phần tử thứ hai là một danh sách các `bool` cho biết hình ảnh tương ứng có chứa nội dung "not-safe-for-work" (nsfw) hay không. `controls` điều khiển quá trình điều kiện thông qua ControlNet. Các `controls` được giả định là đã được tiền xử lý, ví dụ như các bản đồ cạnh đã được tính toán trước. Việc đặt `num_frames` sẽ giới hạn tổng số khung hình đầu ra; nếu không được cung cấp hoặc được gán là None (mặc định), số khung hình đầu ra sẽ khớp với `controls` đầu vào. Suy luận tự hồi quy được hỗ trợ, do đó một cửa sổ trượt gồm `num_frames_per_chunk` khung hình được sử dụng cho mỗi vòng lặp khử nhiễu. Ngoài ra, khi thực hiện suy luận tự hồi quy, `num_ar_latent_conditional_frames` hoặc `num_ar_conditional_frames` khung hình trước đó được dùng để điều kiện hóa các vòng lặp suy luận khử nhiễu tiếp theo. Ví dụ: ```python >>> import cv2 >>> import numpy as np >>> from PIL import Image >>> import torch >>> from diffusers import Cosmos2_5_TransferPipeline, AutoModel >>> from diffusers.utils import export_to_video, load_video >>> model_id = "nvidia/Cosmos-Transfer2.5-2B" >>> # Load a Transfer2.5 controlnet variant (edge, depth, seg, or blur) >>> controlnet = AutoModel.from_pretrained( ... model_id, revision="diffusers/controlnet/general/edge", torch_dtype=torch.bfloat16 ... ) >>> pipe = Cosmos2_5_TransferPipeline.from_pretrained( ... model_id, controlnet=controlnet, revision="diffusers/general", torch_dtype=torch.bfloat16 ... ) >>> pipe = pipe.to("cuda") >>> # Video2World with edge control: Generate video guided by edge maps extracted from input video. >>> prompt = ( ... "The video is a demonstration of robotic manipulation, likely in a laboratory or testing environment. It" ... "features two robotic arms interacting with a piece of blue fabric. The setting is a room with a beige" ... "couch in the background, providing a neutral backdrop for the robotic activity. The robotic arms are" ... "positioned on either side of the fabric, which is placed on a yellow cushion. The left robotic arm is" ... "white with a black gripper, while the right arm is black with a more complex, articulated gripper. At the" ... "beginning, the fabric is laid out on the cushion. The left robotic arm approaches the fabric, its gripper" ... "opening and closing as it positions itself. The right arm remains stationary initially, poised to assist." ... "As the video progresses, the left arm grips the fabric, lifting it slightly off the cushion. The right arm" ... "then moves in, its gripper adjusting to grasp the opposite side of the fabric. Both arms work in" ... "coordination, lifting and holding the fabric between them. The fabric is manipulated with precision," ... "showcasing the dexterity and control of the robotic arms. The camera remains static throughout, focusing" ... "on the interaction between the robotic arms and the fabric, allowing viewers to observe the detailed" ... "movements and coordination involved in the task." ... ) >>> negative_prompt = ( ... "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, " ... "over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, " ... "underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky " ... "movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, " ... "fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. " ... "Overall, the video is of poor quality." ... ) >>> input_video = load_video( ... "https://github.com/nvidia-cosmos/cosmos-transfer2.5/raw/refs/heads/main/assets/robot_example/robot_input.mp4" ... ) >>> num_frames = 93 >>> # Extract edge maps from the input video using Canny edge detection >>> edge_maps = [ ... cv2.Canny(cv2.cvtColor(np.array(frame.convert("RGB")), cv2.COLOR_RGB2BGR), 100, 200) ... for frame in input_video[:num_frames] ... ] >>> edge_maps = np.stack(edge_maps)[None] # (T, H, W) -> (1, T, H, W) >>> controls = torch.from_numpy(edge_maps).expand(3, -1, -1, -1) # (1, T, H, W) -> (3, T, H, W) >>> controls = [Image.fromarray(x.numpy()) for x in controls.permute(1, 2, 3, 0)] >>> export_to_video(controls, "edge_controlled_video_edge.mp4", fps=30) >>> # Transfer inference with controls. >>> video = pipe( ... controls=controls, ... controls_conditioning_scale=1.0, ... prompt=prompt, ... negative_prompt=negative_prompt, ... num_frames=num_frames, ... ).frames[0] >>> export_to_video(video, "edge_controlled_video.mp4", fps=30) ``` #### encode_prompt[[diffusers.Cosmos2_5_TransferPipeline.encode_prompt]] ```python encode_prompt(prompt: typing.Union[str, typing.List[str]], negative_prompt: typing.Union[str, typing.List[str], NoneType] = None, do_classifier_free_guidance: bool = True, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 512, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos2_5_transfer.py#L296) **Tham số:** prompt (`str` hoặc `List[str]`, *tùy chọn*) : prompt cần được mã hóa negative_prompt (`str` hoặc `List[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `negative_prompt_embeds` thay thế. Bỏ qua khi không sử dụng guidance (tức là bị bỏ qua nếu `guidance_scale` nhỏ hơn `1`). do_classifier_free_guidance (`bool`, *tùy chọn*, mặc định là `True`) : Có sử dụng classifier free guidance hay không. num_videos_per_prompt (`int`, *optional*, mặc định là 1) : Số lượng video cần được tạo cho mỗi prompt. Thiết bị torch để đặt các embeddings kết quả lên prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, các vector nhúng văn bản sẽ được tạo từ đối số đầu vào `prompt`. negative_prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, negative_prompt_embeds sẽ được tạo từ đối số đầu vào `negative_prompt`. device : (`torch.device`, *tùy chọn*): thiết bị torch dtype : (`torch.dtype`, *tùy chọn*): torch dtype Mã hóa prompt thành các trạng thái ẩn của text encoder. ## Cosmos2_5_PredictBasePipeline[[diffusers.Cosmos2_5_PredictBasePipeline]] #### diffusers.Cosmos2_5_PredictBasePipeline[[diffusers.Cosmos2_5_PredictBasePipeline]] ```python diffusers.Cosmos2_5_PredictBasePipeline(text_encoder: Qwen2_5_VLForConditionalGeneration, tokenizer: AutoTokenizer, transformer: CosmosTransformer3DModel, vae: AutoencoderKLWan, scheduler: UniPCMultistepScheduler, safety_checker: CosmosSafetyChecker = None) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos2_5_predict.py#L185) **Tham số:** text_encoder (`Qwen2_5_VLForConditionalGeneration`) : Bộ mã hóa văn bản đóng băng. Cosmos Predict2.5 sử dụng bộ mã hóa [Qwen2.5 VL](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct). tokenizer (`AutoTokenizer`) : Tokenizer liên quan đến bộ mã hóa Qwen2.5 VL. transformer ([CosmosTransformer3DModel](/docs/diffusers/main/vi/api/models/cosmos_transformer3d#diffusers.CosmosTransformer3DModel)) : Transformer có điều kiện để khử nhiễu các latents ảnh đã mã hóa. scheduler ([UniPCMultistepScheduler](/docs/diffusers/main/vi/api/schedulers/unipc#diffusers.UniPCMultistepScheduler)) : Một trình lập lịch được sử dụng kết hợp với `transformer` để khử nhiễu các latent ảnh đã mã hóa. vae ([AutoencoderKLWan](/docs/diffusers/main/vi/api/models/autoencoder_kl_wan#diffusers.AutoencoderKLWan)) : Mô hình Variational Auto-Encoder (VAE) để mã hóa và giải mã video sang và từ các biểu diễn ẩn. Pipeline cho mô hình cơ sở [Cosmos Predict2.5](https://github.com/nvidia-cosmos/cosmos-predict2.5). Mô hình này kế thừa từ [DiffusionPipeline](/docs/diffusers/main/vi/api/pipelines/overview#diffusers.DiffusionPipeline). Xem tài liệu của lớp cha để biết các phương thức chung được triển khai cho tất cả các pipeline (tải xuống, lưu, chạy trên một thiết bị cụ thể, v.v.). #### __call__[[diffusers.Cosmos2_5_PredictBasePipeline.__call__]] ```python __call__(image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], NoneType] = None, video: list[typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]] | None = None, prompt: str | list[str] | None = None, negative_prompt: str | list[str] | None = None, height: int = 704, width: int = 1280, num_frames: int = 93, num_inference_steps: int = 36, guidance_scale: float = 7.0, num_videos_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, callback_on_step_end: typing.Optional[typing.Callable[[int, int, NoneType], diffusers.callbacks.PipelineCallback | diffusers.callbacks.MultiPipelineCallbacks]] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512, conditional_frame_timestep: float = 0.0001, num_latent_conditional_frames: int = 2) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos2_5_predict.py#L544) **Tham số:** image (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, *optional*) : Ảnh đơn tùy chọn để điều kiện cho Image2World. Phải là `None` khi `video` được cung cấp. video (`list[PIL.Image.Image]`, `np.ndarray`, `torch.Tensor`, *optional*) : Video đầu vào tùy chọn cho điều kiện Video2World. Phải là `None` khi `image` được cung cấp. prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt hoặc các prompt để hướng dẫn quá trình tạo. Bắt buộc trừ khi `prompt_embeds` được cung cấp. negative_prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `negative_prompt_embeds` thay thế. Bỏ qua khi không sử dụng guidance (tức là bị bỏ qua nếu `guidance_scale` không lớn hơn `1`). height (`int`, mặc định là `704`) : Chiều cao của hình ảnh được tạo ra, tính bằng pixel. width (`int`, mặc định là `1280`) : Độ rộng của hình ảnh được tạo ra, tính bằng pixel. num_frames (`int`, mặc định là `93`) : Số lượng khung hình đầu ra. Sử dụng `93` để tạo thế giới (video); đặt thành `1` để trả về một khung hình duy nhất. num_inference_steps (`int`, mặc định là `35`) : Số bước khử nhiễu. Số bước khử nhiễu nhiều hơn thường dẫn đến hình ảnh có chất lượng cao hơn, với cái giá là suy luận chậm hơn. guidance_scale (`float`, mặc định là `7.0`) : Thang độ dẫn hướng như được định nghĩa trong [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598). `guidance_scale` được định nghĩa là `w` của phương trình 2. trong [Imagen Paper](https://huggingface.co/papers/2205.11487). Thang độ dẫn hướng được kích hoạt bằng cách đặt `guidance_scale > 1`. num_videos_per_prompt (`int`, *tuỳ chọn*, mặc định là 1) : Số lượng hình ảnh cần tạo cho mỗi prompt. generator (`torch.Generator` hoặc `list[torch.Generator]`, *tùy chọn*) : Một [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) để đảm bảo quá trình sinh là tất định. latents (`torch.Tensor`, *tùy chọn*) : Các latents nhiễu được tạo trước, lấy mẫu từ phân phối Gaussian, dùng làm đầu vào cho việc tạo ảnh. Có thể dùng để tinh chỉnh cùng một quá trình tạo với các prompt khác nhau. Nếu không được cung cấp, một tensor latents sẽ được tạo bằng cách lấy mẫu sử dụng `generator` ngẫu nhiên được cung cấp. prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, các vector nhúng văn bản sẽ được tạo từ đối số đầu vào `prompt`. negative_prompt_embeds (`torch.FloatTensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã được tạo trước. Đối với PixArt-Sigma, prompt âm này nên là "". Nếu không được cung cấp, negative_prompt_embeds sẽ được tạo từ đối số đầu vào `negative_prompt`. output_type (`str`, *tùy chọn*, mặc định là `"pil"`) : Định dạng đầu ra của hình ảnh được tạo ra. Chọn giữa `PIL.Image` hoặc `np.array`. return_dict (`bool`, *tùy chọn*, mặc định là `True`) : Có nên trả về một `CosmosPipelineOutput` thay vì một tuple thông thường hay không. callback_on_step_end (`Callable`, `PipelineCallback`, `MultiPipelineCallbacks`, *optional*) : Một hàm hoặc một lớp con của `PipelineCallback` hoặc `MultiPipelineCallbacks` được gọi vào cuối mỗi bước khử nhiễu trong quá trình suy luận, với các đối số sau: `callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)`. `callback_kwargs` sẽ bao gồm một danh sách tất cả các tensor như được chỉ định bởi `callback_on_step_end_tensor_inputs`. callback_on_step_end_tensor_inputs (`List`, *tùy chọn*) : Danh sách các đầu vào tensor cho hàm `callback_on_step_end`. Các tensor được chỉ định trong danh sách sẽ được truyền dưới dạng tham số `callback_kwargs`. Bạn chỉ có thể bao gồm các biến được liệt kê trong thuộc tính `._callback_tensor_inputs` của lớp pipeline của bạn. max_sequence_length (`int`, mặc định là `512`) : Số lượng token tối đa trong prompt. Nếu prompt vượt quá độ dài này, nó sẽ bị cắt bớt. Nếu prompt ngắn hơn độ dài này, nó sẽ được đệm. num_latent_conditional_frames (`int`, mặc định là `2`) : Số lượng khung hình latent điều kiện được sử dụng cho điều kiện Video2World. Số lượng khung hình pixel được trích xuất từ video đầu vào được tính bằng `4 * (num_latent_conditional_frames - 1) + 1`. Đặt thành 1 để có hành vi tương tự Image2World (điều kiện bằng một khung hình duy nhất). conditional_frame_timestep (`float`, *tuỳ chọn*, mặc định là 0.0001) : Giá trị bước thời gian (timestep) được sử dụng cho các khung hình điều kiện trong quá trình khử nhiễu (denoising). **Trả về:** `~CosmosPipelineOutput` hoặc `tuple` Nếu `return_dict` là `True`, `CosmosPipelineOutput` sẽ được trả về, ngược lại một `tuple` sẽ được trả về trong đó phần tử đầu tiên là một danh sách chứa các hình ảnh đã tạo và phần tử thứ hai là một danh sách các `bool` cho biết hình ảnh tương ứng có chứa nội dung "not-safe-for-work" (nsfw) hay không. Hàm gọi cho pipeline để tạo nội dung. Hỗ trợ ba chế độ: - **Text2World**: `image=None`, `video=None`, có `prompt`. Tạo một đoạn clip thế giới. - **Image2World**: cung cấp `image`, `video=None`, cung cấp `prompt`. Điều kiện trên một khung hình duy nhất. - **Video2World**: cung cấp `video`, `image=None`, cung cấp `prompt`. Điều kiện trên một đoạn clip đầu vào. Đặt `num_frames=93` (mặc định) để tạo video thế giới, hoặc `num_frames=1` để tạo một khung hình ảnh đơn lẻ (như ở trên trong "*2Image mode"). Outputs tuân theo `output_type` (ví dụ, `"pil"` trả về một danh sách gồm `num_frames` hình ảnh PIL cho mỗi prompt). Ví dụ: ```python >>> import torch >>> from diffusers import Cosmos2_5_PredictBasePipeline >>> from diffusers.utils import export_to_video, load_image, load_video >>> model_id = "nvidia/Cosmos-Predict2.5-2B" >>> pipe = Cosmos2_5_PredictBasePipeline.from_pretrained( ... model_id, revision="diffusers/base/post-trained", torch_dtype=torch.bfloat16 ... ) >>> pipe = pipe.to("cuda") >>> # Common negative prompt reused across modes. >>> negative_prompt = ( ... "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, " ... "over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, " ... "underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky " ... "movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, " ... "fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. " ... "Overall, the video is of poor quality." ... ) >>> # Text2World: generate a 93-frame world video from text only. >>> prompt = ( ... "As the red light shifts to green, the red bus at the intersection begins to move forward, its headlights " ... "cutting through the falling snow. The snowy tire tracks deepen as the vehicle inches ahead, casting fresh " ... "lines onto the slushy road. Around it, streetlights glow warmer, illuminating the drifting flakes and wet " ... "reflections on the asphalt. Other cars behind start to edge forward, their beams joining the scene. " ... "The stillness of the urban street transitions into motion as the quiet snowfall is punctuated by the slow " ... "advance of traffic through the frosty city corridor." ... ) >>> video = pipe( ... image=None, ... video=None, ... prompt=prompt, ... negative_prompt=negative_prompt, ... num_frames=93, ... generator=torch.Generator().manual_seed(1), ... ).frames[0] >>> export_to_video(video, "text2world.mp4", fps=16) >>> # Image2World: condition on a single image and generate a 93-frame world video. >>> prompt = ( ... "A high-definition video captures the precision of robotic welding in an industrial setting. " ... "The first frame showcases a robotic arm, equipped with a welding torch, positioned over a large metal structure. " ... "The welding process is in full swing, with bright sparks and intense light illuminating the scene, creating a vivid " ... "display of blue and white hues. A significant amount of smoke billows around the welding area, partially obscuring " ... "the view but emphasizing the heat and activity. The background reveals parts of the workshop environment, including a " ... "ventilation system and various pieces of machinery, indicating a busy and functional industrial workspace. As the video " ... "progresses, the robotic arm maintains its steady position, continuing the welding process and moving to its left. " ... "The welding torch consistently emits sparks and light, and the smoke continues to rise, diffusing slightly as it moves upward. " ... "The metal surface beneath the torch shows ongoing signs of heating and melting. The scene retains its industrial ambiance, with " ... "the welding sparks and smoke dominating the visual field, underscoring the ongoing nature of the welding operation." ... ) >>> image = load_image( ... "https://media.githubusercontent.com/media/nvidia-cosmos/cosmos-predict2.5/refs/heads/main/assets/base/robot_welding.jpg" ... ) >>> video = pipe( ... image=image, ... video=None, ... prompt=prompt, ... negative_prompt=negative_prompt, ... num_frames=93, ... generator=torch.Generator().manual_seed(1), ... ).frames[0] >>> export_to_video(video, "image2world.mp4", fps=16) >>> # Video2World: condition on an input clip and predict a 93-frame world video. >>> prompt = ( ... "The video opens with an aerial view of a large-scale sand mining construction operation, showcasing extensive piles " ... "of brown sand meticulously arranged in parallel rows. A central water channel, fed by a water pipe, flows through the " ... "middle of these sand heaps, creating ripples and movement as it cascades down. The surrounding area features dense green " ... "vegetation on the left, contrasting with the sandy terrain, while a body of water is visible in the background on the right. " ... "As the video progresses, a piece of heavy machinery, likely a bulldozer, enters the frame from the right, moving slowly along " ... "the edge of the sand piles. This machinery's presence indicates ongoing construction work in the operation. The final frame " ... "captures the same scene, with the water continuing its flow and the bulldozer still in motion, maintaining the dynamic yet " ... "steady pace of the construction activity." ... ) >>> input_video = load_video( ... "https://github.com/nvidia-cosmos/cosmos-predict2.5/raw/refs/heads/main/assets/base/sand_mining.mp4" ... ) >>> video = pipe( ... image=None, ... video=input_video, ... prompt=prompt, ... negative_prompt=negative_prompt, ... num_frames=93, ... generator=torch.Generator().manual_seed(1), ... ).frames[0] >>> export_to_video(video, "video2world.mp4", fps=16) >>> # To produce an image instead of a world (video) clip, set num_frames=1 and >>> # save the first frame: pipe(..., num_frames=1).frames[0][0]. ``` #### encode_prompt[[diffusers.Cosmos2_5_PredictBasePipeline.encode_prompt]] ```python encode_prompt(prompt: str | list[str], negative_prompt: str | list[str] | None = None, do_classifier_free_guidance: bool = True, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 512, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos2_5_predict.py#L324) **Tham số:** prompt (`str` hoặc `list[str]`, *tùy chọn*) : prompt cần được mã hóa negative_prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `negative_prompt_embeds` thay thế. Bỏ qua khi không sử dụng guidance (tức là bị bỏ qua nếu `guidance_scale` nhỏ hơn `1`). do_classifier_free_guidance (`bool`, *tùy chọn*, mặc định là `True`) : Có sử dụng classifier free guidance hay không. num_videos_per_prompt (`int`, *optional*, mặc định là 1) : Số lượng video cần được tạo cho mỗi prompt. Thiết bị torch để đặt các embeddings kết quả lên prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, các vector nhúng văn bản sẽ được tạo từ đối số đầu vào `prompt`. negative_prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, negative_prompt_embeds sẽ được tạo từ đối số đầu vào `negative_prompt`. device : (`torch.device`, *tùy chọn*): thiết bị torch dtype : (`torch.dtype`, *tùy chọn*): torch dtype Mã hóa prompt thành các trạng thái ẩn của text encoder. ## CosmosTextToWorldPipeline[[diffusers.CosmosTextToWorldPipeline]] #### diffusers.CosmosTextToWorldPipeline[[diffusers.CosmosTextToWorldPipeline]] ```python diffusers.CosmosTextToWorldPipeline(text_encoder: T5EncoderModel, tokenizer: T5Tokenizer, transformer: CosmosTransformer3DModel, vae: AutoencoderKLCosmos, scheduler: EDMEulerScheduler, safety_checker: CosmosSafetyChecker = None) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos_text2world.py#L140) **Tham số:** text_encoder (`T5EncoderModel`) : Bộ mã hóa văn bản đóng băng. Cosmos sử dụng [T5](https://huggingface.co/docs/transformers/model_doc/t5#transformers.T5EncoderModel); cụ thể là biến thể [t5-11b](https://huggingface.co/google-t5/t5-11b). tokenizer (`T5TokenizerFast`) : Tokenizer của lớp [T5Tokenizer](https://huggingface.co/docs/transformers/model_doc/t5#transformers.T5Tokenizer). transformer ([CosmosTransformer3DModel](/docs/diffusers/main/vi/api/models/cosmos_transformer3d#diffusers.CosmosTransformer3DModel)) : Transformer có điều kiện để khử nhiễu các latents ảnh đã mã hóa. scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/vi/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : Một trình lập lịch được sử dụng kết hợp với `transformer` để khử nhiễu các latent ảnh đã mã hóa. vae ([AutoencoderKLCosmos](/docs/diffusers/main/vi/api/models/autoencoderkl_cosmos#diffusers.AutoencoderKLCosmos)) : Mô hình Variational Auto-Encoder (VAE) để mã hóa và giải mã video từ và sang các biểu diễn ẩn. Pipeline để tạo thế giới từ văn bản sử dụng [Cosmos Predict1](https://github.com/nvidia-cosmos/cosmos-predict1). Mô hình này kế thừa từ [DiffusionPipeline](/docs/diffusers/main/vi/api/pipelines/overview#diffusers.DiffusionPipeline). Xem tài liệu của lớp cha để biết các phương thức chung được triển khai cho tất cả các pipeline (tải xuống, lưu, chạy trên một thiết bị cụ thể, v.v.). #### __call__[[diffusers.CosmosTextToWorldPipeline.__call__]] ```python __call__(prompt: str | list[str] = None, negative_prompt: str | list[str] | None = None, height: int = 704, width: int = 1280, num_frames: int = 121, num_inference_steps: int = 36, guidance_scale: float = 7.0, fps: int = 30, num_videos_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, callback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos_text2world.py#L401) **Tham số:** prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt hoặc các prompt để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `prompt_embeds` thay thế. negative_prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `negative_prompt_embeds` thay thế. Bỏ qua khi không sử dụng guidance (tức là bị bỏ qua nếu `guidance_scale` không lớn hơn `1`). height (`int`, mặc định là `720`) : Chiều cao của hình ảnh được tạo ra, tính bằng pixel. width (`int`, mặc định là `1280`) : Độ rộng của hình ảnh được tạo ra, tính bằng pixel. num_frames (`int`, mặc định là `121`) : Số khung hình trong video được tạo ra. num_inference_steps (`int`, mặc định là `36`) : Số bước khử nhiễu. Số bước khử nhiễu nhiều hơn thường dẫn đến hình ảnh có chất lượng cao hơn, với cái giá là suy luận chậm hơn. guidance_scale (`float`, mặc định là `7.0`) : Thang độ dẫn hướng như được định nghĩa trong [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598). `guidance_scale` được định nghĩa là `w` của phương trình 2. trong [Imagen Paper](https://huggingface.co/papers/2205.11487). Thang độ dẫn hướng được kích hoạt bằng cách đặt `guidance_scale > 1`. fps (`int`, mặc định là `30`) : Số khung hình mỗi giây của video được tạo ra. num_videos_per_prompt (`int`, *tuỳ chọn*, mặc định là 1) : Số lượng hình ảnh cần tạo cho mỗi prompt. generator (`torch.Generator` hoặc `list[torch.Generator]`, *tùy chọn*) : Một [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) để đảm bảo quá trình sinh là tất định. latents (`torch.Tensor`, *tùy chọn*) : Các latents nhiễu được tạo trước, lấy mẫu từ phân phối Gaussian, dùng làm đầu vào cho việc tạo ảnh. Có thể dùng để tinh chỉnh cùng một quá trình tạo với các prompt khác nhau. Nếu không được cung cấp, một tensor latents sẽ được tạo bằng cách lấy mẫu sử dụng `generator` ngẫu nhiên được cung cấp. prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, các vector nhúng văn bản sẽ được tạo từ đối số đầu vào `prompt`. negative_prompt_embeds (`torch.FloatTensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã được tạo trước. Đối với PixArt-Sigma, prompt âm này nên là "". Nếu không được cung cấp, negative_prompt_embeds sẽ được tạo từ đối số đầu vào `negative_prompt`. output_type (`str`, *tùy chọn*, mặc định là `"pil"`) : Định dạng đầu ra của hình ảnh được tạo ra. Chọn giữa `PIL.Image` hoặc `np.array`. return_dict (`bool`, *tùy chọn*, mặc định là `True`) : Có nên trả về một `CosmosPipelineOutput` thay vì một tuple thông thường hay không. callback_on_step_end (`Callable`, `PipelineCallback`, `MultiPipelineCallbacks`, *optional*) : Một hàm hoặc một lớp con của `PipelineCallback` hoặc `MultiPipelineCallbacks` được gọi vào cuối mỗi bước khử nhiễu trong quá trình suy luận, với các đối số sau: `callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)`. `callback_kwargs` sẽ bao gồm một danh sách tất cả các tensor như được chỉ định bởi `callback_on_step_end_tensor_inputs`. callback_on_step_end_tensor_inputs (`list`, *optional*) : Danh sách các đầu vào tensor cho hàm `callback_on_step_end`. Các tensor được chỉ định trong danh sách sẽ được truyền dưới dạng tham số `callback_kwargs`. Bạn chỉ có thể bao gồm các biến được liệt kê trong thuộc tính `._callback_tensor_inputs` của lớp pipeline của bạn. max_sequence_length (`int`, mặc định là `512`) : Số lượng token tối đa trong prompt. Nếu prompt vượt quá độ dài này, nó sẽ bị cắt bớt. Nếu prompt ngắn hơn độ dài này, nó sẽ được đệm. **Trả về:** `~CosmosPipelineOutput` hoặc `tuple` Nếu `return_dict` là `True`, `CosmosPipelineOutput` sẽ được trả về, ngược lại một `tuple` sẽ được trả về trong đó phần tử đầu tiên là một danh sách chứa các hình ảnh đã tạo và phần tử thứ hai là một danh sách các `bool` cho biết hình ảnh tương ứng có chứa nội dung "not-safe-for-work" (nsfw) hay không. Hàm gọi call của pipeline để tạo nội dung. Ví dụ: ```python >>> import torch >>> from diffusers import CosmosTextToWorldPipeline >>> from diffusers.utils import export_to_video >>> model_id = "nvidia/Cosmos-1.0-Diffusion-7B-Text2World" >>> pipe = CosmosTextToWorldPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16) >>> pipe.to("cuda") >>> prompt = "A sleek, humanoid robot stands in a vast warehouse filled with neatly stacked cardboard boxes on industrial shelves. The robot's metallic body gleams under the bright, even lighting, highlighting its futuristic design and intricate joints. A glowing blue light emanates from its chest, adding a touch of advanced technology. The background is dominated by rows of boxes, suggesting a highly organized storage system. The floor is lined with wooden pallets, enhancing the industrial setting. The camera remains static, capturing the robot's poised stance amidst the orderly environment, with a shallow depth of field that keeps the focus on the robot while subtly blurring the background for a cinematic effect." >>> output = pipe(prompt=prompt).frames[0] >>> export_to_video(output, "output.mp4", fps=30) ``` #### encode_prompt[[diffusers.CosmosTextToWorldPipeline.encode_prompt]] ```python encode_prompt(prompt: str | list[str], negative_prompt: str | list[str] | None = None, do_classifier_free_guidance: bool = True, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 512, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos_text2world.py#L239) **Tham số:** prompt (`str` hoặc `list[str]`, *tùy chọn*) : prompt cần được mã hóa negative_prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `negative_prompt_embeds` thay thế. Bỏ qua khi không sử dụng guidance (tức là bị bỏ qua nếu `guidance_scale` nhỏ hơn `1`). do_classifier_free_guidance (`bool`, *tùy chọn*, mặc định là `True`) : Có sử dụng classifier free guidance hay không. num_videos_per_prompt (`int`, *optional*, mặc định là 1) : Số lượng video cần được tạo cho mỗi prompt. Thiết bị torch để đặt các embeddings kết quả lên prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, các vector nhúng văn bản sẽ được tạo từ đối số đầu vào `prompt`. negative_prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, negative_prompt_embeds sẽ được tạo từ đối số đầu vào `negative_prompt`. device : (`torch.device`, *tùy chọn*): thiết bị torch dtype : (`torch.dtype`, *tùy chọn*): torch dtype Mã hóa prompt thành các trạng thái ẩn của text encoder. ## CosmosVideoToWorldPipeline[[diffusers.CosmosVideoToWorldPipeline]] #### diffusers.CosmosVideoToWorldPipeline[[diffusers.CosmosVideoToWorldPipeline]] ```python diffusers.CosmosVideoToWorldPipeline(text_encoder: T5EncoderModel, tokenizer: T5Tokenizer, transformer: CosmosTransformer3DModel, vae: AutoencoderKLCosmos, scheduler: EDMEulerScheduler, safety_checker: CosmosSafetyChecker = None) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos_video2world.py#L181) **Tham số:** text_encoder (`T5EncoderModel`) : Bộ mã hóa văn bản đóng băng. Cosmos sử dụng [T5](https://huggingface.co/docs/transformers/model_doc/t5#transformers.T5EncoderModel); cụ thể là biến thể [t5-11b](https://huggingface.co/google-t5/t5-11b). tokenizer (`T5TokenizerFast`) : Tokenizer của lớp [T5Tokenizer](https://huggingface.co/docs/transformers/model_doc/t5#transformers.T5Tokenizer). transformer ([CosmosTransformer3DModel](/docs/diffusers/main/vi/api/models/cosmos_transformer3d#diffusers.CosmosTransformer3DModel)) : Transformer có điều kiện để khử nhiễu các latents ảnh đã mã hóa. scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/vi/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : Một trình lập lịch được sử dụng kết hợp với `transformer` để khử nhiễu các latent ảnh đã mã hóa. vae ([AutoencoderKLCosmos](/docs/diffusers/main/vi/api/models/autoencoderkl_cosmos#diffusers.AutoencoderKLCosmos)) : Mô hình Variational Auto-Encoder (VAE) để mã hóa và giải mã video từ và sang các biểu diễn ẩn. Pipeline cho việc tạo thế giới từ ảnh và từ video sử dụng [Cosmos Predict-1](https://github.com/nvidia-cosmos/cosmos-predict1). Mô hình này kế thừa từ [DiffusionPipeline](/docs/diffusers/main/vi/api/pipelines/overview#diffusers.DiffusionPipeline). Xem tài liệu của lớp cha để biết các phương thức chung được triển khai cho tất cả các pipeline (tải xuống, lưu, chạy trên một thiết bị cụ thể, v.v.). #### __call__[[diffusers.CosmosVideoToWorldPipeline.__call__]] ```python __call__(image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = None, video: list[typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]] = None, prompt: str | list[str] = None, negative_prompt: str | list[str] | None = None, height: int = 704, width: int = 1280, num_frames: int = 121, num_inference_steps: int = 36, guidance_scale: float = 7.0, input_frames_guidance: bool = False, augment_sigma: float = 0.001, fps: int = 30, num_videos_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, callback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos_video2world.py#L511) **Tham số:** image (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, *tuỳ chọn*) : Ảnh được sử dụng làm đầu vào điều kiện cho việc tạo video. video (`list[PIL.Image.Image]`, `np.ndarray`, `torch.Tensor`, *tuỳ chọn*) : Video được sử dụng làm đầu vào điều kiện cho việc tạo video. prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt hoặc các prompt để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `prompt_embeds` thay thế. negative_prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `negative_prompt_embeds` thay thế. Bỏ qua khi không sử dụng guidance (tức là bị bỏ qua nếu `guidance_scale` không lớn hơn `1`). height (`int`, mặc định là `720`) : Chiều cao của hình ảnh được tạo ra, tính bằng pixel. width (`int`, mặc định là `1280`) : Độ rộng của hình ảnh được tạo ra, tính bằng pixel. num_frames (`int`, mặc định là `121`) : Số khung hình trong video được tạo ra. num_inference_steps (`int`, mặc định là `36`) : Số bước khử nhiễu. Số bước khử nhiễu nhiều hơn thường dẫn đến hình ảnh có chất lượng cao hơn, với cái giá là suy luận chậm hơn. guidance_scale (`float`, mặc định là `7.0`) : Thang độ dẫn hướng như được định nghĩa trong [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598). `guidance_scale` được định nghĩa là `w` của phương trình 2. trong [Imagen Paper](https://huggingface.co/papers/2205.11487). Thang độ dẫn hướng được kích hoạt bằng cách đặt `guidance_scale > 1`. input_frames_guidance (`bool`, *tùy chọn*, mặc định là `False`) : Có áp dụng hướng dẫn trên các khung đầu vào có điều kiện hay không. augment_sigma (`float`, *tuỳ chọn*, mặc định là 0.001) : Giá trị Sigma được sử dụng để tăng cường các latents có điều kiện trong quá trình khử nhiễu. fps (`int`, mặc định là `30`) : Số khung hình mỗi giây của video được tạo ra. num_videos_per_prompt (`int`, *tuỳ chọn*, mặc định là 1) : Số lượng hình ảnh cần tạo cho mỗi prompt. generator (`torch.Generator` hoặc `list[torch.Generator]`, *tùy chọn*) : Một [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) để đảm bảo quá trình sinh là tất định. latents (`torch.Tensor`, *tùy chọn*) : Các latents nhiễu được tạo trước, lấy mẫu từ phân phối Gaussian, dùng làm đầu vào cho việc tạo ảnh. Có thể dùng để tinh chỉnh cùng một quá trình tạo với các prompt khác nhau. Nếu không được cung cấp, một tensor latents sẽ được tạo bằng cách lấy mẫu sử dụng `generator` ngẫu nhiên được cung cấp. prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, các vector nhúng văn bản sẽ được tạo từ đối số đầu vào `prompt`. negative_prompt_embeds (`torch.FloatTensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã được tạo trước. Đối với PixArt-Sigma, prompt âm này nên là "". Nếu không được cung cấp, negative_prompt_embeds sẽ được tạo từ đối số đầu vào `negative_prompt`. output_type (`str`, *tùy chọn*, mặc định là `"pil"`) : Định dạng đầu ra của hình ảnh được tạo ra. Chọn giữa `PIL.Image` hoặc `np.array`. return_dict (`bool`, *tùy chọn*, mặc định là `True`) : Có nên trả về một `CosmosPipelineOutput` thay vì một tuple thông thường hay không. callback_on_step_end (`Callable`, `PipelineCallback`, `MultiPipelineCallbacks`, *optional*) : Một hàm hoặc một lớp con của `PipelineCallback` hoặc `MultiPipelineCallbacks` được gọi vào cuối mỗi bước khử nhiễu trong quá trình suy luận, với các đối số sau: `callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)`. `callback_kwargs` sẽ bao gồm một danh sách tất cả các tensor như được chỉ định bởi `callback_on_step_end_tensor_inputs`. callback_on_step_end_tensor_inputs (`list`, *optional*) : Danh sách các đầu vào tensor cho hàm `callback_on_step_end`. Các tensor được chỉ định trong danh sách sẽ được truyền dưới dạng tham số `callback_kwargs`. Bạn chỉ có thể bao gồm các biến được liệt kê trong thuộc tính `._callback_tensor_inputs` của lớp pipeline của bạn. max_sequence_length (`int`, mặc định là `512`) : Số lượng token tối đa trong prompt. Nếu prompt vượt quá độ dài này, nó sẽ bị cắt bớt. Nếu prompt ngắn hơn độ dài này, nó sẽ được đệm. **Trả về:** `~CosmosPipelineOutput` hoặc `tuple` Nếu `return_dict` là `True`, `CosmosPipelineOutput` sẽ được trả về, ngược lại một `tuple` sẽ được trả về trong đó phần tử đầu tiên là một danh sách chứa các hình ảnh đã tạo và phần tử thứ hai là một danh sách các `bool` cho biết hình ảnh tương ứng có chứa nội dung "not-safe-for-work" (nsfw) hay không. Hàm gọi call của pipeline để tạo nội dung. Ví dụ: Điều kiện hình ảnh: ```python >>> import torch >>> from diffusers import CosmosVideoToWorldPipeline >>> from diffusers.utils import export_to_video, load_image >>> model_id = "nvidia/Cosmos-1.0-Diffusion-7B-Video2World" >>> pipe = CosmosVideoToWorldPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16) >>> pipe.to("cuda") >>> prompt = "The video depicts a long, straight highway stretching into the distance, flanked by metal guardrails. The road is divided into multiple lanes, with a few vehicles visible in the far distance. The surrounding landscape features dry, grassy fields on one side and rolling hills on the other. The sky is mostly clear with a few scattered clouds, suggesting a bright, sunny day." >>> image = load_image( ... "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cosmos/cosmos-video2world-input.jpg" ... ) >>> video = pipe(image=image, prompt=prompt).frames[0] >>> export_to_video(video, "output.mp4", fps=30) ``` Điều kiện hóa video: ```python >>> import torch >>> from diffusers import CosmosVideoToWorldPipeline >>> from diffusers.utils import export_to_video, load_video >>> model_id = "nvidia/Cosmos-1.0-Diffusion-7B-Video2World" >>> pipe = CosmosVideoToWorldPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16) >>> pipe.transformer = torch.compile(pipe.transformer) >>> pipe.to("cuda") >>> prompt = "The video depicts a winding mountain road covered in snow, with a single vehicle traveling along it. The road is flanked by steep, rocky cliffs and sparse vegetation. The landscape is characterized by rugged terrain and a river visible in the distance. The scene captures the solitude and beauty of a winter drive through a mountainous region." >>> video = load_video( ... "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/cosmos/cosmos-video2world-input-vid.mp4" ... )[:21] # This example uses only the first 21 frames >>> video = pipe(video=video, prompt=prompt).frames[0] >>> export_to_video(video, "output.mp4", fps=30) ``` #### encode_prompt[[diffusers.CosmosVideoToWorldPipeline.encode_prompt]] ```python encode_prompt(prompt: str | list[str], negative_prompt: str | list[str] | None = None, do_classifier_free_guidance: bool = True, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 512, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos_video2world.py#L283) **Tham số:** prompt (`str` hoặc `list[str]`, *tùy chọn*) : prompt cần được mã hóa negative_prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `negative_prompt_embeds` thay thế. Bỏ qua khi không sử dụng guidance (tức là bị bỏ qua nếu `guidance_scale` nhỏ hơn `1`). do_classifier_free_guidance (`bool`, *tùy chọn*, mặc định là `True`) : Có sử dụng classifier free guidance hay không. num_videos_per_prompt (`int`, *optional*, mặc định là 1) : Số lượng video cần được tạo cho mỗi prompt. Thiết bị torch để đặt các embeddings kết quả lên prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, các vector nhúng văn bản sẽ được tạo từ đối số đầu vào `prompt`. negative_prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, negative_prompt_embeds sẽ được tạo từ đối số đầu vào `negative_prompt`. device : (`torch.device`, *tùy chọn*): thiết bị torch dtype : (`torch.dtype`, *tùy chọn*): torch dtype Mã hóa prompt thành các trạng thái ẩn của text encoder. ## Cosmos2TextToImagePipeline[[diffusers.Cosmos2TextToImagePipeline]] #### diffusers.Cosmos2TextToImagePipeline[[diffusers.Cosmos2TextToImagePipeline]] ```python diffusers.Cosmos2TextToImagePipeline(text_encoder: T5EncoderModel, tokenizer: T5Tokenizer, transformer: CosmosTransformer3DModel, vae: AutoencoderKLWan, scheduler: FlowMatchEulerDiscreteScheduler, safety_checker: CosmosSafetyChecker = None) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos2_text2image.py#L143) **Tham số:** text_encoder (`T5EncoderModel`) : Bộ mã hóa văn bản đóng băng. Cosmos sử dụng [T5](https://huggingface.co/docs/transformers/model_doc/t5#transformers.T5EncoderModel); cụ thể là biến thể [t5-11b](https://huggingface.co/google-t5/t5-11b). tokenizer (`T5TokenizerFast`) : Tokenizer của lớp [T5Tokenizer](https://huggingface.co/docs/transformers/model_doc/t5#transformers.T5Tokenizer). transformer ([CosmosTransformer3DModel](/docs/diffusers/main/vi/api/models/cosmos_transformer3d#diffusers.CosmosTransformer3DModel)) : Transformer có điều kiện để khử nhiễu các latents ảnh đã mã hóa. scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/vi/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : Một trình lập lịch được sử dụng kết hợp với `transformer` để khử nhiễu các latent ảnh đã mã hóa. vae ([AutoencoderKLWan](/docs/diffusers/main/vi/api/models/autoencoder_kl_wan#diffusers.AutoencoderKLWan)) : Mô hình Variational Auto-Encoder (VAE) để mã hóa và giải mã video sang và từ các biểu diễn ẩn. Pipeline để tạo ảnh từ văn bản sử dụng [Cosmos Predict2](https://github.com/nvidia-cosmos/cosmos-predict2). Mô hình này kế thừa từ [DiffusionPipeline](/docs/diffusers/main/vi/api/pipelines/overview#diffusers.DiffusionPipeline). Xem tài liệu của lớp cha để biết các phương thức chung được triển khai cho tất cả các pipeline (tải xuống, lưu, chạy trên một thiết bị cụ thể, v.v.). #### __call__[[diffusers.Cosmos2TextToImagePipeline.__call__]] ```python __call__(prompt: str | list[str] = None, negative_prompt: str | list[str] | None = None, height: int = 768, width: int = 1360, num_inference_steps: int = 35, guidance_scale: float = 7.0, num_images_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, callback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos2_text2image.py#L417) **Tham số:** prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt hoặc các prompt để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `prompt_embeds` thay thế. negative_prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `negative_prompt_embeds` thay thế. Bỏ qua khi không sử dụng guidance (tức là bị bỏ qua nếu `guidance_scale` không lớn hơn `1`). height (`int`, mặc định là `768`) : Chiều cao của hình ảnh được tạo ra, tính bằng pixel. width (`int`, mặc định là `1360`) : Độ rộng của hình ảnh được tạo ra, tính bằng pixel. num_inference_steps (`int`, mặc định là `35`) : Số bước khử nhiễu. Số bước khử nhiễu nhiều hơn thường dẫn đến hình ảnh có chất lượng cao hơn, với cái giá là suy luận chậm hơn. guidance_scale (`float`, mặc định là `7.0`) : Thang độ dẫn hướng như được định nghĩa trong [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598). `guidance_scale` được định nghĩa là `w` của phương trình 2. trong [Imagen Paper](https://huggingface.co/papers/2205.11487). Thang độ dẫn hướng được kích hoạt bằng cách đặt `guidance_scale > 1`. num_images_per_prompt (`int`, *tuỳ chọn*, mặc định là 1) : Số lượng hình ảnh cần tạo cho mỗi prompt. generator (`torch.Generator` hoặc `list[torch.Generator]`, *tùy chọn*) : Một [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) để đảm bảo quá trình sinh là tất định. latents (`torch.Tensor`, *tùy chọn*) : Các latents nhiễu được tạo trước, lấy mẫu từ phân phối Gaussian, dùng làm đầu vào cho việc tạo ảnh. Có thể dùng để tinh chỉnh cùng một quá trình tạo với các prompt khác nhau. Nếu không được cung cấp, một tensor latents sẽ được tạo bằng cách lấy mẫu sử dụng `generator` ngẫu nhiên được cung cấp. prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, các vector nhúng văn bản sẽ được tạo từ đối số đầu vào `prompt`. negative_prompt_embeds (`torch.FloatTensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã được tạo trước. Đối với PixArt-Sigma, prompt âm này nên là "". Nếu không được cung cấp, negative_prompt_embeds sẽ được tạo từ đối số đầu vào `negative_prompt`. output_type (`str`, *tùy chọn*, mặc định là `"pil"`) : Định dạng đầu ra của hình ảnh được tạo ra. Chọn giữa `PIL.Image` hoặc `np.array`. return_dict (`bool`, *tùy chọn*, mặc định là `True`) : Có nên trả về một `CosmosImagePipelineOutput` thay vì một tuple thông thường hay không. callback_on_step_end (`Callable`, `PipelineCallback`, `MultiPipelineCallbacks`, *optional*) : Một hàm hoặc một lớp con của `PipelineCallback` hoặc `MultiPipelineCallbacks` được gọi vào cuối mỗi bước khử nhiễu trong quá trình suy luận, với các đối số sau: `callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)`. `callback_kwargs` sẽ bao gồm một danh sách tất cả các tensor như được chỉ định bởi `callback_on_step_end_tensor_inputs`. callback_on_step_end_tensor_inputs (`list`, *optional*) : Danh sách các đầu vào tensor cho hàm `callback_on_step_end`. Các tensor được chỉ định trong danh sách sẽ được truyền dưới dạng tham số `callback_kwargs`. Bạn chỉ có thể bao gồm các biến được liệt kê trong thuộc tính `._callback_tensor_inputs` của lớp pipeline của bạn. max_sequence_length (`int`, mặc định là `512`) : Số lượng token tối đa trong prompt. Nếu prompt vượt quá độ dài này, nó sẽ bị cắt bớt. Nếu prompt ngắn hơn độ dài này, nó sẽ được đệm. **Trả về:** `~CosmosImagePipelineOutput` hoặc `tuple` Nếu `return_dict` là `True`, `CosmosImagePipelineOutput` sẽ được trả về, ngược lại một `tuple` sẽ được trả về trong đó phần tử đầu tiên là một danh sách chứa các hình ảnh đã tạo và phần tử thứ hai là một danh sách các `bool` cho biết hình ảnh tương ứng có chứa nội dung "không an toàn" (nsfw) hay không. Hàm gọi call của pipeline để tạo nội dung. Ví dụ: ```python >>> import torch >>> from diffusers import Cosmos2TextToImagePipeline >>> # Available checkpoints: nvidia/Cosmos-Predict2-2B-Text2Image, nvidia/Cosmos-Predict2-14B-Text2Image >>> model_id = "nvidia/Cosmos-Predict2-2B-Text2Image" >>> pipe = Cosmos2TextToImagePipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16) >>> pipe.to("cuda") >>> prompt = "A close-up shot captures a vibrant yellow scrubber vigorously working on a grimy plate, its bristles moving in circular motions to lift stubborn grease and food residue. The dish, once covered in remnants of a hearty meal, gradually reveals its original glossy surface. Suds form and bubble around the scrubber, creating a satisfying visual of cleanliness in progress. The sound of scrubbing fills the air, accompanied by the gentle clinking of the dish against the sink. As the scrubber continues its task, the dish transforms, gleaming under the bright kitchen lights, symbolizing the triumph of cleanliness over mess." >>> negative_prompt = "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality." >>> output = pipe( ... prompt=prompt, negative_prompt=negative_prompt, generator=torch.Generator().manual_seed(1) ... ).images[0] >>> output.save("output.png") ``` #### encode_prompt[[diffusers.Cosmos2TextToImagePipeline.encode_prompt]] ```python encode_prompt(prompt: str | list[str], negative_prompt: str | list[str] | None = None, do_classifier_free_guidance: bool = True, num_images_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 512, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos2_text2image.py#L254) **Tham số:** prompt (`str` hoặc `list[str]`, *tùy chọn*) : prompt cần được mã hóa negative_prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `negative_prompt_embeds` thay thế. Bỏ qua khi không sử dụng guidance (tức là bị bỏ qua nếu `guidance_scale` nhỏ hơn `1`). do_classifier_free_guidance (`bool`, *tùy chọn*, mặc định là `True`) : Có sử dụng classifier free guidance hay không. num_images_per_prompt (`int`, *optional*, mặc định là 1) : Số lượng video cần được tạo cho mỗi prompt. Thiết bị torch để đặt các embeddings kết quả lên prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, các vector nhúng văn bản sẽ được tạo từ đối số đầu vào `prompt`. negative_prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, negative_prompt_embeds sẽ được tạo từ đối số đầu vào `negative_prompt`. device : (`torch.device`, *tùy chọn*): thiết bị torch dtype : (`torch.dtype`, *tùy chọn*): torch dtype Mã hóa prompt thành các trạng thái ẩn của text encoder. ## Cosmos2VideoToWorldPipeline[[diffusers.Cosmos2VideoToWorldPipeline]] #### diffusers.Cosmos2VideoToWorldPipeline[[diffusers.Cosmos2VideoToWorldPipeline]] ```python diffusers.Cosmos2VideoToWorldPipeline(text_encoder: T5EncoderModel, tokenizer: T5Tokenizer, transformer: CosmosTransformer3DModel, vae: AutoencoderKLWan, scheduler: FlowMatchEulerDiscreteScheduler, safety_checker: CosmosSafetyChecker = None) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos2_video2world.py#L162) **Tham số:** text_encoder (`T5EncoderModel`) : Bộ mã hóa văn bản đóng băng. Cosmos sử dụng [T5](https://huggingface.co/docs/transformers/model_doc/t5#transformers.T5EncoderModel); cụ thể là biến thể [t5-11b](https://huggingface.co/google-t5/t5-11b). tokenizer (`T5TokenizerFast`) : Tokenizer của lớp [T5Tokenizer](https://huggingface.co/docs/transformers/model_doc/t5#transformers.T5Tokenizer). transformer ([CosmosTransformer3DModel](/docs/diffusers/main/vi/api/models/cosmos_transformer3d#diffusers.CosmosTransformer3DModel)) : Transformer có điều kiện để khử nhiễu các latents ảnh đã mã hóa. scheduler ([FlowMatchEulerDiscreteScheduler](/docs/diffusers/main/vi/api/schedulers/flow_match_euler_discrete#diffusers.FlowMatchEulerDiscreteScheduler)) : Một trình lập lịch được sử dụng kết hợp với `transformer` để khử nhiễu các latent ảnh đã mã hóa. vae ([AutoencoderKLWan](/docs/diffusers/main/vi/api/models/autoencoder_kl_wan#diffusers.AutoencoderKLWan)) : Mô hình Variational Auto-Encoder (VAE) để mã hóa và giải mã video sang và từ các biểu diễn ẩn. Pipeline để tạo thế giới từ video sử dụng [Cosmos Predict2](https://github.com/nvidia-cosmos/cosmos-predict2). Mô hình này kế thừa từ [DiffusionPipeline](/docs/diffusers/main/vi/api/pipelines/overview#diffusers.DiffusionPipeline). Xem tài liệu của lớp cha để biết các phương thức chung được triển khai cho tất cả các pipeline (tải xuống, lưu, chạy trên một thiết bị cụ thể, v.v.). #### __call__[[diffusers.Cosmos2VideoToWorldPipeline.__call__]] ```python __call__(image: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]] = None, video: list[typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]] = None, prompt: str | list[str] = None, negative_prompt: str | list[str] | None = None, height: int = 704, width: int = 1280, num_frames: int = 93, num_inference_steps: int = 35, guidance_scale: float = 7.0, fps: int = 16, num_videos_per_prompt: int | None = 1, generator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: str | None = 'pil', return_dict: bool = True, callback_on_step_end: typing.Union[typing.Callable[[int, int], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: list[str] = ['latents'], max_sequence_length: int = 512, sigma_conditioning: float = 0.0001) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos2_video2world.py#L485) **Tham số:** image (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, *tuỳ chọn*) : Ảnh được sử dụng làm đầu vào điều kiện cho việc tạo video. video (`list[PIL.Image.Image]`, `np.ndarray`, `torch.Tensor`, *tuỳ chọn*) : Video được sử dụng làm đầu vào điều kiện cho việc tạo video. prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt hoặc các prompt để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `prompt_embeds` thay thế. negative_prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `negative_prompt_embeds` thay thế. Bỏ qua khi không sử dụng guidance (tức là bị bỏ qua nếu `guidance_scale` không lớn hơn `1`). height (`int`, mặc định là `704`) : Chiều cao của hình ảnh được tạo ra, tính bằng pixel. width (`int`, mặc định là `1280`) : Độ rộng của hình ảnh được tạo ra, tính bằng pixel. num_frames (`int`, mặc định là `93`) : Số khung hình trong video được tạo ra. num_inference_steps (`int`, mặc định là `35`) : Số bước khử nhiễu. Số bước khử nhiễu nhiều hơn thường dẫn đến hình ảnh có chất lượng cao hơn, với cái giá là suy luận chậm hơn. guidance_scale (`float`, mặc định là `7.0`) : Thang độ dẫn hướng như được định nghĩa trong [Classifier-Free Diffusion Guidance](https://huggingface.co/papers/2207.12598). `guidance_scale` được định nghĩa là `w` của phương trình 2. trong [Imagen Paper](https://huggingface.co/papers/2205.11487). Thang độ dẫn hướng được kích hoạt bằng cách đặt `guidance_scale > 1`. fps (`int`, mặc định là `16`) : Số khung hình mỗi giây của video được tạo ra. num_videos_per_prompt (`int`, *tuỳ chọn*, mặc định là 1) : Số lượng hình ảnh cần tạo cho mỗi prompt. generator (`torch.Generator` hoặc `list[torch.Generator]`, *tùy chọn*) : Một [`torch.Generator`](https://pytorch.org/docs/stable/generated/torch.Generator.html) để đảm bảo quá trình sinh là tất định. latents (`torch.Tensor`, *tùy chọn*) : Các latents nhiễu được tạo trước, lấy mẫu từ phân phối Gaussian, dùng làm đầu vào cho việc tạo ảnh. Có thể dùng để tinh chỉnh cùng một quá trình tạo với các prompt khác nhau. Nếu không được cung cấp, một tensor latents sẽ được tạo bằng cách lấy mẫu sử dụng `generator` ngẫu nhiên được cung cấp. prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, các vector nhúng văn bản sẽ được tạo từ đối số đầu vào `prompt`. negative_prompt_embeds (`torch.FloatTensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã được tạo trước. Đối với PixArt-Sigma, prompt âm này nên là "". Nếu không được cung cấp, negative_prompt_embeds sẽ được tạo từ đối số đầu vào `negative_prompt`. output_type (`str`, *tùy chọn*, mặc định là `"pil"`) : Định dạng đầu ra của hình ảnh được tạo ra. Chọn giữa `PIL.Image` hoặc `np.array`. return_dict (`bool`, *tùy chọn*, mặc định là `True`) : Có nên trả về một `CosmosPipelineOutput` thay vì một tuple thông thường hay không. callback_on_step_end (`Callable`, `PipelineCallback`, `MultiPipelineCallbacks`, *optional*) : Một hàm hoặc một lớp con của `PipelineCallback` hoặc `MultiPipelineCallbacks` được gọi vào cuối mỗi bước khử nhiễu trong quá trình suy luận, với các đối số sau: `callback_on_step_end(self: DiffusionPipeline, step: int, timestep: int, callback_kwargs: Dict)`. `callback_kwargs` sẽ bao gồm một danh sách tất cả các tensor như được chỉ định bởi `callback_on_step_end_tensor_inputs`. callback_on_step_end_tensor_inputs (`list`, *optional*) : Danh sách các đầu vào tensor cho hàm `callback_on_step_end`. Các tensor được chỉ định trong danh sách sẽ được truyền dưới dạng tham số `callback_kwargs`. Bạn chỉ có thể bao gồm các biến được liệt kê trong thuộc tính `._callback_tensor_inputs` của lớp pipeline của bạn. max_sequence_length (`int`, mặc định là `512`) : Số lượng token tối đa trong prompt. Nếu prompt vượt quá độ dài này, nó sẽ bị cắt bớt. Nếu prompt ngắn hơn độ dài này, nó sẽ được đệm. sigma_conditioning (`float`, mặc định là `0.0001`) : Giá trị sigma được sử dụng để chuẩn hóa các latent điều kiện. Về lý tưởng, giá trị này không nên được thay đổi hoặc nên được đặt thành một giá trị nhỏ gần bằng không. **Trả về:** `~CosmosPipelineOutput` hoặc `tuple` Nếu `return_dict` là `True`, `CosmosPipelineOutput` sẽ được trả về, ngược lại một `tuple` sẽ được trả về trong đó phần tử đầu tiên là một danh sách chứa các hình ảnh đã tạo và phần tử thứ hai là một danh sách các `bool` cho biết hình ảnh tương ứng có chứa nội dung "not-safe-for-work" (nsfw) hay không. Hàm gọi call của pipeline để tạo nội dung. Ví dụ: ```python >>> import torch >>> from diffusers import Cosmos2VideoToWorldPipeline >>> from diffusers.utils import export_to_video, load_image >>> # Available checkpoints: nvidia/Cosmos-Predict2-2B-Video2World, nvidia/Cosmos-Predict2-14B-Video2World >>> model_id = "nvidia/Cosmos-Predict2-2B-Video2World" >>> pipe = Cosmos2VideoToWorldPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16) >>> pipe.to("cuda") >>> prompt = "A close-up shot captures a vibrant yellow scrubber vigorously working on a grimy plate, its bristles moving in circular motions to lift stubborn grease and food residue. The dish, once covered in remnants of a hearty meal, gradually reveals its original glossy surface. Suds form and bubble around the scrubber, creating a satisfying visual of cleanliness in progress. The sound of scrubbing fills the air, accompanied by the gentle clinking of the dish against the sink. As the scrubber continues its task, the dish transforms, gleaming under the bright kitchen lights, symbolizing the triumph of cleanliness over mess." >>> negative_prompt = "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality." >>> image = load_image( ... "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/yellow-scrubber.png" ... ) >>> video = pipe( ... image=image, prompt=prompt, negative_prompt=negative_prompt, generator=torch.Generator().manual_seed(1) ... ).frames[0] >>> export_to_video(video, "output.mp4", fps=16) ``` #### encode_prompt[[diffusers.Cosmos2VideoToWorldPipeline.encode_prompt]] ```python encode_prompt(prompt: str | list[str], negative_prompt: str | list[str] | None = None, do_classifier_free_guidance: bool = True, num_videos_per_prompt: int = 1, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, max_sequence_length: int = 512, device: typing.Optional[torch.device] = None, dtype: typing.Optional[torch.dtype] = None) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos2_video2world.py#L273) **Tham số:** prompt (`str` hoặc `list[str]`, *tùy chọn*) : prompt cần được mã hóa negative_prompt (`str` hoặc `list[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `negative_prompt_embeds` thay thế. Bỏ qua khi không sử dụng guidance (tức là bị bỏ qua nếu `guidance_scale` nhỏ hơn `1`). do_classifier_free_guidance (`bool`, *tùy chọn*, mặc định là `True`) : Có sử dụng classifier free guidance hay không. num_videos_per_prompt (`int`, *optional*, mặc định là 1) : Số lượng video cần được tạo cho mỗi prompt. Thiết bị torch để đặt các embeddings kết quả lên prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, các vector nhúng văn bản sẽ được tạo từ đối số đầu vào `prompt`. negative_prompt_embeds (`torch.Tensor`, *tùy chọn*) : Các vector nhúng văn bản âm đã được tạo trước. Có thể được sử dụng để dễ dàng điều chỉnh các đầu vào văn bản, *vd.* trọng số prompt. Nếu không được cung cấp, negative_prompt_embeds sẽ được tạo từ đối số đầu vào `negative_prompt`. device : (`torch.device`, *tùy chọn*): thiết bị torch dtype : (`torch.dtype`, *tùy chọn*): torch dtype Mã hóa prompt thành các trạng thái ẩn của text encoder. ## CosmosPipelineOutput[[diffusers.pipelines.cosmos.pipeline_output.CosmosPipelineOutput]] #### diffusers.pipelines.cosmos.pipeline_output.CosmosPipelineOutput[[diffusers.pipelines.cosmos.pipeline_output.CosmosPipelineOutput]] ```python diffusers.pipelines.cosmos.pipeline_output.CosmosPipelineOutput(frames: Tensor) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_output.py#L14) **Tham số:** frames (`torch.Tensor`, `np.ndarray`, hoặc list[list[PIL.Image.Image]]) : danh sách các đầu ra video - Có thể là một danh sách lồng nhau có độ dài `batch_size,` trong đó mỗi danh sách con chứa các chuỗi hình ảnh PIL đã khử nhiễu có độ dài `num_frames.` Nó cũng có thể là một mảng NumPy hoặc tensor Torch có hình dạng `(batch_size, num_frames, channels, height, width)`. Lớp đầu ra cho các pipeline any-to-world/video của Cosmos. ## CosmosImagePipelineOutput[[diffusers.pipelines.cosmos.pipeline_output.CosmosImagePipelineOutput]] #### diffusers.pipelines.cosmos.pipeline_output.CosmosImagePipelineOutput[[diffusers.pipelines.cosmos.pipeline_output.CosmosImagePipelineOutput]] ```python diffusers.pipelines.cosmos.pipeline_output.CosmosImagePipelineOutput(images: list[PIL.Image.Image] | numpy.ndarray) ``` [Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_output.py#L29) **Tham số:** images (`list[PIL.Image.Image]` hoặc `np.ndarray`) : danh sách các hình ảnh PIL đã khử nhiễu có độ dài `batch_size` hoặc mảng numpy có hình dạng `(batch_size, height, width, num_channels)`. Các hình ảnh PIL hoặc mảng numpy thể hiện các hình ảnh đã khử nhiễu của pipeline khuếch tán. Lớp đầu ra cho các pipeline any-to-image của Cosmos.
#
# Được cấp phép theo Giấy phép Apache, Phiên bản 2.0 (gọi là "Giấy phép");
# bạn có thể không sử dụng tệp này ngoại trừ tuân thủ theo Giấy phép.
# Bạn có thể nhận được một bản sao của Giấy phép tại
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Trừ khi được yêu cầu bởi luật pháp có hiệu lực hoặc được thỏa thuận bằng văn bản, phần mềm
# được phân phối theo Giấy phép được phân phối trên cơ sở
# KHÔNG CÓ BẢO HÀNH HOẶC ĐIỀU KIỆN DƯỚI BẤT KỲ HÌNH THỨC NÀO, dù được nêu rõ hay ngụ ý.
# Xem Giấy phép để biết ngôn ngữ cụ thể điều chỉnh các quyền và
# giới hạn theo Giấy phép. -->
# Cosmos
[Nền tảng Mô hình Nền tảng Thế giới Cosmos cho AI Vật lý](https://huggingface.co/papers/2501.03575) của NVIDIA.
*Physical AI cần được huấn luyện kỹ thuật số trước. Nó cần một bản sao kỹ thuật số của chính nó, mô hình chính sách, và một bản sao kỹ thuật số của thế giới, mô hình thế giới. Trong bài báo này, chúng tôi giới thiệu Nền tảng Mô hình Nền tảng Thế giới Cosmos để hỗ trợ các nhà phát triển xây dựng các mô hình thế giới tùy chỉnh cho các hệ thống Physical AI của họ. Chúng tôi định vị một mô hình nền tảng thế giới như một mô hình thế giới đa năng, có thể được tinh chỉnh thành các mô hình thế giới tùy chỉnh cho các ứng dụng hạ nguồn. Nền tảng của chúng tôi bao gồm một quy trình tuyển chọn video, các mô hình nền tảng thế giới đã được huấn luyện trước, các ví dụ về huấn luyện sau của các mô hình nền tảng thế giới đã được huấn luyện trước, và các bộ mã hóa video. Để hỗ trợ các nhà xây dựng Physical AI giải quyết những vấn đề quan trọng nhất của xã hội, chúng tôi mã nguồn mở nền tảng của mình và cung cấp các mô hình với trọng số mở theo giấy phép cho phép, có sẵn tại https://github.com/NVIDIA/Cosmos.*
> [!TIP]
> Hãy chắc chắn xem qua [hướng dẫn](../../using-diffusers/schedulers) về Schedulers để tìm hiểu cách khám phá sự đánh đổi giữa tốc độ và chất lượng của scheduler, và xem phần [tái sử dụng các thành phần giữa các pipeline](../../using-diffusers/loading#reusing-models-in-multiple-pipelines) để tìm hiểu cách nạp các thành phần giống nhau vào nhiều pipeline một cách hiệu quả.
## Cách sử dụng cơ bản
```python
import torch
from diffusers import Cosmos2_5_PredictBasePipeline
from diffusers.utils import export_to_video
model_id = "nvidia/Cosmos-Predict2.5-2B"
pipe = Cosmos2_5_PredictBasePipeline.from_pretrained(
model_id, revision="diffusers/base/post-trained", dtype=torch.bfloat16
)
pipe.to("cuda") # or "mps", "xpu", "cpu"
prompt = "As the red light shifts to green, the red bus at the intersection begins to move forward, its headlights cutting through the falling snow. The snowy tire tracks deepen as the vehicle inches ahead, casting fresh lines onto the slushy road. Around it, streetlights glow warmer, illuminating the drifting flakes and wet reflections on the asphalt. Other cars behind start to edge forward, their beams joining the scene. The stillness of the urban street transitions into motion as the quiet snowfall is punctuated by the slow advance of traffic through the frosty city corridor."
negative_prompt = "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality."
output = pipe(
image=None,
video=None,
prompt=prompt,
negative_prompt=negative_prompt,
num_frames=93,
generator=torch.Generator().manual_seed(1),
).frames[0]
export_to_video(output, "text2world.mp4", fps=16)
```
## Cosmos2_5_TransferPipeline[[diffusers.Cosmos2_5_TransferPipeline]]
#### diffusers.Cosmos2_5_TransferPipeline[[diffusers.Cosmos2_5_TransferPipeline]]
```python
diffusers.Cosmos2_5_TransferPipeline(text_encoder: Qwen2_5_VLForConditionalGeneration, tokenizer: AutoTokenizer, transformer: CosmosTransformer3DModel, vae: AutoencoderKLWan, scheduler: UniPCMultistepScheduler, controlnet: CosmosControlNetModel, safety_checker: typing.Optional[diffusers.pipelines.cosmos.pipeline_cosmos2_5_transfer.CosmosSafetyChecker] = None)
```
[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos2_5_transfer.py#L152)
**Tham số:**
text_encoder (`Qwen2_5_VLForConditionalGeneration`) : Bộ mã hóa văn bản đóng băng. Cosmos Transfer2.5 sử dụng bộ mã hóa [Qwen2.5 VL](https://huggingface.co/Qwen/Qwen2.5-VL-7B-Instruct).
tokenizer (`AutoTokenizer`) : Tokenizer liên quan đến bộ mã hóa Qwen2.5 VL.
transformer ([CosmosTransformer3DModel](/docs/diffusers/main/vi/api/models/cosmos_transformer3d#diffusers.CosmosTransformer3DModel)) : Transformer có điều kiện để khử nhiễu các latents ảnh đã mã hóa.
scheduler ([UniPCMultistepScheduler](/docs/diffusers/main/vi/api/schedulers/unipc#diffusers.UniPCMultistepScheduler)) : Một trình lập lịch được sử dụng kết hợp với `transformer` để khử nhiễu các latent ảnh đã mã hóa.
vae ([AutoencoderKLWan](/docs/diffusers/main/vi/api/models/autoencoder_kl_wan#diffusers.AutoencoderKLWan)) : Mô hình Variational Auto-Encoder (VAE) để mã hóa và giải mã video sang và từ các biểu diễn ẩn.
controlnet (`CosmosControlNetModel`) : ControlNet được sử dụng để điều kiện hóa quá trình tạo dựa trên các đầu vào điều khiển.
Pipeline cho Cosmos Transfer2.5, hỗ trợ suy luận tự hồi quy.
Mô hình này kế thừa từ [DiffusionPipeline](/docs/diffusers/main/vi/api/pipelines/overview#diffusers.DiffusionPipeline). Xem tài liệu của lớp cha để biết các phương thức chung được triển khai cho tất cả các pipeline (tải xuống, lưu, chạy trên một thiết bị cụ thể, v.v.).
#### __call__[[diffusers.Cosmos2_5_TransferPipeline.__call__]]
```python
__call__(controls: typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor], typing.List[typing.Union[PIL.Image.Image, numpy.ndarray, torch.Tensor, list[PIL.Image.Image], list[numpy.ndarray], list[torch.Tensor]]]], controls_conditioning_scale: typing.Union[float, typing.List[float]] = 1.0, prompt: typing.Union[str, typing.List[str], NoneType] = None, negative_prompt: typing.Union[str, typing.List[str]] = 'The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, underexposed and overexposed scenes, poor color balance, washed out colors, choppy sequences, jerky movements, low frame rate, artifacting, color banding, unnatural transitions, outdated special effects, fake elements, unconvincing visuals, poorly edited content, jump cuts, visual noise, and flickering. Overall, the video is of poor quality.', height: int = 704, width: typing.Optional[int] = None, num_frames: typing.Optional[int] = None, num_frames_per_chunk: int = 93, num_inference_steps: int = 36, guidance_scale: float = 3.0, num_videos_per_prompt: int = 1, generator: typing.Union[torch.Generator, typing.List[torch.Generator], NoneType] = None, latents: typing.Optional[torch.Tensor] = None, prompt_embeds: typing.Optional[torch.Tensor] = None, negative_prompt_embeds: typing.Optional[torch.Tensor] = None, output_type: typing.Optional[str] = 'pil', return_dict: bool = True, callback_on_step_end: typing.Union[typing.Callable[[int, int, typing.Dict], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = None, callback_on_step_end_tensor_inputs: typing.List[str] = ['latents'], max_sequence_length: int = 512, conditional_frame_timestep: float = 0.1, num_ar_conditional_frames: typing.Optional[int] = 1, num_ar_latent_conditional_frames: typing.Optional[int] = None)
```
[Nguồn](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/cosmos/pipeline_cosmos2_5_transfer.py#L569)
**Tham số:**
controls (`PipelineImageInput`, `List[PipelineImageInput]`) : Ảnh hoặc video đầu vào điều khiển được sử dụng bởi ControlNet.
controls_conditioning_scale (`float` hoặc `List[float]`, *tùy chọn*, mặc định là `1.0`) : Hệ số tỷ lệ cho các đầu ra của ControlNet. Một giá trị float đơn lẻ sẽ được phát sóng (broadcast) đến tất cả các khối điều khiển.
prompt (`str` hoặc `List[str]`, *tùy chọn*) : Prompt hoặc các prompt để hướng dẫn quá trình tạo. Bắt buộc trừ khi `prompt_embeds` được cung cấp.
negative_prompt (`str` hoặc `List[str]`, *tùy chọn*) : Prompt hoặc các prompt không được dùng để hướng dẫn việc tạo ảnh. Nếu không được định nghĩa, bạn phải truyền `negative_prompt_embeds` thay thế. Bỏ qua khi không sử dụng guidance (tức là bị bỏ qua nếu `guidance_scale` không lớn hơn `1`).
height (`int`, mặc định là `704`) : Chiều cao của hình ảnh được tạo ra, tính bằng pixel.
width (`int`, *optional*) : Độ rộng của hình ảnh được tạo ra, tính bằng pixel. Nếu không được cung cấp, giá trị này sẽ được xác định dựa trên tỷ lệ khung hình của đầu vào và chiều cao được cung cấp.
num_frames (`int`, *optional*) : Số lượng khung hình đầu ra. Mặc định là `None` để xuất ra cùng số lượng khung hình với đầu vào `controls`.

Xet Storage Details

Size:
94.1 kB
·
Xet hash:
4ddc939244d61af8a5455f26cdf43fe2b0f482b285f9d65929aafc41fa172758

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.