weichen010
/

weichen010 pepijn223 HF Staff commited on
Commit
196f755
·
0 Parent(s):

Duplicate from lerobot/pi0_base

Browse files

Co-authored-by: Pepijn Kooijmans <pepijn223@users.noreply.huggingface.co>

.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ library_name: lerobot
5
+ pipeline_tag: robotics
6
+ tags:
7
+ - vision-language-action
8
+ - imitation-learning
9
+ - lerobot
10
+ inference: false
11
+ license: gemma
12
+ ---
13
+
14
+ # π₀ (Pi0) (LeRobot)
15
+
16
+ π₀ is a Vision-Language-Action (VLA) foundation model from Physical Intelligence that jointly reasons over vision, language, and actions to control robots, serving as the base architecture that later enabled π₀.₅’s open-world generalization.
17
+
18
+
19
+ **Original paper:** π0: A Vision-Language-Action Flow Model for General Robot Controlion
20
+ **Reference implementation:** https://github.com/Physical-Intelligence/openpi
21
+ **LeRobot implementation:** Follows the original reference code for compatibility.
22
+
23
+
24
+ ## Model description
25
+
26
+ - **Inputs:** images (multi-view), proprio/state, optional language instruction
27
+ - **Outputs:** continuous actions
28
+ - **Training objective:** flow matching
29
+ - **Action representation:** continuous
30
+ - **Intended use:** Base model to fine tune on your specific use case
31
+
32
+
33
+ ## Quick start (inference on a real batch)
34
+
35
+ ### Installation
36
+
37
+ ```bash
38
+ pip install "lerobot[pi]@git+https://github.com/huggingface/lerobot.git"
39
+ ```
40
+ For full installation details (including optional video dependencies such as ffmpeg for torchcodec), see the official documentation: https://huggingface.co/docs/lerobot/installation
41
+
42
+ ### Load model + dataset, run `select_action`
43
+
44
+ ```python
45
+ import torch
46
+ from lerobot.datasets.lerobot_dataset import LeRobotDataset
47
+ from lerobot.policies.factory import make_pre_post_processors
48
+
49
+ # Swap this import per-policy
50
+ from lerobot.policies.pi0 import PI0Policy
51
+
52
+ # load a policy
53
+ model_id = "lerobot/pi0_base" # <- swap checkpoint
54
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
55
+
56
+ policy = PI0Policy.from_pretrained(model_id).to(device).eval()
57
+
58
+ preprocess, postprocess = make_pre_post_processors(
59
+ policy.config,
60
+ model_id,
61
+ preprocessor_overrides={"device_processor": {"device": str(device)}},
62
+ )
63
+ # load a lerobotdataset
64
+ dataset = LeRobotDataset("lerobot/libero")
65
+
66
+ # pick an episode
67
+ episode_index = 0
68
+
69
+ # each episode corresponds to a contiguous range of frame indices
70
+ from_idx = dataset.meta.episodes["dataset_from_index"][episode_index]
71
+ to_idx = dataset.meta.episodes["dataset_to_index"][episode_index]
72
+
73
+ # get a single frame from that episode (e.g. the first frame)
74
+ frame_index = from_idx
75
+ frame = dict(dataset[frame_index])
76
+
77
+ batch = preprocess(sample)
78
+ with torch.inference_mode():
79
+ pred_action = policy.select_action(frame)
80
+ # use your policy postprocess, this post process the action
81
+ # for instance unnormalize the actions, detokenize it etc..
82
+ pred_action = postprocess(pred_action)
83
+ ```
84
+
85
+
86
+ ## Training step (loss + backward)
87
+
88
+ If you’re training / fine-tuning, you typically call `forward(...)` to get a loss and then:
89
+
90
+ ```python
91
+ policy.train()
92
+ batch = dict(dataset[0])
93
+ batch = preprocess(batch)
94
+
95
+ loss, outputs = policy.forward(batch)
96
+ loss.backward()
97
+
98
+ ```
99
+
100
+ > Notes:
101
+ >
102
+ > - Some policies expose `policy(**batch)` or return a dict; keep this snippet aligned with the policy API.
103
+ > - Use your trainer script (`lerobot-train`) for full training loops.
104
+
105
+
106
+ ## How to train / fine-tune
107
+
108
+ ```bash
109
+ lerobot-train \
110
+ --dataset.repo_id=${HF_USER}/<dataset> \
111
+ --output_dir=./outputs/[RUN_NAME] \
112
+ --job_name=[RUN_NAME] \
113
+ --policy.repo_id=${HF_USER}/<desired_policy_repo_id> \
114
+ --policy.path=lerobot/[BASE_CHECKPOINT] \
115
+ --policy.dtype=bfloat16 \
116
+ --policy.device=cuda \
117
+ --steps=100000 \
118
+ --batch_size=4
119
+ ```
120
+
121
+ Add policy-specific flags below:
122
+
123
+ - `-policy.chunk_size=...`
124
+ - `-policy.n_action_steps=...`
125
+ - `-policy.max_action_tokens=...`
126
+ - `-policy.gradient_checkpointing=true`
127
+
128
+
129
+ ## Real-World Inference & Evaluation
130
+
131
+ You can use the `record` script from [**`lerobot-record`**](https://github.com/huggingface/lerobot/blob/main/src/lerobot/scripts/lerobot_record.py) with a policy checkpoint as input, to run inference and evaluate your policy.
132
+
133
+ For instance, run this command or API example to run inference and record 10 evaluation episodes:
134
+
135
+ ```
136
+ lerobot-record \
137
+ --robot.type=so100_follower \
138
+ --robot.port=/dev/ttyACM1 \
139
+ --robot.cameras="{ up: {type: opencv, index_or_path: /dev/video10, width: 640, height: 480, fps: 30}, side: {type: intelrealsense, serial_number_or_name: 233522074606, width: 640, height: 480, fps: 30}}" \
140
+ --robot.id=my_awesome_follower_arm \
141
+ --display_data=false \
142
+ --dataset.repo_id=${HF_USER}/eval_so100 \
143
+ --dataset.single_task="Put lego brick into the transparent box" \
144
+ # <- Teleop optional if you want to teleoperate in between episodes \
145
+ # --teleop.type=so100_leader \
146
+ # --teleop.port=/dev/ttyACM0 \
147
+ # --teleop.id=my_awesome_leader_arm \
148
+ --policy.path=${HF_USER}/my_policy
149
+ ```
config.json ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "type": "pi0",
3
+ "n_obs_steps": 1,
4
+ "input_features": {
5
+ "observation.images.base_0_rgb": {
6
+ "type": "VISUAL",
7
+ "shape": [
8
+ 3,
9
+ 224,
10
+ 224
11
+ ]
12
+ },
13
+ "observation.images.left_wrist_0_rgb": {
14
+ "type": "VISUAL",
15
+ "shape": [
16
+ 3,
17
+ 224,
18
+ 224
19
+ ]
20
+ },
21
+ "observation.images.right_wrist_0_rgb": {
22
+ "type": "VISUAL",
23
+ "shape": [
24
+ 3,
25
+ 224,
26
+ 224
27
+ ]
28
+ },
29
+ "observation.state": {
30
+ "type": "STATE",
31
+ "shape": [
32
+ 32
33
+ ]
34
+ }
35
+ },
36
+ "output_features": {
37
+ "action": {
38
+ "type": "ACTION",
39
+ "shape": [
40
+ 32
41
+ ]
42
+ }
43
+ },
44
+ "device": "cuda",
45
+ "use_amp": false,
46
+ "push_to_hub": true,
47
+ "repo_id": null,
48
+ "private": null,
49
+ "tags": null,
50
+ "license": null,
51
+ "paligemma_variant": "gemma_2b",
52
+ "action_expert_variant": "gemma_300m",
53
+ "dtype": "float32",
54
+ "chunk_size": 50,
55
+ "n_action_steps": 50,
56
+ "max_action_dim": 32,
57
+ "max_state_dim": 32,
58
+ "num_inference_steps": 10,
59
+ "time_sampling_beta_alpha": 1.5,
60
+ "time_sampling_beta_beta": 1.0,
61
+ "min_period": 0.004,
62
+ "max_period": 4.0,
63
+ "image_resolution": [
64
+ 224,
65
+ 224
66
+ ],
67
+ "gradient_checkpointing": false,
68
+ "compile_model": false,
69
+ "compile_mode": "max-autotune",
70
+ "optimizer_lr": 2.5e-05,
71
+ "optimizer_betas": [
72
+ 0.9,
73
+ 0.95
74
+ ],
75
+ "optimizer_eps": 1e-08,
76
+ "optimizer_weight_decay": 0.01,
77
+ "optimizer_grad_clip_norm": 1.0,
78
+ "scheduler_warmup_steps": 1000,
79
+ "scheduler_decay_steps": 30000,
80
+ "scheduler_decay_lr": 2.5e-06,
81
+ "tokenizer_max_length": 48
82
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8229fd9a7c3c2aafc1e223567b61b5fe3e25eef873bb4233928dbee4bd836303
3
+ size 14005618584
policy_postprocessor.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "policy_postprocessor",
3
+ "steps": [
4
+ {
5
+ "registry_name": "unnormalizer_processor",
6
+ "config": {
7
+ "eps": 1e-08,
8
+ "features": {},
9
+ "norm_map": {
10
+ "VISUAL": "IDENTITY",
11
+ "STATE": "MEAN_STD",
12
+ "ACTION": "MEAN_STD"
13
+ }
14
+ }
15
+ },
16
+ {
17
+ "registry_name": "absolute_actions_processor",
18
+ "config": {
19
+ "enabled": false
20
+ }
21
+ },
22
+ {
23
+ "registry_name": "device_processor",
24
+ "config": {
25
+ "device": "cpu",
26
+ "float_dtype": null
27
+ }
28
+ }
29
+ ]
30
+ }
policy_preprocessor.json ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "policy_preprocessor",
3
+ "steps": [
4
+ {
5
+ "registry_name": "rename_observations_processor",
6
+ "config": {
7
+ "rename_map": {}
8
+ }
9
+ },
10
+ {
11
+ "registry_name": "to_batch_processor",
12
+ "config": {}
13
+ },
14
+ {
15
+ "registry_name": "pi0_new_line_processor",
16
+ "config": {}
17
+ },
18
+ {
19
+ "registry_name": "tokenizer_processor",
20
+ "config": {
21
+ "max_length": 48,
22
+ "task_key": "task",
23
+ "padding_side": "right",
24
+ "padding": "max_length",
25
+ "truncation": true,
26
+ "tokenizer_name": "google/paligemma-3b-pt-224"
27
+ }
28
+ },
29
+ {
30
+ "registry_name": "device_processor",
31
+ "config": {
32
+ "device": "cuda",
33
+ "float_dtype": null
34
+ }
35
+ },
36
+ {
37
+ "registry_name": "relative_actions_processor",
38
+ "config": {
39
+ "enabled": false,
40
+ "exclude_joints": [
41
+ "gripper"
42
+ ],
43
+ "action_names": null
44
+ }
45
+ },
46
+ {
47
+ "registry_name": "normalizer_processor",
48
+ "config": {
49
+ "eps": 1e-08,
50
+ "features": {},
51
+ "norm_map": {
52
+ "VISUAL": "IDENTITY",
53
+ "STATE": "MEAN_STD",
54
+ "ACTION": "MEAN_STD"
55
+ }
56
+ }
57
+ }
58
+ ]
59
+ }