Skip to content

fix(transformers): keep FSDP vision paths active for mixed batches - #374

Merged
kevssim merged 1 commit into
modelscope:dev-swift-v5from
werwrewe:fix/fsdp-mixed-modality
Nov 12, 2026
Merged

kevssim merged 1 commit into
modelscope:dev-swift-v5from
werwrewe:fix/fsdp-mixed-modality

Conversation

@werwrewe

Copy link
Copy Markdown
Contributor

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

图文混合训练中,纯文本微批会跳过视觉模块,导致各rank的FSDP通信顺序不一致,训练卡住。

本次接通已有视觉保活机制,为纯文本微批补充占位图、屏蔽对应loss并将视觉特征置零。冻结视觉模块时也启用该机制,保证前向通信一致。

@kevssim

kevssim commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator

twinkle 里出现了 swift 的东西。 multimodal_graph_adapter、uniform_multimodal_graph、install_zero_hooks 都是 swift 的名字,twinkle 自己并不认识它们。最好是swift去引用twinkle。

建议把置零 hook 下沉到 twinkle:
• twinkle 定义一个占位图标记常量,把 VisionKeepAlive 这套搬过来。它本来就跟具体模型无关,只要 aligner 路径,而 model_arch['aligner'] twinkle 已经有了。
• 在 _lazy_wrap_model 里、wrap 之前装:LoRA 都已经加完了,而且只执行一次。aligner 从 base model 上找,读标记的 pre-hook 挂在最外层 self.model 上(PEFT 的
BaseTuner.forward 会直接调内层的 .forward(),挂在内层会被绕过)。
• hook 只在有标记时才置零。
• swift 只保留塞假图那一半,标记从 twinkle 导入。开关由 swift recipe 根据分布式配置决定传不传(开 CP 时不传),模型侧那几个函数可以删掉

@werwrewe
werwrewe force-pushed the fix/fsdp-mixed-modality branch from 40ef8ad to 1009649 Compare November 11, 2026 07:49
@werwrewe

Copy link
Copy Markdown
Contributor Author

定义公共占位图标记,根据 model_arch['aligner'] 在模型 wrap 前安装 hook。标记在最外层 forward 读取,仅对占位图特征置零并保留计算图。

@kevssim
kevssim merged commit ab2f73a into modelscope:dev-swift-v5 Nov 12, 2026
0 of 5 checks passed
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.

2 participants