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

Introduce multiprocess logger #337

Merged
merged 7 commits into from
May 2, 2022
Merged

Introduce multiprocess logger #337

merged 7 commits into from
May 2, 2022

Conversation

muellerzr
Copy link
Collaborator

Introduce Multi-Process aware Logger

What does this add?

Adds a new LoggerAdapter and a get_logger helper to help aid with printing logs repeatedly when in multiprocess

Why is it needed?

Users were reporting that the logs can confuse them with the actions actually occuring (such as logging multiple times a model was saved even though it only happened once).

Rather than an onslaught of if statements, this PR takes the simpler approach of creating an Adapter that will do the check for us.

By default it will only log to the main processor, but if all processes should log just pass main_process_only=False (see examples below)

What parts of the API does this impact?

User-facing:

Loggers in Accelerate now accept a main_process_only kwarg

Basic Usage Example(s):

from accelerate.logging import get_logger
logger = get_logger("my_logger")

# If we only want it called in the main process
logger.info("My message!")
# or
logger.info("My message!", main_process_only=True)

# If it should be called across all processes
logger.info("My message!", main_process_only=False)

@muellerzr muellerzr added the enhancement New feature or request label Apr 29, 2022
@muellerzr muellerzr requested a review from sgugger April 29, 2022 16:27
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Apr 29, 2022

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.

Looks really neat!

"""
Delegates logger call after checking if we should log
"""
main_process_only = kwargs.pop("main_process_only", True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants