nemo-mbridge-perf-sequence-packing
Validate and use packed sequences and long-context training in Megatron-Bridge, distinguishing offline packed SFT for LLMs from in-batch packing for VLMs, and applying the right CP constraints.
Security Assessment
About nemo-mbridge-perf-sequence-packing
nemo-mbridge-perf-sequence-packing is an NVIDIA operational guide for validating and using packed sequences and long-context training in Megatron-Bridge. It solves the problem of correctly enabling sequence packing while respecting the framework's many interacting constraints, and it draws a clear distinction between offline packed SFT for LLM finetuning and in-batch packing for VLM finetuning. It provides ready-to-use config snippets for each path, including PackedSequenceSpecs setup, micro-batch-size requirements, and a long-context baseline.
A central focus is context-parallel (CP) and sequence-parallel (SP) correctness. The skill shows how to set pad_seq_to_mult for CP, notes that ConfigContainer computes the CP/SP LCM automatically only for in-batch packing (so offline packing must be aligned explicitly), and flags that pad_cu_seqlens with CUDA graphs additionally requires a metadata JSON file or dataset initialization will hit an assertion. It backs this with code anchors into Bridge source for the packed SFT config surface and the validation logic that enforces mutual exclusivity of offline and in-batch packing, the presence of offline_packing_specs, per-token-loss requirements under CP, and micro-batch-size limits.
It is aimed at ML engineers enabling sequence packing or long-context SFT, or investigating a commit that broke packing behavior. Output is configuration instructions plus source references — no destructive operations, credentials, or network access. NVSkills-Eval reported a 100% Security score and a strong uplift over the no-skill baseline.
FAQ
What is the difference between the two packing modes?
Offline packed SFT (enable_offline_packing with PackedSequenceSpecs) is for LLM finetuning and requires micro_batch_size=1; in-batch packing (enable_in_batch_packing) is for VLM finetuning. The two are mutually exclusive.
What do I need to change when context parallelism is on?
Set calculate_per_token_loss=True, average_in_collective=False, and pad_seq_to_mult to context_parallel_size*2. If sequence parallel is also on, align offline samples to the CP/SP LCM explicitly, since ConfigContainer only auto-computes it for in-batch packing.
Why does my packed dataset hit an assertion at init?
Setting pad_cu_seqlens=True with CUDA graphs requires a metadata JSON file alongside the packed dataset (asserted in sft.py); custom packed datasets omitting it will fail at dataset initialization.
When should I load this skill?
When enabling sequence packing or long-context SFT, or investigating a commit that changed or broke packing behavior.
Does it run anything?
No. It supplies config snippets and code anchors you apply yourself; verification is done through the referenced Bridge validation logic.
Install nemo-mbridge-perf-sequence-packing
Quick Setup:
- Copy the skill folder to
.claude/skills/ - Claude will automatically detect and use the skill
Repository
nvidia/skills