Skip to content
zhigenzhaoPublic

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

VQActFlow

Variational Flow Matching robot control policy implemented as a LeRobot plugin, with a contrastive feasibility critic for inference-time guidance. This is the minimal code release accompanying the paper, set up to reproduce the LIBERO-90 experiments.

Citation

This codebase is the companion code release for our paper. If you find it useful in your research, please cite:

@article{zhao2026vqactflow,
  title={VQActFlow: Vector-Quantized Action Mode Steering for Multi-Task Robot Manipulation},
  author={Zhao, Zhigen and Leggiero, Mark and Chen, Yipu and Liu, Haoran and Wu, Yifan and Xue, Huishu and Zhan, Sirui and Zhao, Ye},
  journal={arXiv preprint arXiv:2606.21600},
  year={2026}
}

VQVFM performs Variational Flow Matching over a VQVAE codebook (continuous ODE transport, categorical output). It is a two-stage policy: it requires a pre-trained VQVAE action tokenizer that discretizes continuous action sequences into codebook tokens. A standalone training policy is provided for this first stage.

VQVFM additionally supports inference-time physics guidance via a contrastive feasibility critic that steers the flow toward physically plausible code selections without retraining the VFM or VQVAE.

VQVFM also supports text-conditioned classifier-free guidance (CFG): a CLIP text encoder conditions the flow on language instructions, and CFG amplifies the text signal at inference time by interpolating between conditional and unconditional predictions. CFG is orthogonal to critic guidance and the two can be combined.

Installation

Clone the repo:

git clone https://github.com/zhigenzhao/VQActFlow.git
cd VQActFlow

System dependencies

Install FFmpeg (required by torchcodec for video decoding) and the matching Python development headers (required to build the evdev C extension pulled in by lerobot):

sudo apt install ffmpeg python3.xx-dev

Replace python3.xx-dev with the version matching your interpreter (e.g. python3.10-dev, python3.12-dev).

Python environment (venv)

python3.10 -m venv .venv
source .venv/bin/activate

# Install VFM Policy (includes lerobot as a dependency)
GIT_LFS_SKIP_SMUDGE=1 pip install -e .

# (Optional) Install with LIBERO simulation support
GIT_LFS_SKIP_SMUDGE=1 pip install -e ".[libero]"

Pretrained checkpoints

The LIBERO-90 checkpoints behind the VQActFlow rows of Table I in the paper are on the Hugging Face Hub:

Component Repository
VQVAE action tokenizer kelvinzhaozg/VQActFlow-LIBERO90-VQVAE
VQActFlow policy (VFM) kelvinzhaozg/VQActFlow-LIBERO90-Policy
Feasibility critic kelvinzhaozg/VQActFlow-LIBERO90-Critic

The policy references the VQVAE and the critic references both other repositories by Hub id, so no local paths need to be set. The training data is kelvinzhaozg/libero_90.

Reproducing Table I (LIBERO-90)

Each cell is 90 tasks × 20 episodes at evaluation seed 1000 (the lerobot default), with 128×128 observations:

CFG weight Critic weight λ Success rate (%)
1.0 0 72.3
1.0 1.0 74.3
2.0 0 77.6
2.0 1.0 80.5
# Without critic guidance (set --policy.cfg_guidance_weight to 1.0 or 2.0)
python scripts/eval.py \
  --policy.path=kelvinzhaozg/VQActFlow-LIBERO90-Policy \
  --policy.cfg_guidance_weight=2.0 \
  --env.type=libero --env.task=libero_90 \
  --env.observation_height=128 --env.observation_width=128 \
  --eval.n_episodes=20 --eval.batch_size=20 --rename_map='{}' \
  --output_dir=outputs/eval/vqactflow_libero_90_w2

# With critic guidance (λ = 1.0)
python scripts/eval.py \
  --policy.path=kelvinzhaozg/VQActFlow-LIBERO90-Policy \
  --policy.cfg_guidance_weight=2.0 \
  --policy.critic_repo_path=kelvinzhaozg/VQActFlow-LIBERO90-Critic \
  --policy.guidance_weight_max=1.0 \
  --env.type=libero --env.task=libero_90 \
  --env.observation_height=128 --env.observation_width=128 \
  --eval.n_episodes=20 --eval.batch_size=20 --rename_map='{}' \
  --output_dir=outputs/eval/vqactflow_libero_90_w2_critic

The training configs under config/libero_90/vqvfm_cfg/ match the released checkpoints. To train only a later stage, point it at the released earlier stage, e.g. --policy.vqvae_repo_path=kelvinzhaozg/VQActFlow-LIBERO90-VQVAE for Stage 2. For Stage 3, set both --policy.vqvae_repo_path and --policy.vfm_repo_path.

Training

Training runs through LeRobot's training entry point (Stage 3 through a thin wrapper, scripts/train_critic.py). Policies are registered as plugins and discovered via the --policy.discover_packages_path CLI argument.

Training configs for LIBERO-90 are under config/libero_90/vqvfm_cfg/. The full pipeline is three stages:

Stage 1 — Train the VQVAE action tokenizer

lerobot-train \
  --config_path=config/libero_90/vqvfm_cfg/train_vqvae.json \
  --policy.discover_packages_path=lerobot_policy_vqvae_action_tokenizer

This saves a VQVAE checkpoint under outputs/train/.../checkpoints/last/pretrained_model. The Stage 2 config already points to this local path via vqvae_repo_path.

Stage 2 — Train the flow matching policy (VFM)

lerobot-train \
  --config_path=config/libero_90/vqvfm_cfg/train_vfm.json \
  --policy.discover_packages_path=lerobot_policy_vqvfm

The config's vqvae_repo_path field points to the Stage 1 checkpoint produced locally. The Stage 3 config already points to the Stage 2 output via vfm_repo_path.

Stage 3 — Train the feasibility critic (optional)

An optional third stage trains a feasibility critic for inference-time guidance. The critic is trained contrastively on demonstrations using a frozen VQVAE and frozen VFM visual backbone.

python scripts/train_critic.py \
  --config_path=config/libero_90/vqvfm_cfg/train_critic.json

Use scripts/train_critic.py rather than plain lerobot-train for this stage. The config enables same-episode temporal negatives (temporal_neg_enabled), which need the dataset wrapper and batch-key patch that the script installs. Under plain lerobot-train those negatives are skipped without an error, and the resulting critic differs from the released one.

Text-conditioned VQVFM with classifier-free guidance (CFG)

VQVFM supports text-conditioned generation using a CLIP text encoder and classifier-free guidance. During training, language instructions are randomly dropped (controlled by cfg_drop_rate) so the model learns both conditional and unconditional predictions. At inference, CFG amplifies the text conditioning by extrapolating away from the unconditional prediction.

The vqvfm_cfg configs already wire up CFG — the same three-stage pipeline applies.

Key config fields for CFG:

  • cfg_drop_rate — Probability of dropping the text condition during training (default: 0.1)
  • cfg_guidance_weight — CFG scale at inference (default: 1.0 = no guidance; values > 1.0 amplify text conditioning)
  • clip_model_name — CLIP model for text encoding (default: openai/clip-vit-base-patch32)

Overriding config values

Any config field can be overridden from the CLI:

lerobot-train \
  --config_path=config/libero_90/vqvfm_cfg/train_vfm.json \
  --policy.discover_packages_path=lerobot_policy_vqvfm \
  --batch_size=128 \
  --policy.hidden_size=512 \
  --wandb.enable=false

LIBERO-90 Simulation

The LIBERO benchmark provides tabletop manipulation tasks with two cameras (agentview + wrist). Training and evaluation follows a three-step pipeline: dataset conversion, training, and evaluation.

1. Convert LIBERO-90 demos to LeRobot format

Download the LIBERO-90 task suite and convert the HDF5 demos:

python scripts/dataset/convert_libero_to_lerobot.py \
  --data_path=~/Downloads/libero_90 \
  --repo_id=<HF_USER>/libero_90 \
  --image_size 128 128

The native LIBERO HDF5 images are 128x128. The --image_size flag defaults to 128 128 and controls the resolution stored in the dataset.

2. Train

Follow the three-stage training workflow described above using configs under config/libero_90/vqvfm_cfg/.

3. Evaluate in simulation

Use the eval wrapper script, which pre-imports VFM policy plugins:

python scripts/eval.py \
  --policy.path=<CHECKPOINT_PATH> \
  --env.type=libero \
  --env.task=libero_90 \
  --env.observation_height=128 \
  --env.observation_width=128 \
  --eval.n_episodes=10 \
  --eval.batch_size=1

The --env.observation_height and --env.observation_width must match the image_size used during dataset conversion (default 128x128). A mismatch will cause shape errors in the SpatialSoftmax encoder.

Inference with CFG — Override cfg_guidance_weight at eval time:

python scripts/eval.py \
  --policy.path=<CFG_VFM_CHECKPOINT> \
  --policy.cfg_guidance_weight=3.0 \
  --env.type=libero \
  --env.task=libero_90 \
  --eval.n_episodes=10

Combined CFG + critic guidance — Use both at inference:

python scripts/eval.py \
  --policy.path=<CFG_VFM_CHECKPOINT> \
  --policy.cfg_guidance_weight=3.0 \
  --policy.critic_repo_path=<CRITIC_CHECKPOINT> \
  --policy.guidance_weight_max=1.0 \
  --env.type=libero --env.task=libero_90 --eval.n_episodes=10

When critic_repo_path is empty or guidance_weight_max is 0 (the defaults), the original unguided ODE solver path is used — fully backward compatible.

4. Sweep guidance weight (VQVFM with critic)

To find the optimal critic guidance strength, sweep across multiple guidance_weight_max values:

python scripts/sweep_guidance.py \
  --policy_path=<VFM_CHECKPOINT> \
  --critic_path=<CRITIC_CHECKPOINT> \
  --env_task=libero_90 \
  --weights 0.0 0.25 0.5 0.75 1.0 1.5 2.0 \
  --n_episodes=10 --batch_size=1 \
  --env.observation_height=128 --env.observation_width=128

The script runs scripts/eval.py for each weight, collects results, and produces:

  • A summary table printed to stdout with per-task success rates
  • summary.json with full per-weight breakdown
  • guidance_sweep.png line plot of success rate vs guidance weight

The sweep supports resuming — if a weight's eval_info.json already exists in the output directory, it is skipped. Use --output_dir to set a fixed output path for resumable runs. When weight=0.0, the critic is not loaded (unguided baseline). Any extra flags (e.g. --env.observation_height=128) are forwarded directly to eval.py.

5. Sweep CFG guidance weight (text-conditioned VQVFM)

To find the optimal classifier-free guidance scale for a text-conditioned VQVFM checkpoint:

python scripts/sweep_cfg_guidance.py \
  --policy_path=<CFG_VFM_CHECKPOINT> \
  --env_task=libero_90 \
  --weights 1.0 1.5 2.0 3.0 5.0 7.0 \
  --n_episodes=10 --batch_size=1 \
  --env.observation_height=128 --env.observation_width=128

Optionally combine with a fixed critic guidance weight for joint CFG + critic sweeps:

python scripts/sweep_cfg_guidance.py \
  --policy_path=<CFG_VFM_CHECKPOINT> \
  --critic_path=<CRITIC_CHECKPOINT> --critic_weight=1.0 \
  --env_task=libero_90 \
  --weights 1.0 2.0 3.0 5.0 \
  --n_episodes=10

The script produces the same outputs as the critic sweep: a summary table, summary.json, and cfg_guidance_sweep.png. It supports the same resume logic — existing results are skipped. The weight 1.0 serves as the no-guidance baseline.

6. Sweep posterior temperature

To sweep the posterior temperature parameter at inference:

python scripts/sweep_posterior_temperature.py \
  --policy_path=<VFM_CHECKPOINT> \
  --temperatures 0.5 0.7 0.9 1.0 1.2 1.5 \
  --env_task=libero_90 \
  --n_episodes=10 --batch_size=1 \
  --env.observation_height=128 --env.observation_width=128

Project Structure

src/
  vfm_shared/               # Shared modules: VQVAE, RgbEncoder, SpatialSoftmax, CodebookSpaceCritic
  lerobot_policy_vqvae_action_tokenizer/  # Stage 1: standalone VQVAE training
  lerobot_policy_vqvfm/     # Variational Flow Matching policy (with optional critic guidance)
  lerobot_policy_vqvfm_critic/  # Stage 3: contrastive feasibility critic training
config/
  libero_90/vqvfm_cfg/      # LIBERO-90 training configs (train_vqvae.json, train_vfm.json, train_critic.json)
scripts/
  eval.py                   # Evaluation wrapper
  sweep_guidance.py         # Sweep critic guidance weight
  sweep_cfg_guidance.py     # Sweep CFG guidance weight
  sweep_posterior_temperature.py  # Sweep posterior temperature

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages