A Source-Level Guide to VLA Robot Policies Based on openpi: Config, Architecture, and Training
This article provides a source-level walkthrough of Vision-Language-Action (VLA) robot policies, using the openpi codebase developed by Physical Intelligence as a concrete reference. It explains the two-layer configuration system (Pi0Config and TrainConfig), the overall model structure combining a vision encoder, a language backbone, and an action expert, and the flow-matching training objective used by the diffusion-style action head. It also covers the fast inference variant based on discrete action tokens, key implementation details of the underlying Gemma and SigLip modules, and a practical training checklist. The goal is to help readers build a clear mapping between configuration fields, module implementations, and the training pipeline.
1. Establish the Code Baseline
This article uses the openpi codebase from Physical Intelligence as a reference implementation. The library is released under the Apache-2.0 license. File names, class names, and commands mentioned here are based on the main branch at the time of writing. Because different commits may introduce changes, readers should verify against their own checked-out commit.
The main directory structure at the time of writing is as follows:
src/openpi/models/model.py # Input abstractions such as Observationpi0.py # Flow-matching (diffusion-style) action headpi0_config.py # Pi0Config model configuration classpi0_fast.py # Autoregressive discrete action variantgemma.py # Language backbonesiglip.py # Vision towertraining/config.py # TrainConfig and preset registryscripts/train.pycompute_norm_stats.pyserve_policy.py
Before reading the source code, record the current commit with git log -1 and note it in your experiment log. This makes it possible to later attribute behavioral differences to specific code versions.
2. Configuration System: From Pi0Config to TrainConfig
The codebase follows a configuration-driven design. Model hyperparameters, data sources, and training strategies are centralized in configuration classes, and a registry manages multiple presets.
Two layers of configuration exist:
- Model config (
Pi0Config, located inpi0_config.py): describes the model structure. - Training config (
TrainConfig, located intraining/config.py): describes a full training run. Itsmodelfield references the model config, and it additionally contains data configuration, weight loading, freezing strategy, and training steps.
The table below lists common fields and where they are consumed in the code. Field names reflect the version at the time of writing; readers should verify them with search tools.
| Field | Meaning | Consumption location (example) |
|---|---|---|
action_dim |
Action dimensionality; the model pads it to a fixed length internally | Projection layers for action input and output |
action_horizon |
Length of an action chunk predicted at once | Shape of denoising tensors; slicing of inference results |
max_token_len |
Maximum number of instruction tokens | Tokenization of observations; determines prefix length |
paligemma_variant |
Specification of the language and vision backbone | Instantiation in gemma.py and siglip.py |
action_expert_variant |
Specification of the action expert | Instantiation of the action expert module |
In TrainConfig, the freeze_filter field controls which parameters are frozen through regular-expression matching on parameter paths. For example, one can train only the action expert while freezing the vision and language backbones.
A practical suggestion: write down each field, then use full-text search to locate its usage. This quickly builds a mapping between configuration entries and the modules they affect.
3. Observation Object and Flow-Matching Action Head
3.1 Observation Object
Model inputs are encapsulated as an immutable observation object containing multiple image views, image masks, tokenized instruction sequences, and robot proprioceptive states (joint angles, gripper opening, etc.). This separation between data preprocessing and model forward logic allows the same model code to support different robot morphologies and data formats.
3.2 Overall Structure
The model consists of three parts:
- Vision encoder: encodes each image view into a set of visual tokens; multi-view outputs are concatenated along the sequence dimension.
- Language backbone: an approximately 2-billion-parameter open-source language model that fuses visual tokens with instruction tokens.
- Action expert: a separate set of attention layers running in parallel with the language backbone. It receives a noisy action sequence and iteratively denoises it to predict future actions over several steps.
The prefix formed by images and instructions only needs to be computed once, and its key-value cache can be reused. The multi-step denoising updates only the action tokens. This KV-cache sharing is valid only because the prefix does not change across denoising steps; if the prefix contained step-dependent content, the cache would be invalidated.
3.3 Flow-Matching Training Objective
During training, the model learns a velocity field pointing from noise toward real actions. The code below is provided to illustrate shapes and main steps; it is not directly executable.
# Pseudocode, not runnable. Shapes: batch B, action chunk length H, action dim Dnoise = jax.random.normal(rng, (B, H, D)) # (B, H, D)t = sample_t(rng_t, (B,)) # sampled from a Beta distribution in source; range (0, 1]t_b = t[:, None, None]x_t = t_b * noise + (1 - t_b) * actions # point on the interpolation path, (B, H, D)u_t = noise - actions # target velocity field, (B, H, D)v_pred = action_expert(x_t, t, prefix_kv_cache) # (B, H, D)loss = jnp.mean(jnp.square(v_pred - u_t)) # the actual implementation also masks padded dimensions
Refer to the source code for the exact Beta distribution parameters and time-step range.
3.4 Inference
Inference starts from pure noise and integrates along the predicted velocity field using Euler’s method for 10 steps.
# Pseudocode, not runnablex = jax.random.normal(rng, (B, H, D))num_steps = 10dt = -1.0 / num_stepst = 1.0for _ in range(num_steps):v = action_expert(x, t, prefix_kv_cache)x = x + dt * vt += dt# At the end, x is the action chunk; it must be denormalized using dataset statistics before execution
Actions are normalized before training, typically via quantile normalization based on dataset statistics. Inference outputs must be denormalized; otherwise the physical scale of the actions will be incorrect.
4. Fast Inference Variant: Discrete Actions
Multi-step denoising adds latency. In high-frequency control scenarios, this latency can become a bottleneck. The FAST variant converts continuous actions into discrete tokens and generates them autoregressively using the standard language modeling approach.
The implementation first applies a discrete cosine transform (DCT) to compress the action chunk, then uses BPE to split it into tokens. This is not residual quantization. The vocabulary size and special token definitions are specified in the configuration and tokenizer; refer to pi0_fast.py and the corresponding tokenization code.
When reading the FAST variant side by side with the diffusion version, the following differences are worth noting:
- Same: observation object, vision encoding, and configuration registry mechanism are identical.
- Different: the model config no longer contains denoising-related parameters; instead, it defines the action vocabulary and special tokens. The loss function changes from regression-based to cross-entropy.
Reading both variants side by side helps clarify the design: the backbone structure stays the same, and the action head is replaceable.
5. Underlying Backbone and JAX Programming Paradigm
The language model and vision tower implementations are located in gemma.py and siglip.py. Key points to examine include:
- Module definition: embedding layers, transformer blocks, normalization layers, and output heads are defined compositionally. Parameters are explicitly managed by the framework rather than attached to objects.
- Attention implementation: chunked or fused attention kernels are used to fit accelerator hardware. Training and inference versions may differ.
- Vision tower: a ViT-style structure with patch embedding, positional encoding, and stacked self-attention, producing patch-level features for cross-modal fusion.
The entire project is built on JAX, following the paradigm of pure functions, explicit random keys, and just-in-time compilation. Parameters are passed as explicit inputs. The training step is compiled into a static computation graph, and the first run incurs a long compilation time; this is expected behavior.
When modifying context length, switching attention implementations, or adjusting precision, first confirm the location and scope of the change before making the modification.
6. Practical Training Checklist
The following steps are adapted from the openpi README. Specific commands and parameters depend on the checked-out version.
- Environment: follow the README to install Python and the
uvpackage manager, and confirm that JAX can detect the GPU. - Data: set the data source in the
datafield ofTrainConfig.
