lerobot/tests/test_regression.py

32 lines
1.0 KiB
Python
Raw Normal View History

2024-05-02 01:44:33 +08:00
from pathlib import Path
2024-04-30 17:55:57 +08:00
import pytest
import torch
2024-05-02 01:44:33 +08:00
from safetensors.torch import load_file
2024-04-30 17:55:57 +08:00
2024-05-02 01:44:33 +08:00
from tests.scripts.save_policy_to_safetensor import get_policy_stats
2024-04-30 17:55:57 +08:00
@pytest.mark.parametrize(
2024-05-02 01:44:33 +08:00
"env_name,policy_name",
2024-04-30 17:55:57 +08:00
[
2024-05-02 01:44:33 +08:00
# ("xarm", "tdmpc"),
("pusht", "diffusion"),
2024-05-01 01:23:06 +08:00
("aloha", "act"),
2024-04-30 17:55:57 +08:00
],
)
2024-05-01 01:23:06 +08:00
def test_backward_compatibility(env_name, policy_name):
2024-05-02 01:44:33 +08:00
env_policy_dir = Path("tests/data/save_policy_to_safetensors") / f"{env_name}_{policy_name}"
saved_grad_stats = load_file(env_policy_dir / "grad_stats")
saved_param_stats = load_file(env_policy_dir / "param_stats")
saved_actions = load_file(env_policy_dir / "actions")
grad_stats, param_stats, actions = get_policy_stats(env_name, policy_name)
for key in saved_grad_stats:
assert torch.isclose(grad_stats[key], saved_grad_stats[key]).all()
for key in saved_param_stats:
assert torch.isclose(param_stats[key], saved_param_stats[key]).all()
for key in saved_actions:
assert torch.isclose(actions[key], saved_actions[key]).all()