Skip to content

Add LeRobot ACT - #38

Open
ravediamond wants to merge 5 commits into
VinRobotics:mainfrom
ravediamond:feat/act
Open

ravediamond wants to merge 5 commits into
VinRobotics:mainfrom
ravediamond:feat/act

Conversation

@ravediamond

Copy link
Copy Markdown
Contributor

Adds LeRobot's ACT policy, as discussed in #37.

scripts/convert_act_to_gguf.py converts a LeRobot pretrained_model directory. It folds the ResNet's frozen batch norms into the convs, drops the VAE encoder (the latent is zero at inference) and stores the normalizer stats, so predict() takes raw state and pixels and returns actions in robot units. Older checkpoints that keep the stats in model.safetensors work too. Camera count, image size, state and action widths all come from the checkpoint config.

src/models/act.cpp runs the ResNet on each view at the camera's own size (the graph is cached per size), then the encoder and decoder. It prints the camera order at load, since views have to arrive in training order.

A few small changes outside the model: vla-server accepts a request with no language tokens when the model takes none (ACT reports n_lang 0), vla-bench --height and VLA_IMG_H in vla_predict_check allow non square inputs like 640x480, and there is a converter remap test.

Checked with vla_predict_check against LeRobot's PyTorch ACTPolicy on the same synthetic inputs, at 640x480, on lerobot/act_aloha_sim_transfer_cube_human (1 camera, 14 dims) and on my SO-101 checkpoint (2 cameras, 6 dims). For SO-101 the reference goes through LeRobot's own pre and post processors.

aloha max abs error SO-101 max abs error
CPU 1.9e-7 3.4e-5
CUDA (Orin NX) 2.4e-4 0.024
Metal (M series) 2.1e-4 0.021

Aloha actions span about 1.4 and SO-101 about 100 (degrees), so the GPU differences are matmul precision, the CPU build matches to float precision.

Speed on the Orin NX 16 GB (MAXN_SUPER), 2 cameras at 640x480, 100 action chunk:

min ms
vla.cpp, defaults 82.3
vla.cpp, --flash-attn 72.4
vla.cpp, --weight-dtype f16 --flash-attn 69.8
PyTorch ACTPolicy (CUDA, same board) 57.0

So on a Jetson it is slower than PyTorch for now. Most of the time goes to im2col in the ResNet convs (cuDNN does better there), and I'd rather look at that in a follow up. The point here is running ACT without PyTorch, which matters most on CPU only boards.

I haven't run it on the real arm yet. The --arch act client change for the LeRobot fork is ready and I'll open it there.

@khanhnd61-vr

Copy link
Copy Markdown
Collaborator

Thanks for this, it's a clean port that already follows our model conventions closely. I checked it against LeRobot's PyTorch ACT on lerobot/act_aloha_sim_transfer_cube_human and a 2-camera SO-101 checkpoint at 640x480. Parity matches your numbers: CPU 4e-7 / 3e-5, CUDA 2.4e-4 / 0.016.

I pushed four commits on top:

  • ResNet on CUDA: on Turing or newer, the convs now run as ggml's direct convolution on F16 kernels. That's an implicit GEMM on tensor cores with no im2col buffer, which was the bottleneck you saw. CPU, older GPUs and the other backends keep your F32 im2col path, and so does --weight-dtype f32.
  • One pass for all cameras: the views go through the ResNet as one batch. The stem ReLU now runs after the max-pool, the encoder position table is uploaded once per image size, and the normalization eps is folded into the stds at load.
  • Shared code: your conv helper and Octo's identical one now live in src/layers/conv.h. preprocess_image_chw gained a non-square core (image_to_chw), which ACT uses. Its U8 path uses an exact lookup table, so host preprocessing drops from 0.83 to 0.21 ms per call and the output is bit-identical for the other models.
  • vla-cli: it had no act case and required --text/--tokens. It now runs ACT without an instruction.

RTX 3060, 640x480, min ms:

before after PyTorch
aloha, defaults 10.7 7.3 8.4
aloha, --weight-dtype f16 --flash-attn 9.6 5.8
SO-101 (2 cameras), defaults 22.0 13.9

CPU (i5-12400F) is unchanged at about 173 ms. About 18 ms of that is ggml's max-pool on the CPU backend, which runs on one thread; that's an upstream ggml fix.

Action items for you:

  1. Please re-run vla_predict_check and vla-bench on the Orin NX, which should take the new direct-conv path, and on Metal. Update the speed table in the PR description, since its GPU numbers are now out of date.
  2. Metal now runs multi-camera checkpoints through the batched graph. A parity re-check of your SO-101 checkpoint there would be good.
  3. Optional: once you publish a GGUF on the Hub, point the README row at it, like the other models.
  4. When the LeRobot-side --arch act client is up, link it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants