Support InternVL3.5 model - #4867
Conversation
There was a problem hiding this comment.
| 序号 | 位置 | 优先级 | 状态 |
|---|---|---|---|
| 1 | modeling.py:270 | ✅ | |
| 2 | modeling.py:92 | ✅ | |
| 3 | processor.py:97 | ✅ | |
| 4 | internvl3_5/modeling.py:23 | ❌ | |
| 5 | internvl3_5/modeling.py:507 | ✅ |
| llm_config = {"architectures": ["Qwen3ForCausalLM"]} | ||
|
|
||
| self.vision_config = InternVisionConfig(**vision_config) if isinstance(vision_config, dict) else vision_config | ||
| self.llm_config = Qwen3Config(**llm_config) if isinstance(llm_config, dict) else llm_config |
There was a problem hiding this comment.
这里把所有
llm_config 都构造成 dense Qwen3Config,但公开的 OpenGVLab/InternVL3_5-30B-A3B 和 OpenGVLab/InternVL3_5-241B-A28B 配置声明的是 model_type: qwen3_moe / Qwen3MoeForCausalLM。随后 InternVLChatModel.__init__ 又固定实例化 Qwen3ForCausalLMDeprecated,因此这些官方 InternVL3.5 检查点会创建 dense 层,expert/router 权重无法匹配。请按 llm_config.model_type 或 architectures 分派 Qwen3/Qwen3Moe 的配置、模型及转换规则;若本次只支持 dense 变体,也应在这里显式拒绝不支持的架构,避免静默构造错误模型。
There was a problem hiding this comment.
仍未完全解决:modeling.py:258-272 的 transpose_weight_keys 没有包含 MoE router 的 gate。load_checkpoint_format="" 从 HF 权重加载时会保留 [num_experts, hidden_size],无法匹配 Paddle Linear 的 [hidden_size, num_experts];请补上 gate,并增加该加载路径的 MoE checkpoint 转换测试。
There was a problem hiding this comment.
已确认当前提交将 gate 加入 transpose_weight_keys,并新增 load_checkpoint_format="" 从 HF safetensors 回读 router 权重的回归测试;该问题已解决。
|
|
||
| def forward(self, pixel_values): | ||
| target_dtype = self.patch_embedding.weight.dtype | ||
| patch_embeds = self.patch_embedding(pixel_values) |
There was a problem hiding this comment.
InternVLImageProcessor 固定返回 float32 的 pixel_values,而官方 InternVL3.5 配置带有 torch_dtype: bfloat16,from_pretrained 会据此以 bf16 创建这里的卷积权重。当前输入未经转换就进入 Conv2D,所以 model.generate(**processor(...)) 在真实 bf16 检查点上会遇到输入与权重 dtype 不一致;仓库内其他 VLM 也都在视觉 patch embedding 前按权重 dtype 转换。请先将 pixel_values 转成 target_dtype,并增加一个 bf16 模型接收处理器输出的集成测试。
There was a problem hiding this comment.
已确认当前提交在视觉 patch embedding 前将 pixel_values 转为卷积权重 dtype,并补充了 bf16 回归测试;该问题已解决。
|
|
||
| text_inputs = self.tokenizer(text, **output_kwargs["text_kwargs"], return_tensors=return_tensors) | ||
| data = dict(text_inputs) | ||
| data.update(dict(image_inputs)) |
There was a problem hiding this comment.
There was a problem hiding this comment.
已确认当前提交在展开图像 token 后移除 num_patches_list,最终处理器输出与模型前向参数一致;该问题已解决。
PaddleFormers Log Analysis
日志分析报告
失败的测试case: 根本原因分析:
修复建议:
🔄 每次 Re-run 后自动更新 |
| CausalLMOutputWithPast, | ||
| ) | ||
| from ..model_utils import PretrainedModel | ||
| from ..qwen3.modeling import Qwen3ForCausalLMDeprecated |
There was a problem hiding this comment.
这里的顶层导入会让标准安装无法导入 InternVL3.5:
qwen3.modeling 无条件导入 gpt_provider,而后者在未安装可选 extra paddlefleet 时会在模块导入阶段抛出 ImportError。setup.py 只在 paddleformers[paddlefleet] 中声明该依赖,因此即使这里只构造不依赖 Fleet 的 Qwen3ForCausalLMDeprecated,from paddleformers.transformers import InternVLChatModel 也会失败。请恢复 lazy/guarded import,或把 deprecated 实现从 Fleet provider 的导入链中隔离,并补充无 PaddleFleet 的 import smoke test。
| labels: Optional[paddle.Tensor] = None, | ||
| use_cache: Optional[bool] = None, | ||
| output_attentions: Optional[bool] = None, | ||
| output_hidden_states: Optional[bool] = None, |
There was a problem hiding this comment.
There was a problem hiding this comment.
已确认当前提交移除了 InternVLChatModel 不支持的 output_hidden_states 参数,并将回归测试明确改为 InternVisionModel;该问题已解决。
PR 类型
新增模型支持 / Models
PR 变更
新增 InternVL3.5-1B 在 PaddleFormers 中的模型接入,包括配置、模型、Processor、ImageProcessor、Auto 注册、单测与本地真实权重验证。
主要内容
新增
paddleformers/transformers/internvl3_5InternVLChatConfigInternVisionConfigInternVLChatModelInternVisionModelInternVLProcessorInternVLImageProcessor接入 Auto 入口
AutoConfigAutoModelAutoProcessorAutoImageProcessor支持从原始 HuggingFace 权重加载
/sda/housaijie/code/InternVL3_5-1Bconvert_from_hf=Truemodel.safetensors权重可完整加载复用主线 Qwen3 / Qwen3-MoE 实现
Qwen3ForCausalLMDeprecatedQwen3MoeForCausalLMDeprecated新增测试
tests/transformers/internvl3_5/test_modeling.pytests/transformers/internvl3_5/test_processor.py验证结果
1. 单卡前向精度对齐
使用本地真实 InternVL3.5-1B 权重,对齐 transformers/PyTorch 与 PaddleFormers 的 FP32 forward logits。
固定输入:
/sda/housaijie/code/InternVL3_5-1Bpixel_values shape = (1, 3, 448, 448)Describe the image.256<IMG_CONTEXT>token id:151671结果: