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

Refactor Tracker logic and write guards for logging_dir #316

Merged
merged 8 commits into from
Apr 19, 2022

Conversation

muellerzr
Copy link
Collaborator

Refactor logging_dir logic and make better guards for trackers that need one

What does this add?

This PR refactors much of the logic when it comes to how Trackers are initialized and checked inside of Accelerate

Who is it for?

  • Users of Accelerate who want to use W&B, TensorBoard, etc and want clear errors as to what went wrong

Why is it needed?

I noticed that users were finding it confusing as to why a logging_dir must always be passed in when using "all", and this was because of TensorBoard requiring a logging directory.

On top of this, the current logic to check if a tracker can be added is a heap of spaghetti code that isn't maintainable.

What parts of the API does this impact?

User-facing:

When users forget to pass in a logging_dir to Accelerate.__init__ and a particular tracker needs them, an error is now raised stating:

Logging with `TensorBoardTracker` requires a `logging_dir` to be passed in.

Internal structure:

Each GeneralTracker implementation now requires that the requires_logging_directory be set, as this is a foundational method for checking whether logging_dir should be passed. As a result this is an abstract property, not a default (as the user should know explicitly).

There also now exists a LOGGER_TYPE_TO_CLASS dictionary to severely reduce the boilerplate code needed in Accelerator.init_trackers when it comes to checking if a logging_dir argument is needed

@muellerzr muellerzr added enhancement New feature or request bug Something isn't working labels Apr 14, 2022
@muellerzr muellerzr requested a review from sgugger April 14, 2022 20:52
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Apr 14, 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.

Thanks for fixing! The logic for all the logging in the init of Accelerator is starting to take a lot of code, so I think we should refactor it in a separate method to keep the init cleam.

src/accelerate/tracking.py Outdated Show resolved Hide resolved
self.trackers.append(WandBTracker(project_name))
elif str(tracker).lower() == "comet_ml" and is_comet_ml_available():
self.trackers.append(CometMLTracker(project_name))
else:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Very nice!

@muellerzr muellerzr requested a review from sgugger April 19, 2022 13:53
@muellerzr
Copy link
Collaborator Author

@sgugger pinging for a rereview just to make sure the refactor seems sound to you 😄

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.

LGTM, thanks for refactoring the bit that gets all loggers outside of the Accelerator!

self.logging_dir = logging_dir
self.log_with = filter_trackers(log_with, self.logging_dir)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Much cleaner!

@muellerzr muellerzr merged commit 461ac7d into main Apr 19, 2022
@muellerzr muellerzr deleted the defensive_trackers branch April 19, 2022 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants