Phase 5: Train an ACT policy

Next you train an ACT (Action Chunking with Transformers) policy on your dataset of reviewed demonstrations. You submit one custom training job, wait for it to finish, and check that the model learned something. That gets you the first milestone: a trained xarm-stacking model in your registry.

What the training script does

The training script, viam-labs:lerobot-training, comes from the Viam registry, and the job runs it against your dataset. It trains any LeRobot policy, and this workshop uses ACT. For each job, the script:

  1. Checks that every component you name appears in the dataset.
  2. Copies the images from your organization’s data storage to local disk.
  3. Converts the dataset to a LeRobot dataset. Each frame pairs one image from each camera with the arm and gripper readings nearest in time. The gripper reading is scaled so that 0 is open and 1 is closed.
  4. Holds out 10 percent of the episodes for evaluation.
  5. Trains the policy with lerobot-train, and measures the loss on the held-out episodes every 1,000 steps.
  6. Packages the checkpoint with the lowest evaluation loss, plus model_metrics.json and train_metadata.json.

For how custom training works in general, see Custom training scripts.

Register the training container

A training job runs its script inside a container image, here a public image with LeRobot pinned to commit 02655292c, the same LeRobot version the viam-labs:vla module runs in Phase 6, so the model you train here loads there unchanged. An organization can only use a custom container after it registers it, once. Registering takes the Viam CLI, logged in with viam login.

  1. Register the image in your organization:

    viam train containers register --org-id=<org-id> \
      --uri=docker.io/hipsterbrown/viam-lerobot-training:0.1.0-2 \
      --description="LeRobot 02655292c training"
    
  2. Copy the container ID from the output. The CLI path below needs it.

If someone in your organization already registered it, skip this step. viam train containers list --org-id=<org-id> lists the registered containers and their IDs.

Checkpoint

viam train containers list --org-id=<org-id> lists a container described as LeRobot 02655292c training.

Choose the training arguments

The script takes its settings as key and value arguments, the same ones whether you submit the job in the Viam app or with the CLI. Each value depends on choices you made in earlier phases, so the table says where it comes from.

ArgumentValueWhy
armxarmThe arm whose joint positions become the policy’s state and its actions. The controller in Phase 6 drives this same arm.
grippersxarm-gripperAdds the jaw to the state and actions, so the policy learns when to grasp and when to let go. Without it, the policy can move the arm but never close the gripper.
gripper_keyposThe xArm gripper answers the captured {"get": true} with {"pos": <position>}. The script looks for position by default, so it needs the real key.
gripper_open850Teleop commands the jaw from 0 to gripper_range, 850, set in Phase 2, so every recorded reading is between 0 and 850. The script rescales readings to 0 for open and 1 for closed, the scale the controller feeds the policy, so both ends of the range are needed.
gripper_closed0The other end of the same range. On a block the jaw stops partway closed, which still falls inside it. Phase 6’s controller uses these same two numbers.
cameras"'scene-cam wrist-cam'"The two image features the policy sees. The first camera sets the frame clock: each frame is built around its image, with the other readings nearest in time. The value has a space, so it needs its own quotes.
policyactACT trains from scratch in under an hour on one task, and its evaluation loss tracks how good its actions are, so the script can package the best checkpoint. It ignores the task text, which is fine for one task. act is the default, so this only makes the choice visible.
steps20000The most steps the job runs. Without it, LeRobot trains for 100,000 steps, several hours for this dataset. With early_stop_patience, the job usually stops well before 20,000.
early_stop_patience3Stops the job after three evaluations in a row, 3,000 steps, without a lower evaluation loss. Once the evaluation loss stops falling, more steps on the same demonstrations don’t help, and the script packages the best checkpoint either way.
batch_size32How many frames each GPU trains on per step. ACT’s default is 8. A larger batch averages each update over more frames, which gives smoother updates on a small dataset, and it fills the GPU better. The batch is per GPU, so on a two-GPU job each step sees 64 frames.
state_noise_std0.2Adds random noise to the joint state during training, so the policy can’t rely on the joint readings alone to know where it is in the task. It has to look at the cameras, which is what tells it where the blocks are. Without it, a policy tends to replay a memorized path and miss a block that’s somewhere new.
extra"'--policy.chunk_size 20 --policy.n_action_steps 20 --policy.optimizer_lr 4e-5'"Raw lerobot-train flags. The first two shorten ACT’s action chunk to 2 seconds. The third raises the learning rate to match the larger batch. See below.

ACT predicts a chunk of future actions at once, 100 by default. At 10 Hz, that’s 10 seconds of motion, and in Phase 6 the controller runs nearly a whole chunk before it looks at the cameras again. A chunk of 20 actions is 2 seconds, so the arm reacts to what it sees every couple of seconds.

ACT’s default learning rate, 1e-5, is tuned for its default batch of 8. With four times the batch, each update is less noisy, so the policy can take larger steps: 4e-5 scales the rate with the batch. The flag sets the rate for every part of the policy except the pretrained image backbone. The backbone keeps its own, lower rate, so the larger rate doesn’t undo what it already knows about images.

The fps argument defaults to 10, the rate you captured at in Phase 3. If your gripper reports a different key or range, read a gripper DoCommand response with {"get": true} while the gripper is open, then closed, and use those values here and in Phase 6. Without gripper_open and gripper_closed, the script trains on the raw readings, and the controller can’t match them.

The script has more optional arguments, listed in its README.

Submit the job in the Viam app

The app suits a one-off job: you fill in a form, and it names the model version for you.

  1. Go to your DATASETS and select xarm-stacking-v1.
  2. Click Train model.
  3. Select Train on a custom training script and follow the prompts. Name the model xarm-stacking when asked.
  4. Choose viam-labs:lerobot-training as the training script, at its latest version. It’s published with the Robot policy task type, so your model shows up as a robot policy. As the container, choose the one you registered, LeRobot 02655292c training.
  5. In the Arguments section, click Add argument for each key and value in the table in Choose the training arguments. In the app, wrap a value that has a space in single quotes only, for example 'scene-cam wrist-cam'.
  6. Submit the job.
The Arguments section of the Train a model form, with name and value rows for arm, grippers, gripper_key, gripper_open, gripper_closed, cameras, policy, steps, and extra.

The screenshot shows an earlier job’s arguments. Add early_stop_patience, batch_size, and state_noise_std too, and the full extra value from the table.

The Train a model form for the xarm-stacking-v1 dataset, with the lerobot-training script, version 0.2.1, the Robot policy task type, and the LeRobot 02655292c training container selected.

The app names the model version after the time you submit, for example 2026-12-02T18-32-33. Note it, because Phase 6 deploys that version.

Submit the job with the CLI

The CLI suits a job you’ll repeat, such as a retrain in Phase 7: the whole job is one command you can edit and run again. You need the dataset ID from Phase 4, your organization ID, and the container ID from Register the training container.

  1. Submit the job:

    viam train submit custom from-registry --dataset-id=<dataset-id> \
      --org-id=<org-id> --model-name=xarm-stacking \
      --model-version=1 --version=0.2.1 \
      --script-name=viam-labs:lerobot-training \
      --container-id=<container-id> \
      --args=arm=xarm,grippers=xarm-gripper,gripper_key=pos,gripper_open=850,gripper_closed=0,cameras="'scene-cam wrist-cam'",policy=act,steps=20000,early_stop_patience=3,batch_size=32,state_noise_std=0.2,extra="'--policy.chunk_size 20 --policy.n_action_steps 20 --policy.optimizer_lr 4e-5'"
    
  2. Copy the job ID from the output.

The flags that aren’t the script’s arguments:

  • --script-name and --version pick the training script and its version, not the model’s. Pinning the version keeps a retrain on the same script.
  • --model-name and --model-version name what the job produces. Every --model-version must be new, so increase it for each retrain.
  • --container-id is the container you registered.
  • --args holds the arguments from the table, separated by commas. Viam splits --args on commas, so a value with a space needs its own quotes, as cameras and extra have. The script removes the inner quotes.
  • The CLI refuses an --args value that contains =, so extra gives each lerobot-train flag and its value separated by a space: --policy.chunk_size 20, not --policy.chunk_size=20.

The script rejects an argument it doesn’t know, so a typo fails the job right away instead of being ignored.

Watch it run

Find the job in the app, or use the job ID the CLI printed. In the Viam app, go to the DATA page, click the MODELS tab, and expand Active Training. Click a job ID to view its logs.

From the CLI, stream the logs:

viam train logs --job-id=<job-id>

The first lines say whether the job found a GPU. Then the script copies the images and converts the dataset, which takes a few minutes. After that, it logs the training loss every 100 steps and the evaluation loss every 1,000 steps.

For more on job status and logs, see Monitor and debug.

Take a break

The job takes about 45 to 60 minutes. On the reference cell, it stopped early at step 10,000, about 50 minutes after it was submitted. You don’t need to watch it: Viam emails you when it succeeds or fails. While you wait, read Phase 6 to see how you deploy the model.

Read the loss charts

When the job finishes, open it from the MODELS tab. The job page charts the metrics from model_metrics.json. Two of them matter:

A completed training job page showing the xarm-stacking model, the xarm-stacking-v1 dataset, the lerobot-training script version 0.2.1, and the final log lines.
  • loss is the training loss, on the episodes the policy trained on.
  • eval_loss is the same loss on the 10 percent of episodes the policy never trained on.

A healthy run looks like this:

  • Both curves fall, then flatten. The policy learned what it could from the data.
  • eval_loss flattens a little above loss. If eval_loss turns back up while loss keeps falling, the policy is memorizing its training episodes. The packaged checkpoint is the one from before the rise, so the model is still usable.
  • With early_stop_patience, the run ends a few thousand steps after eval_loss flattens. On the reference cell, eval_loss settled near 0.19 by step 4,000, reached its lowest at step 7,000, and the job stopped at step 10,000.
  • A loss that’s flat from the start means a data problem. Check that the dataset holds enough sequences, and that the gripper value changes across an episode.

train_metadata.json, in the model version’s files, records which step was packaged, the final losses, and how many episodes and frames were used.

Checkpoint

The job shows Completed, and your registry has a new xarm-stacking model version.

If the job fails

The script checks its inputs and stops with a clear message. The common failures:

  • Components not found in the export. A name in arm, grippers, or cameras doesn’t match any component in the dataset. The message lists the components the dataset has. Fix the argument and submit again with a new --model-version.
  • No numeric pos in the gripper’s DoCommand output. gripper_key doesn’t match the field the gripper returns. Send {"get": true} to the gripper from its DoCommand test panel, find the numeric field in the response, and submit again with that key and a new --model-version.
  • No convertible episodes. The converter skipped every sequence. The usual causes are missing camera images or sequences without a task: tag. Check that each sequence in the dataset has camera frames and a task: tag from Phase 3.
  • No GPU available. The job logs a warning and trains on the CPU, which is far too slow. Cancel it, check that you chose the training container, and submit again.