Skip to content

Commit 80df5e0

Browse files
committed
added quantization, direct conversion and evaluation script to lerobot act
1 parent e83e59a commit 80df5e0

File tree

4 files changed

+1649
-62
lines changed

4 files changed

+1649
-62
lines changed

notebooks/lerobot_act/README.md

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# ACT Policy → OpenVINO IR Conversion (Notebook Guide)
2-
32
This README documents the current workflow implemented in `act_to_openvino.ipynb` for converting a LeRobot ACT (Action Chunking Transformer) PyTorch checkpoint into an OpenVINO IR (XML/BIN) model. The notebook presently performs FP32 export (Model Optimizer invoked with FP16 compression flag but output standardized to `act_model_fp32.xml/bin`).
43

54

@@ -10,13 +9,17 @@ Place these next to the notebook:
109
* `train_config.json` – optional (reproducibility record)
1110
* `stats.json` – optional normalization statistics
1211

12+
## Required dataset Files (`dataset/G1_BlockStacking_Dataset/`)
13+
Download the G1_BlockStacking_Dataset from hugging face:
14+
https://huggingface.co/datasets/unitreerobotics/G1_Dex3_BlockStacking_Dataset
15+
16+
1317
## Minimal Installation & Launch
1418
Recommended (Conda environment):
1519
```bash
20+
bash setup_unitree_lerobot_env.sh
1621
conda create -n unitree_lerobot python=3.10 -y
1722
conda activate unitree_lerobot
18-
# Optional helper script if present in this folder
19-
bash setup_unitree_lerobot_env.sh
2023
# Launch notebook with correct kernel
2124
jupyter lab act_to_openvino.ipynb --NotebookApp.kernel_name=unitree_lerobot
2225
```
@@ -49,16 +52,75 @@ Artifacts are copied / renamed to:
4952
* `act_model_fp32.xml`
5053
* `act_model_fp32.bin`
5154

52-
## Directory Layout After Successful Conversion
55+
## Direct PyTorch FX Conversion
56+
Instead of exporting full temporal tensors via ONNX you can generate a smaller IR directly from PyTorch using OpenVINO's FX path. The wrapper internally creates placeholder temporal inputs (`action`, `action_is_pad`, history) so the IR exposes only observation features:
57+
* `observation_state`
58+
* `observation_images_0..N` (one input per camera)
59+
60+
Resulting files:
61+
* `act_model_direct_fp32.xml/bin`
62+
* `act_model_direct_fp16.xml/bin`
63+
64+
## INT8 Quantization (NNCF)
65+
You can produce an INT8 version for reduced size / latency using NNCF post‑training quantization.
66+
67+
Prerequisites:
68+
* Direct FP32 IR: `act_model_direct_fp32.xml`
69+
* Representative dataset root (`ACT_DATASET_ROOT`) with episodes
70+
* Normalization stats: `stats.json`
71+
72+
Generated files:
73+
* `openvino_ir_outputs/int8/model_int8.xml/bin`
74+
75+
Tips:
76+
* Increase calibration samples for better accuracy.
77+
* Use `preset='accuracy'` if performance preset degrades results too much.
78+
* Ensure OpenVINO and NNCF versions are compatible (>= 2025.0.0 for OpenVINO runtime if using latest NNCF).
79+
80+
81+
## Evaluation of Variants
82+
The notebook / helper script can compare PyTorch baseline vs IR variants (Direct FP32, FP16, MO FP32, INT8).
83+
84+
Environment variables (set before running evaluation cell):
85+
| Var | Purpose |
86+
|-----|---------|
87+
| `OPENVINO_MODEL_PATH` | Path to IR `.xml` file to evaluate |
88+
| `STATS_PATH` | Path to `stats.json` for normalization |
89+
| `OPENVINO_DEVICE` | `CPU|GPU|NPU|AUTO` (compile target) |
90+
| `OPENVINO_PRECISION_HINT` | Optional override (`FP32|FP16|INT8`) |
91+
92+
93+
Evaluation pipeline steps:
94+
1. Load PyTorch ACT and normalization stats.
95+
2. Compile OpenVINO model.
96+
3. Run action predictions over dataset episodes.
97+
4. Apply optional temporal smoothing ensemble.
98+
5. Plot per‑joint trajectories & error statistics (saved as `actions_comparison_<variant>.png`).
99+
100+
101+
## Directory Layout (Example After Conversion, FP16 & INT8 Quantization)
53102
```
54103
act_to_openvino.ipynb
55104
act_checkpoint/
56105
model.safetensors
57106
config.json
58107
train_config.json
59-
stats.json (optional)
108+
stats.json # normalization (recommended, required for eval & INT8)
109+
dataset/
110+
G1_BlockStacking_Dataset/
60111
openvino_ir_outputs/
61-
model.onnx
62-
act_model_fp32.xml
112+
model.onnx # ONNX baseline export
113+
act_model_fp32.xml # MO baseline IR (full inputs)
63114
act_model_fp32.bin
115+
act_model_direct_fp32.xml # Direct minimal-input IR
116+
act_model_direct_fp32.bin
117+
int8/
118+
model_int8.xml # Post-training quantized INT8 IR
119+
model_int8.bin
120+
121+
figure_actions_comparison_direct_fp32.png
122+
figure_actions_comparison_direct_fp16.png
123+
figure_actions_comparison_mo_fp32.png
124+
figure_actions_comparison_int8.png
125+
64126
```

0 commit comments

Comments
 (0)