[lint] Update lint (#16)
* update lint * update readme * update ruff lint
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import yaml
|
||||
import torch
|
||||
import matplotlib.pyplot as plt
|
||||
from wall_x.model.qwen2_5_based.modeling_qwen2_5_vl_act import Qwen2_5_VLMoEForAction
|
||||
from wall_x.data.load_lerobot_dataset import load_test_dataset, get_data_configs
|
||||
|
||||
@@ -8,20 +9,24 @@ from wall_x.data.load_lerobot_dataset import load_test_dataset, get_data_configs
|
||||
model_path = "path/to/model"
|
||||
action_tokenizer_path = "path/to/action_tokenizer"
|
||||
save_dir = "path/to/plot"
|
||||
model = Qwen2_5_VLMoEForAction.from_pretrained(model_path, action_tokenizer_path=action_tokenizer_path)
|
||||
model = Qwen2_5_VLMoEForAction.from_pretrained(
|
||||
model_path, action_tokenizer_path=action_tokenizer_path
|
||||
)
|
||||
model.eval()
|
||||
model = model.to("cuda")
|
||||
model = model.bfloat16()
|
||||
|
||||
|
||||
def load_config(config_path):
|
||||
"""Load configuration from YAML file."""
|
||||
with open(config_path, "r") as f:
|
||||
config = yaml.load(f, Loader=yaml.FullLoader)
|
||||
|
||||
|
||||
config["data"]["model_type"] = config.get("model_type")
|
||||
|
||||
|
||||
return config
|
||||
|
||||
|
||||
# get test dataloader
|
||||
path = "path/to/config"
|
||||
config = load_config(path)
|
||||
@@ -38,7 +43,7 @@ gt_traj = torch.zeros((total_frames, action_dim))
|
||||
pred_traj = torch.zeros((total_frames, action_dim))
|
||||
|
||||
for idx, batch in enumerate(dataloader):
|
||||
if idx % pred_horizon ==0 and idx + pred_horizon < total_frames:
|
||||
if idx % pred_horizon == 0 and idx + pred_horizon < total_frames:
|
||||
batch = batch.to("cuda")
|
||||
with torch.no_grad():
|
||||
outputs = model(
|
||||
@@ -46,36 +51,36 @@ for idx, batch in enumerate(dataloader):
|
||||
action_dim=action_dim,
|
||||
pred_horizon=pred_horizon,
|
||||
mode="predict",
|
||||
predict_mode="fast"
|
||||
predict_mode="fast",
|
||||
)
|
||||
pred_traj[idx : idx + pred_horizon] = outputs['predict_action'].detach().cpu()
|
||||
|
||||
pred_traj[idx : idx + pred_horizon] = outputs["predict_action"].detach().cpu()
|
||||
|
||||
# Denormalize ground truth actions
|
||||
gt_action_chunk = batch['action_chunk'][:, :, :action_dim]
|
||||
gt_action_chunk = batch["action_chunk"][:, :, :action_dim]
|
||||
dof_mask = batch["dof_mask"].to(gt_action_chunk.dtype)
|
||||
denormalized_gt = model.action_preprocessor.normalizer_action.unnormalize_data(gt_action_chunk, ["x2_normal"], dof_mask)
|
||||
denormalized_gt = model.action_preprocessor.normalizer_action.unnormalize_data(
|
||||
gt_action_chunk, ["x2_normal"], dof_mask
|
||||
)
|
||||
gt_traj[idx : idx + pred_horizon] = denormalized_gt.detach().cpu()
|
||||
|
||||
|
||||
|
||||
gt_traj_np = gt_traj.numpy()
|
||||
pred_traj_np = pred_traj.numpy()
|
||||
|
||||
timesteps = gt_traj.shape[0]
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
fig, axs = plt.subplots(action_dim, 1, figsize=(15, 5 * action_dim), sharex=True)
|
||||
fig.suptitle(f'Action Comparison for lerobot', fontsize=16)
|
||||
fig.suptitle("Action Comparison for lerobot", fontsize=16)
|
||||
|
||||
for i in range(action_dim):
|
||||
axs[i].plot(range(timesteps), gt_traj_np[:, i], label='Ground Truth')
|
||||
axs[i].plot(range(timesteps), pred_traj_np[:, i], label='Prediction')
|
||||
axs[i].set_ylabel(f'Action Dim {i+1}')
|
||||
axs[i].plot(range(timesteps), gt_traj_np[:, i], label="Ground Truth")
|
||||
axs[i].plot(range(timesteps), pred_traj_np[:, i], label="Prediction")
|
||||
axs[i].set_ylabel(f"Action Dim {i+1}")
|
||||
axs[i].legend()
|
||||
axs[i].grid(True)
|
||||
|
||||
axs[-1].set_xlabel('Timestep')
|
||||
|
||||
axs[-1].set_xlabel("Timestep")
|
||||
plt.tight_layout(rect=[0, 0.03, 1, 0.95])
|
||||
os.makedirs(save_dir, exist_ok=True)
|
||||
plt.savefig(os.path.join(save_dir, f"lerobot_comparison.png"))
|
||||
plt.savefig(os.path.join(save_dir, "lerobot_comparison.png"))
|
||||
plt.close()
|
||||
|
||||
+16
-11
@@ -10,10 +10,14 @@ batch_size = 1
|
||||
seq_length = 50
|
||||
|
||||
torch.manual_seed(0)
|
||||
fake_input_ids = torch.randint(0, len(model.processor.tokenizer), (batch_size, seq_length), dtype=torch.long)
|
||||
fake_input_ids = torch.randint(
|
||||
0, len(model.processor.tokenizer), (batch_size, seq_length), dtype=torch.long
|
||||
)
|
||||
fake_attention_mask = torch.ones((batch_size, seq_length), dtype=torch.long)
|
||||
fake_moe_token_types = torch.zeros((batch_size, seq_length), dtype=torch.long)
|
||||
fake_position_ids = torch.arange(seq_length, dtype=torch.long).unsqueeze(0).expand(batch_size, -1)
|
||||
fake_position_ids = (
|
||||
torch.arange(seq_length, dtype=torch.long).unsqueeze(0).expand(batch_size, -1)
|
||||
)
|
||||
fake_proprioception = torch.randn((batch_size, 1, 20), dtype=torch.float32)
|
||||
fake_agent_pos_mask = torch.ones((batch_size, 1, 20), dtype=torch.float32)
|
||||
fake_dof_mask = torch.ones((batch_size, 32, 20), dtype=torch.float32)
|
||||
@@ -44,37 +48,38 @@ try:
|
||||
agent_pos_mask=fake_agent_pos_mask,
|
||||
dof_mask=fake_dof_mask,
|
||||
dataset_names=fake_dataset_names,
|
||||
mode="validate"
|
||||
mode="validate",
|
||||
)
|
||||
|
||||
|
||||
print("✅ Fake inference test successful!")
|
||||
print(f"Output logits shape: {outputs.logits.shape}")
|
||||
print(f"Output logits dtype: {outputs.logits.dtype}")
|
||||
print(f"Output logits device: {outputs.logits.device}")
|
||||
|
||||
|
||||
# Check if output is reasonable
|
||||
if outputs.logits.shape == (batch_size, seq_length, model.config.vocab_size):
|
||||
print("✅ Output shape correct")
|
||||
else:
|
||||
print("❌ Output shape incorrect")
|
||||
|
||||
|
||||
if not torch.isnan(outputs.logits).any():
|
||||
print("✅ Output contains no NaN values")
|
||||
else:
|
||||
print("❌ Output contains NaN values")
|
||||
|
||||
|
||||
if not torch.isinf(outputs.logits).any():
|
||||
print("✅ Output contains no infinity values")
|
||||
else:
|
||||
print("❌ Output contains infinity values")
|
||||
|
||||
print(f"Output logits statistics:")
|
||||
|
||||
print("Output logits statistics:")
|
||||
print(f" Min value: {outputs.logits.min().item():.4f}")
|
||||
print(f" Max value: {outputs.logits.max().item():.4f}")
|
||||
print(f" Mean: {outputs.logits.mean().item():.4f}")
|
||||
print(f" Standard deviation: {outputs.logits.std().item():.4f}")
|
||||
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Fake inference test failed: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
traceback.print_exc()
|
||||
|
||||
@@ -8,13 +8,15 @@ use_fast_tokenizer = True
|
||||
processor = AutoProcessor.from_pretrained(processor_path, use_fast=True)
|
||||
processor.tokenizer.padding_side = "left"
|
||||
|
||||
action_tokenizer = AutoProcessor.from_pretrained(action_tokenizer_path, trust_remote_code=True)
|
||||
action_tokenizer = AutoProcessor.from_pretrained(
|
||||
action_tokenizer_path, trust_remote_code=True
|
||||
)
|
||||
|
||||
new_tokens = ["<|propri|>", "<|action|>"]
|
||||
new_tokens += [f"<|action_token_{i}|>" for i in range(action_tokenizer.vocab_size)]
|
||||
num_added_tokens = processor.tokenizer.add_tokens(new_tokens)
|
||||
|
||||
begin_idx_token = f"<|action_token_0|>"
|
||||
begin_idx_token = "<|action_token_0|>"
|
||||
token_id = processor.tokenizer.convert_tokens_to_ids(begin_idx_token)
|
||||
processor.tokenizer.init_kwargs["action_token_start_index"] = token_id
|
||||
processor.tokenizer.init_kwargs["action_token_vocab_size"] = action_tokenizer.vocab_size
|
||||
@@ -22,4 +24,3 @@ processor.tokenizer.init_kwargs["action_token_vocab_size"] = action_tokenizer.vo
|
||||
new_tokenizer_dir = "/path/to/new_tokenizer"
|
||||
os.makedirs(new_tokenizer_dir, exist_ok=True)
|
||||
processor.save_pretrained(new_tokenizer_dir)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user