> ## Documentation Index
> Fetch the complete documentation index at: https://docs.m-star.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Cosmos3

> Choose a checkpoint for images, video, visual chat or DROID policy actions.

Pick the checkpoint for the output you need. Nano and Edge have one-GPU defaults. Super and its two distilled checkpoints default to two GPUs. The DROID policies predict robot actions from observations.

## Install and start

Video uploads require TorchCodec. Sound output also needs a checkpoint with a sound tokenizer and the `ffmpeg` and `ffprobe` binaries.

For dense attention, match the `fa3-fwd` wheel to PyTorch’s CUDA major version. Use `fa3-fwd==0.0.2` with CUDA 12 and `fa3-fwd==0.0.3` with CUDA 13. Check the ABI with `python -c "import fa3_fwd_interface"`. If the import fails, the server warns and uses FlashInfer ragged prefill for dense attention. On CUDA, bf16 VAE decode requires cuDNN 9.16 or newer. Earlier versions use fp32.

### `cosmos3`

Text, image, video → image, video, audio, action. The default `cosmos3_nano.yaml` uses 1 GPU. The [weights](https://huggingface.co/nvidia/Cosmos3-Nano) use OpenMDW-1.1.

```bash theme={null}
uv pip install --torch-backend=auto "mstar-ai[cosmos3]"
mstar serve cosmos3
```

[Send the request](#generate-video).

### `cosmos3_droid`

Text, image → action, video. The default `cosmos3_droid.yaml` uses 1 GPU. The [weights](https://huggingface.co/nvidia/Cosmos3-Nano-Policy-DROID) use OpenMDW-1.1.

```bash theme={null}
uv pip install --torch-backend=auto "mstar-ai[cosmos3]"
mstar serve cosmos3_droid
```

[Prepare the plain caption and send the Nano policy request](#droid-action).

### `cosmos3_edge`

Text, image, video → text, image, video, action. The default `cosmos3_edge.yaml` uses 1 GPU. The [weights](https://huggingface.co/nvidia/Cosmos3-Edge) use OpenMDW-1.1.

```bash theme={null}
uv pip install --torch-backend=auto "mstar-ai[cosmos3]"
mstar serve cosmos3_edge
```

[Send the request](#generate-video).

### `cosmos3_edge_droid`

Text, image → action, video. The default `cosmos3_edge_droid.yaml` uses 1 GPU. The [weights](https://huggingface.co/nvidia/Cosmos3-Edge-Policy-DROID) use OpenMDW-1.1.

```bash theme={null}
uv pip install --torch-backend=auto "mstar-ai[cosmos3]"
mstar serve cosmos3_edge_droid
```

[Prepare the JSON caption and send the Edge policy request](#droid-action).

### `cosmos3_super`

Text, image, video → image, video, audio. The default `cosmos3_super_tp2.yaml` uses 2 GPUs. The [weights](https://huggingface.co/nvidia/Cosmos3-Super) use OpenMDW-1.1.

```bash theme={null}
uv pip install --torch-backend=auto "mstar-ai[cosmos3]"
mstar serve cosmos3_super
```

[Send the request](#generate-video).

### `cosmos3_super_i2v_4step`

Text, image → video. The default `cosmos3_super_i2v_4step_tp2.yaml` uses 2 GPUs. The [weights](https://huggingface.co/nvidia/Cosmos3-Super-Image2Video-4Step) use OpenMDW-1.1.

```bash theme={null}
uv pip install --torch-backend=auto "mstar-ai[cosmos3]"
mstar serve cosmos3_super_i2v_4step
```

[Send the request](#animate-image).

### `cosmos3_super_t2i_4step`

Text → image. The default `cosmos3_super_t2i_4step_tp2.yaml` uses 2 GPUs. The [weights](https://huggingface.co/nvidia/Cosmos3-Super-Text2Image-4Step) use OpenMDW-1.1.

```bash theme={null}
uv pip install --torch-backend=auto "mstar-ai[cosmos3]"
mstar serve cosmos3_super_t2i_4step
```

[Send the request](#distilled-image).

## Send a request

Run either client example in a second terminal after `/health` returns 200.

### Generate a clip

Write the returned MP4 to disk.

**Python SDK**

```python theme={null}
from pathlib import Path
from mstar import MStarClient

client = MStarClient("http://localhost:8000")
reply = client.generate(
    text='A train crosses a stone bridge in mountain fog.',
    output_modalities=('video',),
    size='832x480',
    num_frames=33,
)
Path("clip.mp4").write_bytes(next(part["bytes"] for part in reply.raw if part["modality"] == "video"))
```

**curl**

```bash theme={null}
curl -fsS http://localhost:8000/generate \
  --form-string 'text=A train crosses a stone bridge in mountain fog.' \
  --form-string output_modalities=video \
  --form-string streaming=false \
  --form-string 'model_kwargs={"size":"832x480","num_frames":33}' \
  | python3 -c '
import base64, json, sys

outputs = json.load(sys.stdin)["outputs"]
with open("clip.mp4", "wb") as file:
    for chunk in outputs["video"]:
        file.write(base64.b64decode(chunk["data"]))
'
```

### Predict a DROID action chunk

From the root of an M\* source checkout, prepare the inputs for either request with the [DROID client helpers](https://github.com/mstar-project/mstar/blob/main/examples/cosmos3_action_ws_client.py). Use three RGB frames from the same observation. The helper stacks the wrist view above the two half-size exterior views, resizes the composite to 640×540 and reflection-pads it to 736×544. Both policies take the task, camera layout, duration, frame rate and resolution. Nano takes a plain caption and Edge takes a JSON caption.

```python theme={null}
import json
from pathlib import Path
from urllib.request import urlopen

import numpy as np
from PIL import Image
from examples.cosmos3_action_ws_client import compose_observation, policy_prompt

views = [np.asarray(Image.open(path).convert("RGB"))
         for path in ("wrist.png", "exterior-1.png", "exterior-2.png")]
Image.fromarray(compose_observation(*views)).save("observation.png")
with urlopen("http://localhost:8000/v1/models") as response:
    model = json.load(response)["data"][0]["id"]
json_prompt = {"cosmos3_droid": False, "cosmos3_edge_droid": True}[model]
Path("caption.txt").write_text(policy_prompt("Pick up the cup.", json_prompt))
```

Replace the example state with the seven observed joint positions followed by the gripper position. Both requests save the returned float32 action tensor.

**Python SDK**

```python theme={null}
from pathlib import Path
from mstar import MStarClient

client = MStarClient("http://localhost:8000")
reply = client.generate(
    text=Path("caption.txt").read_text(),
    images='observation.png',
    input_modalities=('image', 'text'),
    output_modalities=('action',),
    robot_state=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    size='736x544',
)
Path("actions.f32").write_bytes(next(part["bytes"] for part in reply.raw if part["modality"] == "action"))
```

**curl**

```bash theme={null}
curl -fsS http://localhost:8000/generate \
  -F 'text=<caption.txt' \
  -F files=@observation.png \
  --form-string input_modalities=image,text \
  --form-string output_modalities=action \
  --form-string streaming=false \
  --form-string 'model_kwargs={"robot_state":[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],"size":"736x544"}' \
  | python3 -c '
import base64, json, sys

outputs = json.load(sys.stdin)["outputs"]
with open("actions.f32", "wb") as file:
    for chunk in outputs["action"]:
        file.write(base64.b64decode(chunk["data"]))
'
```

### Animate a first frame

Supply a first frame as `scene.png`. Write the returned MP4 to disk.

**Python SDK**

```python theme={null}
from pathlib import Path
from mstar import MStarClient

client = MStarClient("http://localhost:8000")
reply = client.generate(
    text='A train crosses a stone bridge in mountain fog.',
    images='scene.png',
    input_modalities=('image', 'text'),
    output_modalities=('video',),
    num_frames=33,
)
Path("clip.mp4").write_bytes(next(part["bytes"] for part in reply.raw if part["modality"] == "video"))
```

**curl**

```bash theme={null}
curl -fsS http://localhost:8000/generate \
  --form-string 'text=A train crosses a stone bridge in mountain fog.' \
  -F files=@scene.png \
  --form-string input_modalities=image,text \
  --form-string output_modalities=video \
  --form-string streaming=false \
  --form-string 'model_kwargs={"num_frames":33}' \
  | python3 -c '
import base64, json, sys

outputs = json.load(sys.stdin)["outputs"]
with open("clip.mp4", "wb") as file:
    for chunk in outputs["video"]:
        file.write(base64.b64decode(chunk["data"]))
'
```

### Generate an image

Save the returned PNG.

**Python SDK**

```python theme={null}
from pathlib import Path
from mstar import MStarClient

client = MStarClient("http://localhost:8000")
image = client.generate_image("An orange cat watching snow fall.")
Path("image.png").write_bytes(image)
```

**curl**

```bash theme={null}
curl -fsS http://localhost:8000/v1/images/generations \
  -H 'Content-Type: application/json' \
  -d '{"prompt":"An orange cat watching snow fall."}' \
  | python3 -c 'import json, sys; print(json.load(sys.stdin)["data"][0]["b64_json"])' \
  | base64 --decode > image.png
```

### Image and video chat

`cosmos3_edge` serves `POST /v1/chat/completions` with image and video content parts, streamed. The Edge DROID checkpoint has no reasoner. `extra_body` takes `enable_thinking` (a `<think>` block opens by default), `top_k`, `repetition_penalty`, `penalize_prompt`, `video_fps` and `video_num_frames`. `max_tokens` defaults to 2048, and `min_p` is refused unless the checkpoint's `generation_config.json` sets one.

### Streaming rollout

Long clips can be generated window by window, each window streamed as soon as it is decoded. The deployment must set `enable_windowed_video: true`, which `configs/cosmos3_edge.yaml` and `configs/cosmos3_nano_ar.yaml` do:

```bash theme={null}
mstar serve cosmos3 --config configs/cosmos3_nano_ar.yaml
python examples/cosmos3_stream_video_ws_client.py --port 8000 \
  --prompt "a drone flies over a coastal town at dawn" --frames 241 --mode chained --out /tmp/rollout
```

Request knobs, in `model_kwargs` or the video request body:

| Knob | Default | Meaning |
| - | - | - |
| `window_mode` | none; `chained` when `stream_video` is set | `chained`: each window is a full denoise conditioned on the previous window's last frames. `kv`: experimental, later windows attend to committed K/V. |
| `window_frames` | 61 on Edge, 29 elsewhere; 29 for `kv` | Frames per window. |
| `overlap_frames` | 32 on Edge, 8 elsewhere | `chained` only: frames carried over from the previous window. |
| `context_frames` | 61 | `kv` only: committed frames kept; `0` keeps all. |
| `stream_video` | `false` | Emit each window as its own chunk. `/v1/videos/generations` then returns NDJSON. |
| `session_id`, `resume_session`, `end_session`, `session_timeout_s` | | Keep a rollout's state and continue it in a later request. Idle sessions expire after 600 s by default. |

Windowed requests take no sound and no video conditioning.

### Robot actions

The DROID policies predict a chunk of robot actions from one observation image (the client composes it from the wrist and exterior cameras), the task text and the robot's current state. For a control loop use `/generate/ws`:

```bash theme={null}
mstar serve cosmos3_droid
python examples/cosmos3_action_ws_client.py --host localhost --port 8000 \
  --wrist wrist.png --exterior-1 ext1.png --exterior-2 ext2.png \
  --joints=-0.07,0.26,0.02,-2.21,0.02,2.48,0.79 --gripper 0.0 \
  --prompt "put the marker in the pot" --iters 20
```

Add `--json-prompt` for `cosmos3_edge_droid`. A request with `output_modalities: ["action"]` and a `robot_state` is a policy request; the chunk (32 rows), the observation rate (15 fps) and the domain (`droid_lerobot`) come from the checkpoint or the config. The reply is float32 `[chunk, padded width]`, and the first `raw_action_dim` columns are the robot's actions.

The code fixes no DROID action width. `raw_action_dim` sets it, from 1 to the checkpoint's padded width (64 by default); when it is left out, the length of `robot_state` (or of a forward-dynamics `action` row) sets it. The shipped DROID configs and the example client send 8 values: the 7 joint positions and the gripper. The configs map the gripper to the checkpoint's `1 - gripper` on the way in and back on the way out (`inverted_action_dims: [7]`).

`action_mode` also takes `forward_dynamics` and `inverse_dynamics`. Those requests, and any action request to a checkpoint that is not a DROID policy, must name `domain_name` or `domain_id`.

## Deployment configs

| File | GPUs | Parallelism | When to use |
| - | - | - | - |
| `cosmos3_nano.yaml` | 1 | none | Nano default. |
| `cosmos3_nano_ar.yaml` | 1 | none | Nano with windowed video. |
| `cosmos3_nano_dp2.yaml` | 2 | replica per GPU | Throughput under concurrency. |
| `cosmos3_nano_sp2.yaml` | 2 | `sp_size: 2` | One request's latency. |
| `cosmos3_nano_sp4.yaml` | 4 | `sp_size: 4` | One request's latency. |
| `cosmos3_nano_tp2.yaml` | 2 | `tp_size: 2` | Weights split across GPUs. |
| `cosmos3_nano_tp4.yaml` | 4 | `tp_size: 4` | Weights split across GPUs. |
| `cosmos3_nano_tp2_sp2.yaml` | 4 | `tp_size: 2`, `sp_size: 2` | Both. |
| `cosmos3_droid.yaml`, `cosmos3_edge_droid.yaml` | 1 | none | DROID policies, with the observation encode warmed at startup. |
| `cosmos3_edge.yaml` | 1 | none | Edge generator, reasoner and windowed video. |
| `cosmos3_edge_dp2.yaml` | 2 | replica per GPU | Edge throughput, chat kept. |
| `cosmos3_edge_sp2.yaml` | 2 | `sp_size: 2` | Edge generation latency; the reasoner is off. |
| `cosmos3_super_tp2.yaml` | 2 | `tp_size: 2` | Super default; Super does not fit one GPU. |
| `cosmos3_super_tp4.yaml` | 4 | `tp_size: 4` | Super on four GPUs. |
| `cosmos3_super_tp2_sp2.yaml` | 4 | `tp_size: 2`, `sp_size: 2` | Super on four GPUs. |
| `cosmos3_super_t2i_4step_tp2.yaml`, `cosmos3_super_i2v_4step_tp2.yaml` | 2 | `tp_size: 2` | The distilled Super checkpoints. |

To use an alternative, pass `--config configs/<file>` after the launcher name. From a wheel installation, [copy the shipped YAML](https://docs.m-star.org/serving.md#custom-configs) and pass its local path.

## Settings and defaults

Set these under `model_kwargs` in the config.

| Knob | Default | Effect |
| - | - | - |
| `accelerator_graph` | `true` | Capture the denoise, prefill and reasoner steps. `false` serves eagerly. The `COSMOS3_DISABLE_ACCELERATOR_GRAPH` variable also turns capture off. |
| `graph_max_latent_area` | `2000` | Capture only resolutions whose latent height x width is at most this. |
| `gen_capture_image` | 192x320, 480x832, 720x1280 | `[height, width]` image tiers to capture. |
| `gen_capture_video` | none | `[height, width, frames]` video tiers to capture. |
| `max_batched_vision_tokens` | none | A step whose requests total more vision tokens runs them one at a time. There is no cap by default, since the right value depends on the GPU; on an H100, set 16384. |
| `enable_sound` | `true` | Serve sound when the checkpoint ships a sound tokenizer. |
| `enable_windowed_video` | `false` | Serve windowed requests. |
| `enable_reasoner` | `true` | Serve Edge's chat. |
| `conditioning_resize` | `aspect_crop` | `stretch` resizes the image-to-video frame to the output size without keeping its aspect ratio. |
| `compile_denoise` | `true` | Compile the denoise step. |
| `denoise_compile_mode` | `deterministic` | `deterministic` gives the same video for a seed in every server process. `default` uses torch.compile's defaults and `level` the `mstar serve -O` level's options. |
| `vae_decode_fast` | `true` | Channels-last, compiled VAE decode for video. |

## Limits

* The 4-step distilled checkpoints fix the step count and guidance (leave `num_inference_steps` and `guidance_scale` unset) and refuse action, sound, windowed and video-conditioned requests.
* Sound is for video requests only, on a checkpoint that ships a `sound_tokenizer/`. The Nano DROID checkpoint has none.
* Requests that share a step can differ from their solo results at bf16 rounding. Serve one request at a time when outputs must be bitwise repeatable.
* `window_mode: kv` is experimental: with an image prompt the rollout can leave the scene at the first window boundary.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.