[Perf] Reuse single-element media tensors in qwen3_vl_sft_collator and SequenceContext.cat (follow-up of #2239)

Aperta
#2,246 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
62/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, pytorch

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement good first 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:

  1. qwen3_vl_sft_collator — xtuner/v1/datasets/collator.py:280,287:
    pixel_values / image_grid_thw are unconditionally torch.cat-ed even when
    the pack contains a single media item. The _reuse_single_or_cat helper added
    in #2239 sits in the same file and can be applied directly.

  2. 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 via SequenceContext.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 cat pattern 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.
Lingua principale
Python
Stelle
5.2k
Fork
466
Merge medio
5g 8h
PR unite (30g)
44

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di InternLM/xtuner

Tutte le issue di InternLM/xtuner

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.