执行摘要
修复 PaddleOCR-VL 图像处理器在 Transformers v4/v5 中 max_pixels 访问差异的 bug。
根据 PR body,动机是修复 PaddleOCR-VL 在不同 Transformers 版本中的 max_pixels 处理差异:Transformers 4.x 需要 trust_remote_code=True 且 max_pixels 存储在 image_processor.max_pixels 中,而 Transformers-native 实现(如 v5)则存储在 image_processor.size.longest_edge 中。trust_remote_code 被用作区分代码路径的标记。
此 PR 是一个小修复,不值得深度阅读,但可以作为跨版本兼容性处理的示例。建议工程师在类似场景中关注 trust_remote_code 作为版本区分的设计决策,并考虑添加测试以覆盖不同 Transformers 版本路径。
review 中的核心讨论聚焦于 image_processor.size.longest_edge 的属性访问正确性。gemini-code-assist[bot] 指出这可能导致 AttributeError,因为 image_processor.size 通常是字典,建议使用字典访问。Isotr0py 澄清 Transformers v5 引入了 SizedDict,支持通过属性和键访问。结论是当前实现正确,无需修改,因为 v5 支持属性访问。讨论还涉及与同一文件中 get_num_image_tokens 方法的逻辑一致性。
参与讨论