Skip to content

[DEV] torch_dist fixes, speed improvements and memory reduction for layerwise distopt - #1965

Merged
FDecaYed merged 11 commits into
NVIDIA:devfrom
FDecaYed:deyuf/layerwise_improvements
Nov 6, 2025
Merged

[DEV] torch_dist fixes, speed improvements and memory reduction for layerwise distopt#1965
FDecaYed merged 11 commits into
NVIDIA:devfrom
FDecaYed:deyuf/layerwise_improvements

Conversation

@FDecaYed

@FDecaYed FDecaYed commented Oct 27, 2025

Copy link
Copy Markdown
Contributor

What does this PR do ?

PR to main

Adding some optimizations that misses initial PR adding layerwise dist opt:

  • switch to faster all gather
  • sort param size and assign to rank in a ping-pong loop for balanced memory usage

Also added 3 minor fixes for layerwise:

  • for dist ckpt, correctly set Tensor Factory
  • for unwrap accidentally wrapped adam optimizers(FP32) before chained
  • handle empty group after sharding when generate sharded_state_dict for ckpting

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

(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.

@FDecaYed
FDecaYed requested review from a team as code owners October 27, 2025 07:52
@copy-pr-bot

copy-pr-bot Bot commented Oct 27, 2025

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.

@FDecaYed FDecaYed changed the title speed and memory improvements for layerwise distopt [DEV] speed and memory improvements for layerwise distopt Oct 27, 2025
@FDecaYed

Copy link
Copy Markdown
Contributor Author

/ok to test bb76f7f

@ko3n1g ko3n1g added this to the Core 0.16 milestone Oct 27, 2025
@FDecaYed
FDecaYed force-pushed the deyuf/layerwise_improvements branch from 09971f8 to f44b3fa Compare October 27, 2025 11:22
@skyw

skyw commented Oct 28, 2025

Copy link
Copy Markdown
Contributor

Could we add more tests with current broadcast path as reference? They should exact match after all communication is done.

@FDecaYed

FDecaYed commented Nov 4, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test 572cf0a

@FDecaYed

FDecaYed commented Nov 4, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test c30e51d

@skyw skyw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to parameterize and test different combination of parallelisms.

Looks good overall.

Comment thread megatron/core/optimizer/layer_wise_optimizer.py Outdated
Comment thread megatron/core/optimizer/layer_wise_optimizer.py Outdated
Comment thread megatron/core/optimizer/layer_wise_optimizer.py
Comment thread tests/unit_tests/test_layer_wise_optimizer.py Outdated
Comment thread tests/unit_tests/test_layer_wise_optimizer.py
Comment thread tests/unit_tests/test_layer_wise_optimizer.py Outdated
Comment thread tests/unit_tests/test_layer_wise_optimizer.py
@FDecaYed

FDecaYed commented Nov 5, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test 325366c

@FDecaYed

FDecaYed commented Nov 5, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test 2c01a2d

@FDecaYed

FDecaYed commented Nov 5, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test ac64381

Comment thread tests/unit_tests/test_layer_wise_optimizer.py
@FDecaYed

FDecaYed commented Nov 6, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test 75a42dc

@yaox12 yaox12 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

4 participants