[Perf] Reuse single-element media tensors in qwen3_vl_sft_collator and SequenceContext.cat (follow-up of #2239)
维护者通常 4 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 62/100
- Issue 类型
- 重构
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 领域
- data, machine-learning
调研方向
Start with the _reuse_single_or_cat helper in xtuner/v1/datasets/collator.py and the qwen3_vl_sft_collator lines around 280-287, then read SequenceContext.cat in xtuner/v1/data_proto/sequence_context.py at about lines 393-418. Apply the single-element reuse pattern at both sites and add a comment about the read-only sharing invariant from #2239. Done means single-media packs skip torch.cat and a test asserts the media tensors are bitwise unchanged after use.
由索引模型根据 Issue 内容生成。
描述
Background
#2239 removed full torch.cat copies for single-media packs on the GLM-5.3 SFT
path (collator helper _reuse_single_or_cat, tokenize fn, and the compose model
entry). The same "single-element list still pays a full copy" pattern remains at
two sites outside that PR's scope:
-
qwen3_vl_sft_collator—xtuner/v1/datasets/collator.py:280,287:
pixel_values/image_grid_thware unconditionallytorch.cat-ed even when
the pack contains a single media item. The_reuse_single_or_cathelper added
in #2239 sits in the same file and can be applied directly. -
SequenceContext.cat—xtuner/v1/data_proto/sequence_context.py:393-403
(pixel_values/pixel_values_videos) and:415,418(image_grid_thw/
video_grid_thw): single-element lists are unconditionally copied. This is on
the RL path — the RL controller merges seq_ctx lists viaSequenceContext.cat
(xtuner/v1/rl/trainer/controller.py:236).
Impact
No correctness issue today. GLM-5.3 SFT does not go through either site, so this
is pure follow-up: qwen3_vl SFT benefits for single-media packs; the RL path
benefits if rollout packing of media seq_ctx becomes hot.
Suggested fix
- Apply the same
len == 1 → reuse, else catpattern at both sites. - Mind the invariant pinned in #2239: a reused tensor shares storage with its
source, so the downstream path must stay read-only — add the same kind of
comment + a "media tensor bitwise unchanged after use" test assertion.
- 主要语言
- Python
- 星标
- 5.2k
- 派生
- 466
- 平均合并
- 5 天 8 小时
- 30 天内合并 PR
- 44
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
InternLM/xtuner 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 42/100
维护者通常 4 天内回复
-
难度 4/5 3-5 天 新手友好度 52/100
InternLM/xtuner#2134 · 1 个 reaction ·
维护者通常 4 天内回复
-
[NPU] reduce_sum_across_dp_group builds the all_reduce tensor on CPU when CUDA is unavailable可能已有人在做 @li-lizhe 于 70 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 30/100
维护者通常 4 天内回复
-
难度 5/5 一周以上 新手友好度 15/100
InternLM/xtuner#2118 · 6 条评论 ·
维护者通常 4 天内回复
-
难度 4/5 3-5 天 新手友好度 38/100
维护者通常 4 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
AIR-Bench Foundation reads the first letter of the word after "answer" as the model's choice可能已有人在做 @beartester34 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
modelscope/evalscope#2330 ·
维护者通常 1 天内回复
-
Distribution plot crashes when a numeric feature is constant in the train or test set可能已有人在做 @adembilge 今天认领。 未关闭bug good first issue
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 10 天内回复
-
难度 1/5 1-3 小时 新手友好度 85/100
维护者通常 2 天内回复
-
namespace team:operations
难度 2/5 1-3 小时 新手友好度 60/100
EclipseFdn/open-vsx.org#16738 ·
维护者通常 1 天内回复