镜像自地址
https://github.com/MINT-SJTU/Evo-RL.git
已同步 2026-11-20 18:17:06 +00:00
chore(ci): make quality checks pass across repo
- fix ruff violations in dataset, recording, and value modules - fix typos findings and markdown/workflow lint issues - update pages workflow checkout to disable credential persistence - apply pre-commit auto-formatting and EOF normalization - include requested repo housekeeping updates (.gitignore and README)
这个提交包含在:
2
.github/workflows/deploy-website-pages.yml
vendored
2
.github/workflows/deploy-website-pages.yml
vendored
@ -29,6 +29,8 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Setup Pages
|
||||
uses: actions/configure-pages@v5
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -177,3 +177,4 @@ outputs/
|
||||
*.urdf
|
||||
*.xml
|
||||
*.part
|
||||
AGENTS.md
|
||||
|
||||
@ -22,7 +22,7 @@ If using `conda activate /llm_jzm/cache/conda_env/lerobot`:
|
||||
- Treat it as shared machine mode.
|
||||
- Hugging Face cache is not in the default location.
|
||||
- Set Hugging Face token to the shared token for runs on this machine.
|
||||
- Set Wandb token to hte shared token for runs on this machine
|
||||
- Set Wandb token to the shared token for runs on this machine
|
||||
|
||||
Use:
|
||||
|
||||
|
||||
15
README.md
15
README.md
@ -1,7 +1,7 @@
|
||||
<h1 align="center">Evo-RL</h1>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://elvin-yk.github.io/Evo-RL/"><img alt="project website" src="https://img.shields.io/badge/Project-Website-0ea5e9"/></a>
|
||||
<a href="https://MINT-SJTU.github.io/Evo-RL/"><img alt="project website" src="https://img.shields.io/badge/Project-Website-0ea5e9"/></a>
|
||||
<a href="https://github.com/huggingface/lerobot"><img alt="lerobot version" src="https://img.shields.io/badge/LeRobot-0.4.4-f59e0b"/></a>
|
||||
<a href="https://evorl.example.com/wechat-post"><img alt="wechat post" src="https://img.shields.io/badge/WeChat-Official%20Post-07c160"/></a>
|
||||
<a href="#community-channels"><img alt="wechat group join us" src="https://img.shields.io/badge/WeChat%20Group-Join%20Us-a855f7?logo=wechat&logoColor=white"/></a>
|
||||
@ -84,6 +84,7 @@ For SO101 setup, please follow the [official SO101 tutorial](https://wiki.seeeds
|
||||
#### Device path recommendation
|
||||
|
||||
Recommended path strategy:
|
||||
|
||||
- **Robot serial:** use `/dev/serial/by-id/` (stable across reboots).
|
||||
- **Cameras:** prefer `/dev/v4l/by-id/`; if IDs are not unique, use `/dev/v4l/by-path/`.
|
||||
- In examples below: robot ports use `by-id`, camera paths use `by-path`.
|
||||
@ -213,6 +214,7 @@ lerobot-human-inloop-record \
|
||||
Recommendation: use **`fourcc: "MJPG"`** for OpenCV and **`warmup_s`** for RealSense. In this example `front` uses RealSense, but you can switch it to OpenCV with the same structure.
|
||||
|
||||
Hotkeys:
|
||||
|
||||
- `i`: toggle intervention mode (policy <-> teleop takeover)
|
||||
- `s`: mark success and end current episode
|
||||
- `f`: mark failure and end current episode
|
||||
@ -230,7 +232,7 @@ This prints: dataset meta, totals, episode-length stats/histogram, success/inter
|
||||
|
||||
### 4) Value Function Training
|
||||
|
||||
Train the value function on the current dataset. Current default: [Pi*0.6](https://www.pi.website/blog/pistar06) (`--value.type=pistar06`).
|
||||
Train the value function on the current dataset. Current default: [Pi\*0.6](https://www.pi.website/blog/pistar06) (`--value.type=pistar06`).
|
||||
|
||||
Single-GPU template:
|
||||
|
||||
@ -260,6 +262,7 @@ CUDA_VISIBLE_DEVICES=<GPU_ID_LIST> accelerate launch \
|
||||
```
|
||||
|
||||
To plug in a different value function, minimal path in this repo:
|
||||
|
||||
- Add `src/lerobot/values/<your_value>/configuration_<your_value>.py` with `@PreTrainedConfig.register_subclass("<your_value>")`.
|
||||
- Add `src/lerobot/values/<your_value>/modeling_<your_value>.py` with `<YourValue>Policy(PreTrainedPolicy)` (implement at least `forward`, `predict_value`, and `build_training_raw_batch_hook` for `lerobot-value-train`).
|
||||
- Add `src/lerobot/values/<your_value>/processor_<your_value>.py` with `make_<your_value>_pre_post_processors(...)`.
|
||||
@ -268,6 +271,7 @@ To plug in a different value function, minimal path in this repo:
|
||||
### 5) Value Inference
|
||||
|
||||
Infer value signals and write value/advantage/indicator back to the dataset:
|
||||
|
||||
- `value`: estimated return-to-go of the current frame.
|
||||
- `advantage`: relative improvement signal (higher means better-than-baseline trajectory quality).
|
||||
- `indicator`: binarized training tag derived from advantage.
|
||||
@ -302,10 +306,12 @@ CUDA_VISIBLE_DEVICES=<GPU_ID_LIST> accelerate launch \
|
||||
```
|
||||
|
||||
Parameter notes:
|
||||
|
||||
- `--acp.n_step`: n-step advantage horizon.
|
||||
- `--acp.positive_ratio`: positive label ratio after advantage binarization (e.g., `0.3` = top 30% per task).
|
||||
|
||||
Expected new columns:
|
||||
|
||||
- `complementary_info.value_<TAG>`
|
||||
- `complementary_info.advantage_<TAG>`
|
||||
- `complementary_info.acp_indicator_<TAG>`
|
||||
@ -313,6 +319,7 @@ Expected new columns:
|
||||
These columns are written back to the original dataset specified by `--dataset.repo_id`.
|
||||
|
||||
Visualization (optional):
|
||||
|
||||
- Enable with `--viz.enable=true`.
|
||||
- Output videos are saved to `outputs/value_infer/<RUN_NAME>/value/viz/`.
|
||||
- Each video overlays a value curve and per-frame text (`advantage`, `acp_indicator`) on top of camera frames.
|
||||
@ -323,6 +330,7 @@ Visualization (optional):
|
||||
- `--viz.vcodec=<CODEC>` and `--viz.frame_storage_mode=memory|disk`
|
||||
|
||||
Value overlay examples (SO101, smooth=11):
|
||||
|
||||
- GIF assets are stored under `website/assets/gifs/`.
|
||||
|
||||
### 6) Policy Training
|
||||
@ -354,6 +362,7 @@ lerobot-train \
|
||||
`--acp.indicator_dropout_prob` controls tag drop rate in task text; `0.3` helps learn both tagged and untagged conditions.
|
||||
|
||||
Important checks:
|
||||
|
||||
- `--acp.indicator_field` must exist in the dataset and be **binary (`0/1`)**.
|
||||
|
||||
Multi-GPU template:
|
||||
@ -396,6 +405,7 @@ lerobot-human-inloop-record \
|
||||
```
|
||||
|
||||
Dataset continuation options:
|
||||
|
||||
- **Append in place:** keep `--resume=true` and continue recording into the same dataset.
|
||||
- **Merge multiple rounds:** use the official dataset editor to merge separate datasets.
|
||||
|
||||
@ -407,6 +417,7 @@ lerobot-edit-dataset \
|
||||
```
|
||||
|
||||
Additional data attributes vs default `lerobot-record` behavior:
|
||||
|
||||
- `complementary_info.policy_action`: policy output action at each step.
|
||||
- `complementary_info.is_intervention`: whether current step is in intervention.
|
||||
- `complementary_info.state`: intervention state-machine state.
|
||||
|
||||
@ -41,7 +41,9 @@ class ValueTargetsConfig:
|
||||
if self.c_fail_coef < 0:
|
||||
raise ValueError("'targets.c_fail_coef' must be non-negative.")
|
||||
if not self.target_field.startswith("observation."):
|
||||
raise ValueError("'targets.target_field' must start with 'observation.' to survive processor conversion.")
|
||||
raise ValueError(
|
||||
"'targets.target_field' must start with 'observation.' to survive processor conversion."
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -113,7 +115,7 @@ class ValueTrainPipelineConfig(HubMixin):
|
||||
self.targets.validate()
|
||||
|
||||
if hasattr(self.value, "target_key"):
|
||||
setattr(self.value, "target_key", self.targets.target_field)
|
||||
self.value.target_key = self.targets.target_field
|
||||
|
||||
if not self.job_name:
|
||||
self.job_name = f"{self.value.type}_value"
|
||||
@ -136,7 +138,9 @@ class ValueTrainPipelineConfig(HubMixin):
|
||||
self.scheduler = self.value.get_scheduler_preset()
|
||||
|
||||
if self.value.push_to_hub and not self.value.repo_id:
|
||||
raise ValueError("'value.repo_id' argument missing. Please specify it to push the model to the hub.")
|
||||
raise ValueError(
|
||||
"'value.repo_id' argument missing. Please specify it to push the model to the hub."
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def __get_path_fields__(cls) -> list[str]:
|
||||
|
||||
@ -836,7 +836,11 @@ def _copy_and_reindex_episodes_metadata(
|
||||
for key in schema.names:
|
||||
if key in {"episode_index", "tasks", "length"}:
|
||||
continue
|
||||
if key.startswith("stats/") or key.startswith("__index_level_") or key.startswith("meta/episodes/"):
|
||||
if (
|
||||
key.startswith("stats/")
|
||||
or key.startswith("__index_level_")
|
||||
or key.startswith("meta/episodes/")
|
||||
):
|
||||
continue
|
||||
if key not in seen_preserved_keys:
|
||||
seen_preserved_keys.add(key)
|
||||
|
||||
@ -729,15 +729,14 @@ class LeRobotDataset(torch.utils.data.Dataset):
|
||||
# Check if cached dataset contains all requested episodes
|
||||
if not self._check_cached_episodes_sufficient():
|
||||
raise FileNotFoundError("Cached dataset doesn't contain all requested episodes")
|
||||
except (AssertionError, FileNotFoundError, NotADirectoryError):
|
||||
except (AssertionError, FileNotFoundError, NotADirectoryError) as err:
|
||||
if is_valid_version(self.revision):
|
||||
self.revision = get_safe_version(self.repo_id, self.revision)
|
||||
self.download(download_videos)
|
||||
self.hf_dataset = self.load_hf_dataset()
|
||||
if not self._check_cached_episodes_sufficient():
|
||||
missing_videos_hint = (
|
||||
" Missing video files are required by this dataset. "
|
||||
"Retry with `download_videos=True`."
|
||||
" Missing video files are required by this dataset. Retry with `download_videos=True`."
|
||||
if len(self.meta.video_keys) > 0 and not download_videos
|
||||
else ""
|
||||
)
|
||||
@ -745,7 +744,7 @@ class LeRobotDataset(torch.utils.data.Dataset):
|
||||
"Cached dataset is incomplete after download. "
|
||||
"Some requested episodes or files are missing."
|
||||
f"{missing_videos_hint}"
|
||||
)
|
||||
) from err
|
||||
|
||||
# Create mapping from absolute indices to relative indices when only a subset of the episodes are loaded
|
||||
# Build a mapping: absolute_index -> relative_index_in_filtered_dataset
|
||||
|
||||
@ -60,10 +60,7 @@ def _from_meta_stats(dataset: Any, indicator_field: str) -> ACPIndicatorStats |
|
||||
|
||||
count_raw = _stats_entry_to_scalar(field_stats, "count")
|
||||
total_count = int(round(count_raw)) if count_raw is not None else -1
|
||||
if total_count >= 0:
|
||||
positive_count = int(round(ratio * total_count))
|
||||
else:
|
||||
positive_count = -1
|
||||
positive_count = int(round(ratio * total_count)) if total_count >= 0 else -1
|
||||
|
||||
return ACPIndicatorStats(
|
||||
indicator_field=indicator_field,
|
||||
|
||||
@ -136,7 +136,9 @@ def build_report(dataset_root: Path) -> dict[str, Any]:
|
||||
episodes_df = episodes_ds.to_pandas()
|
||||
|
||||
actual_episode_count = int(len(episodes_df))
|
||||
episode_success_labels = episodes_df["episode_success"].tolist() if "episode_success" in episodes_df else []
|
||||
episode_success_labels = (
|
||||
episodes_df["episode_success"].tolist() if "episode_success" in episodes_df else []
|
||||
)
|
||||
normalized_labels = [_normalize_label(v) for v in episode_success_labels]
|
||||
|
||||
success_count = sum(1 for v in normalized_labels if v == "success")
|
||||
@ -153,7 +155,11 @@ def build_report(dataset_root: Path) -> dict[str, Any]:
|
||||
intervention_frames = 0
|
||||
intervention_episode_count = 0
|
||||
|
||||
if intervention_col in data_schema_names and episode_index_col in data_schema_names and actual_frame_count > 0:
|
||||
if (
|
||||
intervention_col in data_schema_names
|
||||
and episode_index_col in data_schema_names
|
||||
and actual_frame_count > 0
|
||||
):
|
||||
table = data_dataset.to_table(columns=[episode_index_col, intervention_col])
|
||||
episode_indices = table[episode_index_col].to_pylist()
|
||||
intervention_values = table[intervention_col].to_pylist()
|
||||
@ -190,10 +196,14 @@ def build_report(dataset_root: Path) -> dict[str, Any]:
|
||||
|
||||
fps = float(info.get("fps", 0) or 0)
|
||||
episode_lengths_frames = (
|
||||
episodes_df["length"].astype(int).tolist() if "length" in episodes_df and actual_episode_count > 0 else []
|
||||
episodes_df["length"].astype(int).tolist()
|
||||
if "length" in episodes_df and actual_episode_count > 0
|
||||
else []
|
||||
)
|
||||
episode_lengths_seconds = [frames / fps for frames in episode_lengths_frames] if fps > 0 else []
|
||||
length_mean = float(sum(episode_lengths_seconds) / len(episode_lengths_seconds)) if episode_lengths_seconds else 0.0
|
||||
length_mean = (
|
||||
float(sum(episode_lengths_seconds) / len(episode_lengths_seconds)) if episode_lengths_seconds else 0.0
|
||||
)
|
||||
length_min = float(min(episode_lengths_seconds)) if episode_lengths_seconds else 0.0
|
||||
length_max = float(max(episode_lengths_seconds)) if episode_lengths_seconds else 0.0
|
||||
length_histogram = _build_episode_length_histogram(episode_lengths_seconds, bins=20)
|
||||
|
||||
@ -22,16 +22,16 @@ Phase A/B goals:
|
||||
- Keyboard-toggled intervention lets teleop temporarily take over execution.
|
||||
"""
|
||||
|
||||
import logging
|
||||
import json
|
||||
import logging
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from lerobot.configs import parser
|
||||
from lerobot.scripts.lerobot_record import RecordConfig, record
|
||||
from lerobot.utils.import_utils import register_third_party_plugins
|
||||
from lerobot.utils.constants import HF_LEROBOT_HOME
|
||||
from lerobot.utils.import_utils import register_third_party_plugins
|
||||
from lerobot.utils.recording_annotations import EPISODE_FAILURE, infer_collector_policy_version
|
||||
|
||||
|
||||
@ -64,7 +64,9 @@ def _load_failure_reset_pose(pose_path: Path) -> dict[str, float]:
|
||||
payload = json.load(f)
|
||||
joint_pos_raw = payload["joint_pos"] if isinstance(payload, dict) and "joint_pos" in payload else payload
|
||||
if not isinstance(joint_pos_raw, dict):
|
||||
raise ValueError(f"Invalid failure reset pose payload in {pose_path}: expected dict, got {type(joint_pos_raw)}")
|
||||
raise ValueError(
|
||||
f"Invalid failure reset pose payload in {pose_path}: expected dict, got {type(joint_pos_raw)}"
|
||||
)
|
||||
joint_pos = {str(key): float(value) for key, value in joint_pos_raw.items() if str(key).endswith(".pos")}
|
||||
if not joint_pos:
|
||||
raise ValueError(f"Invalid failure reset pose payload in {pose_path}: no '.pos' joints found.")
|
||||
|
||||
@ -97,6 +97,13 @@ from lerobot.robots import ( # noqa: F401
|
||||
so_follower,
|
||||
unitree_g1 as unitree_g1_robot,
|
||||
)
|
||||
from lerobot.scripts.recording_hil import (
|
||||
ACPInferenceConfig,
|
||||
PolicySyncDualArmExecutor,
|
||||
_capture_policy_runtime_state, # noqa: F401
|
||||
_predict_policy_action_with_acp_inference, # noqa: F401
|
||||
)
|
||||
from lerobot.scripts.recording_loop import record_loop
|
||||
from lerobot.teleoperators import ( # noqa: F401
|
||||
TeleoperatorConfig,
|
||||
bi_openarm_leader,
|
||||
@ -110,13 +117,6 @@ from lerobot.teleoperators import ( # noqa: F401
|
||||
so_leader,
|
||||
unitree_g1,
|
||||
)
|
||||
from lerobot.scripts.recording_hil import (
|
||||
ACPInferenceConfig,
|
||||
PolicySyncDualArmExecutor,
|
||||
_capture_policy_runtime_state, # noqa: F401
|
||||
_predict_policy_action_with_acp_inference, # noqa: F401
|
||||
)
|
||||
from lerobot.scripts.recording_loop import record_loop
|
||||
from lerobot.utils.constants import ACTION
|
||||
from lerobot.utils.control_utils import (
|
||||
init_keyboard_listener,
|
||||
@ -288,6 +288,7 @@ class RecordConfig:
|
||||
"""This enables the parser to load config from the policy using `--policy.path=local/dir`"""
|
||||
return ["policy"]
|
||||
|
||||
|
||||
@parser.wrap()
|
||||
def record(cfg: RecordConfig) -> LeRobotDataset:
|
||||
init_logging()
|
||||
@ -325,10 +326,7 @@ def record(cfg: RecordConfig) -> LeRobotDataset:
|
||||
)
|
||||
if cfg.intervention_state_machine_enabled and cfg.policy is not None and cfg.teleop is not None:
|
||||
action_names = dataset_features[ACTION]["names"]
|
||||
if action_names is None:
|
||||
action_names = list(robot.action_features)
|
||||
else:
|
||||
action_names = list(action_names)
|
||||
action_names = list(robot.action_features) if action_names is None else list(action_names)
|
||||
dataset_features["complementary_info.policy_action"] = {
|
||||
"dtype": "float32",
|
||||
"shape": (len(action_names),),
|
||||
@ -524,9 +522,7 @@ def record(cfg: RecordConfig) -> LeRobotDataset:
|
||||
continue
|
||||
|
||||
extra_episode_metadata = (
|
||||
{"episode_success": episode_success}
|
||||
if cfg.enable_episode_outcome_labeling
|
||||
else None
|
||||
{"episode_success": episode_success} if cfg.enable_episode_outcome_labeling else None
|
||||
)
|
||||
dataset.save_episode(extra_episode_metadata=extra_episode_metadata)
|
||||
recorded_episodes += 1
|
||||
|
||||
@ -35,6 +35,9 @@ from lerobot.configs.value import ValueInferencePipelineConfig
|
||||
from lerobot.datasets.lerobot_dataset import LeRobotDataset
|
||||
from lerobot.datasets.utils import load_info, write_info
|
||||
from lerobot.policies.factory import make_policy, make_pre_post_processors
|
||||
from lerobot.scripts.value_infer_viz import (
|
||||
_export_overlay_videos,
|
||||
)
|
||||
from lerobot.utils.constants import (
|
||||
CHECKPOINTS_DIR,
|
||||
LAST_CHECKPOINT_LINK,
|
||||
@ -44,11 +47,6 @@ from lerobot.utils.import_utils import register_third_party_plugins
|
||||
from lerobot.utils.random_utils import set_seed
|
||||
from lerobot.utils.recording_annotations import EPISODE_SUCCESS, resolve_episode_success_label
|
||||
from lerobot.utils.utils import init_logging, inside_slurm
|
||||
from lerobot.scripts.value_infer_viz import (
|
||||
_export_overlay_videos,
|
||||
_get_episode_value_bounds,
|
||||
_get_video_encode_options,
|
||||
)
|
||||
from lerobot.values.pistar06.configuration_pistar06 import Pistar06Config
|
||||
from lerobot.values.pistar06.modeling_pistar06 import (
|
||||
EpisodeTargetInfo,
|
||||
@ -310,8 +308,8 @@ def _binarize_advantages(
|
||||
|
||||
for i in range(advantages.shape[0]):
|
||||
task_idx = int(task_indices[i])
|
||||
thr = thresholds[task_idx]
|
||||
indicators[i] = 1 if float(advantages[i]) >= thr else 0
|
||||
threshold = thresholds[task_idx]
|
||||
indicators[i] = 1 if float(advantages[i]) >= threshold else 0
|
||||
|
||||
if force_intervention_positive:
|
||||
intervention_mask = interventions.astype(np.float32) > 0.5
|
||||
|
||||
@ -52,7 +52,9 @@ def update_policy(
|
||||
if grad_clip_norm > 0:
|
||||
grad_norm = accelerator.clip_grad_norm_(policy.parameters(), grad_clip_norm)
|
||||
else:
|
||||
grad_norm = torch.nn.utils.clip_grad_norm_(policy.parameters(), float("inf"), error_if_nonfinite=False)
|
||||
grad_norm = torch.nn.utils.clip_grad_norm_(
|
||||
policy.parameters(), float("inf"), error_if_nonfinite=False
|
||||
)
|
||||
|
||||
with lock if lock is not None else nullcontext():
|
||||
optimizer.step()
|
||||
|
||||
@ -14,7 +14,6 @@
|
||||
|
||||
"""Human-in-loop recording helpers used by `lerobot_record.py`."""
|
||||
|
||||
import logging
|
||||
from collections import deque
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from copy import deepcopy
|
||||
@ -53,7 +52,9 @@ def _get_torch_rng_state(device: torch.device) -> tuple[torch.Tensor, torch.Tens
|
||||
return cpu_state, cuda_state
|
||||
|
||||
|
||||
def _set_torch_rng_state(device: torch.device, cpu_state: torch.Tensor, cuda_state: torch.Tensor | None) -> None:
|
||||
def _set_torch_rng_state(
|
||||
device: torch.device, cpu_state: torch.Tensor, cuda_state: torch.Tensor | None
|
||||
) -> None:
|
||||
torch.set_rng_state(cpu_state)
|
||||
if device.type == "cuda" and cuda_state is not None:
|
||||
torch.cuda.set_rng_state(cuda_state, device)
|
||||
|
||||
@ -35,10 +35,10 @@ from lerobot.processor import (
|
||||
)
|
||||
from lerobot.robots import Robot
|
||||
from lerobot.scripts.recording_hil import (
|
||||
ACPInferenceConfig,
|
||||
INTERVENTION_STATE_ACTIVE,
|
||||
INTERVENTION_STATE_POLICY,
|
||||
INTERVENTION_STATE_RELEASE,
|
||||
ACPInferenceConfig,
|
||||
PolicySyncDualArmExecutor,
|
||||
_capture_policy_runtime_state,
|
||||
_predict_policy_action_with_acp_inference,
|
||||
@ -155,8 +155,8 @@ def record_loop(
|
||||
action_feature_names = list(robot.action_features.keys())
|
||||
else:
|
||||
action_feature_names = list(robot.action_features)
|
||||
zero_policy_action = {name: 0.0 for name in action_feature_names}
|
||||
has_teleop = isinstance(teleop, Teleoperator) or isinstance(teleop, list)
|
||||
zero_policy_action = dict.fromkeys(action_feature_names, 0.0)
|
||||
has_teleop = isinstance(teleop, (Teleoperator, list))
|
||||
intervention_enabled = intervention_state_machine_enabled and policy is not None and has_teleop
|
||||
intervention_state = INTERVENTION_STATE_POLICY
|
||||
last_teleop_action: RobotAction | None = None
|
||||
@ -282,8 +282,12 @@ def record_loop(
|
||||
# Get action from policy and/or teleop
|
||||
act_processed_policy: RobotAction | None = None
|
||||
act_processed_teleop: RobotAction | None = None
|
||||
if policy is not None and preprocessor is not None and postprocessor is not None:
|
||||
if not (intervention_enabled and intervention_state == INTERVENTION_STATE_ACTIVE):
|
||||
if (
|
||||
policy is not None
|
||||
and preprocessor is not None
|
||||
and postprocessor is not None
|
||||
and not (intervention_enabled and intervention_state == INTERVENTION_STATE_ACTIVE)
|
||||
):
|
||||
policy_action = _predict_policy_action_with_acp_inference(
|
||||
observation_frame=observation_frame,
|
||||
policy=policy,
|
||||
@ -325,7 +329,9 @@ def record_loop(
|
||||
last_teleop_action = act_processed_teleop
|
||||
teleop_fallback_warned = False
|
||||
|
||||
policy_action_for_storage = act_processed_policy if act_processed_policy is not None else zero_policy_action
|
||||
policy_action_for_storage = (
|
||||
act_processed_policy if act_processed_policy is not None else zero_policy_action
|
||||
)
|
||||
|
||||
is_intervention = 0.0
|
||||
if intervention_enabled and intervention_state == INTERVENTION_STATE_ACTIVE:
|
||||
@ -367,12 +373,14 @@ def record_loop(
|
||||
if policy_sync_executor is not None and selected_from_policy:
|
||||
_sent_action = run_with_connection_retry(
|
||||
"policy_sync_executor.send_action",
|
||||
lambda: policy_sync_executor.send_action(robot_action_to_send),
|
||||
lambda robot_action_to_send=robot_action_to_send: policy_sync_executor.send_action(
|
||||
robot_action_to_send
|
||||
),
|
||||
)
|
||||
else:
|
||||
_sent_action = run_with_connection_retry(
|
||||
"robot.send_action",
|
||||
lambda: robot.send_action(robot_action_to_send),
|
||||
lambda robot_action_to_send=robot_action_to_send: robot.send_action(robot_action_to_send),
|
||||
)
|
||||
|
||||
# Write to dataset
|
||||
|
||||
@ -116,15 +116,11 @@ class BiSOLeader(Teleoperator):
|
||||
def send_feedback(self, feedback: dict[str, float]) -> None:
|
||||
# Remove "left_" prefix
|
||||
left_feedback = {
|
||||
key.removeprefix("left_"): value
|
||||
for key, value in feedback.items()
|
||||
if key.startswith("left_")
|
||||
key.removeprefix("left_"): value for key, value in feedback.items() if key.startswith("left_")
|
||||
}
|
||||
# Remove "right_" prefix
|
||||
right_feedback = {
|
||||
key.removeprefix("right_"): value
|
||||
for key, value in feedback.items()
|
||||
if key.startswith("right_")
|
||||
key.removeprefix("right_"): value for key, value in feedback.items() if key.startswith("right_")
|
||||
}
|
||||
|
||||
self.left_arm.send_feedback(left_feedback)
|
||||
|
||||
@ -165,9 +165,7 @@ class SOLeader(Teleoperator):
|
||||
# For phase-A dual-arm execution, reuse leader as a commanded arm by
|
||||
# mapping `{joint}.pos` to motor goal positions.
|
||||
self.set_manual_control(False)
|
||||
goal_pos = {
|
||||
key.removesuffix(".pos"): val for key, val in feedback.items() if key.endswith(".pos")
|
||||
}
|
||||
goal_pos = {key.removesuffix(".pos"): val for key, val in feedback.items() if key.endswith(".pos")}
|
||||
if not goal_pos:
|
||||
return
|
||||
self.bus.sync_write("Goal_Position", goal_pos)
|
||||
|
||||
@ -103,4 +103,3 @@ def resolve_collector_policy_id(
|
||||
if intervention_enabled:
|
||||
return human_id if is_intervention else policy_id
|
||||
return policy_id if selected_from_policy else human_id
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ from typing import TYPE_CHECKING, Any
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
import torch.nn.functional as functional
|
||||
from huggingface_hub import hf_hub_download
|
||||
from huggingface_hub.constants import SAFETENSORS_SINGLE_FILE
|
||||
from huggingface_hub.errors import HfHubHTTPError
|
||||
@ -78,7 +78,7 @@ def project_values_to_bins(values: torch.Tensor, bin_centers: torch.Tensor) -> t
|
||||
|
||||
|
||||
def expected_value_from_logits(logits: torch.Tensor, bin_centers: torch.Tensor) -> torch.Tensor:
|
||||
probs = F.softmax(logits, dim=-1)
|
||||
probs = functional.softmax(logits, dim=-1)
|
||||
return (probs * bin_centers).sum(dim=-1)
|
||||
|
||||
|
||||
@ -198,13 +198,13 @@ def _resolve_image_size(image_processor: Any) -> tuple[int, int]:
|
||||
return 384, 384
|
||||
|
||||
|
||||
def _resolve_norm_stats(image_processor: Any) -> tuple[tuple[float, float, float], tuple[float, float, float]]:
|
||||
def _resolve_norm_stats(
|
||||
image_processor: Any,
|
||||
) -> tuple[tuple[float, float, float], tuple[float, float, float]]:
|
||||
mean_raw = getattr(image_processor, "image_mean", [0.5, 0.5, 0.5])
|
||||
std_raw = getattr(image_processor, "image_std", [0.5, 0.5, 0.5])
|
||||
if len(mean_raw) != 3 or len(std_raw) != 3:
|
||||
raise ValueError(
|
||||
f"Expected RGB normalization stats of len=3, got mean={mean_raw} std={std_raw}."
|
||||
)
|
||||
raise ValueError(f"Expected RGB normalization stats of len=3, got mean={mean_raw} std={std_raw}.")
|
||||
mean = (float(mean_raw[0]), float(mean_raw[1]), float(mean_raw[2]))
|
||||
std = (float(std_raw[0]), float(std_raw[1]), float(std_raw[2]))
|
||||
if any(v <= 0 for v in std):
|
||||
@ -367,7 +367,7 @@ class Pistar06Model(nn.Module):
|
||||
|
||||
flat_images = images.view(bsize * num_cameras, *images.shape[2:])
|
||||
if flat_images.shape[-2:] != self.image_resolution:
|
||||
flat_images = F.interpolate(
|
||||
flat_images = functional.interpolate(
|
||||
flat_images,
|
||||
size=self.image_resolution,
|
||||
mode="bilinear",
|
||||
@ -435,7 +435,9 @@ class Pistar06Model(nn.Module):
|
||||
|
||||
language_context = torch.no_grad() if self.cfg.freeze_language_model else nullcontext()
|
||||
with language_context:
|
||||
language_features = self._encode_language(input_ids=input_ids, attention_mask=language_mask.long())
|
||||
language_features = self._encode_language(
|
||||
input_ids=input_ids, attention_mask=language_mask.long()
|
||||
)
|
||||
|
||||
feature_dtype = torch.float32
|
||||
image_features = image_features.to(dtype=feature_dtype)
|
||||
@ -445,7 +447,9 @@ class Pistar06Model(nn.Module):
|
||||
camera_token_mask = image_attention_mask.unsqueeze(-1).to(dtype=image_tokens.dtype)
|
||||
image_tokens = image_tokens * camera_token_mask
|
||||
|
||||
camera_denominator = image_attention_mask.sum(dim=1, keepdim=True).to(dtype=image_tokens.dtype).clamp_min(1.0)
|
||||
camera_denominator = (
|
||||
image_attention_mask.sum(dim=1, keepdim=True).to(dtype=image_tokens.dtype).clamp_min(1.0)
|
||||
)
|
||||
image_pooled = image_tokens.sum(dim=1) / camera_denominator
|
||||
language_token = self.language_projector(language_features)
|
||||
|
||||
@ -743,7 +747,7 @@ class Pistar06Policy(PreTrainedPolicy):
|
||||
|
||||
bin_centers = self.bin_centers.to(device=device)
|
||||
soft_target = project_values_to_bins(value_target, bin_centers)
|
||||
log_probs = F.log_softmax(logits, dim=-1)
|
||||
log_probs = functional.log_softmax(logits, dim=-1)
|
||||
per_sample_loss = -(soft_target * log_probs).sum(dim=-1)
|
||||
|
||||
sample_weight = None
|
||||
@ -769,13 +773,12 @@ class Pistar06Policy(PreTrainedPolicy):
|
||||
pred_value = expected_value_from_logits(logits, bin_centers)
|
||||
value_mae = (pred_value - value_target).abs().mean()
|
||||
|
||||
if reduction == "none":
|
||||
loss = per_sample_loss
|
||||
else:
|
||||
loss = per_sample_loss.mean()
|
||||
loss = per_sample_loss if reduction == "none" else per_sample_loss.mean()
|
||||
|
||||
loss_dict = {
|
||||
"loss": float(loss.mean().detach().item()) if reduction == "none" else float(loss.detach().item()),
|
||||
"loss": float(loss.mean().detach().item())
|
||||
if reduction == "none"
|
||||
else float(loss.detach().item()),
|
||||
"value_mae": float(value_mae.detach().item()),
|
||||
}
|
||||
if sample_weight is not None:
|
||||
|
||||
@ -8,7 +8,7 @@ from typing import Any
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
import torch.nn.functional as functional
|
||||
from torch import Tensor
|
||||
|
||||
from lerobot.configs.types import PipelineFeatureType, PolicyFeature
|
||||
@ -39,7 +39,7 @@ PISTAR06_IMAGE_MASK_KEY = "observation.pistar06.image_attention_mask"
|
||||
def _pad_last_dim(vector: Tensor, new_dim: int) -> Tensor:
|
||||
if vector.shape[-1] >= new_dim:
|
||||
return vector
|
||||
return F.pad(vector, (0, new_dim - vector.shape[-1]))
|
||||
return functional.pad(vector, (0, new_dim - vector.shape[-1]))
|
||||
|
||||
|
||||
@ProcessorStepRegistry.register(name="pistar06_prepare_task_prompt")
|
||||
@ -216,7 +216,7 @@ def make_pistar06_pre_post_processors(
|
||||
]:
|
||||
camera_features = list(config.camera_features)
|
||||
if not camera_features:
|
||||
camera_features = [k for k in (config.input_features or {}).keys() if k.startswith(OBS_IMAGES)]
|
||||
camera_features = [k for k in (config.input_features or {}) if k.startswith(OBS_IMAGES)]
|
||||
|
||||
input_steps: list[ProcessorStep] = [
|
||||
RenameObservationsProcessorStep(rename_map={}),
|
||||
|
||||
@ -729,7 +729,9 @@ def test_delete_episodes_preserves_extra_episode_metadata(tmp_path, empty_lerobo
|
||||
)
|
||||
|
||||
assert "episode_success" in new_dataset.meta.episodes.column_names
|
||||
assert [new_dataset.meta.episodes[i]["episode_success"] for i in range(new_dataset.meta.total_episodes)] == [
|
||||
assert [
|
||||
new_dataset.meta.episodes[i]["episode_success"] for i in range(new_dataset.meta.total_episodes)
|
||||
] == [
|
||||
"success",
|
||||
"success",
|
||||
]
|
||||
|
||||
@ -15,9 +15,8 @@
|
||||
# limitations under the License.
|
||||
|
||||
import json
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from collections import deque
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
@ -25,12 +24,12 @@ import torch
|
||||
|
||||
from lerobot.datasets.lerobot_dataset import LeRobotDataset
|
||||
from lerobot.scripts.lerobot_calibrate import CalibrateConfig, calibrate
|
||||
from lerobot.scripts.lerobot_human_inloop_record import human_inloop_record
|
||||
from lerobot.scripts.lerobot_human_inloop_record import (
|
||||
_HumanInloopFailureResetController,
|
||||
_load_failure_reset_pose,
|
||||
_save_failure_reset_pose,
|
||||
_slow_reset_all_arms_to_pose,
|
||||
human_inloop_record,
|
||||
)
|
||||
from lerobot.scripts.lerobot_record import (
|
||||
ACPInferenceConfig,
|
||||
@ -39,8 +38,8 @@ from lerobot.scripts.lerobot_record import (
|
||||
RecordConfig,
|
||||
_capture_policy_runtime_state,
|
||||
_predict_policy_action_with_acp_inference,
|
||||
record_loop,
|
||||
record,
|
||||
record_loop,
|
||||
)
|
||||
from lerobot.scripts.lerobot_replay import DatasetReplayConfig, ReplayConfig, replay
|
||||
from lerobot.scripts.lerobot_teleoperate import TeleoperateConfig, teleoperate
|
||||
@ -211,9 +210,7 @@ def test_record_loop_sets_leader_manual_control_during_reset():
|
||||
|
||||
|
||||
def test_save_and_load_failure_reset_pose(tmp_path):
|
||||
robot = MockRobot(
|
||||
MockRobotConfig(n_motors=2, random_values=False, static_values=[12.5, -3.0])
|
||||
)
|
||||
robot = MockRobot(MockRobotConfig(n_motors=2, random_values=False, static_values=[12.5, -3.0]))
|
||||
robot.connect()
|
||||
pose_path = tmp_path / "failure_reset_pose.json"
|
||||
|
||||
|
||||
@ -9,7 +9,9 @@ def test_contiguous_distributed_eval_sampler_has_contiguous_shards_with_tail_pad
|
||||
|
||||
shards: list[list[int]] = []
|
||||
for rank in range(world_size):
|
||||
sampler = ContiguousDistributedEvalSampler(dataset_size=dataset_size, num_replicas=world_size, rank=rank)
|
||||
sampler = ContiguousDistributedEvalSampler(
|
||||
dataset_size=dataset_size, num_replicas=world_size, rank=rank
|
||||
)
|
||||
shard = list(iter(sampler))
|
||||
shards.append(shard)
|
||||
assert len(shard) == len(sampler) == 4
|
||||
@ -30,7 +32,9 @@ def test_contiguous_distributed_eval_sampler_handles_more_ranks_than_samples():
|
||||
|
||||
shards: list[list[int]] = []
|
||||
for rank in range(world_size):
|
||||
sampler = ContiguousDistributedEvalSampler(dataset_size=dataset_size, num_replicas=world_size, rank=rank)
|
||||
sampler = ContiguousDistributedEvalSampler(
|
||||
dataset_size=dataset_size, num_replicas=world_size, rank=rank
|
||||
)
|
||||
shard = list(iter(sampler))
|
||||
shards.append(shard)
|
||||
assert len(shard) == len(sampler) == 1
|
||||
|
||||
@ -13,8 +13,7 @@ from lerobot.configs.value import (
|
||||
ValueInferencePipelineConfig,
|
||||
ValueInferenceVizConfig,
|
||||
)
|
||||
from lerobot.scripts import lerobot_value_infer as value_infer
|
||||
from lerobot.scripts import value_infer_viz
|
||||
from lerobot.scripts import lerobot_value_infer as value_infer, value_infer_viz
|
||||
|
||||
|
||||
class _FakeHFDataset:
|
||||
|
||||
@ -10,8 +10,6 @@ from torch import nn
|
||||
|
||||
import lerobot.processor.tokenizer_processor as tokenizer_processor
|
||||
import lerobot.values.pistar06.modeling_pistar06 as pistar06_modeling
|
||||
import lerobot.values.pistar06.processor_pistar06 as pistar06_processor
|
||||
from lerobot.configs.value_train import ValueTargetsConfig
|
||||
from lerobot.utils.constants import OBS_LANGUAGE_ATTENTION_MASK, OBS_LANGUAGE_TOKENS, OBS_STATE
|
||||
from lerobot.values.pistar06.configuration_pistar06 import Pistar06Config
|
||||
from lerobot.values.pistar06.modeling_pistar06 import (
|
||||
@ -95,10 +93,7 @@ class _DummyAutoModel:
|
||||
@classmethod
|
||||
def from_pretrained(cls, repo_id, **kwargs):
|
||||
output_loading_info = bool(kwargs.pop("output_loading_info", False))
|
||||
if "siglip" in repo_id.lower():
|
||||
model = _DummyVisionModel()
|
||||
else:
|
||||
model = _DummyLanguageModel()
|
||||
model = _DummyVisionModel() if "siglip" in repo_id.lower() else _DummyLanguageModel()
|
||||
if output_loading_info:
|
||||
return model, {"missing_keys": [], "unexpected_keys": [], "mismatched_keys": []}
|
||||
return model
|
||||
|
||||
在新工单中引用
屏蔽一个用户