# OpenVLA-7B在transformers≥4.50下忽略图像输入输出恒定动作

> 原文链接：https://robotics.hellobike.com/pitfalls/2026-09-16-openvla-346
> 频道：pitfalls | 更新日期：2026-09-16 | 标签：auto, github-issue, openvla
> 核心摘要：因新版transformers使用空DynamicCache导致首步prompt被截断，视觉塔未执行；需修复prepare_inputs_for_generation逻辑。

# OpenVLA-7B在transformers≥4.50下忽略图像输入输出恒定动作

::: v-pre
> 本文由 AI 根据公开内容整理，可能有误，请以原文为准：[OpenVLA-7B silently ignores the image on transformers ≥4.50 — constant action for every input](https://github.com/openvla/openvla/issues/346)（GitHub openvla/openvla #346）

**状态**：有绕过办法

## 问题

OpenVLA-7B在transformers≥4.50环境下调用predict_action时，无论输入何种图像（含纯黑/白/噪声），均输出相同动作token 31872。Hook验证显示vision_backbone与projector调用次数为0，语言模型首步input_ids形状为(1,1)而非(1,35)，表明35-token prompt被错误切片，模型进入仅依赖缓存的生成路径，完全绕过视觉编码。

## 环境

openvla/openvla-7b-finetuned-libero-spatial, transformers 4.56.2, torch 2.10.0+cu128, timm 0.9.16, bitsandbytes 0.50.0, RTX 5000 Ada 16GB

## 解决办法

1. 修改 `modeling_prismatic.py` 中 `prepare_inputs_for_generation` 方法，将 `if past_key_values is not None` 判断改为检查 `past_key_values` 是否非空且包含实际缓存内容（如 `len(past_key_values) > 0`），避免空 `DynamicCache` 触发首步 prompt 截断。
2. 在模型类中添加 `_supports_sdpa = True` 属性以兼容新版 transformers 的 SDPA 检查机制。
3. 确保模型类正确继承或注入 `GenerationMixin`，解决远程代码加载时的 MRO 兼容性问题。
4. 应用官方修复 PR #348 中的完整补丁，同步更新上述三处改动以恢复视觉通路正常执行。

讨论原作者：@jashshah999 等，版权归原作者所有。
:::

## 原始参考来源 (Sources)

- [GitHub openvla/openvla #346：OpenVLA-7B silently ignores the image on transformers ≥4.50 — constant action for every input](https://github.com/openvla/openvla/issues/346)