Views
No views yet
1model download ./Alpamayo-R1-10B-4bit
2
3GPU 12G/16G Memory Run able
4
512G Memory is num_frames is 1 ~ 8, over OOM
6
7Transformers is 4.57.5 ( 5.0.0rc not run)
8
9nvidia/Alpamayo-R1-10B 이 대용량 메모리를 요구하고 4bit 로 로딩하여 저장한 모델입니다.
1012G 에서도 실행가능해졌습니다만 주어지는 프레임수는 1~8정도, 그 이상이면 OOM이 떨어집니다.
11트랜스포머 버전 5.0.0rc에서는 동작하지 않습니다.
12
13git clone https://github.com/NVlabs/alpamayo 하고
14cd alpamayo
15pip install . 로 설치해야 합니다만
16
17pyproject.toml을 수정하는게 좋습니다.
18python 3.13을 사용하면 requires-python = "==3.13.*"
19transformers 와 torch를 라인을 제거하고 설치하면 설치된 버전이 교체되지 않습니다.1import torch
2import numpy as np
3from alpamayo_r1.models.alpamayo_r1 import AlpamayoR1
4from alpamayo_r1.load_physical_aiavdataset import load_physical_aiavdataset
5from alpamayo_r1 import helper
6
7model_path = "Alpamayo-R1-10B-4bit"
8model = AlpamayoR1.from_pretrained(model_path, dtype=torch.bfloat16).to("cuda")
9
10processor = helper.get_processor(model.tokenizer)
11
12clip_id = "030c760c-ae38-49aa-9ad8-f5650a545d26"
13print(f"Loading dataset for clip_id: {clip_id}...")
14#need set access token or huggingface-cli login...
15data = load_physical_aiavdataset(clip_id, t0_us=15_100_000,num_frames=1)
16print("Dataset loaded.")
17
18messages = helper.create_message(data["image_frames"].flatten(0, 1))
19
20inputs = processor.apply_chat_template(
21 messages,
22 tokenize=True,
23 add_generation_prompt=False,
24 continue_final_message=True,
25 return_dict=True,
26 return_tensors="pt",
27)
28
29model_inputs = {
30 "tokenized_data": inputs,
31 "ego_history_xyz": data["ego_history_xyz"],
32 "ego_history_rot": data["ego_history_rot"],
33}
34
35model_inputs = helper.to_device(model_inputs, "cuda")
36torch.cuda.manual_seed_all(42)
37with torch.autocast("cuda", dtype=torch.bfloat16):
38 pred_xyz, pred_rot, extra = model.sample_trajectories_from_data_with_vlm_rollout(
39 data=model_inputs,
40 top_p=0.98,
41 temperature=0.6,
42 num_traj_samples=1, # Feel free to raise this for more output trajectories and CoC traces.
43 max_generation_length=256,
44 return_extra=True,
45 )
46
47
48print("Chain-of-Causation (per trajectory):\n", extra["cot"][0])
49gt_xy = data["ego_future_xyz"].cpu()[0, 0, :, :2].T.numpy()
50pred_xy = pred_xyz.cpu().numpy()[0, 0, :, :, :2].transpose(0, 2, 1)
51diff = np.linalg.norm(pred_xy - gt_xy[None, ...], axis=1).mean(-1)
52min_ade = diff.min()
53print("minADE:", min_ade, "meters")
54print(
55 "Note: VLA-reasoning models produce nondeterministic outputs due to trajectory sampling, "
56 "hardware differences, etc. With num_traj_samples=1 (set for GPU memory compatibility), "
57 "variance in minADE is expected. For visual sanity checks, see notebooks/inference.ipynb"
58)1
2
3Chain-of-Causation (per trajectory):
4[['Nudge to the left to pass the stopped truck encroaching into the lane.']]
5minADE: 1.7749525 meters
6Note: VLA-reasoning models produce nondeterministic outputs due to trajectory sampling, hardware differences, etc. With num_traj_samples=1 (set for GPU memory compatibility), variance in minADE is expected. For visual sanity checks, see notebooks/inference.ipynb1#ZeroTime init Base Image(1 photo on load image)
2import torch
3import numpy as np
4from PIL import Image
5from alpamayo_r1.models.alpamayo_r1 import AlpamayoR1
6from alpamayo_r1.load_physical_aiavdataset import load_physical_aiavdataset
7from alpamayo_r1 import helper
8
9num_history_steps = 16 # 과거 스텝 수
10num_future_steps = 64 # 미래 스텝 수
11
12# 더미 위치 데이터 (xyz 좌표)
13ego_history_xyz = torch.zeros((1, 1, num_history_steps, 3)) # (batch, agent, steps, xyz)
14ego_future_xyz = torch.zeros((1, 1, num_future_steps, 3))
15
16# 더미 회전 데이터 (3x3 회전행렬)
17ego_history_rot = torch.eye(3).repeat(1, 1, num_history_steps, 1, 1) # (1,1,steps,3,3)
18ego_future_rot = torch.eye(3).repeat(1, 1, num_future_steps, 1, 1)
19
20print("ego_history_xyz:", ego_history_xyz.shape)
21print("ego_future_xyz:", ego_future_xyz.shape)
22print("ego_history_rot:", ego_history_rot.shape)
23print("ego_future_rot:", ego_future_rot.shape)
24N_cameras = 1
25camera_indices = torch.arange(N_cameras, dtype=torch.long) # (N_cameras,) - long 타입 명시
26
27data={
28 "camera_indices": camera_indices, # (N_cameras,)
29 "ego_history_xyz": ego_history_xyz, # (1, 1, num_history_steps, 3)
30 "ego_history_rot": ego_history_rot, # (1, 1, num_history_steps, 3, 3)
31 "ego_future_xyz": ego_future_xyz, # (1, 1, num_future_steps, 3)
32 "ego_future_rot": ego_future_rot, # (1, 1, num_future_steps, 3, 3)
33# "relative_timestamps": relative_timestamps, # (N_cameras, num_frames)
34# "absolute_timestamps": absolute_timestamps # (N_cameras, num_frames)
35}
36img_path = "IMG_20260116_065921.jpg"
37# 예측하고 싶은 JPG 파일 경로
38image = Image.open(img_path).convert("RGB")
39# helper.create_message는 tensor 입력을 기대하므로 변환
40# PIL Image를 numpy array로 변환 후 float32로 변환
41image_array = np.array(image).astype(np.float32) / 255.0 # 0-1 범위로 정규화
42image_tensor = torch.from_numpy(image_array).unsqueeze(0) # [batch, H, W, C]
43# 메시지 생성
44messages = helper.create_message(image_tensor)
45
46# Example clip ID
47model_path = "Alpamayo-R1-10B-4bit"
48model = AlpamayoR1.from_pretrained(model_path, dtype=torch.bfloat16).to("cuda")
49processor = helper.get_processor(model.tokenizer)
50
51
52
53# 설정값
54
55inputs = processor.apply_chat_template(
56 messages,
57 tokenize=True,
58 add_generation_prompt=False,
59 continue_final_message=True,
60 return_dict=True,
61 return_tensors="pt",
62)
63
64model_inputs = {
65 "tokenized_data": inputs,
66 "ego_history_xyz": data["ego_history_xyz"],
67 "ego_history_rot": data["ego_history_rot"],
68}
69
70model_inputs = helper.to_device(model_inputs, "cuda")
71
72torch.cuda.manual_seed_all(42)
73with torch.autocast("cuda", dtype=torch.bfloat16):
74 pred_xyz, pred_rot, extra = model.sample_trajectories_from_data_with_vlm_rollout(
75 data=model_inputs,
76 top_p=0.98,
77 temperature=0.6,
78 num_traj_samples=1, # Feel free to raise this for more output trajectories and CoC traces.
79 max_generation_length=256,
80 return_extra=True,
81 )
82
83# the size is [batch_size, num_traj_sets, num_traj_samples]
84print("Chain-of-Causation (per trajectory):\n", extra["cot"][0])
85
86gt_xy = data["ego_future_xyz"].cpu()[0, 0, :, :2].T.numpy()
87pred_xy = pred_xyz.cpu().numpy()[0, 0, :, :, :2].transpose(0, 2, 1)
88diff = np.linalg.norm(pred_xy - gt_xy[None, ...], axis=1).mean(-1)
89min_ade = diff.min()
90print("minADE:", min_ade, "meters")
91print(
92 "Note: VLA-reasoning models produce nondeterministic outputs due to trajectory sampling, "
93 "hardware differences, etc. With num_traj_samples=1 (set for GPU memory compatibility), "
94 "variance in minADE is expected. For visual sanity checks, see notebooks/inference.ipynb"
95)1
2Chain-of-Causation (per trajectory):
3 [['Keep lane to continue driving since the lane ahead is clear.']]
4minADE: 0.55852604 meters
5Note: VLA-reasoning models produce nondeterministic outputs due to trajectory sampling, hardware differences, etc. With num_traj_samples=1 (set for GPU memory compatibility), variance in minADE is expected. For visual sanity checks, see notebooks/inference.ipynb
6