mirror of
https://github.com/huggingface/lerobot.git
synced 2026-07-14 13:31:53 +00:00
fix(evo1): move LIBERO padding into policy processors
This commit is contained in:
+10
-61
@@ -13,7 +13,7 @@ from gymnasium.envs.registration import register, registry as gym_registry
|
||||
from lerobot.configs.types import PolicyFeature
|
||||
from lerobot.envs.configs import EnvConfig, LiberoEnv
|
||||
from lerobot.envs.factory import make_env, make_env_config, make_env_pre_post_processors
|
||||
from lerobot.processor import LiberoActionProcessorStep, LiberoProcessorStep
|
||||
from lerobot.processor import LiberoProcessorStep
|
||||
from lerobot.utils.constants import OBS_PREFIX, OBS_STATE
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -86,38 +86,18 @@ def test_processors_delegation_supports_legacy_override_signature():
|
||||
assert isinstance(post, DataProcessorPipeline)
|
||||
|
||||
|
||||
def test_libero_evo1_processors_use_padded_state_and_env_action_dim():
|
||||
"""EVO1 uses padded LIBERO state features while env actions stay executable."""
|
||||
|
||||
class _Evo1Config:
|
||||
type = "evo1"
|
||||
max_state_dim = 24
|
||||
|
||||
def test_libero_processors_are_policy_agnostic():
|
||||
cfg = LiberoEnv()
|
||||
pre, post = make_env_pre_post_processors(cfg, policy_cfg=_Evo1Config())
|
||||
pre, post = make_env_pre_post_processors(cfg, policy_cfg=object())
|
||||
|
||||
assert isinstance(pre.steps[0], LiberoProcessorStep)
|
||||
assert pre.steps[0].max_state_dim == 24
|
||||
assert isinstance(post.steps[0], LiberoActionProcessorStep)
|
||||
assert post.steps[0].action_dim == cfg.features["action"].shape[0] == 7
|
||||
assert post.steps[0].binarize_gripper is True
|
||||
|
||||
class _OtherConfig:
|
||||
type = "other"
|
||||
|
||||
pre_other, post_other = make_env_pre_post_processors(cfg, policy_cfg=_OtherConfig())
|
||||
assert pre_other.steps[0].max_state_dim is None
|
||||
assert post_other.steps[0].binarize_gripper is False
|
||||
|
||||
cfg.binarize_gripper = False
|
||||
_, post_disabled = make_env_pre_post_processors(cfg, policy_cfg=_Evo1Config())
|
||||
assert post_disabled.steps[0].binarize_gripper is False
|
||||
assert len(post.steps) == 0
|
||||
|
||||
|
||||
def test_libero_processor_pads_state_to_max_dim():
|
||||
step = LiberoProcessorStep(max_state_dim=24)
|
||||
def test_libero_processor_flattens_state_to_raw_8_dim():
|
||||
step = LiberoProcessorStep()
|
||||
observation = {
|
||||
OBS_PREFIX
|
||||
+ "robot_state": {
|
||||
OBS_PREFIX + "robot_state": {
|
||||
"eef": {
|
||||
"pos": torch.tensor([[1.0, 2.0, 3.0]]),
|
||||
"quat": torch.tensor([[0.0, 0.0, 0.0, 1.0]]),
|
||||
@@ -127,39 +107,8 @@ def test_libero_processor_pads_state_to_max_dim():
|
||||
}
|
||||
|
||||
state = step.observation(observation)[OBS_STATE]
|
||||
assert state.shape == (1, 24)
|
||||
assert torch.allclose(state[:, :8], torch.tensor([[1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 4.0, 5.0]]))
|
||||
assert torch.count_nonzero(state[:, 8:]).item() == 0
|
||||
|
||||
|
||||
def test_libero_action_processor_slices_padded_action():
|
||||
step = LiberoActionProcessorStep(action_dim=7)
|
||||
action = torch.arange(2 * 3 * 24, dtype=torch.float32).reshape(2, 3, 24)
|
||||
|
||||
sliced = step.action(action)
|
||||
assert sliced.shape == (2, 3, 7)
|
||||
assert torch.equal(sliced, action[..., :7])
|
||||
|
||||
with pytest.raises(ValueError, match="smaller than action_dim=7"):
|
||||
step.action(torch.zeros(2, 6))
|
||||
|
||||
|
||||
def test_libero_action_processor_can_binarize_gripper():
|
||||
step = LiberoActionProcessorStep(action_dim=7, binarize_gripper=True)
|
||||
action = torch.tensor(
|
||||
[
|
||||
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 0.5, 7.0],
|
||||
[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 0.6, 7.0],
|
||||
],
|
||||
dtype=torch.float32,
|
||||
)
|
||||
|
||||
processed = step.action(action)
|
||||
|
||||
assert processed.shape == (2, 7)
|
||||
assert torch.equal(processed[:, :6], action[:, :6])
|
||||
assert torch.equal(processed[:, 6], torch.tensor([1.0, -1.0]))
|
||||
assert torch.equal(action[:, 6], torch.tensor([0.5, 0.6]))
|
||||
assert state.shape == (1, 8)
|
||||
assert torch.allclose(state, torch.tensor([[1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 4.0, 5.0]]))
|
||||
|
||||
|
||||
def test_base_create_envs():
|
||||
|
||||
Reference in New Issue
Block a user