Skip to main content
Cosmos3 Policy DROID serves NVIDIA’s policy as a Reactor model. This page explains how the cookbook model is built: what each file does, how the model loads, and what happens in each prediction step. Deploy Cosmos3 Policy DROID deploys these files unchanged. The code on this page is simplified to show how the model works. The full files add logging, metrics, and input validation.

Files

The model has 2 classes. The runtime drives the model class, and the model class calls the policy class, which runs the weights. This is the split that Model Structure describes.
  • cosmos3_policy_droid_types.py declares the contract: the 3 video tracks, the commands, and the message.
  • cosmos3_policy_droid.py holds the model class, Cosmos3PolicyDroid. It decides when to predict and sends each chunk.
  • cosmos3_policy_droid_model.py holds the policy class, Cosmos3PolicyModel. It is plain Python with no Reactor imports. It loads the weights and predicts 1 chunk at a time.
  • cosmos3_policy_droid_assets.py clones the NVIDIA source and downloads the checkpoint.
  • cosmos3_policy_droid.yaml sets the checkpoint, the NVIDIA source revision, and the sampler settings.
The 2 classes exchange 2 dataclasses: PolicyInput goes to the policy, and PolicyResult comes back.

Contract

The contract is everything a client can send or receive:
cosmos3_policy_droid_types.py (simplified)
  • Video tracks: PolicyMedia declares the 3 inbound tracks. The attribute names are the track names that the client publishes on.
  • Commands: each InputField on PolicyState creates a command named set_<field>. For example, set_task_description writes task_description. The runtime checks max_length before the model reads the value. moderate=True asks the deployment to moderate the task text.
  • Counters: _last_executed and _predicted track the prediction loop. Fields that start with _ create no command, the client cannot see them, and they reset when a session ends.
  • Message: ActionPrediction is the action_prediction message. It holds the (32, 8) action array and the chunk number.
The model class also declares the reset command with @event.

Loading

The runtime calls load() once per process, before the first session:
cosmos3_policy_droid.py (simplified)
config_path is cosmos3_policy_droid.yaml, set by runtime.config in reactor.yaml. get_weights_path() returns the folder that holds the NVIDIA source and the weights, set by runtime.weights_path. Cosmos3PolicyModel.load() then does 4 things:
  1. Reads cosmos3_policy_droid.yaml.
  2. Clones the NVIDIA source at the pinned revision, if it is not in the weights folder.
  3. Builds NVIDIA’s policy service, which downloads the checkpoint and tokenizer into the weights folder.
  4. Runs 2 warmup predictions, so the first compilation, about 20 seconds, happens before the first session.

Prediction step

The runtime runs the model in a loop of steps. Each step calls 3 methods in order:
Each step calls three methods in order. process_input() checks the inputs and returns a PolicyInput, or skips the step when an input is missing. generate() passes the PolicyInput to the policy, which returns a PolicyResult. process_output() sends the chunk to the client as action_prediction.
The step loop explains this loop for every model.

Check the inputs

process_input() decides whether the model can predict now. It raises ApplicationError when an input is missing. The runtime then skips the step without calling generate(), and calls process_input() again on the next step:
cosmos3_policy_droid.py (simplified)
The full process_input() has the real logic for each check. The checks run in this order:
  1. Executed step: after the first chunk, executed_step_json must hold a step greater than the last one accepted. When it does, the model asks for a new frame from each camera.
  2. Camera frames: each of the 3 tracks must deliver a new frame. A new frame arrives after the executed step. If the executed step includes observation_time_us, a new frame is one captured at or after that time.
  3. Robot state: proprio_json must parse into rows of 7 joint values and 1 gripper value, all finite.
When all 3 checks pass, process_input() records the executed step and returns a PolicyInput. The first chunk skips the executed-step check.

Predict a chunk

Prediction crosses the 2 classes. The runtime calls generate() on the model class. That method hands the input to generate() on the policy class, which runs the weights:
cosmos3_policy_droid.py (simplified)
cosmos3_policy_droid_model.py (simplified)
The policy class maps the input to the observation names that the DROID checkpoint uses. Then it calls NVIDIA’s policy service, which returns a (32, 8) action array. The policy keeps nothing between predictions. Each chunk depends only on the frames, the robot state, and the task in its PolicyInput. The sampler settings, 4 steps with guidance 3.0, come from cosmos3_policy_droid.yaml.

Send the chunk

process_output() sends the result to the client:
cosmos3_policy_droid.py (simplified)
An error from generate() is a GPU or checkpoint failure. process_output() raises it again, and the runtime ends the session with an error that the client sees.

Sessions and reset

  • Session start: @session_started clears the stored frames and asks for a new frame from each camera.
  • Session end: @session_ended clears the frames and calls Cosmos3PolicyModel.reset(). The policy keeps no state, so its reset is empty. The counters reset with the rest of the state.
  • reset command: sets the counters back, so the next chunk is step 0 and needs no executed step.