Overview
Cosmos3 has three processor utilities in PhyAI, covering two engine plugins:
Schedulers expect canonical requests whose tensors are already tokenized, resized/normalized, and shape-resolved. Tokenization, prompt metadata, observation image preprocessing, action padding, and domain name resolution all live in the processors.
The
cosmos3 generation plugin already decodes video latents into pixels in engine.step; with audio enabled, it also decodes waveform. Cosmos3GenerationPostProcessor handles media export glue, not VAE decode. The cosmos3_policy path’s postprocess slices actions to their real dimension and can denormalize them from a stats JSON.Generation path: Cosmos3Processor
Cosmos3Processor is a Qwen chat-template tokenizer wrapper for Cosmos3T2VRequest in T2V/T2AV generation. It:
- Applies the chat template to the positive prompt, then appends
eosand<|vision_start|>tokens. - Produces
text_idsand an all-onestext_mask. - Tokenizes the negative prompt the same way, producing
neg_text_idsandneg_text_mask. - Appends duration, FPS, and resolution metadata to the positive prompt when
append_metadata=Trueandfps,num_frames,height, andwidthare known. - Uses the built-in Cosmos3 structured bad-quality negative prompt when
negative_prompt=None; pass""for an empty negative prompt.
tokenize_pair maps directly to Cosmos3T2VRequest:
Connect to T2V/T2AV Engine
The example below shows how tokenizer output is assembled intoCosmos3T2VRequest. video_shape is a latent grid, not pixel dimensions; use pixel_to_latent_shape(num_frames, height, width) to convert from pixel dimensions.
with_sound=True, engine.step returns {"video": pixels, "sound": waveform, "sample_rate": int}. Otherwise it returns video pixels shaped (B, 3, T, H, W) with values in [0, 1].
Cosmos3GenerationPostProcessor.postprocess(...) returns Cosmos3GenerationOutput:
Save an mp4:
Action-policy path: Cosmos3PolicyProcessor
Cosmos3PolicyProcessor is used with the cosmos3_policy plugin. It converts an observation image/video, task prompt, optional conditioning action, and domain name into fields required by Cosmos3ActionRequest.
It supports three modes:
Input contract
preprocess accepts a dict. The common fields are:
The output
Cosmos3PolicyProcessedInputs fields are:
Image preprocessing
Cosmos3ImagePreprocessStep converts input images to RGB, then resizes/pads them to one target size:
- Input can be a path, PIL image, numpy array, torch tensor, or list.
- Tensor / numpy inputs may be channel-first or channel-last.
- Floating-point images that look like
[-1, 1]are first mapped to[0, 1]. - Resize uses scale-down BICUBIC and never upscales small images; remaining area is padded with reflect or edge padding.
- Output layout is
(1, 3, T, H, W)with values in[-1, 1].
image_size is not None, the processor does not use constructor height/width directly. Instead, it scales the first frame’s height to image_size, then snaps to one of the predefined Cosmos3 training resolution/aspect-ratio grids. examples/cosmos3/run_cosmos3_policy.py defaults to image_size=480.
Text prompt
Cosmos3TextTokenizeStep supports two prompt formats:
negative_prompt is not metadata-augmented. The policy example defaults to an empty negative prompt.
Action and domain
raw_action_dim can be passed explicitly or resolved from domain_name. Common mappings:
If
domain_name is an integer domain_id, the processor cannot infer the real action width, so you must pass raw_action_dim.
In forward_dynamics, cond_action is trimmed to action_chunk_size or padded by repeating its last frame, then zero-padded to action_dim. In other modes, cond_action is set to None.
Connect to Policy Engine
The example below runs policy inference from a single observation image and asks the plugin to return both action and decoded rollout pixels. For action output, use a policy checkpoint such as Cosmos3-Nano-Policy-DROID; the generalCosmos3-Nano checkpoint remains the T2V/T2AV generation checkpoint.
postprocess returns a dict:
Action denormalization
Ifaction_stats_path is passed to Cosmos3PolicyProcessor, postprocess denormalizes action values back to physical units before moving them to CPU:
action_normalization modes:
Without
action_stats_path, postprocess only slices the action and calls .cpu(); it does not change the numeric scale.
FAQ
Why call pixel_to_latent_shape on video_shape
Cosmos3PolicyProcessedInputs.video_shape is the post-preprocess pixel size (T, H, W). Cosmos3ActionRequest.video_shape expects the latent grid (t_lat, h_lat, w_lat), so call pixel_to_latent_shape(*processed.video_shape).
How are single-image and video observations different
A single image producesT=1. A video or list input keeps all provided frames, and VAE encode also encodes the full observation. Which latent frames stay clean downstream is controlled by cond_frame_indexes; the example script defaults to (0,) for images and (0, 1) for videos.
What are raw_action_dim and action_dim
raw_action_dim is the real action width for the robot embodiment, for example droid_lerobot=10 or agibotworld=29. action_dim is the model’s internal action token width, default 64. The processor pads conditioning actions to action_dim, and postprocess slices model outputs back to raw_action_dim.
Does the tokenizer require network access
The examples use the checkpoint-localtext_tokenizer directory, for example /path/to/Cosmos3-Nano-Policy-DROID/text_tokenizer. If you pass a remote tokenizer name and it is not in the local cache, first construction may trigger a download. In offline environments, pass a local tokenizer path.
