snapshot: sync mint main from current workspace 2026-03-03 16:32:56 +0800

这个提交包含在:
Elvin
2026-03-03 16:32:56 +08:00
当前提交 908eb4bbbc
共有 677 个文件被更改,包括 167208 次插入 和 0 次删除

查看文件

@ -0,0 +1,157 @@
#!/usr/bin/env python
import pytest
import torch
from torch.utils.data import DataLoader
from lerobot.configs.train import ACPConfig
from lerobot.datasets.lerobot_dataset import LeRobotDataset
from lerobot.rl.acp_hook import build_acp_raw_batch_hook
def test_acp_hook_accepts_integer_indicators():
hook = build_acp_raw_batch_hook(
ACPConfig(
enable=True,
indicator_field="acp_indicator",
positive_tag="POS",
negative_tag="NEG",
indicator_dropout_prob=0.0,
),
seed=42,
)
batch = {
"task": ["pick bottle", "place bottle"],
"acp_indicator": torch.tensor([1, 0], dtype=torch.int64),
}
out = hook(batch, 0)
assert out["task"] == [
"pick bottle\nPOS",
"place bottle\nNEG",
]
def test_acp_hook_injects_tags():
hook = build_acp_raw_batch_hook(
ACPConfig(
enable=True,
indicator_field="complementary_info.acp_indicator",
positive_tag="POS",
negative_tag="NEG",
indicator_dropout_prob=0.0,
),
seed=42,
)
batch = {
"task": ["pick bottle", "place bottle"],
"complementary_info.acp_indicator": torch.tensor([1, 0], dtype=torch.int64),
}
out = hook(batch, 0)
assert out["task"] == ["pick bottle\nPOS", "place bottle\nNEG"]
def test_acp_hook_dropout_keeps_original_task():
hook = build_acp_raw_batch_hook(
ACPConfig(
enable=True,
indicator_field="complementary_info.acp_indicator",
positive_tag="POS",
negative_tag="NEG",
indicator_dropout_prob=1.0,
),
seed=42,
)
batch = {
"task": ["pick bottle", "place bottle"],
"complementary_info.acp_indicator": torch.tensor([1, 0], dtype=torch.int64),
}
out = hook(batch, 0)
assert out["task"] == ["pick bottle", "place bottle"]
def test_acp_hook_missing_indicator_skips():
hook = build_acp_raw_batch_hook(
ACPConfig(enable=True, indicator_field="missing_field"),
seed=42,
)
batch = {"task": ["pick bottle"]}
with pytest.raises(KeyError, match="missing_field"):
hook(batch, 0)
def test_acp_hook_non_integer_type_raises():
hook = build_acp_raw_batch_hook(
ACPConfig(
enable=True,
indicator_field="acp_indicator",
positive_tag="POS",
negative_tag="NEG",
indicator_dropout_prob=0.0,
),
seed=42,
)
batch = {
"task": ["pick bottle", "place bottle"],
"acp_indicator": torch.tensor([1.0, 0.0], dtype=torch.float32),
}
with pytest.raises(TypeError, match="integer 0/1"):
hook(batch, 0)
def test_acp_hook_non_binary_value_raises():
hook = build_acp_raw_batch_hook(
ACPConfig(
enable=True,
indicator_field="acp_indicator",
positive_tag="POS",
negative_tag="NEG",
indicator_dropout_prob=0.0,
),
seed=42,
)
batch = {
"task": ["pick bottle", "place bottle"],
"acp_indicator": torch.tensor([2, 0], dtype=torch.int64),
}
with pytest.raises(ValueError, match="must be 0 or 1"):
hook(batch, 0)
def _load_real_batch_or_skip(batch_size: int) -> dict:
repo_id = "local/eval_so101_pick_place_bottle_v0"
try:
dataset = LeRobotDataset(repo_id, download_videos=False)
dataloader = DataLoader(dataset, batch_size=batch_size, shuffle=False, num_workers=0)
return next(iter(dataloader))
except Exception as e:
pytest.skip(f"Cannot load local dataset '{repo_id}': {e}")
@pytest.mark.parametrize("batch_size", [1, 3])
def test_acp_hook_with_real_local_dataset_batch(batch_size: int):
batch = _load_real_batch_or_skip(batch_size)
assert "task" in batch
assert "complementary_info.acp_indicator" not in batch
indicators = torch.randint(0, 2, (batch_size,), dtype=torch.int64)
batch["complementary_info.acp_indicator"] = indicators
hook = build_acp_raw_batch_hook(
ACPConfig(
enable=True,
indicator_field="complementary_info.acp_indicator",
positive_tag="POS",
negative_tag="NEG",
indicator_dropout_prob=0.0,
),
seed=42,
)
out = hook(batch, 0)
assert len(out["task"]) == batch_size
for i in range(batch_size):
expected_tag = "POS" if int(indicators[i].item()) == 1 else "NEG"
assert out["task"][i].endswith(expected_tag)