Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NeMo-UX] Support load_strictness #10612

Merged
merged 18 commits into from
Nov 26, 2024
Merged

Conversation

ashors1
Copy link
Collaborator

@ashors1 ashors1 commented Sep 25, 2024

What does this PR do ?

Add a one line overview of what this PR aims to accomplish.

Collection: llm

Changelog

  • Add specific line by line info of high level changes in this PR.

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this 

GitHub Actions CI

The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.

The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation?
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc)
    • Reviewer: Does the PR have correct import guards for all optional libraries?

PR Type:

  • New Feature
  • Bugfix
  • Documentation

If you haven't finished some of the above items you can still open "Draft" PR.

Who can review?

Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.

Additional Information

  • Related to # (issue)

mikolajblaz
mikolajblaz previously approved these changes Oct 2, 2024
Copy link
Collaborator

@mikolajblaz mikolajblaz left a comment

Choose a reason for hiding this comment

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

Thanks!

@marcromeyn marcromeyn self-requested a review October 2, 2024 08:46
Copy link
Collaborator

@marcromeyn marcromeyn left a comment

Choose a reason for hiding this comment

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

PL does this like this. So I feel like we should adopt the same design and not add a custom arg to our strategy.

@mikolajblaz
Copy link
Collaborator

PL does this like this. So I feel like we should adopt the same design and not add a custom arg to our strategy.

If only we can propagate this flag to dist_checkpointing.load then using this flag would be ideal

@marcromeyn
Copy link
Collaborator

PL does this like this. So I feel like we should adopt the same design and not add a custom arg to our strategy.

If only we can propagate this flag to dist_checkpointing.load then using this flag would be ideal

Yeah, an example of how PL does that can be found here.

Copy link
Contributor

This PR is stale because it has been open for 14 days with no activity. Remove stale label or comment or update or this will be closed in 7 days.

@github-actions github-actions bot added the stale label Oct 17, 2024
Copy link
Contributor

This PR was closed because it has been inactive for 7 days since being marked as stale.

@github-actions github-actions bot closed this Oct 25, 2024
@ashors1 ashors1 reopened this Oct 28, 2024
@ashors1
Copy link
Collaborator Author

ashors1 commented Oct 28, 2024

If only we can propagate this flag to dist_checkpointing.load then using this flag would be ideal

Yeah, an example of how PL does that can be found here.

Revisiting this PR. I don't think this is quite what we want. It looks like PTL's strict is just passed to load_model_state_dict, which is called after the checkpoint is loaded using dist_checkpointing.load, so we're not able to propagate the value of strict to dist_checkpointing.load

@github-actions github-actions bot removed the stale label Oct 29, 2024
nemo/lightning/_strategy_lib.py Fixed Show fixed Hide fixed

ckpt_sharded_metadata = dist_checkpointing.load_tensors_metadata(path)
loaded_keys = []
missing_keys = []

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable missing_keys is not used.
@@ -516,6 +516,19 @@ def load_model_state_dict(megatron_parallel, checkpoint: Mapping[str, Any], stri
from megatron.core import parallel_state
from megatron.core.dist_checkpointing.validation import StrictHandling, parse_strict_flag

## convert from StrictHandling to bool for PTL
if os.environ.get("MCORE_STRICT_HANDLING") is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's avoid such logic, it will be terrible to debug later on.

What's the reason this can't be passed by argument?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My previous approach was using PTL's strict_loading to control mcore load strictness, but that required overwriting PTL's getter and setter because we want to allow strict_loading to be a string, while PTL only allows bool. @marcromeyn was opposed to overwriting the getter and setter. He is working on a separate PR that should make it easier to control load_strictness. This PR is intended as a stopgap solution until that PR is in.

@marcromeyn do you have any comments on the current approach?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would prefer if it's set in a global var as opposed to a environment variable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Discussed with @marcromeyn offline and we decided it would be best to pass the variable as an argument into MegatronStrategy for now. Please take a look at the latest changes and let me know what you think

nemo/lightning/io/pl.py Fixed Show fixed Hide fixed
Signed-off-by: ashors1 <[email protected]>
Signed-off-by: ashors1 <[email protected]>
@ashors1 ashors1 added Run CICD and removed Run CICD labels Nov 22, 2024
Signed-off-by: ashors1 <[email protected]>
@ashors1 ashors1 added Run CICD and removed Run CICD labels Nov 25, 2024
@ashors1 ashors1 added Run CICD and removed Run CICD labels Nov 25, 2024
Signed-off-by: ashors1 <[email protected]>
@ashors1 ashors1 added Run CICD and removed Run CICD labels Nov 26, 2024
@ashors1 ashors1 added Run CICD and removed Run CICD labels Nov 26, 2024
Copy link
Contributor

beep boop 🤖: 🙏 The following files have warnings. In case you are familiar with these, please try helping us to improve the code base.


Your code was analyzed with PyLint. The following annotations have been identified:

************* Module nemo.lightning._strategy_lib
nemo/lightning/_strategy_lib.py:573:0: C0301: Line too long (130/119) (line-too-long)
nemo/lightning/_strategy_lib.py:35:0: C0115: Missing class docstring (missing-class-docstring)
nemo/lightning/_strategy_lib.py:36:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/_strategy_lib.py:139:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/_strategy_lib.py:166:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/_strategy_lib.py:202:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/_strategy_lib.py:515:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/_strategy_lib.py:598:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/_strategy_lib.py:611:4: C0115: Missing class docstring (missing-class-docstring)
************* Module nemo.lightning.io.pl
nemo/lightning/io/pl.py:82:0: C0301: Line too long (130/119) (line-too-long)
nemo/lightning/io/pl.py:58:0: C0115: Missing class docstring (missing-class-docstring)
nemo/lightning/io/pl.py:64:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/io/pl.py:73:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/io/pl.py:303:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/io/pl.py:308:4: C0116: Missing function or method docstring (missing-function-docstring)
************* Module nemo.lightning.pytorch.callbacks.peft
nemo/lightning/pytorch/callbacks/peft.py:381:0: C0301: Line too long (130/119) (line-too-long)
nemo/lightning/pytorch/callbacks/peft.py:207:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/callbacks/peft.py:324:0: C0115: Missing class docstring (missing-class-docstring)
************* Module nemo.lightning.pytorch.strategies.megatron_strategy
nemo/lightning/pytorch/strategies/megatron_strategy.py:315:0: C0301: Line too long (159/119) (line-too-long)
nemo/lightning/pytorch/strategies/megatron_strategy.py:90:0: C0115: Missing class docstring (missing-class-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:272:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:305:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:386:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:396:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:402:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:445:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:449:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:481:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:491:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:558:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:577:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:604:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:612:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:620:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:624:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:663:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:684:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:719:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:742:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:751:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:759:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:771:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:801:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:826:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:842:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:60:0: W0611: Unused _ModuleStepFunction imported from nemo.lightning.megatron_parallel (unused-import)
nemo/lightning/pytorch/strategies/megatron_strategy.py:76:0: W0611: Unused AdapterPath imported from nemo.lightning.resume (unused-import)

-----------------------------------
Your code has been rated at 9.52/10

Thank you for improving NeMo's documentation!

1 similar comment
Copy link
Contributor

beep boop 🤖: 🙏 The following files have warnings. In case you are familiar with these, please try helping us to improve the code base.


Your code was analyzed with PyLint. The following annotations have been identified:

************* Module nemo.lightning._strategy_lib
nemo/lightning/_strategy_lib.py:573:0: C0301: Line too long (130/119) (line-too-long)
nemo/lightning/_strategy_lib.py:35:0: C0115: Missing class docstring (missing-class-docstring)
nemo/lightning/_strategy_lib.py:36:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/_strategy_lib.py:139:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/_strategy_lib.py:166:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/_strategy_lib.py:202:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/_strategy_lib.py:515:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/_strategy_lib.py:598:0: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/_strategy_lib.py:611:4: C0115: Missing class docstring (missing-class-docstring)
************* Module nemo.lightning.io.pl
nemo/lightning/io/pl.py:82:0: C0301: Line too long (130/119) (line-too-long)
nemo/lightning/io/pl.py:58:0: C0115: Missing class docstring (missing-class-docstring)
nemo/lightning/io/pl.py:64:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/io/pl.py:73:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/io/pl.py:303:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/io/pl.py:308:4: C0116: Missing function or method docstring (missing-function-docstring)
************* Module nemo.lightning.pytorch.callbacks.peft
nemo/lightning/pytorch/callbacks/peft.py:381:0: C0301: Line too long (130/119) (line-too-long)
nemo/lightning/pytorch/callbacks/peft.py:207:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/callbacks/peft.py:324:0: C0115: Missing class docstring (missing-class-docstring)
************* Module nemo.lightning.pytorch.strategies.megatron_strategy
nemo/lightning/pytorch/strategies/megatron_strategy.py:315:0: C0301: Line too long (159/119) (line-too-long)
nemo/lightning/pytorch/strategies/megatron_strategy.py:90:0: C0115: Missing class docstring (missing-class-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:272:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:305:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:386:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:396:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:402:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:445:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:449:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:481:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:491:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:558:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:577:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:604:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:612:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:620:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:624:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:663:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:684:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:719:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:742:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:751:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:759:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:771:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:801:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:826:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:842:4: C0116: Missing function or method docstring (missing-function-docstring)
nemo/lightning/pytorch/strategies/megatron_strategy.py:60:0: W0611: Unused _ModuleStepFunction imported from nemo.lightning.megatron_parallel (unused-import)
nemo/lightning/pytorch/strategies/megatron_strategy.py:76:0: W0611: Unused AdapterPath imported from nemo.lightning.resume (unused-import)

-----------------------------------
Your code has been rated at 9.52/10

Thank you for improving NeMo's documentation!

Copy link
Contributor

[🤖]: Hi @ashors1 👋,

We wanted to let you know that a CICD pipeline for this PR just finished successfully

So it might be time to merge this PR or get some approvals

I'm just a bot so I'll leave it you what to do next.

//cc @pablo-garay @ko3n1g

Copy link
Collaborator

@cuichenx cuichenx left a comment

Choose a reason for hiding this comment

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

LGTM

@ashors1 ashors1 merged commit 5d97b70 into main Nov 26, 2024
172 of 173 checks passed
@ashors1 ashors1 deleted the ashors/nemo-ux-ckpt-load-strictness branch November 26, 2024 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants