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

Abierto
#2,246 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 4 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
62/100
Tipo de issue
Refactorización
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python, pytorch

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
Python
Estrellas
5.2k
Forks
466
Merge medio
5 d 8 h
PR fusionados (30 d)
44

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de InternLM/xtuner

Todos los issues de InternLM/xtuner

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.