Skip to content

[DO NOT MERGE] Compact sequence packing for qwen3.5 VL THD layout training - #4027

Closed
zhongbozhu wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
zhongbozhu:compact_thd_cp
Closed

[DO NOT MERGE] Compact sequence packing for qwen3.5 VL THD layout training #4027
zhongbozhu wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
zhongbozhu:compact_thd_cp

Conversation

@zhongbozhu

Copy link
Copy Markdown
Contributor

What does this PR do ?

Similar with #3838, but fixing CP support & directly construct THD layout without a remove padding step.

Changelog

  • Add specific line by line info of high level changes in this PR.

GitHub Actions CI

See the CI section in the Contributing doc for how to trigger the CI. A Nvidia developer will need to approve and trigger the CI for external contributors.

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

If you haven't finished some of the above items you can still open "Draft" PR.

Additional Information

  • Related to # (issue)

cuichenx and others added 2 commits May 18, 2026 15:28
Packed THD training (offline-packed LLM SFT and VLM in-batch packing)
over-counts attention FLOPS by treating the whole pack as one length-
seq_length sequence (pack_length²). Actual attention work is Σᵢ sᵢ²
over the real sub-sequence lengths.

New helper accumulate_flops_metadata() in flop_utils.py extracts the
real sub-seq lengths from cu_seqlens (preferring cu_seqlens_unpadded
when present) and feeds Σᵢ sᵢ² into the existing seqlen_squared_sum
accumulator from NVIDIA-NeMo#3529. Falls back to BSHD mbs * seq_len² when no
cu_seqlens is provided — bit-exact identical to legacy on dense
pretraining and non-packed paths.

Wired into gpt_step, vlm_step, qwen3_vl_step, and qwen3_omni_step.

Verified on cw-dfw (same seed, same data, same iter times, identical
loss values across paired runs — only the reported TFLOPS differs):
- qwen3_8b_sft  seq=2048: baseline 162.6 vs fix 155.8 TFLOP/s/GPU (+4%)
- qwen3_8b_sft  seq=4096: baseline 339.9 vs fix 156.7 TFLOP/s/GPU (+117%)
- qwen35_vl_9b_sft     : baseline 261.6 vs fix  88.9 TFLOP/s/GPU (+194%)

The seq=2048→4096 pair on the same LLM recipe is the cleanest
demonstration: the fix is near-flat (155.8 vs 156.7 — attention work
is determined by per-sample lengths, not pack length) while the
baseline doubles because its pack_length² scales quadratically.

9 new unit tests in test_flop_utils.py::TestAccumulateFlopsMetadata
cover the BSHD fallback, THD with cu_seqlens, padded cu_seqlens via
cu_seqlens_argmin, cu_seqlens_unpadded precedence, additive
accumulation, and the regression headline (32-sample pack → 32x
smaller attention work than BSHD approximation).

Signed-off-by: Chen Cui <chcui@nvidia.com>
Signed-off-by: Zhongbo Zhu <zhongboz@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented May 28, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@zhongbozhu zhongbozhu closed this Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants