Download code/probe_policy.py from slava-research/slava-rollouts: direct link, hf CLI and curl.
- Browser
- Download file 1.99 kB
-
https://huggingface.co/datasets/slava-research/slava-rollouts/resolve/main/code/probe_policy.py
- Command line
-
hf download hf://datasets/slava-research/slava-rollouts/code/probe_policy.py
-
curl -L -o probe_policy.py https://huggingface.co/datasets/slava-research/slava-rollouts/resolve/main/code/probe_policy.py
1.99 kB
| """Изолирующий тест: один вызов политики без среды. | |
| Отвечает на единственный вопрос — модель ли тормозит. Среда, рендер и LIBERO | |
| здесь не участвуют вообще; если этот тест быстрый, а прогон стоит, виновата | |
| среда, и наоборот. | |
| """ | |
| import os, sys, time | |
| os.environ.setdefault("MUJOCO_GL", "egl") | |
| import torch | |
| from lerobot.configs.policies import PreTrainedConfig | |
| from lerobot.envs.configs import LiberoEnv as LiberoEnvConfig | |
| from lerobot.policies import make_policy, make_pre_post_processors | |
| CKPT = sys.argv[1] if len(sys.argv) > 1 else "lerobot/pi05_libero_finetuned" | |
| COMPILE = (len(sys.argv) > 2 and sys.argv[2] == "on") | |
| t = time.time() | |
| cfg = PreTrainedConfig.from_pretrained(CKPT) | |
| cfg.pretrained_path = CKPT | |
| cfg.device = "cuda:0" | |
| cfg.n_action_steps = 10 | |
| if hasattr(cfg, "compile_model"): | |
| print("чекпойнт объявляет compile_model =", cfg.compile_model, flush=True) | |
| cfg.compile_model = COMPILE | |
| env_cfg = LiberoEnvConfig(task="libero_spatial", task_ids=[0]) | |
| policy = make_policy(cfg=cfg, env_cfg=env_cfg) | |
| policy.eval() | |
| pre, post = make_pre_post_processors( | |
| policy_cfg=cfg, pretrained_path=CKPT, | |
| preprocessor_overrides={"device_processor": {"device": "cuda:0"}}) | |
| print(f"загрузка политики: {time.time()-t:.1f} с (compile={COMPILE})", flush=True) | |
| obs = { | |
| "observation.images.image": torch.zeros(1, 3, 256, 256), | |
| "observation.images.image2": torch.zeros(1, 3, 256, 256), | |
| "observation.state": torch.zeros(1, 8), | |
| "task": ["pick up the black bowl"], | |
| } | |
| with torch.no_grad(): | |
| for i in range(12): | |
| t0 = time.time() | |
| a = policy.select_action(pre(obs)) | |
| torch.cuda.synchronize() | |
| print(f"вызов {i}: {time.time()-t0:.3f} с, действие {tuple(a.shape)}", flush=True) | |
| print("ПРОБА ЗАВЕРШЕНА", flush=True) | |