Skip to content

Commit

Permalink
Safely end training even if trackers weren't initialized (#1994)
Browse files Browse the repository at this point in the history
* Update accelerator.py

* init trackers on class init

* dont need getattr because trackers exists
  • Loading branch information
Ben-Epstein authored Oct 11, 2023
1 parent 73640d0 commit 4bef6bc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/accelerate/accelerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def __init__(
kwargs_handlers: list[KwargsHandler] | None = None,
dynamo_backend: DynamoBackend | str | None = None,
):
self.trackers = []
if project_config is not None:
self.project_configuration = project_config
else:
Expand Down Expand Up @@ -2399,7 +2400,6 @@ def init_trackers(self, project_name: str, config: dict | None = None, init_kwar
... )
```
"""
self.trackers = []
for tracker in self.log_with:
if issubclass(type(tracker), GeneralTracker):
# Custom trackers are already initialized
Expand Down Expand Up @@ -2441,7 +2441,7 @@ def get_tracker(self, name: str, unwrap: bool = False):
>>> tensorboard_tracker = accelerator.get_tracker("tensorboard")
```
"""
if len(getattr(self, "trackers", [])) > 0:
if len(self.trackers) > 0:
for tracker in self.trackers:
if tracker.name == name:
return tracker.tracker if unwrap else tracker
Expand Down

0 comments on commit 4bef6bc

Please sign in to comment.