NVlabs/alpamayo 教學手冊

一份「拿到 repo → 跑出第一條軌跡 → 接入既有 pipeline」全程指引。 對應論文:Alpamayo-R1: Bridging Reasoning and Action Prediction for Generalizable Autonomous Driving in the Long Tail(NVIDIA, 2025)

目錄

  1. 專案定位
  2. 安裝指南
  3. 核心架構解析
  4. Helper Scripts 詳細用法
  5. 應用場景
  6. 資安掃描報告
  7. FAQ
  8. 進階技巧
  9. 整合進其他工作流
  10. 重點摘要 Checklist
  11. 進一步閱讀

1. 專案定位

1.1 一句話定位

Alpamayo 1 是 NVIDIA Labs 釋出的 10B 參數 Vision-Language-Action (VLA) end-to-end 自動駕駛 reference model。 它把「多攝影機影像 + 自車歷史軌跡」吃進去,吐出「自然語言推理(Chain-of-Causation)+ 6.4 秒 64 個 waypoints 未來軌跡」,是業界第一個把 reasoning 與 trajectory prediction 綁在同一個 VLA 模型內、並完整開源的案例。

1.2 命名脈絡

Alpamayo 是秘魯安第斯山脈一座 5,947 公尺的雪山,因近乎完美的金字塔狀冰面 fluted face 被譽為「世界最美的山」之一。NVlabs 把 robotics / Physical AI 旗艦級研究專案以雪山命名(後續 1.5 版延續同名),與 NVIDIA Production 線(Nemotron、NeMo、NIM)的「品牌化」命名風格刻意區隔——一邊是研究 codebase,一邊是 production-ready toolkit。

1.3 與 NVIDIA Physical AI 全家桶的關係

Alpamayo 不是孤立專案,而是 NVIDIA 在 2026 年「Physical AI」戰略下的一塊拼圖。下面是它和兄弟專案的角色分工:

專案角色與 alpamayo 的關係
CosmosWorld Foundation Models(影像/影片 generative world model)、合成資料生成alpamayo 訓練資料來源之一;Cosmos-Reason VLM 是 alpamayo 的 backbone(見 README “Vision-Language-Action architecture: Cosmos-Reason backbone + action expert”)
NemotronNVIDIA LLM 家族(Llama Nemotron / Nemotron-Mini / Nemotron Vision);production-ready、Apache-2.0、NIM 部署角色互補:Nemotron 提供 high-level reasoning LLM(如 fleet operator 對話、自然語言指令解譯),alpamayo 負責「看影像 → 動作」的最後一哩。兩者可組合成「Nemotron 為大腦、Alpamayo 為小腦」的 AV pipeline。詳見本檔 §9.2。
NVlabs/Nemotron-Labs-DiffusionNVlabs 線 diffusion model 研究(可能涵蓋 image / video / action diffusion)alpamayo 的 action expert 就是 flow-matching diffusion model(見 src/alpamayo_r1/diffusion/flow_matching.py);很可能共用底層 diffusion infra 或彼此引用
Isaac Sim / Isaac LabNVIDIA 機器人模擬與訓練平台(PhysX、Omniverse、RL gym)alpamayo 是「AV-flavor」的等價物;Isaac 給 manipulator/locomotion,alpamayo 給 driving。技術棧(diffusion policy + VLA)高度共通
DRIVE 平台 / DriveOSNVIDIA production AV 平台(Orin / Thor chip + 認證 stack)alpamayo 是 DRIVE 的 research 對應物。alpamayo 沒有 automotive-grade validation、不能上車(README disclaimer 已明示);DRIVE 才有 ASIL-D 安全認證
AlpasimCES 2026 同期釋出的 driving simulatoralpamayo 的官方測試環境之一(issue #54 有社群在 alpasim 跑 alpamayo 的對比實驗)

要點:alpamayo 不是「孤山」。它是 NVIDIA Physical AI 棋盤上「VLA 研究側」的一顆棋。Cosmos 提供資料與 backbone、Nemotron 提供大腦級推理、Isaac/Alpasim 提供模擬環境、DRIVE 是 production 對接點。要評估 alpamayo 能否進入內部 pipeline,務必先想清楚它在這張棋盤的位置。

1.4 NVIDIA-NeMo vs NVlabs:兩條線的本質差異

NVIDIA-NeMo(如 Nemotron)NVlabs(如 alpamayo)
定位Production / EngineeringResearch / Paper companion
授權Apache-2.0(含 weights)Apache-2.0 code + Non-Commercial weights
部署NIM 容器化、Triton、TensorRT學術 inference,需自行 wrap
API 穩定度嚴格 SemVerresearch-grade,breaking change 頻繁
文件水準完整 user guide + cookbookREADME + paper + 部分 inline docstring

alpamayo 是 NVlabs 線——這意味著拿來內部評估時,需要心理準備:(a) weights 不能直接商用、(b) API 可能在下個 minor release 變動、(c) 文件深度依靠 paper 與 source code,不會有 NIM 級別的部署手冊。

1.5 為什麼值得花時間讀

  1. VLA 架構模板:VLM backbone + diffusion action expert,這個 pattern 完全可以搬到「醫療影像 → 治療決策」、「實驗影片 → 操作建議」這類任務
  2. Chain-of-Causation 標記法:把模型的推理過程顯式 tokenize 出來,便於審計—對 FDA 21 CFR Part 11 audit trail 很有啟發
  3. flow matching action expert:比傳統 DDPM 更穩、訓練快,值得借鑑做 docking pose generation 或 reaction trajectory prediction

2. 安裝指南

2.1 系統需求

項目規格
Python3.12.x(嚴格綁定)
GPUNVIDIA GPU、VRAM ≥ 24 GB(RTX 3090 / 4090 / A5000 / A100 / H100 都行)
OSLinux(其他平台未驗證)
Disk~25 GB(model weights 22 GB + 示範資料 + venv)

24 GB VRAM 是硬門檻。16 GB VRAM 卡會直接 OOM。

2.2 安裝流程(5 步驟)

 1# Step 1:安裝 uv(NVIDIA 強烈建議用 uv,不用 pip / poetry / conda)
 2curl -LsSf https://astral.sh/uv/install.sh | sh
 3export PATH="$HOME/.local/bin:$PATH"
 4
 5# Step 2:clone repo
 6git clone https://github.com/NVlabs/alpamayo.git
 7cd alpamayo
 8
 9# Step 3:建 venv 並同步依賴(uv 會自動讀 pyproject.toml + uv.lock)
10uv venv ar1_venv
11source ar1_venv/bin/activate
12uv sync --active
13
14# Step 4:申請 HuggingFace gated access(兩個都要)
15# (a) https://huggingface.co/datasets/nvidia/PhysicalAI-Autonomous-Vehicles → 點 "Request access"
16# (b) https://huggingface.co/nvidia/Alpamayo-R1-10B → 點 "Request access"
17# 等候 NVIDIA 審核(通常數小時到數天)
18
19# Step 5:登入 huggingface CLI(access token 從 https://huggingface.co/settings/tokens 拿)
20pip install -U huggingface_hub
21hf auth login

2.3 安裝流程圖


flowchart TD
    A[Start] --> B{uv 已安裝?}
    B -->|否| C[curl install.sh]
    B -->|是| D[git clone alpamayo]
    C --> D
    D --> E[uv venv ar1_venv]
    E --> F[uv sync --active]
    F --> G{HF gated 已通過?}
    G -->|否| H[申請 dataset + model 兩個 gated access]
    G -->|是| I[hf auth login]
    H --> I
    I --> J[python src/alpamayo_r1/test_inference.py]
    J --> K{執行成功?}
    K -->|否| L[查 §7 FAQ:CUDA OOM / FA2 / physical_ai_av 版本]
    K -->|是| M[第一條軌跡產出, minADE 印出]
    L --> J

2.4 容易踩到的安裝坑

症狀修法
physical_ai_av 套件版本錯AttributeError: No huggingface_hub attribute is_offline_mode釘住 physical_ai_av==0.2.0(issue #59)
flash-attn 編譯失敗uv sync 卡在 flash-attn 編譯pyproject.toml 已設 no-build-isolation-package=["flash-attn"],先確認 CUDA toolkit 與 PyTorch 同版 (2.8.0);不行就改 attn_implementation="sdpa"
HF gated 未審核就跑 inference403 ForbiddenCannot access gated repo必須兩個 gated(dataset + model)都通過才能跑
cu_seqlens_q must have shape (batch_size + 1)開 flash_attention_2 後爆炸把 expert 釘在 SDPA:config.expert_cfg.attn_implementation = "sdpa"(issue #52 已找根因)

2.5 驗證安裝成功

1python src/alpamayo_r1/test_inference.py

成功時會看到:

1Loading dataset for clip_id: 030c760c-ae38-49aa-9ad8-f5650a545d26...
2Dataset loaded.
3Chain-of-Causation (per trajectory):
4  The ego vehicle is approaching a four-way intersection. Traffic light is green...
5  Therefore, the safe action is to continue straight at moderate speed.
6minADE: 0.42 meters

第一次跑會下載 22 GB 模型 weights,100 MB/s 線約 2.5 分鐘;不要中斷。


3. 核心架構解析

3.1 高階資料流


flowchart LR
    subgraph Input
        A1[Multi-camera Video
0.4s context @ 10Hz] A2[Ego History
1.6s xyz + rot] end subgraph VLM B1[Qwen3-VL-2B Processor] B2[Cosmos-Reason VLM Backbone] end subgraph Reasoning C1[Chain-of-Causation Tokens
natural language CoT] C2[Trajectory Tokens
discrete vocab] end subgraph Expert D1[Diffusion Action Expert
flow matching ODE] end subgraph Output E1[Continuous Waypoints
6.4s × 64 pts @ 10Hz] E2[CoC Text Trace
可審計推理] end A1 --> B1 B1 --> B2 A2 --> B2 B2 --> C1 B2 --> C2 C2 --> D1 D1 --> E1 C1 --> E2

3.2 模組對應檔案

概念檔案行數角色
主模型src/alpamayo_r1/models/alpamayo_r1.py334AlpamayoR1(ReasoningVLA):組裝 VLM + diffusion expert
VLA 基底類src/alpamayo_r1/models/base_model.py445ReasoningVLA:載 Qwen3-VL、預填 KV cache、共用 generation 接口
token 邏輯src/alpamayo_r1/models/token_utils.py253從 output 序列抽 trajectory tokens、stop criteria
軌跡離散化src/alpamayo_r1/models/delta_tokenizer.py216(x,y,θ) → 離散 token 對應表
action projectionsrc/alpamayo_r1/models/action_in_proj.py169action token → expert hidden state
diffusion expertsrc/alpamayo_r1/diffusion/flow_matching.py173flow matching 採樣器 + ODE solver
action spacesrc/alpamayo_r1/action_space/unicycle_accel_curvature.py382unicycle 動力學 + (accel, curvature) 參數化
dataset loadersrc/alpamayo_r1/load_physical_aiavdataset.py222載入 PhysicalAI-AV dataset、clip → image_frames + ego_history
inference demosrc/alpamayo_r1/test_inference.py77end-to-end 範例(從 clip 到 minADE)
訊息組裝src/alpamayo_r1/helper.py100create_message():把 image frames 包成 Qwen3-VL 格式 message

3.3 ExpertLogitsProcessor — 關鍵設計細節

alpamayo_r1.py 內定義的 ExpertLogitsProcessor 是 alpamayo 一個小但重要的設計:

1class ExpertLogitsProcessor(LogitsProcessor):
2    """Masks out the logits for discrete trajectory tokens."""
3    def __call__(self, input_ids, scores):
4        # 把 trajectory token 區段的 logits 設為 -inf
5        scores[:, self.traj_token_offset : self.traj_token_offset + self.traj_vocab_size] = float("-inf")
6        return scores

為什麼這樣設計? 因為 alpamayo 的 vocabulary 同時包含:

  1. Qwen3-VL 原本的 ~150K text tokens
  2. 額外加入的 trajectory tokens(離散化軌跡)
  3. 特殊 markers(如 <|cot_end|><|traj_future_start|><|traj_future_end|>

當 VLM 在生 Chain-of-Causation 推理文字 時,不希望它跳出 trajectory token(那會破壞 CoC text 流暢性)。所以 mask 掉 trajectory 區段,逼模型只在 text vocab 採樣。等到 <|traj_future_start|> 後,再由 diffusion action expert 接手生連續軌跡。

這個設計把「推理(discrete autoregressive)」與「動作(continuous diffusion)」乾淨地解耦,是 alpamayo 與一般 VLA 模型最大差異之一。

3.4 訓練 / 推理階段對應

階段輸入輸出code 位置
SFT (stage 1)image + traj labelnext-token loss on CoC + traj tokensalpamayo-recipes/alpamayo1_sft
RL post-train (VLM)trajectory rolloutGRPO reward on CoC qualityalpamayo-recipes/alpamayo1_x_rl
Inferenceimage + ego historyCoC text + 6.4s trajectorysrc/alpamayo_r1/test_inference.py
Closed-loop eval上面 + simulator整段 driving rolloutAlpasim / HUGSIM

3.5 alpamayo 在 NVIDIA Physical AI 生態系的位置


flowchart TB
    subgraph Data
        D1[Cosmos
World Model 合成資料] D2[Physical AI AV
Dataset HF gated] D3[Real fleet data
NVIDIA internal] end subgraph Brain N1[Nemotron LLM
high-level reasoning
route planning / NL command] end subgraph VLA A1[Alpamayo 1 / 1.5
VLA: image + history → traj] end subgraph Sim S1[Alpasim / Isaac Sim
closed-loop eval] end subgraph Production P1[NVIDIA DRIVE
ASIL-D certified stack] end D1 --> A1 D2 --> A1 D3 --> A1 N1 -.high-level intent.-> A1 A1 -.trajectory.-> S1 S1 -.regression test.-> A1 A1 -.distillation candidate.-> P1 style A1 fill:#ffd700 style N1 fill:#90ee90 style D1 fill:#87ceeb

黃色:alpamayo 本身;綠色:可組合的大腦級 LLM;藍色:訓練資料來源。


4. Helper Scripts 詳細用法

alpamayo 沒有 CLI 入口腳本(不像 NeMo / Nemotron 提供 nemo CLI),主要透過 Python API 使用。下面是核心 helper 的用法。

4.1 helper.create_message(frames)

把 N 張影像包成 Qwen3-VL chat template message。

1from alpamayo_r1 import helper
2import torch
3
4# frames shape: (N, C, H, W),N = 攝影機張數 × 時間步
5frames = torch.randn(7, 3, 360, 640)  # 7 frames、360x640
6messages = helper.create_message(frames)
7# messages 是 list[dict],可直接餵 processor.apply_chat_template

內部做什麼

  • 加 system prompt:「You are a driving assistant that generates safe and accurate actions.」
  • 把每個 frame 包成 {"type": "image", "image": frame}
  • 末尾加 trajectory history placeholder(<|traj_history_start|> × 48 個 padding token <|traj_history_end|>),這 48 對應預訓練時的 ego_history token 數
  • assistant role 留空,由 model 接續生成 CoC + trajectory tokens

4.2 helper.get_processor(tokenizer)

回傳 Qwen2VLProcessor,設定 MIN_PIXELS = 163840MAX_PIXELS = 196608

1processor = helper.get_processor(model.tokenizer)
2inputs = processor.apply_chat_template(messages, tokenize=True, ...)

注意 MIN_PIXELSMAX_PIXELS 是 Qwen3-VL 的硬限制;超過會自動 resize、低於會 pad,與訓練分布不一致會降精度。

4.3 helper.to_device(model_inputs, device)

遞迴把 nested dict / list 內的 tensors 搬到指定 device。

4.4 load_physical_aiavdataset(clip_id, t0_us)

從 HuggingFace gated dataset 拉一個 clip 的 frame + ego history。

 1from alpamayo_r1.load_physical_aiavdataset import load_physical_aiavdataset
 2data = load_physical_aiavdataset(
 3    clip_id="030c760c-ae38-49aa-9ad8-f5650a545d26",
 4    t0_us=5_100_000,   # microseconds,定義「現在時刻」
 5)
 6# data 是 dict:
 7#   image_frames    : (T, C_cam, C_rgb, H, W)
 8#   ego_history_xyz : (1, N_hist, 3)
 9#   ego_history_rot : (1, N_hist, 3, 3)
10#   ego_future_xyz  : (1, 1, N_future, 3)   # ground truth for eval

看不到 dataset?先確認 HuggingFace nvidia/PhysicalAI-Autonomous-Vehicles gated 已通過。

4.5 AlpamayoR1.sample_trajectories_from_data_with_vlm_rollout()

主推理介面。

 1pred_xyz, pred_rot, extra = model.sample_trajectories_from_data_with_vlm_rollout(
 2    data=model_inputs,
 3    top_p=0.98,                # nucleus sampling for CoC
 4    temperature=0.6,           # CoC temperature
 5    num_traj_samples=1,        # 多少條軌跡(吃 VRAM、可 ≥1)
 6    max_generation_length=256, # CoC max tokens
 7    return_extra=True,         # 回傳 cot 文字
 8)
 9# pred_xyz : (B, num_traj_sets, num_traj_samples, 64, 3)
10# extra["cot"] : list[str]  Chain-of-Causation 文字

4.6 用 SDPA 取代 Flash Attention 2(避坑 issue #52)

1from alpamayo_r1.models.alpamayo_r1 import AlpamayoR1
2import torch
3
4# 載入時就把 attn_implementation 設好
5model = AlpamayoR1.from_pretrained(
6    "nvidia/Alpamayo-R1-10B",
7    dtype=torch.bfloat16,
8    attn_implementation="sdpa",     # 避開 FA2 + 4D mask 不相容
9).to("cuda")

5. 應用場景

5.1 場景 A:學術論文重現(最對胃口的用法)

讀 paper 後想驗證 Alpamayo-R1 paper 的 minADE 結果?

1# 跑官方 test
2python src/alpamayo_r1/test_inference.py
3# 改 num_traj_samples=8 看 minADE 收斂

預期 minADE:單樣本 0.3-0.6 m,多樣本 (k=8) 0.2-0.4 m。

5.2 場景 B:當 backbone 做 fine-tuning

把 alpamayo 當預訓練起點,接自己的 driving dataset。

1# 用官方 recipes
2git clone https://github.com/NVlabs/alpamayo-recipes.git
3cd alpamayo-recipes/recipes/alpamayo1_sft
4# 改 config 指向你的 dataset
5# 跑 SFT

⚠️ 不支援 LoRA / PEFT(issue #106 已確認),需 full fine-tune,硬體門檻高(A100 ×8 起跳)。

5.3 場景 C:當 reasoning 教具

不關心軌跡、只想看 VLM 如何「讀懂路況」?

1# 跑完 sample_trajectories_from_data_with_vlm_rollout 後
2print(extra["cot"][0])
3# 印出類似:
4#   "Observation: The ego vehicle is in the center lane of a three-lane highway.
5#    A truck is visible 30m ahead in the right lane, blinker active.
6#    Cause: The truck intends to merge left.
7#    Action: Maintain current lane and speed to allow truck to merge."

可拿這段 CoC text 當「AI 駕駛行為解釋」素材,給 explainable AI 教學、給 demo、給法遵團隊看。

5.4 場景 D:closed-loop simulator regression

Alpasim 或 HUGSIM 內跑 alpamayo policy,做 regression test。

  • Alpasim:NVIDIA 官方、physics-based、與 alpamayo 同 token interface
  • HUGSIM:社群、Gaussian splatting render、相容性需自己處理

issue #54 有實測案例(社群在 HUGSIM 跑 alpamayo,發現它偶爾忽略 navigation command → 改用 alpamayo 1.5 解決)。

5.5 場景 E:auto-labeling reasoning trace

把 alpamayo 當成「reasoning label 產生器」,自動為自家 driving 影片標 CoC text:

1# 對每個 clip 跑 inference,把 extra["cot"] 存成 jsonl
2import json
3with open("auto_label.jsonl", "a") as f:
4    f.write(json.dumps({
5        "clip_id": clip_id,
6        "cot": extra["cot"][0],
7        "trajectory": pred_xyz.tolist(),
8    }) + "\n")

NVIDIA 在 paper 內明確提到他們自己也用 Alpamayo 做 hybrid auto-labeling(hybrid = AI 標 + 人類校對)。

5.6 場景 F:不適用的場景(重要)

場景為什麼 alpamayo 不適合
商用部署 / production AVweights 是 non-commercial license;DRIVE 才是 production answer
邊緣裝置(in-car compute)10B 模型 + 24 GB VRAM 門檻,車載 Orin/Thor 跑不動;需要先 distill
event camera / LiDAR fusion純 RGB 多相機,不支援 event camera 與 LiDAR(issue #69)
顯式 navigation 條件Alpamayo 1.0 不支援;改用 1.5
LoRA / PEFT 低 VRAM 訓練不支援(issue #106)
醫療影像 / 生物資訊管線domain mismatch;只能借 VLA 架構 pattern,不能直接用 weights

6. 資安掃描報告

掃描範圍:src/pyproject.toml、安裝指令 掃描方法:grep -rn -E "eval|exec|os.system|subprocess|shell=True|curl|wget|urlopen|pickle|secret|token|password|api_key" src/ pyproject.toml 掃描結果:原始程式碼無高風險呼叫;風險集中在「依賴鏈」與「授權邊界」。

6.1 🔴 高風險

目前無高風險發現。

特別澄清:

  • eval 字串大量出現,但全部是 eval_modeevaluationevaluator變數名/函式名沒有 eval() 動態執行字串
  • exec 字串只出現在 executorexecute_ 等 ML 慣例命名,沒有 exec() 呼叫
  • 全 repo 無 subprocessos.systemshell=Truecurlwget 呼叫

6.2 🟡 中風險

風險位置說明緩解
HuggingFace token 必填安裝步驟 step 5hf auth login 把 token 寫入 ~/.cache/huggingface/token不要把 ~/.cache/huggingface/ 加進共用映像、不要 commit
22 GB 外部 weights 下載from_pretrained("nvidia/Alpamayo-R1-10B")模型來自 HF gated repo,需網路在 air-gapped 環境需先預下載 weights、改本地 path
flash-attn 第三方 binarypyproject.toml 第 12 行flash-attn>=2.8.3,需 no-build-isolation、自編 CUDA kernel在企業環境建議鎖死版本、做 supply chain audit
HF dataset 下載含路徑控制load_physical_aiavdataset.pydataset loader 依 clip_id 構造 cache 路徑若 clip_id 來自 user input,需 sanitize 避免路徑穿越
PyTorch 載 ckpt 風險AlpamayoR1.from_pretrained()內部走 transformers,預設使用 safetensors(安全),但若手動指定 .pt/.pth 走 torch.load 預設仍會 unpickle永遠用 safetensors、避免載入未驗證 .pt 檔

6.3 🟢 低風險

  • repo 內任何 hardcoded secret / API key / password(grep 全清)
  • pickle 直接呼叫(transformers 內部有,但已是 known-safe usage)
  • 無對外發 HTTP 請求的程式碼(dataset 下載走 huggingface_hub 標準路徑)
  • 授權清楚標示(Apache-2.0 code + Non-Commercial weights)

6.4 授權與商用紅線(這是本 repo 最大風險)

⚠️ alpamayo model weights 是 Non-Commercial License

項目License商用可否
inference code (src/)Apache-2.0✅ 可商用
model weights (nvidia/Alpamayo-R1-10B)Non-Commercial❌ 不可商用
Physical AI AV datasetgated + Non-Commercial❌ 不可商用
Cosmos-Reason backbone (weights 已被 fine-tune 進 alpamayo)繼承 Non-Commercial❌ 不可商用

對 Apotek 等 startup 的提醒:如果未來要做 AV 相關 product(哪怕只是內部 demo 拿去 fundraise pitch),用 alpamayo weights 都是法律風險。只能拿來做研究、論文重現、團隊內部 study。若要 productize,必須走 NVIDIA DRIVE 商業合約。

6.5 結論

🟢 程式碼層面風險低——alpamayo 是 NVIDIA 官方研究 repo,code quality 高,無明顯 injection / arbitrary execution 漏洞。

🟡 依賴鏈與授權需謹慎——flash-attn 等第三方 binary 需 supply chain audit;最關鍵的是 weights 商用授權邊界,必須在內部明示「研究專用」。


7. FAQ

Q1:Alpamayo 1 與 1.5 有什麼差別?該用哪個?

A:1.5 是替代品,建議都用 1.5。1 是初版(CES 2026 釋出),1.5 加了 navigation 條件、RL post-train、更好的長尾表現。1.0 repo 目前僅作為 paper 的 reference implementation 保留。

Q2:我沒有 H100,能跑嗎?

A:能。RTX 3090 / 4090 / A5000(24 GB VRAM)都驗證過。預期吞吐量比 H100 慢 3-5×。低於 24 GB 直接放棄。

Q3:為什麼 minADE 每次跑都不一樣?

A:因為採樣是 stochastic(top_p=0.98, temperature=0.6)+ diffusion sampling 本身隨機。要 reproducible 就把 seed 固定且 temperature=0,但會犧牲多樣性。

Q4:能用 Apple Silicon (M-series) 嗎?

A:不能。flash-attn、bfloat16、CUDA-only operator 都綁定 NVIDIA GPU。MPS 後端跑不起來。

Q5:CoC 文字是英文,能不能改中文?

A:可以做 SFT 再訓練。預訓練資料是英文為主,零 shot 中文輸出品質會掉。改的入口在 helper.create_message() 內的 system prompt 與訓練 dataset。

Q6:和 Tesla FSD、Waymo policy network 有何差別?

A:alpamayo 是「reasoning-first」設計,先 think 再 act;Tesla FSD 主要是 vision → control 直連;Waymo 是 perception → planning 模組化。alpamayo 比較像 OpenAI o1-style reasoning 移植到 driving,是 research direction,不是 deployment system。

Q7:能不能本地 air-gapped 跑?

A:可以,但需要:(1) 預下載 22 GB weights、(2) 預下載 dataset(更大)、(3) 改 from_pretrained 接受本地 path、(4) 設 HF_HUB_OFFLINE=1

Q8:跑 python test_inference.py 報 is_offline_mode 錯?

A:physical_ai_av 套件版本錯,釘 0.2.0(見 issue #59)。

Q9:能跟我們既有的 Nemotron 服務串嗎?

A:可以。alpamayo 吐出的 CoC text 可以餵給 Nemotron 做 high-level reasoning(如 fleet operator 對話、route re-planning);Nemotron 的決策再做為 navigation hint 餵回 alpamayo 1.5(1.5 支援 navigation 輸入)。這是 NVIDIA Physical AI 官方建議的整合 pattern。詳見本檔 §9.2。

Q10:能拿來標自己車隊資料嗎?

A:可以、但只能做研究用途。標完的 CoC label 是 derivative work,受 Non-Commercial 限制。


8. 進階技巧

8.1 多軌跡採樣(k-best evaluation)

1pred_xyz, pred_rot, extra = model.sample_trajectories_from_data_with_vlm_rollout(
2    data=model_inputs,
3    num_traj_samples=8,    # 一次採 8 條
4    top_p=0.95,
5    temperature=0.7,
6)
7# 計算 k-best minADE
8diffs = np.linalg.norm(pred_xy - gt_xy[None, ...], axis=1).mean(-1)
9min_ade_k8 = diffs.min()  # 比 k=1 顯著低

對 VRAM 友善的折衷:num_traj_samples=4

8.2 把 CoC 與軌跡分開輸出

CoC 是純文字、軌跡是 (T, 3) 數值;分開存對下游友善:

1import json, numpy as np
2result = {
3    "clip_id": clip_id,
4    "cot": extra["cot"][0],
5    "pred_xyz": pred_xyz.cpu().numpy().tolist(),  # 6.4 s × 64 pts
6    "minADE": float(min_ade),
7}
8with open(f"out/{clip_id}.json", "w") as f:
9    json.dump(result, f, indent=2)

8.3 SDPA backend 釋放 VRAM

flash-attn 雖快,但會吃額外 workspace VRAM。緊湊環境(如 24 GB RTX 3090)改 SDPA 可省 ~1 GB:

1model = AlpamayoR1.from_pretrained(
2    "nvidia/Alpamayo-R1-10B",
3    dtype=torch.bfloat16,
4    attn_implementation="sdpa",
5)

8.4 expert vs VLM 拆開除錯

issue #52 的根因分析教會的事:alpamayo VLM 用 FA2 沒事,但 expert 必須 SDPA(因為 expert 用了 4D float mask)。

1# 載 config 後手動分開設
2config = AlpamayoR1Config.from_pretrained("nvidia/Alpamayo-R1-10B")
3config.expert_cfg.attn_implementation = "sdpa"  # expert 強制 SDPA
4config.attn_implementation = "flash_attention_2"  # VLM 維持 FA2

8.5 部份 frame inference(短 horizon 模式)

預設 7 frames(攝影機 7 個視角)會吃滿 VRAM。debug / dev 環境可只用 1-2 cameras:

1# 把 image_frames 切掉
2data["image_frames"] = data["image_frames"][:, :2]  # 只用前兩個 camera
3messages = helper.create_message(data["image_frames"].flatten(0, 1))
4# 注意:與訓練分布不一致,輸出精度會掉

8.6 把 CoC reasoning 接到 LLM 後處理

CoC text 是「raw 推理鏈」,可以再餵 LLM 做摘要、翻譯、評分:

1import openai  # 或本地 Nemotron / vLLM
2cot = extra["cot"][0]
3summary = openai_client.chat.completions.create(
4    model="nvidia/llama-3.3-nemotron-super-49b",
5    messages=[{"role": "user", "content": f"Summarize this AV reasoning in 1 sentence:\n{cot}"}],
6)

這條 pipe 在 NVIDIA 內部叫「reasoning auto-labeling pipeline」,paper 內有提到。

8.7 用 alpasim 跑 closed-loop

1git clone https://github.com/NVlabs/alpasim.git
2cd alpasim
3# 跟著 alpasim README 安裝、配 alpamayo policy adapter
4alpasim run --policy alpamayo --scenario merge_left

可以拿來做 regression test、edge case sweep、A/B testing 不同 checkpoint。


9. 整合進其他工作流

9.1 與 ai-knowledge_template 整合

本 repo 不適合直接整合進 ai-knowledge_template(domain mismatch:driving 而非 knowledge work)。

但可以借的東西

  • VLA 架構 pattern(VLM + diffusion expert)可以借鑑到「實驗影片 → 操作建議」這類任務
  • ExpertLogitsProcessor 的解耦設計,對「reasoning + action」雙頭模型有啟發

9.2 與 Nemotron 組合:大腦 + 小腦 pipeline

最有價值的整合 pattern:


sequenceDiagram
    participant User as Fleet Operator
    participant Nemotron as Nemotron LLM
(brain) participant Alpamayo as Alpamayo 1.5
(driving VLA) participant Sim as Alpasim
(sim env) User->>Nemotron: "請所有 AV 在暴雨時改走高架道路" Nemotron->>Nemotron: 解析自然語言 → 結構化指令 Nemotron->>Alpamayo: 路線建議 (navigation hint) Sim->>Alpamayo: 攝影機影像 + ego state Alpamayo->>Alpamayo: CoC reasoning + trajectory diffusion Alpamayo->>Sim: 6.4 s waypoints Alpamayo-->>Nemotron: CoC text (給 audit) Nemotron-->>User: 摘要回報每台車狀態

具體實作:

  • Nemotron:跑 NVIDIA-NeMo/Nemotron 提供的 cookbook(如 fleet-ops cookbook)
  • Alpamayo 1.5:用 navigation input 接收 Nemotron 的指令
  • Alpasim:當 closed-loop test bed
  • 串接細節見 本專案 Nemotron 教學手冊 §5「應用場景」第 5 條 use-case (fleet-ops)

9.3 與 Cosmos 組合:合成資料訓練

1Cosmos World Foundation Model → 生成 N 萬個 driving scenario 影片
2                              → 用 alpamayo SFT recipe 餵進去
3                              → 訓練自家 alpamayo 變體

實作細節:

  • Cosmos:用 nvidia/cosmos 提供的 video generation pipeline,給定 prompt(“highway merge in rain”)生影片
  • alpamayo-recipes:跑 SFT recipe,把 Cosmos 生的影片當訓練 batch
  • 這條 pipeline NVIDIA 在 paper 內提過,是 long-tail scenarios coverage 的關鍵

9.4 與 Isaac Sim / Isaac Lab 組合:跨 embodiment 遷移

如果做「室內機器人 + 戶外 AV」雙場景:

  • Isaac Lab 提供 manipulator / quadruped RL 訓練
  • alpamayo 提供 driving policy
  • 共用 underlying VLA + diffusion-policy 訓練 infra(NVIDIA 內部就是這樣設計的)

9.5 與其他工作流的整合對照

Workflow整合方式
ai-gh-save已整合(gh-save md 一份)
ai-notebooklm可把 paper + README + tutorial md 餵 NotebookLM 做 Q&A
paper-qa-lite可建本 repo + paper 的 RAG cache,問細節用
graphify適合對 src/ 建 code graph,理解模組依賴
doclingpaper PDF → md 後可進 paper-qa-lite
paper-tutorial若把 Alpamayo paper + 後續 3-4 篇延伸 paper 一起讀,可走 paper-tutorial
gh-tutorial-qd(本身)你正在讀的就是這個 workflow 的輸出

10. 重點摘要 Checklist

評估時必看 ✅

  • 24 GB VRAM 門檻——硬性要求,沒卡就不用試
  • HuggingFace gated access——dataset 與 model 兩個都要先審核
  • Non-Commercial weights——僅研究用,不可上 product
  • 建議用 1.5——1.0 是初版,1.5 才是 maintained 主線
  • 不支援 LoRA / PEFT——full fine-tune 起跳
  • physical_ai_av==0.2.0——版本相容性的踩坑點

採用前風險評估

  • 我的使用場景是研究還是 production?(後者直接放棄)
  • 我有 24 GB+ GPU 嗎?沒有就先不要試
  • HF gated 審核需時,pipeline 排程要預留 buffer
  • 內部團隊明白 Non-Commercial 邊界嗎?
  • 若拿來標 label,輸出 derivative 也受限——明白嗎?

推薦使用情境

  • 學術論文重現
  • CoC reasoning 教學素材
  • auto-labeling reasoning trace
  • closed-loop simulator regression(搭 Alpasim)
  • 借 VLA 架構 pattern 做其他 domain

不推薦使用情境

  • ❌ Production 部署
  • ❌ 車載 edge inference
  • ❌ LiDAR / event camera 融合
  • ❌ 24 GB VRAM 以下硬體
  • ❌ 不能接受 Non-Commercial license 的任何 commercial use case

11. 進一步閱讀

11.1 必讀

  1. Alpamayo-R1 paper (arXiv 2511.00088) — 核心論文,含 CoC 設計、SFT/RL 訓練細節、benchmark 結果
  2. HuggingFace Model Card: nvidia/Alpamayo-R1-10B — 模型卡,含完整 inputs/outputs 與測試 hardware
  3. 本 repo README — 安裝指南、FAQ、project structure
  4. Alpamayo 1.5 (主線新版) — 改用 1.5!

11.2 NVIDIA 生態相關

11.3 學術延伸(VLA 領域)

  • OpenVLA (Stanford, 2024) — 第一波開源 VLA,主要 manipulator
  • RT-2 (Google DeepMind, 2023) — VLA 領域開創性工作
  • π0 (Physical Intelligence, 2024) — flow matching VLA,與 alpamayo diffusion action expert 同思路
  • DrivoR / DriveLM — 學術界 driving VLA

11.4 Apotek 內部交叉參考


內部備註:本文件為 Apotek 團隊 AI 知識庫內部研讀資料。alpamayo weights 為 Non-Commercial license,任何商用相關 PoC、demo、pitch 都不得使用本模型 weights;研究、學術討論、架構參考則無限制。