Skip to content

Commit f8ba319

Browse files
committed
Add transfer support to the Cosmos3 modular pipeline
1 parent 74c70a7 commit f8ba319

6 files changed

Lines changed: 965 additions & 12 deletions

File tree

docs/source/en/api/pipelines/cosmos3.md

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ pipe = Cosmos3OmniPipeline.from_pretrained(
740740

741741
## Cosmos3OmniModularPipeline
742742

743-
Cosmos 3 is also available as a Modular Diffusers pipeline. The task-based [`Cosmos3OmniPipeline`] remains available; the modular pipeline coexists with it and covers the same modes (`text2image`, `text2video`, `image2video`, `video2video`, and action-conditioned generation, with optional sound when supported by the checkpoint).
743+
Cosmos 3 is also available as a Modular Diffusers pipeline. The task-based [`Cosmos3OmniPipeline`] remains available; the modular pipeline coexists with it and covers the same modes (`text2image`, `text2video`, `image2video`, `video2video`, action-conditioned generation, and `transfer` (structural control), with optional sound when supported by the checkpoint).
744744

745745
```python
746746
import torch
@@ -786,7 +786,7 @@ image2video_blocks = pipe.blocks.get_workflow("image2video")
786786

787787
### Modular examples for all existing workflows
788788

789-
The modular pipeline supports the same call signatures as the task pipeline. The snippets below mirror every generation example shown above (`text2video`, `text2image`, `image2video`, `video2video`, `video2video_sound`, `text2video_sound`, and `action_policy`).
789+
The modular pipeline supports the same call signatures as the task pipeline. The snippets below mirror every generation example shown above (`text2video`, `text2image`, `image2video`, `video2video`, `video2video_sound`, `text2video_sound`, and `action_policy`). Transfer (structural control) has its own inputs and is shown separately in [Modular transfer](#modular-transfer-structural-control) below.
790790

791791
```python
792792
import json
@@ -931,6 +931,61 @@ if outputs["action"] is not None:
931931
json.dump(outputs["action"][0].tolist(), f)
932932
```
933933

934+
### Modular transfer (structural control)
935+
936+
Transfer follows a **precomputed control video** (edge, blur, depth, segmentation, or a world-scenario map) passed through `control_videos=` as a `{hint: video}` mapping. It is video-only (no `image` / `video` / `action` / `enable_sound`), the prompt is a pre-upsampled JSON caption (see [Prompt upsampling](#prompt-upsampling)), and long clips are generated autoregressively in chunks of `num_video_frames_per_chunk` and stitched automatically. `guidance_scale` is the usual text CFG; `control_guidance` (`!= 1.0`) additionally amplifies the control signal. Recommended starting values per hint:
937+
938+
| Hint | `guidance_scale` | `control_guidance` | `flow_shift` | Geometry |
939+
| --- | --- | --- | --- | --- |
940+
| Edge / Blur / Depth | 3.0 | 1.5 | 10.0 | 121 frames @ 30 FPS |
941+
| Segmentation | 3.0 | 2.0 | 10.0 | 121 frames @ 30 FPS |
942+
| World scenario (WSM) | 1.0 | 3.0 | 10.0 | 101 frames @ 10 FPS |
943+
944+
Diffusers does not ship the control assets. Ready-made ones (a control video + matching `prompt.json` per hint, plus a shared `negative_prompt.json`) live in the [Cosmos cookbook](https://github.com/NVIDIA/cosmos/tree/main/cookbooks/cosmos3/generator/transfer/assets). For the edge example below, download them into a local `assets/` folder:
945+
946+
```bash
947+
base=https://github.com/NVIDIA/cosmos/raw/refs/heads/main/cookbooks/cosmos3/generator/transfer/assets
948+
mkdir -p assets/edge
949+
curl -sL "$base/edge/control_edge.mp4" -o assets/edge/control_edge.mp4
950+
curl -sL "$base/edge/prompt.json" -o assets/edge/prompt.json
951+
curl -sL "$base/negative_prompt.json" -o assets/negative_prompt.json
952+
```
953+
954+
```python
955+
import json
956+
import torch
957+
from diffusers import Cosmos3OmniModularPipeline
958+
from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
959+
from diffusers.utils import export_to_video, load_video
960+
961+
pipe = Cosmos3OmniModularPipeline.from_pretrained("nvidia/Cosmos3-Nano", torch_dtype=torch.bfloat16)
962+
pipe.load_components(torch_dtype=torch.bfloat16)
963+
pipe.to("cuda")
964+
pipe.scheduler = UniPCMultistepScheduler.from_config(
965+
pipe.scheduler.config, flow_shift=10.0, use_karras_sigmas=False
966+
)
967+
968+
# Downloaded into assets/ from the Cosmos cookbook (see the curl snippet above).
969+
json_prompt = json.load(open("assets/edge/prompt.json"))
970+
negative_prompt = json.load(open("assets/negative_prompt.json"))
971+
control_edge = load_video("assets/edge/control_edge.mp4")
972+
973+
videos = pipe(
974+
prompt=json.dumps(json_prompt),
975+
negative_prompt=json.dumps(negative_prompt),
976+
control_videos={"edge": control_edge},
977+
num_frames=121,
978+
height=720,
979+
width=1280,
980+
fps=30.0,
981+
num_inference_steps=35,
982+
guidance_scale=3.0,
983+
control_guidance=1.5,
984+
output="videos",
985+
)
986+
export_to_video(videos, "cosmos3_modular_transfer_edge.mp4", fps=30, macro_block_size=1)
987+
```
988+
934989
[[autodoc]] Cosmos3OmniModularPipeline
935990

936991
- all

0 commit comments

Comments
 (0)