[Perf] Reuse single-element media tensors in qwen3_vl_sft_collator and SequenceContext.cat (follow-up of #2239)
Maintainers usually reply within 4 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 62/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- data, machine-learning
Research direction
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.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- Python
- Stars
- 5.2k
- Forks
- 466
- Avg merge
- 5d 8h
- Merged PRs (30d)
- 44
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from InternLM/xtuner
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
Maintainers usually reply within 4 days
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
InternLM/xtuner#2134 · 1 reaction ·
Maintainers usually reply within 4 days
-
[NPU] reduce_sum_across_dp_group builds the all_reduce tensor on CPU when CUDA is unavailablePossibly taken @li-lizhe claimed this 69 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 30/100
Maintainers usually reply within 4 days
-
Difficulty 5/5 Over a week Newbie friendliness 15/100
InternLM/xtuner#2118 · 6 comments ·
Maintainers usually reply within 4 days
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
Maintainers usually reply within 4 days
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Techiebutler/freeframe#687 ·
Maintainers usually reply within 1 day
-
bug verbose GC
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
IBM/javacore-analyser#677 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Maintainers usually reply within 2 days
-
area/config comp/plugins P1 platform/qqbot tool/file type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
NousResearch/hermes-agent#163932 · 1 comment ·
Maintainers usually reply within 1 day
-
plugins/dsh: todayStr() computes UTC but is documented as local — journal entries written 00:00–08:00 local land in the previous day's filePossibly taken @Beehtrix claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
zilliztech/memsearch#907 · 1 comment ·
Maintainers usually reply within 1 day