opentau.policies.cosmos3.modeling_cosmos3
cosmos3: a Vision-Language-Action flow-matching policy on a frozen Qwen3-VL-32B reasoner.
cosmos3 follows the π0.5 flow-matching recipe (see policies/pi05/modeling_pi05.py)
but swaps the PaliGemma backbone for a frozen Qwen3-VL-32B vision-language model –
the reasoning tower of NVIDIA Cosmos3-Super (extracted to a standalone Qwen3-VL-32B
checkpoint by opentau.scripts.extract_cosmos3_reasoner) – and pairs it with a custom
sub-1B Qwen3-style action expert (qwen3vl_with_expert.py).
- Pipeline:
The frozen reasoner encodes the camera images + language prompt once (the prefix) via the stock
Qwen3VLModel.forward, producing a per-layer key/value cache.The trainable expert denoises a continuous action chunk (the suffix) by flow matching, cross-attending to that cache at every layer. Proprioceptive state is projected into a single token prepended to the expert’s action chunk, so actions are conditioned on state while the backbone sees only images + language.
Continuous actions only (MSE flow matching) – there is no FAST discrete-action branch
and no response/subtask head, so cosmos3 always returns a zero CE term for loss-dict
compatibility with scripts/train.py.
Functions
|
Sine-cosine positional embedding for scalar positions |
|
Build a 2-D attention mask from 1-D pad + block masks (π0.5 convention). |
Classes
|
Flow-matching head: frozen Qwen3-VL prefix + trainable Qwen3 action expert. |
|
OpenTau wrapper around |
- class opentau.policies.cosmos3.modeling_cosmos3.Cosmos3FlowMatching(config: Cosmos3Config, qwen3vl_config: Qwen3VLConfig | None = None)[source]
Bases:
ModuleFlow-matching head: frozen Qwen3-VL prefix + trainable Qwen3 action expert.
- __init__(config: Cosmos3Config, qwen3vl_config: Qwen3VLConfig | None = None)[source]
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- embed_suffix(noisy_actions: Tensor, timestep: Tensor, state: Tensor) tuple[Tensor, Tensor, Tensor, Tensor][source]
Embed the proprioceptive-state token + the noisy action chunk for the expert.
Returns (embs, pad_masks, att_masks, adarms_cond) with sequence length
chunk_size + 1(state token prepended). The state token uses a fixed time of 1.0 for its AdaRMS conditioning; the action tokens usetimestep.
- forward(input_ids: Tensor, attention_mask: Tensor, pixel_values: Tensor | None, image_grid_thw: Tensor | None, state: Tensor, actions: Tensor, actions_is_pad: Tensor | None = None, noise: Tensor | None = None, time: Tensor | None = None, real_action_dim: Tensor | None = None, return_per_sample: bool = False) dict[str, Tensor | PerSampleLoss][source]
Full flow-matching training forward; returns {“MSE”, “CE”(=0)} (+ per-sample).
- class opentau.policies.cosmos3.modeling_cosmos3.Cosmos3Policy(config: Cosmos3Config, per_dataset_stats: list[dict[str, dict[str, Tensor]]] | None = None, dataset_names: list[str] | None = None, qwen3vl_config: Qwen3VLConfig | None = None)[source]
Bases:
PreTrainedPolicyOpenTau wrapper around
Cosmos3FlowMatching(normalization, processor, action queue).- __init__(config: Cosmos3Config, per_dataset_stats: list[dict[str, dict[str, Tensor]]] | None = None, dataset_names: list[str] | None = None, qwen3vl_config: Qwen3VLConfig | None = None)[source]
Initializes the PreTrainedPolicy.
- Parameters:
config – The configuration object for the policy.
*inputs – Variable length argument list.
**kwargs – Arbitrary keyword arguments.
- Raises:
ValueError – If config is not an instance of PreTrainedConfig.
- config_class
alias of
Cosmos3Config
- forward(batch: dict[str, Tensor], noise: Tensor | None = None, time: Tensor | None = None, return_per_sample: bool = False) dict[str, Tensor | PerSampleLoss][source]
Performs a forward pass of the policy.
- Parameters:
batch – A dictionary of input tensors.
- Returns:
- A tuple containing:
The loss tensor.
An optional dictionary of metrics or auxiliary outputs. Apart from the loss, items should be logging-friendly native Python types.
- Return type:
tuple[Tensor, dict | None]
- get_optim_params() list[Parameter][source]
Returns the policy-specific parameters dict to be passed on to the optimizer.
- Returns:
A dictionary of parameters to optimize.
- Return type:
dict
- name: None = 'cosmos3'
The name of the policy. Must be defined in subclasses.
- prepare_multimodal_inputs(batch: dict[str, Tensor]) dict[str, Tensor][source]
Build Qwen3-VL
input_ids/attention_mask/pixel_values/image_grid_thw.Resizes every present camera image to
image_resizeand runs the Qwen3-VL chat template + processor so the language prompt is interleaved with the image tokens.
- prepare_state(batch: dict[str, Tensor]) Tensor[source]
Return the proprioceptive state padded to
max_state_dim(zeros if absent).
- reset() None[source]
Resets the policy state.
This method should be called whenever the environment is reset. It handles tasks like clearing caches or resetting internal states for stateful policies.
- sample_actions(batch: dict[str, Tensor], action_prefix: Tensor | None = None, delay: Tensor | None = None, noise: Tensor | None = None) Tensor[source]
- select_action(batch: dict[str, Tensor], noise: Tensor | None = None) Tensor[source]
Selects an action based on the input batch.
This method handles action selection during inference, including caching for stateful policies (e.g. RNNs, Transformers).
- Parameters:
batch – A dictionary of observation tensors.
- Returns:
The selected action(s).
- Return type:
Tensor
- supports_torch_compile: bool = False
Whether
maybe_compile_for_training()may compile this policy’sself.model. DefaultFalse: opt-in per policy, because the in-placenn.Module.compileonly takes effect if the policy’s trainingforwardinvokes the submodule viaself.model(...)(__call__) rather thanself.model.forward(...). Subclasses whose forward has been switched toself.model(...)(currentlyPI05PolicyandPI07LowLevelPolicy) set thisTrue. Leaving itFalsemakesuse_torch_compile=Truea loud no-op on unwired policies instead of a silent compile-but-never-dispatch.
- opentau.policies.cosmos3.modeling_cosmos3.create_sinusoidal_pos_embedding(time: Tensor, dimension: int, min_period: float, max_period: float, device: device | str = 'cpu') Tensor[source]
Sine-cosine positional embedding for scalar positions
timeof shape (B, N).Returns (B, N, dimension). Mirrors the helper in
pi05/modeling_pi05.py.
- opentau.policies.cosmos3.modeling_cosmos3.make_att_2d_masks(pad_masks: Tensor, att_masks: Tensor, n_cross_att_tokens: int | None = None, cross_att_pad_masks: Tensor | None = None) Tensor[source]
Build a 2-D attention mask from 1-D pad + block masks (π0.5 convention).
pad_masksbool (B, N): True = real token.att_masksint (B, N): 1 opens a new causal block, 0 shares the previous token’s block. Returns (B, N, N) or, whenn_cross_att_tokensis given, (B, N, n_cross + N) with full cross-attention to the (valid) prefix prepended. Mirrorspi05/modeling_pi05.py::make_att_2d_masks.