-
Notifications
You must be signed in to change notification settings - Fork 658
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
Add support for using custom Environments
and Strategies
⚡
#608
Open
amorehead
wants to merge
9
commits into
ashleve:main
Choose a base branch
from
amorehead:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3957020
Add support for using custom Environments and Strategies
amorehead 47707c6
Address pre-commit concerns
amorehead fc265af
Handle edge case for DeepSpeed optimization
amorehead 6709b36
Add warning message for passing ckpt_path that points to a non-existe…
amorehead 70a8bb6
Add missing if-check for edge case
amorehead 0a6d1bb
Add if-check to account for edge case
amorehead bffa428
Add extra guards
amorehead 473cfbf
Add extra guards
amorehead 27fd562
Update docstring
amorehead File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
defaults: | ||
- _self_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
_target_: lightning.fabric.plugins.environments.LightningEnvironment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
_target_: lightning.fabric.plugins.environments.SLURMEnvironment | ||
auto_requeue: true | ||
requeue_signal: null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
_target_: lightning.pytorch.strategies.DDPStrategy | ||
static_graph: false | ||
gradient_as_bucket_view: false | ||
find_unused_parameters: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
_target_: lightning.pytorch.strategies.DeepSpeedStrategy | ||
stage: 2 | ||
offload_optimizer: false | ||
allgather_bucket_size: 200_000_000 | ||
reduce_bucket_size: 200_000_000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
defaults: | ||
- _self_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
_target_: lightning.pytorch.strategies.FSDPStrategy | ||
sharding_strategy: ${resolve_variable:torch.distributed.fsdp.ShardingStrategy.FULL_SHARD} | ||
cpu_offload: null | ||
activation_checkpointing: null | ||
mixed_precision: | ||
_target_: torch.distributed.fsdp.MixedPrecision | ||
param_dtype: null | ||
reduce_dtype: null | ||
buffer_dtype: null | ||
keep_low_precision_grads: false | ||
cast_forward_inputs: false | ||
cast_root_forward_inputs: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
_target_: lightning.pytorch.strategies.DDPStrategy | ||
static_graph: true | ||
gradient_as_bucket_view: true | ||
find_unused_parameters: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import importlib | ||
from typing import Any | ||
|
||
from omegaconf import OmegaConf | ||
|
||
|
||
def resolve_omegaconf_variable(variable_path: str) -> Any: | ||
"""Resolve an OmegaConf variable path to its value.""" | ||
# split the string into parts using the dot separator | ||
parts = variable_path.rsplit(".", 1) | ||
|
||
# get the module name from the first part of the path | ||
module_name = parts[0] | ||
|
||
# dynamically import the module using the module name | ||
try: | ||
module = importlib.import_module(module_name) | ||
# use the imported module to get the requested attribute value | ||
attribute = getattr(module, parts[1]) | ||
except Exception: | ||
module = importlib.import_module(".".join(module_name.split(".")[:-1])) | ||
inner_module = ".".join(module_name.split(".")[-1:]) | ||
# use the imported module to get the requested attribute value | ||
attribute = getattr(getattr(module, inner_module), parts[1]) | ||
|
||
return attribute | ||
|
||
|
||
def register_custom_omegaconf_resolvers(): | ||
"""Register custom OmegaConf resolvers.""" | ||
OmegaConf.register_new_resolver( | ||
"resolve_variable", lambda variable_path: resolve_omegaconf_variable(variable_path) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you can see here, now one can specify an optional
strategy
for Lightning to use e.g., via OmegaConf YAML config files.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gil2rok