Skip to content

[Dev] Add more tests for LayerwiseDistOpt with dist_ckpt - #2132

Merged
BoxiangW merged 25 commits into
NVIDIA:devfrom
BoxiangW:boxiangw/dist_ckpt_tests
Nov 13, 2025
Merged

[Dev] Add more tests for LayerwiseDistOpt with dist_ckpt#2132
BoxiangW merged 25 commits into
NVIDIA:devfrom
BoxiangW:boxiangw/dist_ckpt_tests

Conversation

@BoxiangW

@BoxiangW BoxiangW commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

What does this PR do ?

PR to main

⚠️ For major changes (either in lines of code or in its impact), please make sure to first share discuss a design-doc with the team.

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

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

…factor`

Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
@BoxiangW BoxiangW self-assigned this Nov 4, 2025
@BoxiangW
BoxiangW requested review from a team as code owners November 4, 2025 21:02
@copy-pr-bot

copy-pr-bot Bot commented Nov 4, 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.

@BoxiangW BoxiangW added this to the Core 0.15 milestone Nov 4, 2025
@BoxiangW BoxiangW added Run tests Expert Review [deprecated] Apply this label to indicate that your PR is ready for expert review. labels Nov 4, 2025
@BoxiangW

BoxiangW commented Nov 4, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test 669a16c

@BoxiangW

BoxiangW commented Nov 7, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test 04154c8

Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
@BoxiangW

BoxiangW commented Nov 7, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test 6e4c888

Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
@BoxiangW

BoxiangW commented Nov 7, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test 267b06b

Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
@BoxiangW

BoxiangW commented Nov 7, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test 7057451

Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
@BoxiangW

BoxiangW commented Nov 7, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test aaf7235

@dimapihtar

Copy link
Copy Markdown
Contributor

@BoxiangW looks like we need to add "functional_tests" label in order to trigger that functional tests you added in this PR.

@dimapihtar dimapihtar 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.

LGTM. Thank you!

Comment thread tests/unit_tests/dist_checkpointing/test_layer_wise_optimizer.py
@BoxiangW

BoxiangW commented Nov 7, 2025

Copy link
Copy Markdown
Contributor Author

/ok to test 669a16c

@copy-pr-bot

copy-pr-bot Bot commented Nov 7, 2025

Copy link
Copy Markdown

/ok to test 669a16c

@BoxiangW, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

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

This PR should not be merged.

  • The title says it is only adding tests, but there a lot of code change including public API change. They should be spereate.
  • Test is not thorough, i.e. it doesn't catch a know issue that load fail on empty state_dict.
  • Plus some other improvement suggested.


muon_extra_scale_factor: float = 1.0
"""Additional scale factor for the muon update."""
muon_extra_scale_factor: float = 0.2

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.

FIX: Revert this change. Don't change this default scale factor.
ESPECIALLY not in a unrelated PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reverted, this was recommended by Mkail and we can change it in a separate PR then

def inspect_types(x: Any, prefix: Tuple = (), indent: int = 4):
"""Helper to print types of (nested) dict values."""
print_indent = lambda: print(" " * indent * len(prefix), end="")
print_indent = lambda: print(" " * indent * len(prefix), end="") # pylint: disable=bad-builtin

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.

too many inline disable. just disable it for the section.

# pylint: disable=bad-builtin
...
# pylint: enable=bad-builtin

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.

I'd suggest we just remove changes from this file(the only change is a comment). and thus we don't need to fix lint for it.
For that comment, I think it is ok for it to catch our empty list issue and we should fix it from layerwise side

Comment thread megatron/training/arguments.py Outdated
choices=['blockwise', 'duplicated', 'distributed'],
help='How to perform NS calculation for tensor model parallel weights')
group.add_argument('--muon-extra-scale-factor', type=float, default=1.0,
group.add_argument('--muon-extra-scale-factor', type=float, default=0.2,

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.

FIX: Revert this change.


if succeeded:
logger.info(f"Job succeeded with status: {job_dict["status"]}")
logger.info(f"Job succeeded with status: {job_dict['status']}")

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.

revert meaningless format change, unless their is a new style guide?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it was a pylint guide

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.

but lines above and below all use double quote?

)
assert total_params > 0, "No parameters found in optimizer"

@pytest.mark.parametrize('tp_pp', [(1, 2), (2, 1), (2, 2)])

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.

Fix: Bad variable grouping. should use TP and PP separately.
Same for all other tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is not applicable for all the cases, since we have 8GPU max, if we do

    @pytest.mark.parametrize('tp', [2, 4])
    @pytest.mark.parametrize('pp', [2, 4])

It will reach 16 GPUs in total

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.

you can skip test (with a message) if total number of GPU exceeded.

try:
state_dict = load(load_sharded_sd, ckpt_dir)
optimizer_B.load_state_dict(state_dict)
except Exception:

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.

Don't silently pass tests. Can skip the test if there is a known reason.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed this special treatment

Comment thread tests/unit_tests/dist_checkpointing/test_layer_wise_optimizer.py
optim_param_state_B = optimizer_B.state_dict()

# Test both param state dicts are equal
diffs = diff(optim_param_state_A, optim_param_state_B)

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.

Try not to use self made diff function as testing metric, it mixes things together unnecessarily. e.g. a bug in diff could have very large blast radius because all tests depend on it become faulty.
Better to explicitly compare everything here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a similar but simpler explicitly checking in this file as a util function

def inspect_types(x: Any, prefix: Tuple = (), indent: int = 4):
"""Helper to print types of (nested) dict values."""
print_indent = lambda: print(" " * indent * len(prefix), end="")
print_indent = lambda: print(" " * indent * len(prefix), end="") # pylint: disable=bad-builtin

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.

I'd suggest we just remove changes from this file(the only change is a comment). and thus we don't need to fix lint for it.
For that comment, I think it is ok for it to catch our empty list issue and we should fix it from layerwise side

Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
@BoxiangW

Copy link
Copy Markdown
Contributor Author

/ok to test a6693fc

Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
@BoxiangW

Copy link
Copy Markdown
Contributor Author

/ok to test 73e424b

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

I mostly reviewed unit test part and suggested more improvement. LGTM overall.

I didn't review "functional" test as I don't exactly know what to expect there.

)
assert total_params > 0, "No parameters found in optimizer"

@pytest.mark.parametrize('tp_pp', [(1, 2), (2, 1), (2, 2)])

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.

you can skip test (with a message) if total number of GPU exceeded.

Comment thread tests/unit_tests/dist_checkpointing/test_layer_wise_optimizer.py
pp = dp_size
tp = world_size // pp

if tp == 0:

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.

Should check broadly whether world_size is divisible by pp.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed this part

@BoxiangW

Copy link
Copy Markdown
Contributor Author

/ok to test 896b2d7

Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
Signed-off-by: Boxiang Wang <boxiangw@nvidia.com>
@BoxiangW

Copy link
Copy Markdown
Contributor Author

/ok to test b478987

@FDecaYed FDecaYed 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.

LG after changes

@Victarry

Copy link
Copy Markdown

Hi @BoxiangW , the golden values of this MR is not added, which cause the functional tests fail https://gitlab-master.nvidia.com/ADLR/megatron-lm/-/pipelines/38398052.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev branch Dev branch related issues and development Expert Review [deprecated] Apply this label to indicate that your PR is ready for expert review. Run tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants