策略是连接模型与算法的桥梁,其设计直接影响模型性能。实际应用中需根据任务类型、数据特性和业务目标灵活选择并迭代优化策略

┌─────────────────────────────────────────────────────────────────┐
│ 机器人控制流程 │
├─────────────────────────────────────────────────────────────────┤
│ │
│ 机器人硬件 控制器 Policy Server │
│ │ │ │ │
│ │ 观测数据 │ │ │
│ ├──────────────►│ │ │
│ │ │ select_action │ │
│ │ ├────────────────►│ │
│ │ │ │ 1. 预处理 │
│ │ │ │ 2. sample_actions │
│ │ │ │ 3. 反标准化 │
│ │ │ 动作指令 │ │
│ │ │◄────────────────┤ │
│ │ 执行动作 │ │ │
│ │◄──────────────┤ │ │
│ │ │ │ │
└─────────────────────────────────────────────────────────────────┘

class LingbotVLAv2Server:
def init(
self,
adaptive_ensemble_alpha=0.1, # 自适应混合系数
action_ensemble_horizon=8, # 集成时间跨度
use_length=1, # 使用的动作长度
chunk_ret=False, # 是否返回完整chunk
):
self.last_action_chunk = None # 上一次的动作chunk
self.last_normalized_action_chunk = None

原理 :通过混合当前预测和历史动作,提高动作稳定性。

deploy/lingbot_vla_v2_policy.py#L184 支持自适应动作集成:

def forward(
self,
images, # (B, N_cam, C, H, W) 图像
img_masks, # (B, N_cam) 图像掩码
state, # (B, max_state_dim) 状态
lang_tokens, # (B, max_seq_len) 语言token
lang_masks, # (B, max_seq_len) 语言掩码
actions, # (B, chunk_size, max_action_dim) 动作
joint_mask=None, # 关节掩码
noise=None, # Flow Matching噪声
time=None, # 时间步
depth_targets=None, # 深度对齐目标
future_depth_targets=None, # 未来深度目标
future_video_targets=None, # 未来视频目标

) -> tuple[Tensor, dict[str, Tensor]]:

返回值 :

  • total_loss : 总损失(VLA + 深度 + 视频 + MoE)
  • loss_vla : VLA 动作预测损失
  • loss_depth : 深度对齐损失
  • loss_future_depth : 未来深度损失
  • loss_future_video : 未来视频损失
  • seq_wise_loss : 序列级损失(MoE)
  • loss_dict : 损失字典(含MoE指标)

Policy 类体系

1. 核心 Policy 类(训练+推理)

类 文件 用途 LingbotVlaPolicy modeling_lingbot_vla.py#L613 基础版本,支持训练和推理 LingbotVlaV2Policy modeling_lingbot_vla_v2.py#L1198 V2版本,支持MoE、深度/视频对齐 PI0Policy modeling_pi0.py#L1790 PI0模型,基于PaliGemma

┌─────────────────────────────────────────────────────────────────┐
│ PI0Policy 架构 │
├─────────────────────────────────────────────────────────────────┤
│ │
│ PI0Policy │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ config: PI0_Omni_Config │ │
│ │ language_tokenizer: AutoTokenizer │ │
│ │ model: PI0FlowMatching │ │
│ │ ┌─────────────────────────────────────────────────┐ │ │
│ │ │ paligemma_with_expert: │ │ │
│ │ │ ┌─────────────────────────────────────────┐ │ │ │
│ │ │ │ PaliGemma (SigLIP + Gemma) │ │ │ │
│ │ │ │ - embed_image: 图像嵌入 │ │ │ │
│ │ │ │ - embed_language_tokens: 语言嵌入 │ │ │ │
│ │ │ │ - forward: VLM前向 │ │ │ │
│ │ │ └─────────────────────────────────────────┘ │ │ │
│ │ │ ┌─────────────────────────────────────────┐ │ │ │
│ │ │ │ Gemma Expert x10 │ │ │ │
│ │ │ │ - 动作解码器 │ │ │ │
│ │ │ └─────────────────────────────────────────┘ │ │ │
│ │ │ ├──────────────────────────────────────────────┐ │ │
│ │ │ │ Projection Layers: │ │ │
│ │ │ │ - state_proj: 状态投影 │ │ │
│ │ │ │ - action_in_proj: 动作输入投影 │ │ │
│ │ │ │ - action_out_proj: 动作输出投影 │ │ │
│ │ │ │ - action_time_mlp: 时间-动作融合 │ │ │
│ │ │ └──────────────────────────────────────────────┘ │ │
│ │ └─────────────────────────────────────────────────────┘ │ │
│ └──────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘

def forward(
self, images, img_masks, state, lang_tokens, lang_masks, actions,
joint_mask=None, action_is_pad=None, noise=None, time=None
) -> tuple[Tensor, dict[str, Tensor]]:
loss_dict = {}

# 调用底层 Flow Matching 模型
losses = self.model.forward(
    images, img_masks, lang_tokens, lang_masks, state, actions, noise, time
)

# 处理填充掩码
if action_is_pad is not None:
    in_episode_bound = ~action_is_pad
    losses = losses * in_episode_bound.unsqueeze(-1)

# 去除填充维度
losses = losses[:, :, :self.config.action_dim]
loss_dict["losses"] = losses.clone()

# 计算总损失
loss = losses.mean()
loss_dict["l2_loss"] = loss.item()

return loss, loss_dict

与 LingbotVlaV2Policy 的对比

维度 PI0Policy LingbotVlaV2Policy VLM 基础 PaliGemma (SigLIP + Gemma) Qwen3-VL (Qwen2.5-VL) 动作专家 Gemma Expert x10 Qwen2 Expert x36 (MoE) 专家数量 固定10层 32 experts, top-4 routing 默认动作维度 7 55 投影维度 1024 768 采样步数 10 可配置 深度对齐 支持(DepthAnythingV2) 支持(MoRGBD) 视频对齐 ❌ ✅ DINOv3 聊天模板 PaliGemma 格式 Qwen3 Chat Template

toolName: search_by_regex

status: success

query: DepthAnythingV2

toolName: file_search

status: success

file_pattern: */depth

toolName: view_files

status: success

filePath: /Users/mac/projects/robot/lingbot-vla-v2/lingbotvla/models/vla/vision_models/MoGe/baselines/da_v2.py

toolName: view_files

status: success

filePath: /Users/mac/projects/robot/lingbot-vla-v2/lingbotvla/models/vla/vision_models/MoGe/baselines/da_v2_metric.py

toolName: search_by_regex

status: success

query: build_depth_model|get_depth_target

toolName: view_files

status: success

filePath: /Users/mac/projects/robot/lingbot-vla-v2/lingbotvla/models/vla/vision_models/module_utils.py

DepthAnythingV2 在项目中的作用

核心定位

DepthAnythingV2 是一个预训练的单目深度估计模型,在 lingbot-vla-v2 项目中用于**深度对齐(Depth Alignment)**训练策略,帮助 VLA 模型学习深度感知能力。

┌─────────────────────────────────────────────────────────────────┐
│                     Depth Alignment 流程                       │
├─────────────────────────────────────────────────────────────────┤
│                                                                 │
│  ┌──────────────┐    ┌──────────────────┐    ┌──────────────┐  │
│  │   RGB 图像   │───►│  DepthAnythingV2 │───►│  深度图      │  │
│  │              │    │   (教师模型)      │    │  (监督信号)  │  │
│  └──────────────┘    └──────────────────┘    └──────────────┘  │
│         │                                        │              │
│         │                                        ▼              │
│         │                              ┌──────────────────┐    │
│         │                              │   深度特征提取   │    │
│         ▼                              │   (cls_token)    │    │
│  ┌──────────────┐                     └──────────────────┘    │
│  │   VLA 模型   │◄───────────────────────────────────────┐    │
│  │              │         深度对齐损失                    │    │
│  │  (学生模型)   │───────────────────────────────────────┘    │
│  └──────────────┘                                             │
│                                                                 │
└─────────────────────────────────────────────────────────────────┘

代码实现

1. 基础封装

[da_v2.py](file:///Users/mac/projects/robot/lingbot-vla-v2/lingbotvla/models/vla/vision_models/MoGe/baselines/da_v2.py)

class Baseline(MGEBaselineInterface):
    def __init__(self, repo_path: str, backbone: str, num_tokens: int, device):
        # 加载外部 Depth-Anything-V2 仓库
        from depth_anything_v2.dpt import DepthAnythingV2
        
        # 实例化模型
        model = DepthAnythingV2(
            encoder=backbone,              # vits/vitb/vitl
            features=256,                  # 特征维度
            out_channels=[256, 512, 1024, 1024],  # 各层输出通道
        )
        
        # 加载权重
        checkpoint_path = os.path.join(repo_path, f'checkpoints/depth_anything_v2_{backbone}.pth')
        model.load_state_dict(torch.load(checkpoint_path, map_location='cpu', weights_only=True))
        
        model.to(device).eval()
        self.model = model

支持的 Backbone

Backbone features out_channels 参数量
vits 64 [48, 96, 192, 384] 小模型
vitb 128 [96, 192, 384, 768] 中模型
vitl 256 [256, 512, 1024, 1024] 大模型

2. 推理方法

@torch.inference_mode()
def infer(self, image: torch.Tensor, intrinsics=None) -> Dict[str, torch.Tensor]:
    original_height, original_width = image.shape[-2:]
    
    # 调整图像尺寸(保持 14 的倍数)
    resize_factor = 518 / min(original_height, original_width)
    expected_width = round(original_width * resize_factor / 14) * 14
    expected_height = round(original_height * resize_factor / 14) * 14
    image = TF.resize(image, (expected_height, expected_width), 
                     interpolation=T.InterpolationMode.BICUBIC, antialias=True)
    
    # ImageNet 归一化
    image = TF.normalize(image, mean=[0.485, 0.456, 0.406], 
                        std=[0.229, 0.224, 0.225])
    
    # 预测视差图
    disparity = self.model(image)
    
    # 上采样回原始尺寸
    disparity = F.interpolate(disparity[:, None], size=(original_height, original_width), 
                             mode='bilinear', align_corners=False)[:, 0]
    
    return {'disparity_affine_invariant': disparity}

3. 度量深度版本

[da_v2_metric.py](file:///Users/mac/projects/robot/lingbot-vla-v2/lingbotvla/models/vla/vision_models/MoGe/baselines/da_v2_metric.py) 支持室内/室外场景的度量深度估计:

model_configs = {
    'vits': {'encoder': 'vits', 'features': 64, 'out_channels': [48, 96, 192, 384]},
    'vitb': {'encoder': 'vitb', 'features': 128, 'out_channels': [96, 192, 384, 768]},
    'vitl': {'encoder': 'vitl', 'features': 256, 'out_channels': [256, 512, 1024, 1024]}
}

if domain == 'indoor':
    dataset = 'hypersim'
    max_depth = 20
elif domain == 'outdoor':
    dataset = 'vkitti'
    max_depth = 80

深度对齐训练集成

1. 模型构建(train_pi0.py)

[train_pi0.py#L312-L315](file:///Users/mac/projects/robot/lingbot-vla-v2/tasks/vla/train_pi0.py#L312-L315)

if depth_model_type == 'DepthAnythingV2':
    dav2_backbone, dav2_head = build_depth_model(args.train.align_params)
    if args.train.use_compile:
        dav2_backbone = torch.compile(dav2_backbone)

注意:当前 build_depth_model 函数只支持 MoRGBD,不支持 DepthAnythingV2:

# module_utils.py#L71-L76
def build_depth_model(config):
    model_type = config['depth']['model_type']
    if model_type != 'MoRGBD':
        raise ValueError(f"Only Lingbot-Depth distillation is supported, got {model_type!r}.")
    ...

2. 获取深度目标

[train_pi0.py#L586-L589](file:///Users/mac/projects/robot/lingbot-vla-v2/tasks/vla/train_pi0.py#L586-L589)

if depth_model_type == 'DepthAnythingV2':
    depth_targets, cls_token = get_depth_target(depth_model_type, dav2_backbone, pil_images)

3. 深度损失计算

深度对齐损失会被加入到总损失中:

total_loss = loss_vla + loss_depth + loss_future_depth + ...

深度对齐的作用

1. 提供深度监督信号

VLA 模型本身没有深度感知能力,通过深度对齐:

  • 利用 DepthAnythingV2 提取的深度特征作为监督信号
  • 训练 VLA 模型的视觉编码器学习深度相关信息
  • 提高模型对 3D 空间的理解能力

2. 辅助动作预测

在机器人控制任务中,深度信息对于:

  • 判断物体距离
  • 规划抓取路径
  • 避免碰撞

非常重要。通过深度对齐,模型可以隐式学习深度特征,从而生成更准确的动作。

3. 跨模态对齐

将图像特征与深度特征对齐,增强模型的多模态理解能力。


配置要求

1. 外部依赖

DepthAnythingV2 需要从外部仓库加载:

# 需要克隆 Depth-Anything-V2 仓库
git clone https://github.com/DepthAnything/Depth-Anything-V2.git

# 下载权重文件
# vits: depth_anything_v2_vits.pth
# vitb: depth_anything_v2_vitb.pth  
# vitl: depth_anything_v2_vitl.pth

2. 训练配置

train:
  align_params:
    mode: 'query'
    num_task_tokens: 8
    depth_loss_weight: 0.004
    depth:
      model_type: 'DepthAnythingV2'
      repo_path: '/path/to/Depth-Anything-V2'
      backbone: 'vitl'

3. 支持的深度模型类型

模型类型 说明 文件
DepthAnythingV2 预训练单目深度估计 da_v2.py
DepthAnythingV2 (metric) 度量深度估计 da_v2_metric.py
MoRGBD 自研深度+RGB融合模型 项目内置

当前问题

build_depth_model 函数不支持 DepthAnythingV2

[module_utils.py#L74-L75](file:///Users/mac/projects/robot/lingbot-vla-v2/lingbotvla/models/vla/vision_models/module_utils.py#L74-L75)

if model_type != 'MoRGBD':
    raise ValueError(f"Only Lingbot-Depth distillation is supported, got {model_type!r}.")

这意味着虽然 train_pi0.py 中有 DepthAnythingV2 的分支代码,但实际运行会报错。需要修改 build_depth_model 函数来支持 DepthAnythingV2,或者使用 MoRGBD。


总结

维度 说明
模型类型 预训练单目深度估计
支持 Backbone vits、vitb、vitl
输入 RGB 图像
输出 视差图(disparity)或度量深度图(metric depth)
在项目中的作用 提供深度对齐监督信号,辅助 VLA 模型训练
当前状态 代码框架存在,但 build_depth_model 函数不支持
推荐替代方案 使用 MoRGBD(项目内置支持)

使用建议:如果需要深度对齐功能,建议使用 MoRGBD 模型,因为它是项目内置支持的,配置更简单。如果必须使用 DepthAnythingV2,需要修改 build_depth_model 函数来支持它。

深度对齐实现流程详解

整体架构

深度对齐采用 Knowledge Distillation(知识蒸馏) 策略,将 DepthAnythingV2 作为教师模型,VLA 模型作为学生模型

┌─────────────────────────────────────────────────────────────────────────┐
│                     深度对齐知识蒸馏流程                                 │
├─────────────────────────────────────────────────────────────────────────┤
│                                                                         │
│  ┌──────────────────────────────────────────────────────────────────┐   │
│  │                    教师模型 (DepthAnythingV2)                     │   │
│  │  ┌──────────────┐    ┌──────────────────┐    ┌──────────────┐   │   │
│  │  │   RGB 图像   │───►│  DepthAnythingV2 │───►│  深度特征    │   │   │
│  │  │              │    │   (冻结权重)      │    │  (监督信号)  │   │   │
│  │  └──────────────┘    └──────────────────┘    └──────────────┘   │   │
│  │                                                          │      │   │
│  └──────────────────────────────────────────────────────────┼──────┘   │
│                                                             ▼          │
│  ┌──────────────────────────────────────────────────────────────────┐   │
│  │                    学生模型 (VLA)                                │   │
│  │  ┌──────────────┐    ┌──────────────────┐    ┌──────────────┐   │   │
│  │  │   RGB 图像   │───►│  视觉编码器      │───►│  图像特征    │   │   │
│  │  │              │    │  (可训练)        │    │              │   │   │
│  │  └──────────────┘    └──────────────────┘    └──────┬───────┘   │   │
│  │                                                     │            │   │
│  │                     ┌──────────────────────┐        │            │   │
│  │                     │  DepthAlignHead      │        │            │   │
│  │                     │  (可训练)             │◄───────┘            │   │
│  │                     └──────────┬───────────┘                      │   │
│  │                                ▼                                  │   │
│  │                     ┌──────────────────────┐                      │   │
│  │                     │  预测深度特征        │                      │   │
│  │                     └──────────┬───────────┘                      │   │
│  │                                │                                  │   │
│  │              ┌─────────────────┴─────────────────┐                │   │
│  │              ▼                                   ▼                │   │
│  │       ┌──────────────┐                   ┌──────────────┐        │   │
│  │       │  预测特征    │                   │  目标特征    │        │   │
│  │       └──────┬───────┘                   └──────┬───────┘        │   │
│  │              └──────────────┬──────────────────┘                  │   │
│  │                             ▼                                      │   │
│  │                   ┌──────────────────────┐                        │   │
│  │                   │  MSE Loss            │                        │   │
│  │                   │  (深度对齐损失)       │                        │   │
│  │                   └──────────┬───────────┘                        │   │
│  │                              ▼                                    │   │
│  │                   反向传播更新 VLA 视觉编码器                        │   │
│  └──────────────────────────────────────────────────────────────────┘   │
│                                                                         │
└─────────────────────────────────────────────────────────────────────────┘

步骤1:深度目标特征提取

教师模型推断

module_utils.py#L426-L447

def get_depth_target(model_type, depth_model, pil_images):
    # 当前只支持 MoRGBD,需要扩展支持 DepthAnythingV2
    if model_type != 'MoRGBD':
        raise ValueError(f"Only Lingbot-Depth depth targets are supported, got {model_type!r}.")
    
    # 取第一张图像(主相机)
    pil_images = pil_images[:, :1, :, :, :]  # (B, 1, C, H, W)
    images = einops.rearrange(pil_images, 'b n c h w -> (b n) c h w', n=1)
    
    # 归一化到 [0, 1]
    input_images = _rgb_to_unit_float(images)
    
    # MoRGBD 模型推断
    moge_model, morgbd_model = depth_model
    output_moge = moge_model.infer(input_images, resolution_level=3, num_tokens=256)
    depth_pred = output_moge['depth'].squeeze().detach().clone()
    
    # 获取深度特征(作为监督信号)
    depth_target, cls_token = morgbd_model.infer_feat(
        input_images, depth_pred, 
        resolution_level=3,
        num_tokens=256,
    )
    
    # 调整维度:(B, H, W, C) → (B, H*W, C)
    depth_target = depth_target.permute(0, 2, 3, 1)
    depth_target = depth_target.view(depth_target.shape[0], -1, depth_target.shape[-1])
    
    return depth_target.to(dtype=torch.bfloat16), cls_token

关键设计

  • 深度特征是从深度图重构过程中提取的中间特征
  • 这些特征包含丰富的深度信息,作为监督信号
  • 特征维度:(batch_size, num_tokens, feature_dim)

步骤2:深度对齐头初始化

modeling_lingbot_vla.py#L774-L825

def init_depth_heads(self, config):
    # 配置参数
    self.llm_image_token_size = config['llm']['image_token_size']  # 默认14
    self.depth_token_size = config['depth']['token_size']           # 默认14
    self.align_type = config.get('mode', None)                      # "query"
    self.model_type = config['depth']['model_type']                 # "MoRGBD"
    
    # 可学习的深度对齐任务 token
    self.depth_align_embs = nn.Parameter(
        torch.randn(
            config['depth']['num_backbone_tokens'],  # 196 (14×14)
            config['llm']['dim_out']                 # 768
        )
    )
    self.depth_align_embs.requires_grad = True
    
    # 深度对齐头(TaskTokenDepthHead)
    self.depth_align_head = TaskTokenDepthHead(
        config['depth'], 
        llm_hidden_size=config['llm']['dim_out']
    ).to(dtype=torch.bfloat16)
    
    # 未来深度对齐(可选)
    if self.use_future_depth:
        self.future_depth_align_embs = nn.Parameter(...)
        self.future_depth_align_head = TaskTokenDepthHead(...)

架构图

┌──────────────────────────────────────────────────────────┐
│                   DepthAlignHead                         │
│  ┌────────────────────────────────────────────────────┐  │
│  │  TaskTokenResampler                                │  │
│  │  ┌─────────────┐    ┌───────────────────────────┐  │  │
│  │  │  Attention  │───►│  Feed-Forward Network    │  │  │
│  │  │  (num_layers)│    │  (ff_mult=4)            │  │  │
│  │  └─────────────┘    └───────────────────────────┘  │  │
│  │                          │                         │  │
│  │                          ▼                         │  │
│  │                   ┌─────────────┐                  │  │
│  │                   │  Projection │  → dim_out=768   │  │
│  │                   └─────────────┘                  │  │
│  └────────────────────────────────────────────────────┘  │
└──────────────────────────────────────────────────────────┘

TaskTokenResampler 参数

参数 默认值 说明
dim_in 768 输入维度(LLM隐藏层)
dim_mid 768 中间维度
dim_head 64 注意力头维度
dim_out 768 输出维度
num_layers 2 Transformer层数
num_heads 12 注意力头数
num_queries 196 查询token数(14×14)
ff_mult 4 FFN隐藏层倍数

步骤3:深度特征预测

modeling_lingbot_vla.py#L1418-L1443

def depth_emb_forward(self, hidden_states, depth_targets=None, img_masks=None, future_depth_targets=None):
    # 1. 提取图像特征(从 LLM 隐藏状态中)
    chunk_size = self.llm_image_token_size * self.llm_image_token_size  # 14×14=196
    image_embs = hidden_states[:, chunk_size * 0 + 1 : chunk_size * 1 + 1, :]
    
    # 2. 获取任务 token
    align_embs = self._current_depth_task_tokens(hidden_states, num_images=num_images)
    
    # 3. 拼接图像特征和任务 token
    align_embs = torch.cat([image_embs, align_embs], dim=1)
    
    # 4. 预测深度特征
    depth_preds = self.depth_align_embs.repeat(align_embs.shape[0], 1, 1)
    depth_preds = self.depth_align_head(align_embs, depth_preds).contiguous().float()
    
    # 5. 计算损失
    current_loss = self._emb_loss(depth_preds, depth_targets)
    
    # 6. 未来深度对齐(可选)
    if self.use_future_depth:
        ...
        return current_loss, future_loss, depth_preds, future_depth_preds
    
    return current_loss, 0, depth_preds, None

关键步骤

  1. 提取图像特征:从 LLM 的隐藏状态中提取视觉 token 的特征
  2. 任务 token:使用可学习的深度对齐任务 token
  3. 注意力机制:通过 TaskTokenResampler 的注意力机制,让任务 token 从图像特征中提取深度相关信息
  4. 特征预测:输出与教师模型相同维度的深度特征

步骤4:损失计算

嵌入损失

def _emb_loss(self, preds, targets):
    # MSE 损失
    return F.mse_loss(preds, targets, reduction="none").mean()

总损失

modeling_lingbot_vla.py#L1228-L1229

# 深度对齐损失
loss_depth, _, depth_preds = self.depth_emb_forward(outputs_embeds, depth_targets, img_masks)
loss_depth = loss_depth * self.config.align_params['depth_loss_weight']

# 总损失
total_loss = loss_vla + loss_depth + ...

损失权重配置

train:
  align_params:
    depth_loss_weight: 0.004  # 深度损失权重

步骤5:反向传播与参数更新

训练流程

┌─────────────────────────────────────────────────────────┐
│                    训练循环                              │
├─────────────────────────────────────────────────────────┤
│                                                         │
│  for batch in dataloader:                               │
│      # 1. 获取深度目标特征                               │
│      depth_targets, cls_token = get_depth_target(       │
│          model_type, depth_model, pil_images)           │
│                                                         │
│      # 2. VLA 模型前向传播                              │
│      loss_vla, outputs_embeds = model.forward(          │
│          images, state, lang_tokens, actions, ...)      │
│                                                         │
│      # 3. 深度对齐前向传播                              │
│      loss_depth, _, depth_preds = model.depth_emb_forward(│
│          outputs_embeds, depth_targets, img_masks)     │
│                                                         │
│      # 4. 总损失                                        │
│      total_loss = loss_vla + loss_depth * weight        │
│                                                         │
│      # 5. 反向传播                                      │
│      total_loss.backward()                              │
│                                                         │
│      # 6. 参数更新(优化器)                             │
│      optimizer.step()                                   │
│      optimizer.zero_grad()                              │
│                                                         │
└─────────────────────────────────────────────────────────┘

参数更新范围

参数 是否更新 说明
VLA 视觉编码器 通过深度损失梯度更新
VLA 语言模型 通过 VLA 损失更新
DepthAlignHead 通过深度损失更新
DepthAlignEmbs 通过深度损失更新
DepthAnythingV2 冻结权重,仅提供监督信号

配置示例

完整的深度对齐配置

train:
  align_params:
    mode: 'query'
    num_task_tokens: 8
    depth_loss_weight: 0.004
    depth:
      model_type: 'MoRGBD'           # 当前只支持 MoRGBD
      repo_path: '/path/to/morgbd'
      backbone: 'vitl'
      token_size: 14
      input_size: 224
      num_backbone_tokens: 196
      dim_out: 768
      num_layers: 2
      num_heads: 12
      dim_head: 64
      ff_mult: 4
      use_future_depth: true
    llm:
      image_token_size: 14
      image_input_size: 224
      dim_out: 768

当前限制

DepthAnythingV2 未完全集成

module_utils.py#L427-L428

if model_type != 'MoRGBD':
    raise ValueError(f"Only Lingbot-Depth depth targets are supported, got {model_type!r}.")

modeling_lingbot_vla.py#L783-L784

if self.model_type != "MoRGBD":
    raise ValueError(f"Only MoRGBD depth distillation is supported, got {self.model_type!r}.")

虽然 da_v2.pyda_v2_metric.py 提供了 DepthAnythingV2 的封装,但 get_depth_targetinit_depth_heads 函数不支持它。需要修改这两个函数才能使用 DepthAnythingV2。


总结

深度对齐的实现流程:

步骤 操作 关键代码
1 教师模型推断 get_depth_target()
2 初始化对齐头 init_depth_heads()
3 预测深度特征 depth_emb_forward()
4 计算损失 _emb_loss() (MSE)
5 反向传播 total_loss.backward()

核心原理

  • 通过知识蒸馏,将 DepthAnythingV2 学到的深度特征作为监督信号
  • 训练 VLA 模型的视觉编码器学习深度相关信息
  • 提高模型对 3D 空间的理解能力,从而生成更准确的动作

使用建议:当前只能使用 MoRGBD,如果需要使用 DepthAnythingV2,需要修改 get_depth_targetinit_depth_heads 函数。

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐