opentau 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. opentau/__init__.py +179 -0
  2. opentau/__version__.py +24 -0
  3. opentau/configs/__init__.py +19 -0
  4. opentau/configs/default.py +297 -0
  5. opentau/configs/libero.py +113 -0
  6. opentau/configs/parser.py +393 -0
  7. opentau/configs/policies.py +297 -0
  8. opentau/configs/reward.py +42 -0
  9. opentau/configs/train.py +370 -0
  10. opentau/configs/types.py +76 -0
  11. opentau/constants.py +52 -0
  12. opentau/datasets/__init__.py +84 -0
  13. opentau/datasets/backward_compatibility.py +78 -0
  14. opentau/datasets/compute_stats.py +333 -0
  15. opentau/datasets/dataset_mixture.py +460 -0
  16. opentau/datasets/factory.py +232 -0
  17. opentau/datasets/grounding/__init__.py +67 -0
  18. opentau/datasets/grounding/base.py +154 -0
  19. opentau/datasets/grounding/clevr.py +110 -0
  20. opentau/datasets/grounding/cocoqa.py +130 -0
  21. opentau/datasets/grounding/dummy.py +101 -0
  22. opentau/datasets/grounding/pixmo.py +177 -0
  23. opentau/datasets/grounding/vsr.py +141 -0
  24. opentau/datasets/image_writer.py +304 -0
  25. opentau/datasets/lerobot_dataset.py +1910 -0
  26. opentau/datasets/online_buffer.py +442 -0
  27. opentau/datasets/push_dataset_to_hub/utils.py +132 -0
  28. opentau/datasets/sampler.py +99 -0
  29. opentau/datasets/standard_data_format_mapping.py +278 -0
  30. opentau/datasets/transforms.py +330 -0
  31. opentau/datasets/utils.py +1243 -0
  32. opentau/datasets/v2/batch_convert_dataset_v1_to_v2.py +887 -0
  33. opentau/datasets/v2/convert_dataset_v1_to_v2.py +829 -0
  34. opentau/datasets/v21/_remove_language_instruction.py +109 -0
  35. opentau/datasets/v21/batch_convert_dataset_v20_to_v21.py +60 -0
  36. opentau/datasets/v21/convert_dataset_v20_to_v21.py +183 -0
  37. opentau/datasets/v21/convert_stats.py +150 -0
  38. opentau/datasets/video_utils.py +597 -0
  39. opentau/envs/__init__.py +18 -0
  40. opentau/envs/configs.py +178 -0
  41. opentau/envs/factory.py +99 -0
  42. opentau/envs/libero.py +439 -0
  43. opentau/envs/utils.py +204 -0
  44. opentau/optim/__init__.py +16 -0
  45. opentau/optim/factory.py +43 -0
  46. opentau/optim/optimizers.py +121 -0
  47. opentau/optim/schedulers.py +140 -0
  48. opentau/planner/__init__.py +82 -0
  49. opentau/planner/high_level_planner.py +366 -0
  50. opentau/planner/utils/memory.py +64 -0
  51. opentau/planner/utils/utils.py +65 -0
  52. opentau/policies/__init__.py +24 -0
  53. opentau/policies/factory.py +172 -0
  54. opentau/policies/normalize.py +315 -0
  55. opentau/policies/pi0/__init__.py +19 -0
  56. opentau/policies/pi0/configuration_pi0.py +250 -0
  57. opentau/policies/pi0/modeling_pi0.py +994 -0
  58. opentau/policies/pi0/paligemma_with_expert.py +516 -0
  59. opentau/policies/pi05/__init__.py +20 -0
  60. opentau/policies/pi05/configuration_pi05.py +231 -0
  61. opentau/policies/pi05/modeling_pi05.py +1257 -0
  62. opentau/policies/pi05/paligemma_with_expert.py +572 -0
  63. opentau/policies/pretrained.py +315 -0
  64. opentau/policies/utils.py +123 -0
  65. opentau/policies/value/__init__.py +18 -0
  66. opentau/policies/value/configuration_value.py +170 -0
  67. opentau/policies/value/modeling_value.py +512 -0
  68. opentau/policies/value/reward.py +87 -0
  69. opentau/policies/value/siglip_gemma.py +221 -0
  70. opentau/scripts/actions_mse_loss.py +89 -0
  71. opentau/scripts/bin_to_safetensors.py +116 -0
  72. opentau/scripts/compute_max_token_length.py +111 -0
  73. opentau/scripts/display_sys_info.py +90 -0
  74. opentau/scripts/download_libero_benchmarks.py +54 -0
  75. opentau/scripts/eval.py +877 -0
  76. opentau/scripts/export_to_onnx.py +180 -0
  77. opentau/scripts/fake_tensor_training.py +87 -0
  78. opentau/scripts/get_advantage_and_percentiles.py +220 -0
  79. opentau/scripts/high_level_planner_inference.py +114 -0
  80. opentau/scripts/inference.py +70 -0
  81. opentau/scripts/launch_train.py +63 -0
  82. opentau/scripts/libero_simulation_parallel.py +356 -0
  83. opentau/scripts/libero_simulation_sequential.py +122 -0
  84. opentau/scripts/nav_high_level_planner_inference.py +61 -0
  85. opentau/scripts/train.py +379 -0
  86. opentau/scripts/visualize_dataset.py +294 -0
  87. opentau/scripts/visualize_dataset_html.py +507 -0
  88. opentau/scripts/zero_to_fp32.py +760 -0
  89. opentau/utils/__init__.py +20 -0
  90. opentau/utils/accelerate_utils.py +79 -0
  91. opentau/utils/benchmark.py +98 -0
  92. opentau/utils/fake_tensor.py +81 -0
  93. opentau/utils/hub.py +209 -0
  94. opentau/utils/import_utils.py +79 -0
  95. opentau/utils/io_utils.py +137 -0
  96. opentau/utils/libero.py +214 -0
  97. opentau/utils/libero_dataset_recorder.py +460 -0
  98. opentau/utils/logging_utils.py +180 -0
  99. opentau/utils/monkey_patch.py +278 -0
  100. opentau/utils/random_utils.py +244 -0
  101. opentau/utils/train_utils.py +198 -0
  102. opentau/utils/utils.py +471 -0
  103. opentau-0.1.0.dist-info/METADATA +161 -0
  104. opentau-0.1.0.dist-info/RECORD +108 -0
  105. opentau-0.1.0.dist-info/WHEEL +5 -0
  106. opentau-0.1.0.dist-info/entry_points.txt +2 -0
  107. opentau-0.1.0.dist-info/licenses/LICENSE +508 -0
  108. opentau-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,231 @@
1
+ # Copyright 2024 The HuggingFace Inc. team. All rights reserved.
2
+ # Copyright 2026 Tensor Auto Inc. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ """Configuration module for the PI05 Policy.
17
+
18
+ This module defines the `PI05Config` class, which handles the configuration parameters
19
+ for the PI05 Vision-Language-Action Flow Model. It includes settings for the model architecture,
20
+ optimization, scheduling, and data processing.
21
+ """
22
+
23
+ import logging
24
+ from dataclasses import dataclass, field
25
+ from typing import Literal
26
+
27
+ from opentau.configs.policies import PreTrainedConfig
28
+ from opentau.configs.types import FeatureType, NormalizationMode, PolicyFeature
29
+ from opentau.optim.optimizers import AdamWConfig
30
+ from opentau.optim.schedulers import (
31
+ CosineDecayWithWarmupSchedulerConfig,
32
+ LRSchedulerConfig,
33
+ )
34
+
35
+
36
+ @PreTrainedConfig.register_subclass("pi05")
37
+ @dataclass
38
+ class PI05Config(PreTrainedConfig):
39
+ """Configuration class for the PI05 Policy.
40
+
41
+ This class defines the configuration parameters for the PI05 model, including
42
+ input/output structure, model architecture, training settings, and preprocessing.
43
+
44
+ Args:
45
+ n_obs_steps: Number of observation steps to use. Defaults to 1.
46
+ chunk_size: Size of the action chunk. The upper bound for n_action_steps. Defaults to 50.
47
+ n_action_steps: Number of action steps to predict. Defaults to 50.
48
+ normalization_mapping: Mapping of feature names to normalization modes.
49
+ Defaults to identity for visual features and mean-std for state and action.
50
+ max_state_dim: Maximum dimension for state vectors. Shorter vectors are padded. Defaults to 32.
51
+ max_action_dim: Maximum dimension for action vectors. Shorter vectors are padded. Defaults to 32.
52
+ resize_imgs_with_padding: Target size (height, width) for image resizing with padding.
53
+ Defaults to (224, 224).
54
+ empty_cameras: Number of empty camera inputs to add. Used for specific adaptations like
55
+ Aloha simulation. Defaults to 0.
56
+ tokenizer_max_length: Maximum length for tokenizer. Defaults to 256.
57
+ discrete_action_max_length: Maximum length for discrete action tokens. Defaults to 32.
58
+ proj_width: Width of the projection layer. Defaults to 1024.
59
+ dropout: Dropout rate. Defaults to 0.1.
60
+ num_steps: Number of flow matching steps for decoding. Defaults to 10.
61
+ init_strategy: Initialization strategy. One of "no_init", "full_he_init", "expert_only_he_init".
62
+ Defaults to "full_he_init".
63
+ use_cache: Whether to use KV cache during inference. Defaults to True.
64
+ attention_implementation: Attention implementation to use ("eager" or "fa2"). Defaults to "eager".
65
+ freeze_vision_encoder: Whether to freeze the vision encoder during fine-tuning. Defaults to True.
66
+ train_expert_only: Whether to train only the expert module. Defaults to False.
67
+ optimizer_lr: Learning rate for the optimizer. Defaults to 2.5e-5.
68
+ optimizer_betas: Beta parameters for AdamW optimizer. Defaults to (0.9, 0.95).
69
+ optimizer_eps: Epsilon parameter for AdamW optimizer. Defaults to 1e-8.
70
+ optimizer_weight_decay: Weight decay for AdamW optimizer. Defaults to 1e-10.
71
+ scheduler_warmup_steps: Number of warmup steps for the scheduler. Defaults to 1_000.
72
+ scheduler_decay_steps: Number of decay steps for the scheduler. Defaults to 30_000.
73
+ scheduler_decay_lr: Target learning rate after decay. Defaults to 2.5e-6.
74
+ """
75
+
76
+ # Input / output structure.
77
+ n_obs_steps: int = 1
78
+ chunk_size: int = 50
79
+ n_action_steps: int = 50
80
+
81
+ normalization_mapping: dict[str, NormalizationMode] = field(
82
+ default_factory=lambda: {
83
+ "VISUAL": NormalizationMode.IDENTITY,
84
+ "STATE": NormalizationMode.MEAN_STD,
85
+ "ACTION": NormalizationMode.MEAN_STD,
86
+ }
87
+ )
88
+
89
+ # Shorter state and action vectors will be padded
90
+ max_state_dim: int = 32
91
+ max_action_dim: int = 32
92
+
93
+ # Image preprocessing
94
+ resize_imgs_with_padding: tuple[int, int] = (224, 224)
95
+
96
+ # Add empty images. Used by pi05_aloha_sim which adds the empty
97
+ # left and right wrist cameras in addition to the top camera.
98
+ empty_cameras: int = 0
99
+
100
+ # Tokenizer
101
+ tokenizer_max_length: int = 256
102
+
103
+ # Maximum length of the action tokens
104
+ discrete_action_max_length: int = 32
105
+
106
+ # Projector
107
+ proj_width: int = 1024
108
+
109
+ # Dropout
110
+ dropout: float = 0.1
111
+
112
+ # Decoding
113
+ num_steps: int = 10
114
+
115
+ # Initialization strategy
116
+ init_strategy: Literal["no_init", "full_he_init", "expert_only_he_init"] = "full_he_init"
117
+
118
+ # Attention utils
119
+ use_cache: bool = True
120
+ attention_implementation: str = "eager" # or fa2
121
+
122
+ # Finetuning settings
123
+ freeze_vision_encoder: bool = True
124
+ train_expert_only: bool = False
125
+
126
+ # Training presets
127
+ optimizer_lr: float = 2.5e-5
128
+ optimizer_betas: tuple[float, float] = (0.9, 0.95)
129
+ optimizer_eps: float = 1e-8
130
+ optimizer_weight_decay: float = 1e-10
131
+
132
+ scheduler_warmup_steps: int = 1_000
133
+ scheduler_decay_steps: int = 30_000
134
+ scheduler_decay_lr: float = 2.5e-6
135
+
136
+ def __post_init__(self):
137
+ """Post-initialization validation."""
138
+ super().__post_init__()
139
+
140
+ # TODO(Steven): Validate device and amp? in all policy configs?
141
+ """Input validation (not exhaustive)."""
142
+ if self.n_action_steps > self.chunk_size:
143
+ raise ValueError(
144
+ f"The chunk size is the upper bound for the number of action steps per model invocation. Got "
145
+ f"{self.n_action_steps} for `n_action_steps` and {self.chunk_size} for `chunk_size`."
146
+ )
147
+ if self.n_obs_steps != 1:
148
+ raise ValueError(
149
+ f"Multiple observation steps not handled yet. Got `nobs_steps={self.n_obs_steps}`"
150
+ )
151
+
152
+ assert self.init_strategy in ["no_init", "full_he_init", "expert_only_he_init"], (
153
+ f"Invalid init strategy: {self.init_strategy} must be one of ['no_init', 'full_he_init', 'expert_only_he_init']"
154
+ )
155
+
156
+ if self.init_strategy == "expert_only_he_init" and self.pretrained_path == "lerobot/pi05":
157
+ raise ValueError(
158
+ "You cannot load pretrained PI0 model when init_strategy is 'expert_only_he_init' due to differences in PaliGemma tokenizer vocab sizes."
159
+ )
160
+
161
+ if self.pretrained_path is not None and self.pretrained_path != "lerobot/pi05":
162
+ logging.info("Setting init_strategy to 'no_init' because we are resuming from a checkpoint.")
163
+ self.init_strategy = "no_init"
164
+
165
+ def validate_features(self) -> None:
166
+ """Validates the features and adds empty cameras if configured.
167
+
168
+ This method checks feature configurations and dynamically adds empty camera inputs
169
+ to `self.input_features` based on the `empty_cameras` parameter.
170
+ """
171
+
172
+ for i in range(self.empty_cameras):
173
+ key = f"observation.images.empty_camera_{i}"
174
+ empty_camera = PolicyFeature(
175
+ type=FeatureType.VISUAL,
176
+ shape=(3, 480, 640),
177
+ )
178
+ self.input_features[key] = empty_camera
179
+
180
+ def get_optimizer_preset(self) -> AdamWConfig:
181
+ """Returns the default optimizer configuration.
182
+
183
+ Returns:
184
+ AdamWConfig: The optimizer configuration with default parameters.
185
+ """
186
+ return AdamWConfig(
187
+ lr=self.optimizer_lr,
188
+ betas=self.optimizer_betas,
189
+ eps=self.optimizer_eps,
190
+ weight_decay=self.optimizer_weight_decay,
191
+ )
192
+
193
+ def get_scheduler_preset(self) -> LRSchedulerConfig:
194
+ """Returns the default scheduler configuration.
195
+
196
+ Returns:
197
+ CosineDecayWithWarmupSchedulerConfig: The scheduler configuration with default parameters.
198
+ """
199
+ return CosineDecayWithWarmupSchedulerConfig(
200
+ peak_lr=self.optimizer_lr,
201
+ decay_lr=self.scheduler_decay_lr,
202
+ num_warmup_steps=self.scheduler_warmup_steps,
203
+ num_decay_steps=self.scheduler_decay_steps,
204
+ )
205
+
206
+ @property
207
+ def observation_delta_indices(self) -> None:
208
+ """Indices for observation deltas.
209
+
210
+ Returns:
211
+ None: As observation deltas are not used.
212
+ """
213
+ return None
214
+
215
+ @property
216
+ def action_delta_indices(self) -> list[int]:
217
+ """Indices for action deltas.
218
+
219
+ Returns:
220
+ list[int]: A list of indices corresponding to the chunk size.
221
+ """
222
+ return list(range(self.chunk_size))
223
+
224
+ @property
225
+ def reward_delta_indices(self) -> None:
226
+ """Indices for reward deltas.
227
+
228
+ Returns:
229
+ None: As reward deltas are not used.
230
+ """
231
+ return None