Spaces:
Running on L40S
Running on L40S
File size: 9,587 Bytes
9f818c5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 | # Prompt Upsampling
> **Skill:** `.agents/skills/cosmos3-inference/SKILL.md`
<!--TOC-->
______________________________________________________________________
**Table of Contents**
- [Overview](#overview)
- [Setup](#setup)
- [Inputs](#inputs)
- [Outputs](#outputs)
- [Quick Start](#quick-start)
- [Text-to-Image](#text-to-image)
- [Text-to-Video](#text-to-video)
- [Image-to-Video](#image-to-video)
- [Reasoner Templates](#reasoner-templates)
- [Posttrained I2V](#posttrained-i2v)
- [Template Files](#template-files)
______________________________________________________________________
<!--TOC-->
## Overview
The prompt upsampler converts one prompt per line into structured Cosmos3 JSON prompts. It supports:
- `text2image`
- `text2video`
- `image2video`
- `posttrain_image2video`
Run it as:
```shell
python -m cosmos_framework.inference.prompt_upsampling --help
```
## Setup
Run commands from the repository root. Configure the OpenAI-compatible endpoint and API token:
```shell
export PROMPT_UPSAMPLER_ENDPOINT_URL="[required endpoint url]"
export PROMPT_UPSAMPLER_API_TOKEN="[api key]"
export PROMPT_UPSAMPLER_MODEL_NAME="[model name]"
```
Arguments:
- `--input`: Text file with one prompt per non-empty line.
- `--output`: Output directory. The CLI writes one `prompt_<index>.json` file per input prompt.
- `--mode`: One of `text2image`, `text2video`, `image2video`, or `posttrain_image2video`.
- `--endpoint-url`: OpenAI-compatible endpoint URL. Defaults to `PROMPT_UPSAMPLER_ENDPOINT_URL`.
- `--model`: Model name. Defaults to `PROMPT_UPSAMPLER_MODEL`.
- `--api-token`: API token. Defaults to `PROMPT_UPSAMPLER_API_TOKEN`.
- `--prompt-template`: Optional prompt template override for the selected mode.
- `--json-template`: Optional JSON schema template override for the selected mode.
## Inputs
Prompt files contain one non-empty prompt per line:
```text
A humanoid robot carefully assembles a gearbox on a workbench.
A red sports car drives through rain at night.
```
For `image2video` and `posttrain_image2video`, provide either one shared image:
```shell
--image-url inputs/prompt_upsampler/image_inputs/car_driving.jpg
```
Or provide one image per prompt:
```shell
--image-list inputs/prompt_upsampler/images.txt
```
Image-list files must have the same number of non-empty lines as the prompt file:
```text
inputs/prompt_upsampler/image_inputs/car_driving.jpg
inputs/prompt_upsampler/image_inputs/humanoid_robot.jpg
```
Local image paths, HTTP(S) URLs, and `data:` URLs are accepted.
## Outputs
The CLI creates the output directory and writes one JSON file per input prompt:
```text
outputs/prompt_upsampler/upsampled_t2i_prompts_opus/
+-- prompt_0.json
`-- prompt_1.json
```
Every mode writes one record per prompt with the same shape: the upsampled JSON is a compact string under `prompt`. A record also includes a `negative_prompt` string when the template or model produces one.
```json
{
"prompt": "{\"subjects\": [...], \"resolution\": {\"H\": 480, \"W\": 832}, ...}"
}
```
## Quick Start
The built-in external API templates are used by default. They live in `cosmos_framework/inference/prompting_templates/external_api`.
For example, to use Opus to generate upsampled prompts, set
```shell
export PROMPT_UPSAMPLER_ENDPOINT_URL="https://api.anthropic.com/v1/"
export PROMPT_UPSAMPLER_MODEL_NAME="claude-opus-4-6"
```
### Text-to-Image
```shell
python -m cosmos_framework.inference.prompt_upsampling \
--input inputs/prompt_upsampler/prompts_t2i.txt \
--output outputs/prompt_upsampler/upsampled_t2i_prompts_opus \
--mode text2image \
--endpoint-url "${PROMPT_UPSAMPLER_ENDPOINT_URL}" \
--model "${PROMPT_UPSAMPLER_MODEL_NAME}" \
--api-token "${PROMPT_UPSAMPLER_API_TOKEN}" \
--resolution 720 \
--aspect-ratio "1,1"
```
### Text-to-Video
```shell
python -m cosmos_framework.inference.prompt_upsampling \
--input inputs/prompt_upsampler/prompts_t2v.txt \
--output outputs/prompt_upsampler/upsampled_t2v_prompts_opus \
--mode text2video \
--endpoint-url "${PROMPT_UPSAMPLER_ENDPOINT_URL}" \
--model "${PROMPT_UPSAMPLER_MODEL_NAME}" \
--api-token "${PROMPT_UPSAMPLER_API_TOKEN}" \
--resolution 720 \
--aspect-ratio "16,9" \
--duration "5s" \
--fps 24
```
### Image-to-Video
```shell
python -m cosmos_framework.inference.prompt_upsampling \
--input inputs/prompt_upsampler/prompts_i2v.txt \
--image-list inputs/prompt_upsampler/images.txt \
--output outputs/prompt_upsampler/upsampled_i2v_prompts_opus \
--mode image2video \
--endpoint-url "${PROMPT_UPSAMPLER_ENDPOINT_URL}" \
--model "${PROMPT_UPSAMPLER_MODEL_NAME}" \
--api-token "${PROMPT_UPSAMPLER_API_TOKEN}" \
--resolution 720 \
--aspect-ratio "16,9" \
--duration "5s" \
--fps 24
```
## Reasoner Templates
Reasoner-style prompts use the templates in `cosmos_framework/inference/prompting_templates/reasoner`. Pass them explicitly with `--prompt-template` and `--json-template`.
For using reasoner prompt upsampler in this script, launch a VLLM server. Set the model name, endpoint url and API token served by your endpoint:
```shell
export PROMPT_UPSAMPLER_REASONER_MODEL="cosmos3-reasoner"
```
Text-to-image:
```shell
python -m cosmos_framework.inference.prompt_upsampling \
--input inputs/prompt_upsampler/prompts_t2i.txt \
--output outputs/prompt_upsampler/upsampled_t2i_prompts_reason \
--mode text2image \
--endpoint-url "${PROMPT_UPSAMPLER_ENDPOINT_URL}" \
--model "${PROMPT_UPSAMPLER_REASONER_MODEL}" \
--api-token "${PROMPT_UPSAMPLER_API_TOKEN}" \
--prompt-template cosmos_framework/inference/prompting_templates/reasoner/reasoner_t2i_prompt.txt \
--json-template cosmos_framework/inference/prompting_templates/reasoner/reasoner_t2i_json_schema.json \
--resolution 720 \
--aspect-ratio "1,1"
```
Text-to-video:
```shell
python -m cosmos_framework.inference.prompt_upsampling \
--input inputs/prompt_upsampler/prompts_t2v.txt \
--output outputs/prompt_upsampler/upsampled_t2v_prompts_reason \
--mode text2video \
--endpoint-url "${PROMPT_UPSAMPLER_ENDPOINT_URL}" \
--model "${PROMPT_UPSAMPLER_REASONER_MODEL}" \
--api-token "${PROMPT_UPSAMPLER_API_TOKEN}" \
--prompt-template cosmos_framework/inference/prompting_templates/reasoner/reasoner_t2v_prompt.txt \
--json-template cosmos_framework/inference/prompting_templates/reasoner/reasoner_t2v_json_schema.json \
--resolution 720 \
--aspect-ratio "16,9" \
--duration "5s" \
--fps 24
```
Image-to-video:
```shell
python -m cosmos_framework.inference.prompt_upsampling \
--input inputs/prompt_upsampler/prompts_i2v.txt \
--image-list inputs/prompt_upsampler/images.txt \
--output outputs/prompt_upsampler/upsampled_i2v_prompts_reason \
--mode image2video \
--endpoint-url "${PROMPT_UPSAMPLER_ENDPOINT_URL}" \
--model "${PROMPT_UPSAMPLER_REASONER_MODEL}" \
--api-token "${PROMPT_UPSAMPLER_API_TOKEN}" \
--prompt-template cosmos_framework/inference/prompting_templates/reasoner/reasoner_i2v_prompt.txt \
--json-template cosmos_framework/inference/prompting_templates/reasoner/reasoner_i2v_json_schema.json \
--resolution 720 \
--aspect-ratio "16,9" \
--duration "5s" \
--fps 24
```
## Posttrained I2V
The `posttrain_image2video` mode targets the post-trained Cosmos3-Super-Image2Video model. It produces both an upsampled JSON prompt and a per-sample contextual negative prompt. We use "claude-opus-4-7" for our Cosmos3-Super-Image2Video model.
```shell
python -m cosmos_framework.inference.prompt_upsampling \
--input inputs/prompt_upsampler/prompts_i2v.txt \
--image-list inputs/prompt_upsampler/images.txt \
--output outputs/prompt_upsampler/upsampled_i2v_pos_neg \
--mode posttrain_image2video \
--endpoint-url "${PROMPT_UPSAMPLER_ENDPOINT_URL}" \
--model "${PROMPT_UPSAMPLER_MODEL_NAME}" \
--api-token "${PROMPT_UPSAMPLER_API_TOKEN}" \
--prompt-template cosmos_framework/inference/prompting_templates/external_api/posttrained_i2v_prompt.txt \
--json-template cosmos_framework/inference/prompting_templates/external_api/posttrained_i2v_json_schema.json \
--resolution 480 \
--aspect-ratio "16,9" \
--duration "8s" \
--fps 24
```
The posttrained I2V templates emit a `<negative_prompt>` block, so each output record also carries a `negative_prompt` field.
## Template Files
Default external API templates:
- `cosmos_framework/inference/prompting_templates/external_api/t2i_prompt.txt`
- `cosmos_framework/inference/prompting_templates/external_api/t2i_json_schema.json`
- `cosmos_framework/inference/prompting_templates/external_api/t2v_i2v_video_prompt.txt`
- `cosmos_framework/inference/prompting_templates/external_api/t2v_i2v_video_json_schema.json`
- `cosmos_framework/inference/prompting_templates/external_api/posttrained_i2v_prompt.txt`
- `cosmos_framework/inference/prompting_templates/external_api/posttrained_i2v_json_schema.json`
Reasoner templates:
- `cosmos_framework/inference/prompting_templates/reasoner/reasoner_t2i_prompt.txt`
- `cosmos_framework/inference/prompting_templates/reasoner/reasoner_t2i_json_schema.json`
- `cosmos_framework/inference/prompting_templates/reasoner/reasoner_t2v_prompt.txt`
- `cosmos_framework/inference/prompting_templates/reasoner/reasoner_t2v_json_schema.json`
- `cosmos_framework/inference/prompting_templates/reasoner/reasoner_i2v_prompt.txt`
- `cosmos_framework/inference/prompting_templates/reasoner/reasoner_i2v_json_schema.json`
|