Skip to content

Fix quantize.py script and support packed sequences in pretrain_gpt.py - #3564

Merged
chtruong814 merged 8 commits into
NVIDIA:mainfrom
AAnoosheh:aanoosheh/modelopt-example-import-order
Mar 17, 2026
Merged

Fix quantize.py script and support packed sequences in pretrain_gpt.py#3564
chtruong814 merged 8 commits into
NVIDIA:mainfrom
AAnoosheh:aanoosheh/modelopt-example-import-order

Conversation

@AAnoosheh

@AAnoosheh AAnoosheh commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

What does this PR do ?

  1. Fix quantize.py example script and bug with eval logging
  2. Allow pretrain_gpt.py to support packed sequences, bringing it up to par with pretrain_mamba
  3. Fix bug with CP in both training eval logging and Packed-Sequence data initialization

⚠️ For major changes (either in lines of code or in its impact), please make sure to first share a design doc with the team. If you're unsure what's the best way to do so, contact the @mcore-oncall.

Contribution process

flowchart LR
    A[Pre-checks] --> B[PR Tests]
    subgraph Code Review/Approval
        C1[Expert Review] --> C2[Final Review]
    end
    B --> C1
    C2 --> D[Merge]
Loading

Pre-checks

  • I want this PR in a versioned release and have added the appropriate Milestone (e.g., Core 0.8)
  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

Code review

The following process is enforced via the CODEOWNERS file for changes into megatron/core. For changes outside of megatron/core, it is up to the PR author whether or not to tag the Final Reviewer team.

For MRs into `main` branch

Feel free to message or comment the @mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!

(Step 1): Add PR label Expert Review

(Step 2): Collect the expert reviewers reviews

  1. Attach the Expert Review label when your PR is ready for review.
  2. GitHub auto-assigns expert reviewers based on your changes. They will get notified and pick up your PR soon.

⚠️ Only proceed to the next step once all reviewers have approved, merge-conflict are resolved and the CI is passing.
Final Review might get declined if these requirements are not fulfilled.

(Step 3): Final Review

  1. Add Final Review label
  2. GitHub auto-assigns final reviewers based on your changes. They will get notified and pick up your PR soon.

(Optional Step 4): Cherry-pick into release branch

If this PR also needs to be merged into core_r* release branches, after this PR has been merged, select Cherry-pick to open a new PR into the release branch.

For MRs into `dev` branch The proposed review process for `dev` branch is under active discussion.

MRs are mergable after one approval by either eharper@nvidia.com or zijiey@nvidia.com.

Merging your PR

Any member of core-adlr and core-nemo will be able to merge your PR.

@copy-pr-bot

copy-pr-bot Bot commented Feb 24, 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.

@AAnoosheh AAnoosheh self-assigned this Feb 24, 2026
@AAnoosheh
AAnoosheh requested a review from ChenhanYu February 24, 2026 17:20
@AAnoosheh
AAnoosheh force-pushed the aanoosheh/modelopt-example-import-order branch from 27a6b72 to bae176b Compare February 25, 2026 12:56
@AAnoosheh
AAnoosheh marked this pull request as ready for review March 6, 2026 23:55
@svcnvidia-nemo-ci
svcnvidia-nemo-ci requested a review from a team March 6, 2026 23:55
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Approved All necessary approvals have been made label Mar 6, 2026
Signed-off-by: Asha Anoosheh <aanoosheh@nvidia.com>
Signed-off-by: Asha Anoosheh <aanoosheh@nvidia.com>
@AAnoosheh
AAnoosheh force-pushed the aanoosheh/modelopt-example-import-order branch from bae176b to f43f37c Compare March 7, 2026 00:02
@AAnoosheh

Copy link
Copy Markdown
Contributor Author

/ok to test f43f37c

- Add is_packed_sequence flag (True when args.sft is set) to get_batch and
  is_dataset_built_on_rank, mirroring pretrain_mamba.py behavior
- Middle PP stages with packed sequences return (None×5, PackedSeqParams)
  carrying cu_seqlens/max_seqlen for attention masking, instead of early-
  returning None×6
- Import PackedSeqParams from megatron.core.packed_seq_params
- is_dataset_built_on_rank: packed sequences build dataset on all TP rank-0
  stages (not just first/last PP), consistent with THD format requirements
- Add detailed docstring explaining packed sequence flow and differences
  from pretrain_mamba.py (return format, middle-stage handling, CP, MTP)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@AAnoosheh

Copy link
Copy Markdown
Contributor Author

/ok to test 0e375ba

@AAnoosheh AAnoosheh added the Expert Review [deprecated] Apply this label to indicate that your PR is ready for expert review. label Mar 9, 2026
@AAnoosheh
AAnoosheh requested a review from jaredcasper March 9, 2026 18:13
@Phlip79 Phlip79 removed the Expert Review [deprecated] Apply this label to indicate that your PR is ready for expert review. label Mar 10, 2026
@AAnoosheh AAnoosheh changed the title Fix quantize.py example script and bug with eval logging Fix quantize.py script and support packed sequences in pretrain_gpt.py Mar 10, 2026
Comment thread examples/post_training/modelopt/convert_model.py Outdated
@AAnoosheh

Copy link
Copy Markdown
Contributor Author

/ok to test 2acb2a8

@AAnoosheh

Copy link
Copy Markdown
Contributor Author

/ok to test 326dac9

cu_seqlens_q_padded may not be strictly monotonic when context
parallelism slices sequences across ranks, or when padded cumulative
lengths exceed total_tokens. The diff can go negative, causing
torch.repeat_interleave to fail with "repeats can not be negative".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ChenhanYu
ChenhanYu requested a review from a team as a code owner March 12, 2026 00:04
@ChenhanYu
ChenhanYu requested a review from a team as a code owner March 12, 2026 00:04
@svcnvidia-nemo-ci svcnvidia-nemo-ci added Final Review PR is in the "final review" stage and removed Approved All necessary approvals have been made labels Mar 12, 2026
@AAnoosheh

Copy link
Copy Markdown
Contributor Author

/ok to test 1e064f3

@svcnvidia-nemo-ci svcnvidia-nemo-ci added Approved All necessary approvals have been made and removed Final Review PR is in the "final review" stage labels Mar 12, 2026
@AAnoosheh

Copy link
Copy Markdown
Contributor Author

/ok to test 1e064f3

@chtruong814

Copy link
Copy Markdown
Contributor

/ok to test ae7cd6b

@chtruong814
chtruong814 added this pull request to the merge queue Mar 16, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/23167215405

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 16, 2026
@chtruong814
chtruong814 added this pull request to the merge queue Mar 16, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/23169985301

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/23170131822

Merged via the queue into NVIDIA:main with commit f89744b Mar 17, 2026
77 of 81 checks passed
@AAnoosheh
AAnoosheh deleted the aanoosheh/modelopt-example-import-order branch March 25, 2026 23:45
yangbofun pushed a commit to xlm-research/Megatron-LM that referenced this pull request May 22, 2026
NVIDIA#3564)

Signed-off-by: Asha Anoosheh <aanoosheh@nvidia.com>
Co-authored-by: Chenhan Yu <chenhany@nvidia.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Charlie Truong <chtruong@nvidia.com>
yhgalaxy pushed a commit to yhgalaxy/Megatron-LM that referenced this pull request Jun 17, 2026
NVIDIA#3564)

Signed-off-by: Asha Anoosheh <aanoosheh@nvidia.com>
Co-authored-by: Chenhan Yu <chenhany@nvidia.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Charlie Truong <chtruong@nvidia.com>
Signed-off-by: yhgalaxy <yhgalaxy@outlook.com>
jon-barker pushed a commit to jon-barker/Megatron-LM that referenced this pull request Jul 10, 2026
NVIDIA#3564)

Signed-off-by: Asha Anoosheh <aanoosheh@nvidia.com>
Co-authored-by: Chenhan Yu <chenhany@nvidia.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Charlie Truong <chtruong@nvidia.com>
Signed-off-by: Jon Barker <jbarker@aws-cmh-slurm-1-vscode-02.cm.cluster>
terminator123 pushed a commit to 021ai/Megatron-LM that referenced this pull request Aug 3, 2026
NVIDIA#3564)

Signed-off-by: Asha Anoosheh <aanoosheh@nvidia.com>
Co-authored-by: Chenhan Yu <chenhany@nvidia.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Charlie Truong <chtruong@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved All necessary approvals have been made

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants