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

Editing issue with pickle def with lambda function #23869

Merged
merged 4 commits into from
May 30, 2023

Conversation

Natyren
Copy link
Contributor

@Natyren Natyren commented May 30, 2023

What does this PR do?

In this PR, I address the problem of pickling the constant LR scheduler, which fails during the process (potentially during multi-GPU training, as observed in my case) due to the presence of a lambda function within it.

Fixes #23865 (issue)

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

Thanks for opening a PR! Let's make the helper function private.

@@ -32,6 +32,21 @@
logger = logging.get_logger(__name__)


def get_constant_lambda(_=None):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def get_constant_lambda(_=None):
def _get_constant_lambda(current_step):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 36 to 45
"""
Return 1, independent from args.

Args:
_ ( *optional*, defaults to None):
Placeholder to argument, used to consistency with args in LambdaLR

Return:
1 : int - constant lambda for constant scheduler
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for a documentation for a private function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Delete it.

@@ -46,7 +61,7 @@ def get_constant_schedule(optimizer: Optimizer, last_epoch: int = -1):
`torch.optim.lr_scheduler.LambdaLR` with the appropriate schedule.
"""

return LambdaLR(optimizer, lambda _: 1, last_epoch=last_epoch)
return LambdaLR(optimizer, get_constant_lambda, last_epoch=last_epoch)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return LambdaLR(optimizer, get_constant_lambda, last_epoch=last_epoch)
return LambdaLR(optimizer, _get_constant_lambda, last_epoch=last_epoch)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done refactoring based on function name

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented May 30, 2023

The documentation is not available anymore as the PR was closed or merged.

Copy link
Collaborator

@sgugger sgugger left a comment

Choose a reason for hiding this comment

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

Thanks!

@sgugger sgugger merged commit 6451ad0 into huggingface:main May 30, 2023
sheonhan pushed a commit to sheonhan/transformers that referenced this pull request Jun 1, 2023
* Editing issue with pickle def with lambda function

* fix type

* Made helper function private

* delete tab

---------

Co-authored-by: georgebredis <[email protected]>
gojiteji pushed a commit to gojiteji/transformers that referenced this pull request Jun 5, 2023
* Editing issue with pickle def with lambda function

* fix type

* Made helper function private

* delete tab

---------

Co-authored-by: georgebredis <[email protected]>
novice03 pushed a commit to novice03/transformers that referenced this pull request Jun 23, 2023
* Editing issue with pickle def with lambda function

* fix type

* Made helper function private

* delete tab

---------

Co-authored-by: georgebredis <[email protected]>
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.

Possible pickle issues
3 participants