Add Phi-4 multimodal support#4648
Open
yicycyc wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 新增模型支持:Phi-4-multimodal
本 PR 新增
microsoft/Phi-4-multimodal-instruct支持。复现对齐对象为 Microsoft/HuggingFace remote-code 实现以及 ModelScope 上的原始 safetensors 权重。主要改动
paddleformers/transformers/phi4_multimodal/Phi4MultimodalConfigPhi4MultimodalModelPhi4MultimodalForCausalLMPhi4MultimodalForCausalLMPipePhi4MultimodalProcessorPhi4MultimodalImageProcessorPhi4MultimodalFeatureExtractorpaddleformers.transformersAutoConfigAutoModelAutoModelForCausalLMAutoProcessorAutoImageProcessorAutoFeatureExtractorphi4_multimodaltemplate / MM pluginmm_collate_fn支持image_pixel_values、image_sizes、image_attention_maskmm_collate_fn支持audio_input_features、audio_attention_mask、audio_embed_sizesinput_mode,用于区分 text / vision / speech / vision-speech adapter routePhi4MultimodalPreTrainedModel._gen_aoa_config中实现 HF/ModelScope safetensors 到 PaddleFormers 权重的自动转换规则phi4mmconfig 转 PaddlePhi4MultimodalConfigdocs/zh/model_capability.md能力矩阵前向对齐验证
模型:
microsoft/Phi-4-multimodal-instruct环境设置:
FLAGS_use_accuracy_compatible_kernel=1、FLAGS_cudnn_deterministic=1、NVIDIA_TF32_OVERRIDE=0torch.backends.cudnn.deterministic=True、torch.backends.cudnn.allow_tf32=Falsefp32 最终 logits:
text bf16 补充:
生成对齐
Text-only 生成:
[[100, 101]][220, 17, 87, 659, 220, 18, 88, 314, 220, 899][[100, 101]][220, 17, 87, 659, 220, 18, 88, 314, 220, 899]3.6239624e-052.6317712e-06Vision 生成:
[200, 200, 200, 200, 200, 200, 200, 200, 200, 200]Audio 说明:
Conv1D算子差异。训练验证
1. 文本
使用 GSM8K 做 BF16 full-SFT,Paddle 侧使用 sharding stage3,Torch 侧使用 ms-swift ZeRO-3。
共同设置:
global batch size = 4learning_rate = 1e-5warmup_steps = 0weight_decay = 0loss曲线如下:

2. 视觉多模态
使用小多模态 SFT 数据做 BF16 full-SFT,Paddle 侧使用 sharding stage3,Torch 侧使用 ms-swift ZeRO-3。
loss曲线如下:
