fix: preserve multimodal image token counts#1900
Merged
hhaAndroid merged 1 commit intoJun 10, 2026
Merged
Conversation
hhaAndroid
approved these changes
Jun 10, 2026
braisedpork1964
pushed a commit
to braisedpork1964/xtuner
that referenced
this pull request
Jun 11, 2026
Co-authored-by: shenshuo <shenshuo@pjlab.org.cn>
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.
背景
在 Qwen3-VL / 多模态 RL 训练中,
pixel_values和image_grid_thw已经可以传到 training worker,但num_img_tokens没有完整传到训练侧的SequenceContext。这会导致真实多模态 batch 里明明包含图片,训练日志却显示:
修改内容
本 PR 补齐 num_img_tokens 在 RL 多模态训练链路中的传递:
在 MultimodalInfo 中加入 num_img_tokens
在 RLQwen3VLTokenizeFunction 中把 tokenizer 输出的 num_img_tokens 写入 mm_info
在 SequenceContext packing 时保留 num_img_tokens
在 RLColocateTrainer 构造训练 SequenceContext 时恢复 num_img_tokens
修复前:多模态 payload 能进入训练,但 step_consumed_img_tokens=0
修复后:step_consumed_img_tokens 变为非零,训练和 backward 能正常完成