Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/transformers/integrations/integration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,17 @@ def on_train_begin(self, args, state, control, model=None, **kwargs):
args.run_name = None
if not self._initialized:
self.setup(args, state, model, **kwargs)

# Auto log Accelerate parallelism info to wandb.config
if self._initialized and state.is_world_process_zero and getattr(self._wandb, "run", None) is not None:
acc = getattr(model, "accelerator", None)
pc = getattr(acc, "parallelism_config", None) if acc is not None else None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think the if check is necessary since we can use getattr with NoneType as well in python

Suggested change
pc = getattr(acc, "parallelism_config", None) if acc is not None else None
pc = getattr(acc, "parallelism_config", None)

sizes = getattr(pc, "_sizes", None) if pc is not None else None

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
sizes = getattr(pc, "_sizes", None) if pc is not None else None
sizes = getattr(pc, "_sizes", None)

if isinstance(sizes, dict) and sizes:
try:
self._wandb.config.update({"parallelism": sizes}, allow_val_change=True)
except Exception:
pass

def on_train_end(self, args: TrainingArguments, state, control, model=None, processing_class=None, **kwargs):
if self._wandb is None:
Expand Down