【轻量化复刻大模型 / π0.5】(2)PI0 vs PI0.5
0x00 概要
-
项目github.com/RossiLH/Mod… 和系列博客是我的一个尝试,也是我学习的过程。不确定是否满足读者的需求,我自己会反思改进,也希望大家提出宝贵意见。
-
涉及 KIMI K3,DeepSeek V4,PI0.5,PI0.7 等模型。后续可能会跟踪新模型。
-
全 CPU 复刻,不涉及 GPU,也不涉及大规模训练(这是另外一个庞杂深邃的领域)和硬件。
-
模型的组件尽量是原始大模型的缩小版,如果组件没有开源版本,则用近似组件替代。
-
会解释每个组件在解决一个什么问题、这个问题难在哪、为什么只能这么解、解法的原理是什么,以及组件之间如何咬合成一个整体。重点不是记名词,而是理解一条主线。
-
每个主要组件都有可直接运行的 Gradio demo——无需 GPU。另有若干可视化脚本(
plot_*.py),可生成静态图。 -
所有文件行号基于本地源码快照;源码后续变化时,行号可能移动,但函数名和调用关系仍可作为定位入口。
-
为了保证每个文章可以尽量独立成文,所以有些内容会在不同文章中都存在,可能在系列层面上存在冗余,还请大家理解。
-
Pi 系列(Physical Intelligence)的参考仓库如下,因此,PI0.5系列,基本就是以官方代码为基准,进行学习(适度修改 + 深度解读) 。
0x01 π0 与 π0.5 基本对比
π0 与 π0.5 共享「VLM + action expert」的双专家骨架,但状态接入、时间步注入、掩码块结构、flow 方向四处关键设计都不同。
1.1 对照表
下面这张对照表全部以论文事实为准(对照点:PaliGemma 3B VLM + 300M action expert = 3.3B;π0 掩码三块 blockwise causal;π0 状态是连续向量;π0 用 concat+MLP 注入时间步;flow 方向 τ=0→1):
| 维度 | π0 | π0.5 |
|---|---|---|
| 输入 | 图像、语言指令、本体状态(连续),动作 | 图像、语言指令、本体状态(离散型),动作 |
| 输出 | 连续动作(目标关节角/末端位姿增量+夹爪开合) | 文本(子任务 / VQA / 框)+ FAST 动作 token + 连续动作(目标关节角/末端位姿增量+夹爪开合) |
| 骨干 | PaliGemma 3B | 相同 · SigLIP 400M + Gemma 2.6B |
| action expert | 300M · 从零,全程参与 | 相同尺寸 · 后训练时才加入 |
| 本体状态(state/state_proj) | 连续向量(关节角),作为 suffix 的连续输入,由 state projection 编码 | 离散化为 bin 索引 token 拼进语言 prefix(让 VLM "读"状态语义) |
| 时间步注入 | 连续 state token 拼进 suffix;另用 action-time MLP | adaRMSNorm 条件化:τ → 正弦编码 → TimeMLP → adarms_cond,只作用于 action expert |
| 动作损失 / 生成 | Flow Matching 学速度场 v_θ,Euler 积分(τ=0→1) | 同(Flow Matching),但 x_t = τ·a+(1-τ)·ε(代码方向 τ=1→0 是 openpi 的积分约定) |
| 注意力 | 图文 / qₜ / 动作 三块 | 前缀 · FAST 动作 · expert 动作;两种动作互不可见,VLM 不看 expert |
| 掩码块结构 | 三块 blockwise causal:[images, ℓ]、[q_t](state 独立块)、[actions];块内双向、块间只向前看;actions 可见 state+images+lang,state 可见前两者,未来块不可见 | 两块 prefix/suffix:prefix 双向、suffix 可见 prefix+自身、prefix 不看 suffix(单向流) |
| 相机 | 3 路 | 高层 4 路 · 低层 3 路 |
| prefix KV caching | 已提及 prefix KV caching | 复用(一静一动) |
| 参数量 | VLM PaliGemma 3B(width 2048/depth 18/8 头/kv 1 头/head_dim 256)+ action expert 300M(width 1024/mlp_dim 4096),两专家维度可不同 | 同双专家结构 |
优势
VLM 侧没有新模态、没有新 loss:网页数据、子任务文本、动作 token 用同一套权重、同一个交叉熵训;expert 只在后训练接上
1.2 基础架构异同
两者主干骨架都是 PaliGemma VLM + Action Expert 双专家 Transformer,基础模块结构相似,但在输入编码、注意力掩码、训练目标、信息流向四个核心点做了改动,才带来分层推理能力。
-
π0
- 机器人本体状态:连续向量,单独投影后送入 Action Expert,不属于 VLM 前缀文本 token。
- 输出通路:单一路径,VLM 只提取场景 + 指令的隐式特征,直接交给 Action Expert,Flow Matching 一次性生成连续动作 chunk。
- 训练目标:仅 Flow Matching 的 MSE 损失,没有离散 token 自回归预测分支。
- 推理逻辑:扁平单层映射:
观测+全局指令 → 直接输出底层动作,中间没有显式、可读的高层子任务输出节点。
pi0_overview_hi
-
π0.5
-
机器人本体状态:连续状态量化离散,转成文本 token,放进 VLM 的 prefix 前缀,和图像、语言指令共用同一套 VLM 注意力。
-
双输出分支(同一套 Transformer 权重):
- 高层分支:VLM 骨干自回归生成 FAST 离散 token,代表子任务 / 高层语义指令(例如:拿起盘子、移动到水槽),使用 CE 交叉熵损失。
- 低层分支:Action Expert 接收「原始观测 + 刚刚生成的高层子任务 token」作为条件,Flow Matching 生成连续底层关节动作,MSE 损失。
-
时间条件注入:flow 时间步通过AdaRMSNorm注入 Action Expert 每一层(π0 只是简单拼接 time embedding)。
-
0x02 PI0 与 PI0.5 的输入输出区别
PI0 和 PI0.5 使用相同的总体输入类型:
图像 + 任务语言 + 机器人状态
但两者对 state 的编码方式、时间步的注入方式和 suffix 内容不同。
2.1 输入对比
| 项目 | PI0 | PI0.5 |
|---|---|---|
| 图像输入 | 当前观测图像 | 当前观测图像 |
| 语言输入 | 任务 prompt | 任务 prompt |
| 状态输入 | 连续 state 向量 | 原始 state 经过离散化后,拼入语言 token |
| 动作输入(训练) | 真实动作 a,并构造带噪 x_t | 真实动作 a,并构造带噪 x_t |
时间步 t | 与 action token 拼接后送入 action-time MLP | 经正弦编码和 Time MLP 后作为 adaRMS 条件 |
| prefix | 图像 token + 语言 token | 图像 token + 语言 token + 离散 state token |
| suffix | 连续 state token + noisy action tokens | noisy action tokens |
2.1.1 PI0 的输入路径
PI0 的输入可以表示为:
图像
→ image encoder
→ image tokens
任务语言
→ language embedding
→ language tokens
连续 robot state
→ state_proj
→ 一个连续 state token
带噪动作 x_t
→ action_in_proj
→ noisy action tokens
最终序列为:
PI0:
prefix = 图像 tokens + 语言 tokens
suffix = 连续 state token + noisy action tokens
PI0 的 timestep 会与 action token 拼接:
action tokens + time tokens
↓
action_time_mlp
↓
action expert 输入
2.1.2 PI0.5 的输入路径
PI0.5 的 state 不再作为连续 suffix token 直接输入 action expert, 而是先离散化并放入语言侧:
连续 robot state
→ state discretization
→ state token / state text
→ language prefix
因此:
PI0.5:
prefix = 图像 tokens + 语言 tokens + 离散 state tokens
suffix = noisy action tokens
PI0.5 的 timestep 路径为:
timestep t
→ sine-cosine positional encoding
→ Time MLP
→ adarms_cond
→ action expert 的 adaRMSNorm
因此,PI0.5 的时间步不是作为普通 token 或 action token 的拼接向量输入,而是作为 action expert 的条件信号注入归一化层。
2.1.3 训练输入和推理输入
训练
训练时两者都需要真实动作 a, 并从噪声 ε 和时间步 t 构造带噪动作:
x_t = t * noise + (1 - t) * actions
u_t = noise - actions
然后分别构造自己的 prefix 和 suffix:
PI0: prefix(图像、语言) + suffix(连续 state、x_t)
PI0.5: prefix(图像、语言、离散 state) + suffix(x_t)
两者都预测 v_t, 并与 Flow Matching 目标 u_t 比较。
推理
推理时不再提供真实动作,而是从随机噪声动作 x_1 开始:
随机噪声 x_1
→ 构造 suffix
→ 预测 v_t
→ Euler 更新 x_t
→ 重复
→ 最终连续 action chunk
区别仍然在 suffix 和 timestep 条件:
PI0:
prefix(图像、语言)
suffix(连续 state、当前 x_t)
timestep 与 action token 经 MLP 融合
PI0.5:
prefix(图像、语言、离散 state)
suffix(当前 x_t)
timestep 通过 adaRMS 条件注入 action expert
2.2 输出对比
两者的最终输出形式基本相同,都是连续动作 chunk, 而不是文本 token:
suffix_out
↓
action_out_proj
↓
v_t
↓
Euler / Flow Matching 积分
↓
连续 action chunk
具体如下:
| 输出阶段 | PI0 | PI0.5 |
|---|---|---|
| Transformer 直接输出 | suffix hidden states | suffix hidden states |
| 动作输出头 | action_out_proj | action_out_proj |
| 训练预测目标 | Flow Matching 速度 v_t | Flow Matching 速度 v_t |
| 推理过程 | 从噪声积分到动作 | 从噪声积分到动作 |
| 最终输出 | 连续动作 chunk | 连续动作 chunk |
| 是否输出独立文本 | 否 | 否 |
两者都会从 action horizon 对应的 suffix hidden states 中取出动作输出:
v_t = self.action_out_proj(suffix_out[:, -self.action_horizon :])
因此,PI0.5 并没有因为把 state 放入语言 prefix 就增加一个独立的高层文本 decoder;它最终仍然输出连续控制动作。
2.3 一句话总结
PI0:
连续 state 进入 suffix
timestep 与 action token 拼接
输出连续动作 chunk
PI0.5:
离散 state 进入 prefix
timestep 通过 adaRMS 条件注入
输出连续动作 chunk
所以,PI0 和 PI0.5 的主要差异在于输入表示和条件注入位置,而不是最终输出类型:
输入组织不同
↓
联合 Transformer 内部条件流不同
↓
最终都输出连续 action chunk
0x03 PI0.5 与 PI0 的模型架构差异
PI0.5 的一个特点是:思考模式,比如把「打扫卧室」拆解为「捡起枕头」等分步子任务落地执行。因此我们自然就会认为,PI0.5 与 PI0 的模型架构差异是这个特色的由来。然而,实际上并非如此。我们接下来就进行分析。
3.1 先给结论
基于 openpi-main 代码,PI0.5 并没有一个显式的“高层指令输出模块”,PI0 也不是只能做底层执行。两者在代码中都主要完成:
图像 + 语言 + 状态
↓
VLM expert + action expert
↓
Flow Matching velocity
↓
连续动作 chunk
也就是说:
- PI0 和 PI0.5 都接收语言 prompt;
- PI0 和 PI0.5 都使用 PaliGemma/VLM expert;
- PI0 和 PI0.5 都使用 action expert;
- PI0 和 PI0.5 的
sample_actions()都输出连续动作(action chunk); - 两者都没有在
openpi的Pi0类中返回 “高层子任务文本” 或 “下一条语言指令”。 - PI0.5 论文额外描述了 FAST token、高层 subtask 和低层 action expert 的分层训练/推理流程;这不能简单等同于当前
openpi-main中的PI0类,因为PI0FAST在代码中是独立模型路径。
因此,不能仅根据 openpi 代码得出 “PI0.5 有高层指令输出,而 PI0 没有” 的结论。更准确的说法是:
PI0.5 的训练数据、状态表示、预训练 / 后训练配方和 checkpoint 使其更容易表现出开放世界语义理解与长时程任务能力;这不是由一个新增的高层文本 decoder 直接实现的。
”
3.2 两者真正的代码架构差异
官方 Pi0Config 已经把差异写在注释中:
# Pi05 has two differences from Pi0:
# - the state input is part of the discrete language tokens rather than a continuous input that is part of the suffix
# - the action expert uses adaRMSNorm to inject the flow matching timestep
也就是说,PI0.5 相对于 PI0 的核心代码差异主要是两处:
state 接入方式不同
- PI0: 连续 state 作为 action-side suffix 中的 state token;
- PI0.5: state 离散化后放入语言侧 prompt/token。
timestep 注入方式不同
- PI0: timestep 与 action 表示拼接后经过
action_time_mlp; - PI0.5: timestep 经过 Time MLP,作为 action expert 的
adaRMSNorm条件。
具体如下表:
| 部分 | PI0 | PI0.5 |
|---|---|---|
| 状态输入 | state_proj(obs.state), 作为 suffix 中的连续 state token | 由 discrete_state_input=True 进入 tokenizer, 作为离散语言侧 token |
| timestep | 正弦 timestep 与 action embedding 拼接,经 action_time_mlp | 正弦 timestep 经 time_mlp_in/out, 作为 action expert 的 adarms_cond |
| VLM expert | PaliGemma | PaliGemma |
| action expert | Gemma 300M 类 action expert | 同一类 action expert, 启用 adaRMS 条件 |
| attention | 双 expert 联合 attention | 双 expert 联合 attention |
| 最终输出 | action_out_proj 后的连续动作速度 | action_out_proj 后的连续动作速度 |
因此,PI0.5 不是换成了完全不同的 Transformer,而是在相同双 expert 骨架上改变了 state 和 timestep 的接入方式。
3.3 初始化层差异
两者都创建两个 expert:
_gemma.Module(
configs=[paligemma_config, action_expert_config],
embed_dtype=config.dtype, adarms=config.pi05,
)
PI0.5 额外创建:
self.time_mlp_in
self.time_mlp_out
PI0 创建:
self.state_proj
self.action_time_mlp_in
self.action_time_mlp_out
3.4 embed_suffix() 差异
| 项目 | PI0 | PI0.5 |
|---|---|---|
| state | state_proj(obs.state),生成连续 state token | state 已离散化并放入语言侧 prompt |
| action | action_in_proj(noisy_actions) | action_in_proj(noisy_actions) |
| timestep | 与 action token 拼接,再经过 action_time_mlp | 经过正弦编码和 Time MLP,作为 adarms_cond |
| action expert 条件 | timestep 混入 action token | timestep 通过 adaRMSNorm 注入 |
3.5 PI0 的数据流
3.5.1 总体数据流
LIBERO row
├─ image [256, 256, 3]
├─ state [8]
├─ action [7]
└─ task text string
↓
openpi transforms
├─ image resize [224, 224, 3]
├─ state normalize [8]
├─ action chunk [50, 7]
├─ action padding [50, 32]
└─ prompt tokenize
↓
PI0
├─ VLM expert
├─ action expert
└─ Flow Matching
↓
model output [50, 32]
↓
LIBERO adapter [50, 7]
3.5.2 prefix
PI0.embed_prefix() 处理图像和语言:
image → SigLIP → image tokens
language prompt → PaliGemma embedding → language tokens
image tokens + language tokens → prefix
3.5.3 suffix
PI0.embed_suffix() 在 pi05=False 时处理:
continuous state → state_proj → 一个 state token
noisy action x_t → action_in_proj → action tokens
timestep τ → sinusoidal embedding → 与 action tokens 拼接 → action_time_mlp → suffix action representation
3.5.4 训练
训练不是先完成一个独立的 prefix 阶段,再把结果作为第二个训练阶段输入 suffix;
而是 prefix 和 suffix 在同一次 forward 中联合计算。
prefix = image + language
suffix = continuous state + timestep-conditioned action
真实 action + noise
↓
构造 noisy action x_t
↓
构造目标速度 u_t = noise - action
↓
PaliGemma.llm([prefix, suffix], mask=...) # prefix + suffix 一次联合 Transformer 前向
↓
suffix_out
↓
action_out_proj
↓
预测速度 v_t
↓
MSE (v_t, u_t)
3.4 PI0.5 的数据流
3.4.1 总体数据流
LIBERO row
├─ image [256, 256, 3]
├─ state [8]
├─ action [7]
└─ task text string
↓
openpi transforms
├─ image resize
├─ state normalize
├─ optional state discretization
├─ action chunk + padding
└─ prompt tokenize
↓
PI0.5
├─ VLM expert
├─ action expert
├─ adaRMS/time conditioning
└─ Flow Matching
↓
continuous action chunk [50, 32]
↓
LIBERO adapter [50, 7]
3.4.2 prefix
PI0.5 的 prefix 经过 tokenizer 处理:
prompt + state → TokenizePrompt(discrete_state_input=True) → tokenized_prompt
然后:
image → SigLIP → image tokens
tokenized prompt + discretized state → PaliGemma embedding → language/state tokens
image tokens + language/state tokens → prefix
3.4.3 suffix
suffix 处理为:
noisy action x_t → action_in_proj → action tokens
timestep τ → sinusoidal embedding → time_mlp_in/out → adarms_cond → action expert 的 adaRMSNorm
3.4.4 训练
训练时:
prefix = image + language + discrete state
suffix = noisy continuous action
condition = timestep adarms_cond
↓
PaliGemma.llm([prefix, suffix], adarms_cond=[None, condition])
↓
suffix_out
↓
action_out_proj
↓
v_t
↓
Flow Matching MSE
PI0.5 仍然使用连续 action expert 进行低层动作建模,并不是把低层动作完全替换成离散 token。
3.5 输出处理:两者都没有高层文本输出
我们接下来看看Flow Matching 与最终动作。
3.5.1 训练目标
在 Pi0.compute_loss() 中,模型构造:
noise = Normal(0, I)
x_t = t * noise + (1 - t) * actions
u_t = noise - actions
模型预测:
v_t = self.action_out_proj(suffix_out)
训练目标:
loss = MSE(v_t, u_t)
因此 action expert 学习的是条件速度场:
vθ(x_t, t | image, language, state)
3.5.2 action_out_proj 的输出
action_out_proj 的输出不是最终动作,单次输出的是当前状态下的速度。
v_t: 当前 noisy action x_t 和 timestep t 下的预测速度
v_t = self.action_out_proj(suffix_out[:, -self.action_horizon :])
因此输出是:
(B, action_horizon, action_dim)
训练时,这个输出与 flow target 比较:
mean(square(v_t - u_t))
推理时从噪声开始,这个输出作为 Euler 速度:
x_1 = noise
x_{t+dt} = x_t + dt * v_t
经过若干 Euler/Flow Matching 步骤后,才得到最终连续 action chunk。
在 openpi 的 Pi0 类中没有:
text_logits
subtask_logits
language_decoder
high_level_action_head
如果要在 openpi 中实现显式高层子任务输出,需要额外增加语言 token decoder 或离散 action/token head;当前 Pi0/PI0.5 flow 路径没有这一步。
注意:Pi0FAST 是另一个模型类。它有 FAST token logits 和自回归离散动作输出,但不能把 Pi0FAST 的 token 输出等同于 PI0.5 flow-matching Pi0 类的高层指令输出。
3.6 注意力如何共享?
两者的 attention 结构基本相同,差异不在 “是否共享注意力”。 openpi/models/gemma.py::Module 接收两个 expert 的配置:
configs=[paligemma_config, action_expert_config]
每一层 Block 做:
prefix/PaliGemma norm
suffix/action expert norm
↓
各自生成 Q/K/V
↓
沿 token 序列拼接
↓
一次联合 attention
↓
按 expert 切回
↓
各自 output projection
训练时,PI0 和 PI0.5 都是:
prefix + suffix
↓
同一次 PaliGemma.llm forward
↓
共享 attention
推理时,两者都采用:
prefix forward → 缓存 prefix KV
suffix forward → 读取 prefix KV
这只是 KV cache 优化,不是两者架构差异。
综上所述,从模型架构上,没有看出来支持“高层出指令、底层执行”的调整。于是我们接着看训练。
0x04 PI0.5训练 & 推理
4.1. 非 FAST 情况下的训练和推理
4.1.1 训练:一次联合前向
非 FAST 的 PI0/PI0.5 训练流程是:
prefix + suffix
→ 一次联合 Transformer forward
→ suffix_out
→ Flow Matching MSE
训练时通常不使用 prefix KV cache,因为每个样本只对一个 timestep 执行一次联合 forward,没有重复计算相同 prefix 的多步去噪循环。
4.1.2 推理:prefix prefill 加 suffix 迭代
非 FAST 推理在计算上分为两个部分:
第一部分:
prefix prefill → 缓存 prefix KV
第二部分:
suffix Flow Matching 迭代 → 每个 timestep 读取 prefix KV
流程如下,这是一种推理计算流程,不等同于“先生成 high-level subtask,再生成 low-level action”。
图像 + 语言 + state
↓
↓
prefix prefill 一次
│
└→ prefix KV cache
↓
↓
初始化 x_1 = noise
│
┌──────┼────────────┐
↓ │
suffix(x_t, t) │
↓ │
读取 prefix KV │
↓ │
预测速度 v_t │
↓ │
Euler 更新 x_t │
↓ │
└─ 重复 num_steps 次─┘
↓
↓
连续 action chunk
4.2 FAST 与论文中的高层/低层分层
PI0.5 论文描述了以下训练和推理思路:
pre-training:
使用 FAST action token 进行 next-token prediction
post-training:
增加 action expert
使用更细粒度的连续动作表示
联合保留 token CE 与 Flow Matching
推理:
先生成 high-level subtask
再以该 subtask 为条件生成 low-level action
这说明论文中的 PI0.5 不只是普通的连续 action policy,还包含离散 token 相关的高层行为建模。
4.2.1 FAST 推理流程
PI0FAST.sample_actions() 的推理过程是:
prefix prefill
→ 写入 KV cache
→ 取 prefix 最后位置 logits
→ 生成第一个 token
→ token embedding + KV cache 增量 forward
→ 生成下一个 token
→ 重复至 EOS 或最大长度
→ FASTTokenizer.extract_actions()
→ 连续 action chunk
其 attention 结构是 prefix-LM:
prefix:
prefix 内部双向可见
FAST/action postfix:
可见 prefix 和已经生成的历史 token
不可见未来 token
4.3 openpi-main 的代码组织
而 openpi 中,没有把 FAST token融入在一起。PI0和PI0.5的训练都是 loss = Flow Matching MST。
openpi-main 将两条路径分开:
PI0 / PI0Config(pi05=True)
→ prefix + continuous action suffix
→ Flow Matching MSE
PI0FAST / PI0FASTConfig
→ prefix-LM token sequence
→ next-token CE
→ 自回归 token 推理
因此:
PI0/PI0.5: 连续 Flow Matching 模型。
PI0FAST: 独立的 FAST token 自回归模型。
当前不能简单地说 PI0.sample_actions() 会自动先调用 PI0FAST.sample_actions(),因为代码中没有这样的自动串联。
因此,我们参考 OpenTau,这里 PI0.5 训练同时计算 Flow Matching MSE 和 FAST 离散动作 CE。
4.4 OpenTau-main: 明确结合了 FAST token
OpenTau 的 PI05Policy 明确加载 FAST action tokenizer:
self.discrete_action_processor = AutoProcessor.from_pretrained(
config.discrete_action_tokenizer_path,
trust_remote_code=True,
)
默认配置路径是:
physical-intelligence/fast
训练 forward 中,OpenTau 同时准备:
batch["discrete_actions"]
以及连续动作:
actions = batch["actions"]
随后 PI05FlowMatching.forward() 同时计算两类损失。
4.4.1 连续动作 Flow Matching MSE
代码先构造 noisy action 和 flow target,然后调用:
mse_result = flow_matching_masked_mse(
u_t=u_t,
v_t=v_t,
...
)
4.4.2 FAST 离散动作 CE
代码使用 discrete_action_processor 对动作 chunk 编码,再由 discrete action head 预测 token:
discrete_action_emb = self.paligemma_with_expert.embed_discrete_actions(
discrete_actions
)
...
logits = self.paligemma_with_expert.da_head(discrete_action_out)
...
discrete_action_ce_loss = F.cross_entropy(
logits,
labels,
reduction="none",
)
最终模型 forward 返回:
out = {
"MSE": mse_loss,
"CE": discrete_action_ce_loss + response_ce_loss,
...
}
训练脚本再依据配置加权:
loss = _assemble_weighted_loss(
losses,
train_config.loss_weighting,
)
默认配置为:
loss_weighting = {
"MSE": 1,
"CE": 1,
}
因此 OpenTau 的实际训练目标可以写成:
total_loss
= w_mse × Flow Matching MSE
+ w_ce × FAST action-token CE
+ w_ce × optional response CE
这比 openpi-main 当前 PI0.compute_loss() 更接近 π0.5 论文中描述的联合训练方式。
4.5 OpenTau 中对应的关键代码
| 文件 | 作用 |
|---|---|
OpenTau-main/src/opentau/policies/pi05/modeling_pi05.py | PI0.5 模型、Flow MSE、离散动作 CE |
OpenTau-main/src/opentau/policies/pi05/configuration_pi05.py | FAST tokenizer 路径、state_type、loss 相关配置 |
OpenTau-main/src/opentau/scripts/train.py | 加权组合 MSE 和 CE |
OpenTau-main/src/opentau/policies/utils.py | flow_matching_masked_mse()、ce_per_sample() 等损失工具 |
OpenTau 的代码注释也明确把离散 action 标记为:
discrete actions are to predict actions using autoregressive technique
and not flow matching
也就是说,OpenTau 的 PI0.5 同时保留:
离散动作 token 路径 → CE
连续动作 expert 路径 → Flow Matching MSE
4.6 最终结论
OpenTau-main:
PI0.5 训练结合了 FAST token。
同一个 PI0.5 forward 同时产出:
MSE = 连续 Flow Matching 损失
CE = FAST 离散动作 token 损失
训练脚本再按权重合并二者。
0x05 高层能力究竟来自哪里?
5.1 显式高层指令输出
PI0.5 是否有显式高层指令输出?答案取决于讨论层次。
5.1.1 openpi-main 的 PI0/PI0.5 Flow 类
PI0.compute_loss() 和 PI0.sample_actions() 的主要输出路径是:
v_t = self.action_out_proj(suffix_out[:, -self.action_horizon:])
没有看到以下独立输出头:
text decoder
subtask logits head
language decoder
high-level instruction head
因此,在当前 PI0/PI0.5 Flow 类中:
输入:图像 + 语言 + state
输出:连续 action chunk
5.1.2 PI0FAST
PI0FAST 有自回归 token logits 和离散 token 输出:
prefix
→ next-token prediction
→ FAST/PaliGemma token
→ FAST decode
→ 连续 action chunk
但 PI0FAST 是独立模型类,不能直接说它就是 PI0 类内部新增的高层文本 decoder。
5.1.3 更准确的表述
论文层面:
PI0.5 具有 FAST/high-level subtask 相关的分层训练和推理描述。
openpi-main 代码层面:
PI0/PI0.5 Flow 类直接输出连续动作;
PI0FAST 独立执行 token 生成;
完整的 FAST → Flow 两阶段串联需要额外 orchestration。
5.2 PI0 和 PI0.5 的能力差异来自哪里?
5.2.1 共同能力
PI0 和 PI0.5 都可以接收语言条件,例如:
"pick up the fork"
"fold the towel"
语言和图像经过 VLM expert 后,条件化 action expert 生成连续动作。因此 PI0 不是没有语言理解能力,也不是只能执行完全无语义的动作。
5.2.2 为什么 PI0.5 看起来更能 “高层出指令、底层执行”?
严格按 openpi 代码,PI0.5 的实际调用仍然是:
语言 prompt
→ prefix 条件
→ action expert
→ 连续动作 chunk
不是:
语言 prompt
→ 显式生成高层文本指令
→ 再把高层指令送给低层控制器
因此更准确的解释是:
- PI0.5 的 VLM 仍能读取语言和图像;
- state 被编码到语言侧,便于语义条件建模;
- 更广泛的训练数据和高层监督增强了长时程任务表示;
- action expert 继续负责连续低层执行;
- 最终通过同一个双 expert Transformer 将高层语义条件映射为低层 action chunk。
这是一种隐式的高层语义规划 + 低层动作执行,而不是代码中新增了一个独立的高层文本输出头。
5.2.3 PI0.5 的潜在优势来源
PI0.5 的能力差异可能来自:
- state 被离散化并放入语言侧 token;
- timestep 通过 adaRMSNorm 注入 action expert;
- 论文中的 FAST/token 训练目标;
- 更广泛的多模态、语言和机器人数据;
- post-training 数据与损失配方;
- checkpoint 和初始化方式;
- knowledge insulation 等训练策略。
这些因素大多不体现在 Pi0.sample_actions() 的几行输出代码里,而体现在训练数据、权重和 checkpoint 来源中。这些因素共同影响开放世界理解、长时程任务和跨任务泛化能力。不能把差异单独归因于:共享 attention。也不能简单归因于:新增一个高层文本 decoder。
PI0.5 的离散 state 接入
PI0.5 将 state 放入语言侧 token 流:
state → 离散 token → PaliGemma embedding
这使状态与图像、语言在 VLM 语义空间中共同建模,更适合广泛多模态和语义数据的 co-training。
PI0 则把 state 作为连续 suffix token:
state → state_proj → action-side suffix
它更直接地服务于低层连续控制。
PI0.5 的 timestep 条件化
PI0.5 将 flow timestep 通过 adaRMSNorm 注入 action expert:
τ → TimeMLP → scale/shift/gate
PI0 将 timestep 与 action embedding 拼接后送入 MLP:
τ + action embedding → action_time_mlp
这会改变 action expert 在 flow 过程中的条件化方式,但本身不产生高层语言输出。
5.3 最终对照表
| 维度 | PI0 | PI0.5 |
|---|---|---|
| VLM expert | PaliGemma/Gemma expert | PaliGemma/Gemma expert |
| action expert | llm 内部第二个 expert | llm 内部第二个 expert |
| 视觉编码器 | img 中的 SigLIP | img 中的 SigLIP |
| state | 连续 state suffix token | 离散 state language token |
| timestep | action-time MLP | Time MLP + adaRMSNorm |
| Flow Matching | 有 | 有 |
| 主输出 | 连续 action chunk | 连续 action chunk |
PI0 类高层文本输出 | 没有 | 没有 |
| FAST token 路径 | 独立 PI0FAST | 论文强调;openpi-main 中独立 PI0FAST |
| 双 expert 联合 attention | 有 | 有 |
| 训练 prefix/suffix | 一次联合前向 | 一次联合前向 |
| 推理 prefix/suffix | prefix cache + suffix Flow loop | prefix cache + suffix Flow loop |
5.4 最终结论
架构骨架: PI0 ≈ PI0.5。
PI0 与 PI0.5 的基础架构可以概括为:
SigLIP + PaliGemma/VLM expert + action expert + Flow Matching + action_out_proj 输出连续动作
PI0.5 的主要代码差异是:
state:
连续 suffix → 离散语言侧 token
timestep:
action-time MLP → Time MLP + adaRMSNorm
在 openpi-main 中:
img:
SigLIP 视觉编码器。
llm:
expert 0 是 VLM/PaliGemma;
expert 1 是 action expert。
PI0/PI0.5:
连续 Flow Matching 路径。
PI0FAST:
独立 FAST token 自回归路径。
论文中的 “先生成 high-level subtask,再生成 low-level action” 是 PI0.5 完整训练 / 推理配方的描述;当前 openpi-main 的 Pi0/PI0.5 类本身并没有内置一个显式高层文本输出接口,也不会自动调用 Pi0FAST 完成两阶段串联。
所以,PI0.5 的 “高层理解更强、长时程任务更好” 不能简单归因于共享注意力,也不能归因于一个显式高层输出模块;在 openpi 中,它主要是相同双 expert 骨架上的输入表示、条件注入、训练数据和权重差异共同造成的。
TransFormer-封面
0xFF 参考
本文使用 markdown.com.cn 排版