Skip to content

add FastVLM - #4864

Open
yicycyc wants to merge 4 commits into
PaddlePaddle:developfrom
yicycyc:feat/fastvlm
Open

add FastVLM#4864
yicycyc wants to merge 4 commits into
PaddlePaddle:developfrom
yicycyc:feat/fastvlm

Conversation

@yicycyc

@yicycyc yicycyc commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Description

PR 新增模型支持:FastVLM

本 PR 新增 apple/FastVLM-0.5B 支持。复现对齐对象为模型仓库中的 HuggingFace remote-code 实现及原始 safetensors 权重,验证使用完整的 0.5B checkpoint。

主要改动

  • 新增 paddleformers/transformers/fastvlm/
    • FastVLMConfig
    • FastVLMModel
    • FastVLMForConditionalGeneration
    • FastVLMVisionModel
    • FastVLMProcessor
    • FastVLMImageProcessor
    • Qwen2 文本 backbone、MobileCLIP/FastViT 视觉塔及 MLP projector
    • 图像占位 token 展开、图文特征合并、loss 和 greedy generation
  • 注册 FastVLM 到:
    • paddleformers.transformers
    • AutoConfig
    • AutoModelForConditionalGeneration
    • AutoProcessor
    • AutoImageProcessor
  • 权重加载:
    • 支持直接加载原始 HuggingFace safetensors 目录
    • 转换 Qwen2、MobileCLIP/FastViT 和 projector 权重,并校验 missing、unexpected 和 shape mismatch
    • 用户无需预先运行离线权重转换脚本
  • 新增 tests/transformers/fastvlm/test_modeling.py
    • 覆盖多模态 forward/loss、backward、AutoModel 加载和图像预处理

前向对齐验证

模型:apple/FastVLM-0.5B

验证设置:

  • Transformers 与 PaddleFormers 加载相同原始权重和相同图文输入
  • 单张 NVIDIA A100 40GB
  • FP32
  • attention backend:两侧均使用 eager
  • 输出 logits shape:[1, 283, 151936]

结果:

对比范围 max abs diff mean abs diff p99 abs diff cosine Top-1 一致率
完整图文序列 4.96e-2 8.96e-4 6.31e-3 0.99999990 100%
有效文本位置 1.94e-3 4.67e-5 4.38e-4 0.9999999995 100%

满足前向对齐标准。

生成对齐

使用相同权重和输入进行 greedy generation,关闭采样,两侧前 10 个新 token 完全一致。

结论:前 10 个 token 匹配率为 10/10,生成对齐通过。

训练验证

PaddleFormers 与 ms-swift 使用相同的预处理结果和样本顺序,在完整 apple/FastVLM-0.5B 上完成单卡 BF16 full-parameter SFT。

共同设置:

  • 单张 NVIDIA A100 40GB
  • max_steps = 300
  • per_device_train_batch_size = 1
  • gradient_accumulation_steps = 1
  • learning_rate = 1e-5
  • lr_scheduler_type = constant
  • warmup_steps = 0
  • weight_decay = 0
  • gradient clipping:global norm 1.0
  • seed = 42
  • shuffle 关闭
  • attention eager
  • full-parameter SFT

1、纯文本

使用 GSM8K 300 条固定样本做 300-step full-SFT。

指标 ms-swift PaddleFormers Paddle - ms-swift
final loss 0.57808 0.59387 +0.01578
300-step mean loss 0.48863 0.54707 +0.05845
last 50 mean loss 0.50698 0.59787 +0.09088
loss correlation 0.95631
gsm_loss_comparison

2、多模态

使用 PaddleFormers 多模态 SFT 数据格式准备 300 条固定图文样本,两侧使用完全相同的 token、label、图像张量和样本顺序。

指标 ms-swift PaddleFormers Paddle - ms-swift
final loss 3.01865 3.04167 +0.02303
300-step mean loss 1.94669 1.93208 -0.01461
last 50 mean loss 1.77980 1.77458 -0.00523
loss correlation 0.98178
loss_comparison

纯文本和多模态训练均跑满 300 step,两侧 loss 收敛趋势一致。

@risemeup1111 risemeup1111 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

序号 位置 优先级 状态
1 modeling.py:248 P1
2 processing.py:64 P1
3 modeling.py:211 P1
4 modeling.py:475 P1
Powered by Nyanpasu with gpt-5.5 xhigh, please check the suggestions carefully.

Comment thread paddleformers/transformers/fastvlm/modeling.py Outdated
Comment thread paddleformers/transformers/auto/processing.py
Comment thread paddleformers/transformers/fastvlm/modeling.py Outdated
Comment thread paddleformers/transformers/fastvlm/modeling.py
@Paddle-CI-Bot

Paddle-CI-Bot commented Aug 11, 2026

Copy link
Copy Markdown

PaddleFormers Log Analysis

Run #31481631716 · Attempt 1

Job logs (requires authentication)

gh api repos/PaddlePaddle/PaddleFormers/actions/jobs/93731862468/logs > /tmp/job_93731862468.log
gh api repos/PaddlePaddle/PaddleFormers/actions/jobs/93732148782/logs > /tmp/job_93732148782.log


Once I have the raw log content, I'll produce the full structured report including:
- Root-cause analysis tied to PR changes
- Failed test case listing
- Local `/tmp/bot_results/` artifacts with verified paths
- Gist uploads for each pipeline

---
> 🔍 **准确性记录**:请点击评论底部 😊 图标,选择 👍(准确)或 👎(有误),将自动记录到 CI 监控系统

<sub>🔄 每次 Re-run 后自动更新</sub>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants