Skip to content

perf(sft): add a direct path for Megatron-LM prepacked inputs - #3380

Merged
terrykong merged 74 commits into
NVIDIA-NeMo:mainfrom
seonjinn:sna/megatron-sft-prepacked-inputs
Oct 8, 2026
Merged

terrykong merged 74 commits into
NVIDIA-NeMo:mainfrom
seonjinn:sna/megatron-sft-prepacked-inputs

Conversation

@seonjinn

@seonjinn seonjinn commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in Megatron-only megatron_sft_packed path for SFT.

Each JSONL row is packed offline and passed directly to MCore, preserving conversation boundaries, labels, loss masks, positions, and cu_seqlens. Existing SFT datasets are unchanged.

Requirements:

  • Megatron backend
  • Micro batch size 1
  • Dynamic batching disabled
  • sft.only_unmask_final: false
  • Fused linear log-probability loss disabled
  • policy.sequence_packing.enabled: true when context parallelism is greater than 1

See docs/guides/sft.md for the dataset format and configuration.

Performance

Latest full-scale validation (ed4d5342, 64 nodes / 512 H100, steady-state steps 3–20):

Implementation Mean step time
Megatron-LM reference 51.9744 s
NeMo RL 52.4850 s
Gap +0.98%
Relative throughput 99.03%

The run used the same packed data, row schedule, topology, and performance-critical settings as the preserved Megatron-LM reference. It was not a new same-container rerun.

Loss comparison remained finite and closely aligned:

  • Mean absolute difference: 0.001722
  • Maximum absolute difference: 0.003830

W&B performance report

Validation

  • 102 focused tests passed for the full-scale validated revision.
  • Current head 77bd36c8 includes the latest main (a43d71b3) and follow-up compatibility/documentation fixes.
  • Local config, Pyrefly, Ruff, formatting, and diff checks pass.
  • Current-head upstream CI and final GPU parity validation remain pending.

seonjinn added 29 commits July 27, 2026 00:45
@copy-pr-bot

copy-pr-bot Bot commented Jul 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.

@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test65f132f

@seonjinn seonjinn added CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) and removed CI:L1 Run doctests, unit tests, and functional tests labels Sep 17, 2026
@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test 2510b16

Preserve direct MLM and Energon packed input paths, use the shared FP8 alignment helper, and fix pad-token type narrowing reported by CI.

Signed-off-by: seonjinn <[email protected]>
@seonjinn

Copy link
Copy Markdown
Contributor Author

/ok to test 5ccc1fb

@seonjinn

seonjinn commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 6d46c64

Comment thread docs/guides/sft.md Resolved
Comment thread examples/configs/sft.yaml Resolved
terrykong
terrykong previously approved these changes Oct 6, 2026
@terrykong

Copy link
Copy Markdown
Collaborator

/ok to test 28de69d

@seonjinn

seonjinn commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test e0e612a

@terrykong

Copy link
Copy Markdown
Collaborator

@seonjinn looks like some test failures that need to be resolved

@seonjinn

seonjinn commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 48d776e

@seonjinn

seonjinn commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

@terrykong addressed issues and launched ci again

@seonjinn

seonjinn commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 76aafa8

@seonjinn

seonjinn commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 641cac7

@terrykong
terrykong merged commit 03fa05a into NVIDIA-NeMo:main Oct 8, 2026
94 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants