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.
- opentau/__init__.py +179 -0
- opentau/__version__.py +24 -0
- opentau/configs/__init__.py +19 -0
- opentau/configs/default.py +297 -0
- opentau/configs/libero.py +113 -0
- opentau/configs/parser.py +393 -0
- opentau/configs/policies.py +297 -0
- opentau/configs/reward.py +42 -0
- opentau/configs/train.py +370 -0
- opentau/configs/types.py +76 -0
- opentau/constants.py +52 -0
- opentau/datasets/__init__.py +84 -0
- opentau/datasets/backward_compatibility.py +78 -0
- opentau/datasets/compute_stats.py +333 -0
- opentau/datasets/dataset_mixture.py +460 -0
- opentau/datasets/factory.py +232 -0
- opentau/datasets/grounding/__init__.py +67 -0
- opentau/datasets/grounding/base.py +154 -0
- opentau/datasets/grounding/clevr.py +110 -0
- opentau/datasets/grounding/cocoqa.py +130 -0
- opentau/datasets/grounding/dummy.py +101 -0
- opentau/datasets/grounding/pixmo.py +177 -0
- opentau/datasets/grounding/vsr.py +141 -0
- opentau/datasets/image_writer.py +304 -0
- opentau/datasets/lerobot_dataset.py +1910 -0
- opentau/datasets/online_buffer.py +442 -0
- opentau/datasets/push_dataset_to_hub/utils.py +132 -0
- opentau/datasets/sampler.py +99 -0
- opentau/datasets/standard_data_format_mapping.py +278 -0
- opentau/datasets/transforms.py +330 -0
- opentau/datasets/utils.py +1243 -0
- opentau/datasets/v2/batch_convert_dataset_v1_to_v2.py +887 -0
- opentau/datasets/v2/convert_dataset_v1_to_v2.py +829 -0
- opentau/datasets/v21/_remove_language_instruction.py +109 -0
- opentau/datasets/v21/batch_convert_dataset_v20_to_v21.py +60 -0
- opentau/datasets/v21/convert_dataset_v20_to_v21.py +183 -0
- opentau/datasets/v21/convert_stats.py +150 -0
- opentau/datasets/video_utils.py +597 -0
- opentau/envs/__init__.py +18 -0
- opentau/envs/configs.py +178 -0
- opentau/envs/factory.py +99 -0
- opentau/envs/libero.py +439 -0
- opentau/envs/utils.py +204 -0
- opentau/optim/__init__.py +16 -0
- opentau/optim/factory.py +43 -0
- opentau/optim/optimizers.py +121 -0
- opentau/optim/schedulers.py +140 -0
- opentau/planner/__init__.py +82 -0
- opentau/planner/high_level_planner.py +366 -0
- opentau/planner/utils/memory.py +64 -0
- opentau/planner/utils/utils.py +65 -0
- opentau/policies/__init__.py +24 -0
- opentau/policies/factory.py +172 -0
- opentau/policies/normalize.py +315 -0
- opentau/policies/pi0/__init__.py +19 -0
- opentau/policies/pi0/configuration_pi0.py +250 -0
- opentau/policies/pi0/modeling_pi0.py +994 -0
- opentau/policies/pi0/paligemma_with_expert.py +516 -0
- opentau/policies/pi05/__init__.py +20 -0
- opentau/policies/pi05/configuration_pi05.py +231 -0
- opentau/policies/pi05/modeling_pi05.py +1257 -0
- opentau/policies/pi05/paligemma_with_expert.py +572 -0
- opentau/policies/pretrained.py +315 -0
- opentau/policies/utils.py +123 -0
- opentau/policies/value/__init__.py +18 -0
- opentau/policies/value/configuration_value.py +170 -0
- opentau/policies/value/modeling_value.py +512 -0
- opentau/policies/value/reward.py +87 -0
- opentau/policies/value/siglip_gemma.py +221 -0
- opentau/scripts/actions_mse_loss.py +89 -0
- opentau/scripts/bin_to_safetensors.py +116 -0
- opentau/scripts/compute_max_token_length.py +111 -0
- opentau/scripts/display_sys_info.py +90 -0
- opentau/scripts/download_libero_benchmarks.py +54 -0
- opentau/scripts/eval.py +877 -0
- opentau/scripts/export_to_onnx.py +180 -0
- opentau/scripts/fake_tensor_training.py +87 -0
- opentau/scripts/get_advantage_and_percentiles.py +220 -0
- opentau/scripts/high_level_planner_inference.py +114 -0
- opentau/scripts/inference.py +70 -0
- opentau/scripts/launch_train.py +63 -0
- opentau/scripts/libero_simulation_parallel.py +356 -0
- opentau/scripts/libero_simulation_sequential.py +122 -0
- opentau/scripts/nav_high_level_planner_inference.py +61 -0
- opentau/scripts/train.py +379 -0
- opentau/scripts/visualize_dataset.py +294 -0
- opentau/scripts/visualize_dataset_html.py +507 -0
- opentau/scripts/zero_to_fp32.py +760 -0
- opentau/utils/__init__.py +20 -0
- opentau/utils/accelerate_utils.py +79 -0
- opentau/utils/benchmark.py +98 -0
- opentau/utils/fake_tensor.py +81 -0
- opentau/utils/hub.py +209 -0
- opentau/utils/import_utils.py +79 -0
- opentau/utils/io_utils.py +137 -0
- opentau/utils/libero.py +214 -0
- opentau/utils/libero_dataset_recorder.py +460 -0
- opentau/utils/logging_utils.py +180 -0
- opentau/utils/monkey_patch.py +278 -0
- opentau/utils/random_utils.py +244 -0
- opentau/utils/train_utils.py +198 -0
- opentau/utils/utils.py +471 -0
- opentau-0.1.0.dist-info/METADATA +161 -0
- opentau-0.1.0.dist-info/RECORD +108 -0
- opentau-0.1.0.dist-info/WHEEL +5 -0
- opentau-0.1.0.dist-info/entry_points.txt +2 -0
- opentau-0.1.0.dist-info/licenses/LICENSE +508 -0
- opentau-0.1.0.dist-info/top_level.txt +1 -0
opentau/envs/configs.py
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
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
|
+
r"""This module contains configuration files for different environments. Only LIBERO is supported for now."""
|
|
17
|
+
|
|
18
|
+
import abc
|
|
19
|
+
import logging
|
|
20
|
+
from copy import copy
|
|
21
|
+
from dataclasses import dataclass, field
|
|
22
|
+
|
|
23
|
+
import draccus
|
|
24
|
+
|
|
25
|
+
from opentau.configs.types import FeatureType, PolicyFeature
|
|
26
|
+
from opentau.constants import ACTION, OBS_IMAGES, OBS_STATE
|
|
27
|
+
from opentau.utils.accelerate_utils import get_proc_accelerator
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass
|
|
31
|
+
class EnvConfig(draccus.ChoiceRegistry, abc.ABC):
|
|
32
|
+
"""Base configuration for an environment.
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
import_name: Name under which the environment should be imported. For LIBERO, this doesn't need to be set.
|
|
36
|
+
make_id: Gymnasium/Gym environment id (e.g., ``"CartPole-v1"``) when using ``gym.make``-style construction.
|
|
37
|
+
task: Optional task or suite identifier understood by the environment.
|
|
38
|
+
fps: Target frames-per-second used for stepping/rendering.
|
|
39
|
+
features: Mapping from logical feature names (e.g., ``"action"``,
|
|
40
|
+
``"pixels/agentview_image"``) to :class:`~opentau.configs.types.PolicyFeature`
|
|
41
|
+
definitions consumed by policies.
|
|
42
|
+
features_map: Mapping from environment keys to standardized OpenTau keys
|
|
43
|
+
(e.g., mapping env observations into ``OBS_IMAGES`` / ``OBS_STATE``).
|
|
44
|
+
max_parallel_tasks: Maximum number of tasks to run in parallel within the env.
|
|
45
|
+
disable_env_checker: Whether to disable Gymnasium environment checking.
|
|
46
|
+
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
import_name: str = None
|
|
50
|
+
make_id: str = None
|
|
51
|
+
task: str | None = None
|
|
52
|
+
fps: int = 30
|
|
53
|
+
features: dict[str, PolicyFeature] = field(default_factory=dict)
|
|
54
|
+
features_map: dict[str, str] = field(default_factory=dict)
|
|
55
|
+
max_parallel_tasks: int = 1
|
|
56
|
+
disable_env_checker: bool = True
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def type(self) -> str:
|
|
60
|
+
"""Return the registered choice name for this config.
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
The draccus choice name used in configs/CLI.
|
|
64
|
+
"""
|
|
65
|
+
return self.get_choice_name(self.__class__)
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
@abc.abstractmethod
|
|
69
|
+
def gym_kwargs(self) -> dict:
|
|
70
|
+
"""Keyword arguments used to construct the environment.
|
|
71
|
+
|
|
72
|
+
Subclasses must implement this to return the kwargs consumed by the project’s
|
|
73
|
+
environment builder (often ``gym.make`` or an equivalent factory).
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
A dict of keyword arguments for environment construction.
|
|
77
|
+
"""
|
|
78
|
+
raise NotImplementedError()
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@EnvConfig.register_subclass("libero")
|
|
82
|
+
@dataclass
|
|
83
|
+
class LiberoEnv(EnvConfig):
|
|
84
|
+
r"""Configuration for the LIBERO environment.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
task: The LIBERO task or suite to use (e.g., ``"libero_10"``).
|
|
88
|
+
task_ids: Optional list of specific task IDs within the suite to use (if ``None``, all tasks in the suite are used).
|
|
89
|
+
fps: Target frames-per-second for stepping/rendering.
|
|
90
|
+
episode_length: Maximum length of each episode in steps.
|
|
91
|
+
obs_type: Type of observations to use (e.g., ``"pixels_agent_pos"``).
|
|
92
|
+
render_mode: Rendering mode for the environment (e.g., ``"rgb_array"``).
|
|
93
|
+
camera_name: Comma-separated names of cameras to use for rendering.
|
|
94
|
+
init_states: Whether to initialize states randomly.
|
|
95
|
+
camera_name_mapping: Optional mapping from camera names to standardized keys.
|
|
96
|
+
features: Mapping from logical feature names to :class:`~opentau.configs.types.PolicyFeature` definitions.
|
|
97
|
+
features_map: Mapping from environment keys to standardized OpenTau keys.
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
task: str = "libero_10" # can also choose libero_spatial, libero_object, etc.
|
|
101
|
+
task_ids: list[int] | None = None
|
|
102
|
+
fps: int = 30
|
|
103
|
+
episode_length: int = 520
|
|
104
|
+
obs_type: str = "pixels_agent_pos"
|
|
105
|
+
render_mode: str = "rgb_array"
|
|
106
|
+
camera_name: str = "agentview_image,robot0_eye_in_hand_image"
|
|
107
|
+
init_states: bool = True
|
|
108
|
+
camera_name_mapping: dict[str, str] | None = None
|
|
109
|
+
features: dict[str, PolicyFeature] = field(
|
|
110
|
+
default_factory=lambda: {
|
|
111
|
+
"action": PolicyFeature(type=FeatureType.ACTION, shape=(7,)),
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
features_map: dict[str, str] = field(
|
|
115
|
+
default_factory=lambda: {
|
|
116
|
+
"action": ACTION,
|
|
117
|
+
"agent_pos": OBS_STATE, # TODO: fix the name
|
|
118
|
+
"pixels/agentview_image": f"{OBS_IMAGES}.image", # TODO: fix the name
|
|
119
|
+
"pixels/robot0_eye_in_hand_image": f"{OBS_IMAGES}.image2", # TODO: fix the name
|
|
120
|
+
}
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
def __post_init__(self):
|
|
124
|
+
if self.obs_type == "pixels":
|
|
125
|
+
self.features["pixels/agentview_image"] = PolicyFeature(
|
|
126
|
+
type=FeatureType.VISUAL, shape=(360, 360, 3)
|
|
127
|
+
)
|
|
128
|
+
self.features["pixels/robot0_eye_in_hand_image"] = PolicyFeature(
|
|
129
|
+
type=FeatureType.VISUAL, shape=(360, 360, 3)
|
|
130
|
+
)
|
|
131
|
+
elif self.obs_type == "pixels_agent_pos":
|
|
132
|
+
self.features["agent_pos"] = PolicyFeature(type=FeatureType.STATE, shape=(8,))
|
|
133
|
+
self.features["pixels/agentview_image"] = PolicyFeature(
|
|
134
|
+
type=FeatureType.VISUAL, shape=(360, 360, 3)
|
|
135
|
+
)
|
|
136
|
+
self.features["pixels/robot0_eye_in_hand_image"] = PolicyFeature(
|
|
137
|
+
type=FeatureType.VISUAL, shape=(360, 360, 3)
|
|
138
|
+
)
|
|
139
|
+
else:
|
|
140
|
+
raise ValueError(f"Unsupported obs_type: {self.obs_type}")
|
|
141
|
+
|
|
142
|
+
@property
|
|
143
|
+
def gym_kwargs(self) -> dict:
|
|
144
|
+
r"""Return the keyword arguments used to construct the LIBERO environment."""
|
|
145
|
+
suite_names = [s.strip() for s in str(self.task).split(",") if s.strip()]
|
|
146
|
+
|
|
147
|
+
accelerator = get_proc_accelerator()
|
|
148
|
+
|
|
149
|
+
task_ids: dict[str, list[int] | None]
|
|
150
|
+
|
|
151
|
+
if accelerator is None:
|
|
152
|
+
task_ids = {suite: copy(self.task_ids) for suite in suite_names}
|
|
153
|
+
logging.info(f"[LIBERO environment] No accelerator found, using {task_ids=}.")
|
|
154
|
+
else:
|
|
155
|
+
from opentau.envs.libero import _get_suite
|
|
156
|
+
|
|
157
|
+
task_ids = {
|
|
158
|
+
suite: _get_suite(suite).tasks if self.task_ids is None else self.task_ids
|
|
159
|
+
for suite in suite_names
|
|
160
|
+
}
|
|
161
|
+
logging.info(f"[LIBERO environment] Before distributing, using {task_ids=}.")
|
|
162
|
+
task_ids = {
|
|
163
|
+
suite: [
|
|
164
|
+
tsk
|
|
165
|
+
for idx, tsk in enumerate(tasks)
|
|
166
|
+
if idx % accelerator.num_processes == accelerator.process_index
|
|
167
|
+
]
|
|
168
|
+
for suite, tasks in task_ids.items()
|
|
169
|
+
}
|
|
170
|
+
logging.info(
|
|
171
|
+
f"[LIBERO environment] After distributing, using {task_ids=} on {accelerator.process_index=}."
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
"obs_type": self.obs_type,
|
|
176
|
+
"render_mode": self.render_mode,
|
|
177
|
+
"task_ids": task_ids,
|
|
178
|
+
}
|
opentau/envs/factory.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
# Copyright 2024 The HuggingFace Inc. team. All rights reserved.
|
|
4
|
+
# Copyright 2026 Tensor Auto Inc. All rights reserved.
|
|
5
|
+
#
|
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
# you may not use this file except in compliance with the License.
|
|
8
|
+
# You may obtain a copy of the License at
|
|
9
|
+
#
|
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
#
|
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
# See the License for the specific language governing permissions and
|
|
16
|
+
# limitations under the License.
|
|
17
|
+
r"""This module contains factory methods to create environments based on their configuration."""
|
|
18
|
+
|
|
19
|
+
import importlib
|
|
20
|
+
from functools import partial
|
|
21
|
+
|
|
22
|
+
import gymnasium as gym
|
|
23
|
+
|
|
24
|
+
from opentau.configs.train import TrainPipelineConfig
|
|
25
|
+
from opentau.envs.configs import EnvConfig, LiberoEnv
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def make_env_config(env_type: str, **kwargs) -> EnvConfig:
|
|
29
|
+
r"""Factory method to create an environment config based on the env_type.
|
|
30
|
+
Right now, only 'libero' is supported.
|
|
31
|
+
"""
|
|
32
|
+
if env_type == "libero":
|
|
33
|
+
return LiberoEnv(**kwargs)
|
|
34
|
+
else:
|
|
35
|
+
raise ValueError(f"Env type '{env_type}' is not available.")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def make_envs(
|
|
39
|
+
cfg: EnvConfig, train_cfg: TrainPipelineConfig, n_envs: int = 1, use_async_envs: bool = False
|
|
40
|
+
) -> dict[str, dict[int, gym.vector.VectorEnv]]:
|
|
41
|
+
"""Makes a nested collection of gym vector environment according to the config.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
cfg (EnvConfig): the config of the environment to instantiate.
|
|
45
|
+
n_envs (int, optional): The number of parallelized env to return. Defaults to 1.
|
|
46
|
+
use_async_envs (bool, optional): Whether to return an AsyncVectorEnv or a SyncVectorEnv. Defaults to
|
|
47
|
+
False.
|
|
48
|
+
|
|
49
|
+
Raises:
|
|
50
|
+
ValueError: if n_envs < 1
|
|
51
|
+
ModuleNotFoundError: If the requested env package is not installed
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
dict[str, dict[int, gym.vector.VectorEnv]]:
|
|
55
|
+
A mapping from suite name to indexed vectorized environments.
|
|
56
|
+
- For multi-task benchmarks (e.g., LIBERO): one entry per suite, and one vec env per task_id.
|
|
57
|
+
- For single-task environments: a single suite entry (cfg.type) with task_id=0."""
|
|
58
|
+
|
|
59
|
+
if n_envs < 1:
|
|
60
|
+
raise ValueError("`n_envs must be at least 1")
|
|
61
|
+
|
|
62
|
+
# "spawn" is more robust (and, for libero on oracle, the only option) than "fork".
|
|
63
|
+
# Caveat is that the entry point must be protected by `if __name__ == "__main__":`.
|
|
64
|
+
env_cls = (
|
|
65
|
+
partial(gym.vector.AsyncVectorEnv, context="spawn") if use_async_envs else gym.vector.SyncVectorEnv
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
# Note: The official LeRobot repo makes a special case for Libero envs here.
|
|
69
|
+
# cf. https://github.com/huggingface/lerobot/commit/25384727812de60ff6e7a5e705cc016ec5def552
|
|
70
|
+
if isinstance(cfg, LiberoEnv):
|
|
71
|
+
from opentau.envs.libero import create_libero_envs
|
|
72
|
+
|
|
73
|
+
return create_libero_envs(
|
|
74
|
+
task=cfg.task,
|
|
75
|
+
n_envs=n_envs,
|
|
76
|
+
camera_name=cfg.camera_name,
|
|
77
|
+
init_states=cfg.init_states,
|
|
78
|
+
gym_kwargs=cfg.gym_kwargs,
|
|
79
|
+
env_cls=env_cls,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
try:
|
|
83
|
+
importlib.import_module(cfg.import_name)
|
|
84
|
+
except ModuleNotFoundError as e:
|
|
85
|
+
print(f"{cfg.import_name} is not installed. Please install it with `uv sync --all-extras'`")
|
|
86
|
+
raise e
|
|
87
|
+
|
|
88
|
+
def _make_one():
|
|
89
|
+
return gym.make(
|
|
90
|
+
cfg.make_id, disable_env_checker=cfg.disable_env_checker, **cfg.gym_kwargs, train_cfg=train_cfg
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
env = env_cls([_make_one] * n_envs) # safe to repeat the same callable object
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
cfg.type: {
|
|
97
|
+
0: env,
|
|
98
|
+
}
|
|
99
|
+
}
|