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)
这个提交包含在:
Elvin
2026-03-04 11:02:06 +08:00
父节点 8b6a85cf0f
当前提交 c96c678772
共有 26 个文件被更改,包括 143 次插入 和 115 次删除

查看文件

@ -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,22 +282,26 @@ 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):
policy_action = _predict_policy_action_with_acp_inference(
observation_frame=observation_frame,
policy=policy,
device=get_safe_torch_device(policy.config.device),
preprocessor=preprocessor,
postprocessor=postprocessor,
use_amp=policy.config.use_amp,
task=single_task,
robot_type=robot.robot_type,
acp_inference=acp_inference,
cond_runtime_state=cond_policy_runtime_state,
uncond_runtime_state=uncond_policy_runtime_state,
)
act_processed_policy = make_robot_action(policy_action, dataset.features)
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,
device=get_safe_torch_device(policy.config.device),
preprocessor=preprocessor,
postprocessor=postprocessor,
use_amp=policy.config.use_amp,
task=single_task,
robot_type=robot.robot_type,
acp_inference=acp_inference,
cond_runtime_state=cond_policy_runtime_state,
uncond_runtime_state=uncond_policy_runtime_state,
)
act_processed_policy = make_robot_action(policy_action, dataset.features)
if isinstance(teleop, Teleoperator):
act = run_with_connection_retry("teleop.get_action", teleop.get_action)
@ -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