mirror of
https://github.com/huggingface/lerobot.git
synced 2026-08-08 17:39:44 +00:00
refactor(g05): keep recipe runtime unchanged
This commit is contained in:
@@ -47,17 +47,6 @@ def test_message_turn_requires_a_stream():
|
||||
MessageTurn(role="user", content="${task}")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("dropout", [-0.1, 1.1, float("inf"), float("nan")])
|
||||
def test_message_turn_rejects_invalid_dropout(dropout):
|
||||
with pytest.raises(ValueError, match="between 0 and 1"):
|
||||
MessageTurn(role="user", content="${task}", stream="high_level", dropout=dropout)
|
||||
|
||||
|
||||
def test_message_turn_rejects_non_numeric_dropout():
|
||||
with pytest.raises(TypeError, match="probability"):
|
||||
MessageTurn(role="user", content="${task}", stream="high_level", dropout="half")
|
||||
|
||||
|
||||
def test_message_recipe_requires_at_least_one_target():
|
||||
with pytest.raises(ValueError, match="target"):
|
||||
TrainingRecipe(
|
||||
@@ -163,7 +152,7 @@ def test_from_dict_with_nested_blend():
|
||||
assert isinstance(recipe.blend["a"].messages[0], MessageTurn)
|
||||
|
||||
|
||||
def test_message_dropout_round_trips_from_dict():
|
||||
def test_message_if_present_round_trips_from_dict():
|
||||
recipe = TrainingRecipe.from_dict(
|
||||
{
|
||||
"messages": [
|
||||
@@ -174,13 +163,11 @@ def test_message_dropout_round_trips_from_dict():
|
||||
"stream": "low_level",
|
||||
"target": True,
|
||||
"if_present": "subtask",
|
||||
"dropout": 0.5,
|
||||
},
|
||||
]
|
||||
}
|
||||
)
|
||||
|
||||
assert recipe.messages[1].dropout == 0.5
|
||||
assert recipe.messages[1].if_present == "subtask"
|
||||
|
||||
|
||||
|
||||
@@ -176,35 +176,7 @@ def test_deterministic_blend_sampling():
|
||||
assert first == second
|
||||
|
||||
|
||||
def test_message_dropout_skips_missing_optional_bindings():
|
||||
recipe = TrainingRecipe(
|
||||
messages=[
|
||||
MessageTurn(role="user", content="${task}", stream="low_level"),
|
||||
MessageTurn(
|
||||
role="assistant",
|
||||
content="${subtask}",
|
||||
stream="low_level",
|
||||
target=True,
|
||||
if_present="subtask",
|
||||
dropout=0.5,
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
rendered = render_sample(
|
||||
recipe=recipe,
|
||||
persistent=[],
|
||||
events=[],
|
||||
t=0.0,
|
||||
sample_idx=0,
|
||||
task="pick the cup",
|
||||
)
|
||||
|
||||
assert rendered["messages"] == [{"role": "user", "content": "pick the cup"}]
|
||||
assert rendered["target_message_indices"] == []
|
||||
|
||||
|
||||
def test_g05_dropout_produces_all_bbox_subtask_combinations():
|
||||
def test_g05_recipe_emits_available_bbox_and_subtask():
|
||||
recipe = TrainingRecipe.from_yaml("src/lerobot/configs/recipes/g05_bbox_subtask.yaml")
|
||||
persistent = [persistent_row("assistant", "grasp the cup", "subtask", 0.0)]
|
||||
events = [
|
||||
@@ -216,64 +188,18 @@ def test_g05_dropout_produces_all_bbox_subtask_combinations():
|
||||
}
|
||||
]
|
||||
|
||||
rendered_by_targets = {}
|
||||
for sample_idx in range(100):
|
||||
rendered = render_sample(
|
||||
recipe=recipe,
|
||||
persistent=persistent,
|
||||
events=events,
|
||||
t=0.0,
|
||||
sample_idx=sample_idx,
|
||||
task="pick the cup",
|
||||
)
|
||||
targets = tuple(
|
||||
rendered["messages"][idx]["content"].split(":", 1)[0]
|
||||
for idx in rendered["target_message_indices"]
|
||||
)
|
||||
rendered_by_targets.setdefault(targets, rendered)
|
||||
|
||||
assert set(rendered_by_targets) == {
|
||||
(),
|
||||
("BBoxJSON",),
|
||||
("Subtask",),
|
||||
("BBoxJSON", "Subtask"),
|
||||
}
|
||||
joint = rendered_by_targets[("BBoxJSON", "Subtask")]
|
||||
assert joint["messages"][1]["content"].startswith("BBoxJSON:")
|
||||
assert joint["messages"][2]["content"] == "Subtask: grasp the cup"
|
||||
|
||||
|
||||
def test_message_dropout_is_deterministic_for_sample_index():
|
||||
recipe = TrainingRecipe(
|
||||
messages=[
|
||||
MessageTurn(role="user", content="${task}", stream="low_level"),
|
||||
MessageTurn(
|
||||
role="assistant",
|
||||
content="${subtask}",
|
||||
stream="low_level",
|
||||
target=True,
|
||||
dropout=0.5,
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
first = render_sample(
|
||||
rendered = render_sample(
|
||||
recipe=recipe,
|
||||
persistent=PERSISTENT,
|
||||
events=[],
|
||||
persistent=persistent,
|
||||
events=events,
|
||||
t=0.0,
|
||||
sample_idx=42,
|
||||
sample_idx=0,
|
||||
task="pick the cup",
|
||||
)
|
||||
second = render_sample(
|
||||
recipe=recipe,
|
||||
persistent=PERSISTENT,
|
||||
events=[],
|
||||
t=0.0,
|
||||
sample_idx=42,
|
||||
task="pick the cup",
|
||||
)
|
||||
assert first == second
|
||||
|
||||
assert rendered["target_message_indices"] == [1, 2]
|
||||
assert rendered["messages"][1]["content"].startswith("BBoxJSON:")
|
||||
assert rendered["messages"][2]["content"] == "Subtask: grasp the cup"
|
||||
|
||||
|
||||
def test_emitted_at_filters_vqa_by_camera():
|
||||
|
||||
Reference in New Issue
Block a user