make it work

This commit is contained in:
Jade Choghari
2025-11-20 18:17:20 +01:00
parent 70582ed226
commit 119ee85dab
12 changed files with 57 additions and 8 deletions
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -1,5 +1,5 @@
lerobot-eval \ lerobot-eval \
--policy.path="/raid/jade/models/xvla-lib" \ --policy.path="/raid/jade/models/xvla-libero-new_migrated2" \
--env.type=libero \ --env.type=libero \
--env.task=libero_spatial \ --env.task=libero_spatial \
--env.control_mode=absolute \ --env.control_mode=absolute \
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -244,7 +244,7 @@ class LiberoEnv(gym.Env):
eef_quat = raw_obs.get("robot0_eef_quat") eef_quat = raw_obs.get("robot0_eef_quat")
# rotation matrix from controller # rotation matrix from controller
eef_mat = self._env.robots[0].controller.ee_ori_mat if eef_pos is not None else None eef_mat = self._env.robots[0].controller.ee_ori_mat
gripper_qpos = raw_obs.get("robot0_gripper_qpos") gripper_qpos = raw_obs.get("robot0_gripper_qpos")
gripper_qvel = raw_obs.get("robot0_gripper_qvel") gripper_qvel = raw_obs.get("robot0_gripper_qvel")
joint_pos = raw_obs.get("robot0_joint_pos") joint_pos = raw_obs.get("robot0_joint_pos")
+6
View File
@@ -0,0 +1,6 @@
from lerobot.policies.xvla.processor_xvla import (
XVLAAddDomainIdProcessorStep,
XVLAImageScaleProcessorStep,
XVLARotation6DToAxisAngleProcessorStep,
make_xvla_pre_post_processors,
)
+43
View File
@@ -0,0 +1,43 @@
import numpy as np
import os
# --- CHANGE THESE TWO PATHS ---
dir_a = "/home/jade_choghari/robot/lerobot"
dir_b = "/home/jade_choghari/robot/robot2/lerobot"
# keys = ["input_ids", "image_input", "image_mask", "domain_id", "proprio"]
keys = ["domain_id"]
def load_np(path, key):
file_path = os.path.join(path, f"{key}.npy")
if not os.path.exists(file_path):
raise FileNotFoundError(f"Missing file: {file_path}")
return np.load(file_path)
for k in keys:
print(f"\n===== {k} =====")
a = load_np(dir_a, k)
b = load_np(dir_b, k)
print(a)
print(b)
print("Shapes:", a.shape, b.shape)
same_shape = a.shape == b.shape
print("Same shape:", same_shape)
if not same_shape:
continue
# Allclose for numeric, array_equal for boolean
if a.dtype == bool or b.dtype == bool:
equal = np.array_equal(a, b)
print("Equal:", equal)
# For boolean arrays, diff = xor
diff = np.sum(a ^ b)
print("Num differing elements:", diff)
else:
close = np.allclose(a, b, atol=1e-6, rtol=1e-6)
print("Allclose:", close)
diff = np.max(np.abs(a - b))
print("Max difference:", diff)
+4 -3
View File
@@ -62,6 +62,7 @@ def make_xvla_pre_post_processors(
padding_side=config.tokenizer_padding_side, padding_side=config.tokenizer_padding_side,
), ),
DeviceProcessorStep(device=config.device), DeviceProcessorStep(device=config.device),
XVLAAddDomainIdProcessorStep(),
NormalizerProcessorStep( NormalizerProcessorStep(
features=features, norm_map=config.normalization_mapping, stats=dataset_stats features=features, norm_map=config.normalization_mapping, stats=dataset_stats
), ),
@@ -276,7 +277,7 @@ class XVLAAddDomainIdProcessorStep(ProcessorStep):
device: Device to place the domain_id tensor on (default: "cuda") device: Device to place the domain_id tensor on (default: "cuda")
""" """
domain_id: int = 3 domain_id: int = 0
device: str = "cuda" device: str = "cuda"
def __call__(self, transition: EnvTransition) -> EnvTransition: def __call__(self, transition: EnvTransition) -> EnvTransition:
@@ -293,7 +294,7 @@ class XVLAAddDomainIdProcessorStep(ProcessorStep):
if isinstance(v, torch.Tensor): if isinstance(v, torch.Tensor):
batch_size = v.shape[0] batch_size = v.shape[0]
break break
# Add domain_id tensor # Add domain_id tensor
comp["domain_id"] = torch.tensor([int(self.domain_id)] * batch_size, dtype=torch.long).to(self.device) comp["domain_id"] = torch.tensor([int(self.domain_id)] * batch_size, dtype=torch.long).to(self.device)
@@ -387,7 +388,7 @@ def make_xvla_libero_pre_post_processors(
""" """
pre_processor_steps: list[ProcessorStep] = [] pre_processor_steps: list[ProcessorStep] = []
post_processor_steps: list[ProcessorStep] = [] post_processor_steps: list[ProcessorStep] = []
pre_processor_steps.extend([LiberoProcessorStep(), XVLAImageScaleProcessorStep(), XVLAAddDomainIdProcessorStep()]) pre_processor_steps.extend([LiberoProcessorStep(), XVLAAddDomainIdProcessorStep()])
post_processor_steps.extend([XVLARotation6DToAxisAngleProcessorStep()]) post_processor_steps.extend([XVLARotation6DToAxisAngleProcessorStep()])
return ( return (
PolicyProcessorPipeline[dict[str, Any], dict[str, Any]]( PolicyProcessorPipeline[dict[str, Any], dict[str, Any]](
+1 -1
View File
@@ -338,7 +338,7 @@ class _NormalizationMixin:
return (tensor * std + mean) * 255.0 return (tensor * std + mean) * 255.0
# Normalize # Normalize
return (tensor / 255.0 - mean) / std return (tensor - mean) / std
stats = self._tensor_stats[key] stats = self._tensor_stats[key]
if norm_mode == NormalizationMode.MEAN_STD: if norm_mode == NormalizationMode.MEAN_STD:
+1 -2
View File
@@ -167,10 +167,8 @@ def rollout(
# Infer "task" from attributes of environments. # Infer "task" from attributes of environments.
# TODO: works with SyncVectorEnv but not AsyncVectorEnv # TODO: works with SyncVectorEnv but not AsyncVectorEnv
observation = add_envs_task(env, observation) observation = add_envs_task(env, observation)
# Apply environment-specific preprocessing (e.g., LiberoProcessorStep for LIBERO) # Apply environment-specific preprocessing (e.g., LiberoProcessorStep for LIBERO)
observation = env_preprocessor(observation) observation = env_preprocessor(observation)
observation = preprocessor(observation) observation = preprocessor(observation)
with torch.inference_mode(): with torch.inference_mode():
action = policy.select_action(observation) action = policy.select_action(observation)
@@ -178,6 +176,7 @@ def rollout(
action_transition = {"action": action} action_transition = {"action": action}
action_transition = env_postprocessor(action_transition) action_transition = env_postprocessor(action_transition)
action = action_transition["action"] action = action_transition["action"]
# Convert to CPU / numpy. # Convert to CPU / numpy.
action_numpy: np.ndarray = action.to("cpu").numpy() action_numpy: np.ndarray = action.to("cpu").numpy()
assert action_numpy.ndim == 2, "Action dimensions should be (batch, action_dim)" assert action_numpy.ndim == 2, "Action dimensions should be (batch, action_dim)"