Prhub

#44484 [MM][CG] Simplify ViT CUDA graph interfaces

原始 PR 作者 shen-shanshan 合并时间 2026-06-08 13:57 文件变更 2 提交数 2 评论 1 代码增减 +2 / -8

执行摘要

简化 ViT CUDA Graph 接口默认输入模态

PR 正文说明:"This PR add default value ('image') for get_input_modality() to simplify ViT cuda graph interfaces. Thus, for image-only VLMs, they don't need to overwrite the get_input_modality() interface anymore." 即简化纯图像 VLM 的接口实现。

本 PR 为简单的重构清理,值得合并以保持代码整洁。无需精读,可以快速通过 review。

讨论亮点

无 review 评论。PR 由 Isotr0py 批准,无讨论或争议。

实现拆解

  1. 修改协议接口:在 vllm/model_executor/models/interfaces.pySupportsEncoderCudaGraph 协议中,将 get_input_modality 方法的默认行为从抽象方法(...)改为返回字符串 "image",并更新文档字符串为 "Return the modality of the inputs (default: image-only)."
  2. 移除具体实现:在 vllm/model_executor/models/step3_vl.py 中,删除 get_input_modality 方法的覆盖实现(该实现原本也返回 "image"),从此类继承默认实现。
  3. 合并分支:第二个提交将 main 分支合并到功能分支,确保没有冲突。
文件 模块 状态 重要度
vllm/model_executor/models/interfaces.py 模型接口 modified 5.11
vllm/model_executor/models/step3_vl.py 模型实现 modified 5.39

关键符号

get_input_modality

关键源码片段

vllm/model_executor/models/interfaces.py data-contract

定义了 `SupportsEncoderCudaGraph` 协议,是本 PR 的核心变更文件:为 `get_input_modality` 添加默认返回值 `"image"`。

# vllm/model_executor/models/interfaces.py
@runtime_checkable
class SupportsEncoderCudaGraph(Protocol):
    """Interface for models whose vision encoder supports CUDA graph
    capture/replay.
    ...
    """
    supports_encoder_cudagraph: ClassVar[Literal[True]] = True
​
    def get_encoder_cudagraph_config(self) -> "EncoderCudaGraphConfig": ...
​
    def get_input_modality(
        self,
        mm_kwargs: dict[str, Any],
    ) -> str:
        """Return the modality of the inputs (default: image-only)."""
        return "image" # 默认返回 "image",纯图像模型无需重写此方法
​
    def get_max_frames_per_video(self) -> int: ...

评论区精华

没有提炼出高价值讨论线程

当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。

风险与影响

风险极低。该变更仅将重复的默认值移至父协议,且被删除的覆盖实现与新的默认实现完全一致,不会改变行为。潜在风险:若模型中存在依赖 step3_vl.pyget_input_modality 覆盖实现且返回非 "image" 的特殊用例,但本 PR 中不存在这种情形。整体回归风险很小。

影响范围小,仅涉及纯图像 VLM 模型。正面影响:减少了样板代码,未来新增纯图像 VLM 模型时无需再写 get_input_modality 方法。负面影响:无。

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论