huggingface / huggingface/diffusers

Potential incorrect indentation for logging in train_dreambooth.py

Offen
#12,641 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

stale
Vorherrschende Sprache
Python
Sterne
34.5k
Forks
7.3k
Ø Merge
3 T. 3 Std.
Gemergte PRs (30 T.)
91

Beschreibung

Description:

In the train_dreambooth.py script, the logging and progress bar updates appear to be executed on every training step, even when using gradient accumulation. This might lead to incorrect or redundant logging.

The relevant code is located around lines 1393-1395:

https://github.com/huggingface/diffusers/blob/093cd3f040ee4f44908df8e1b441954f3f25c214/examples/dreambooth/train_dreambooth.py#L1346-L1395

The global_step is only incremented when accelerator.sync_gradients is true. However, the logging calls (progress_bar.set_postfix and accelerator.log) are outside this block. This means that when gradient accumulation is used, these lines are executed for every batch, but the global_step value passed to accelerator.log does not change until an optimization step occurs. This could result in multiple log entries for the same global_step.

It seems more appropriate to move the logging logic inside the if accelerator.sync_gradients: block to ensure that logging only happens once per optimization step.

Proposed Change:

  if accelerator.sync_gradients: 
      progress_bar.update(1) 
      global_step += 1 

      if accelerator.is_main_process: 
          # ... checkpointing and validation logic ...
 
- logs = {"loss": loss.detach().item(), "lr": lr_scheduler.get_last_lr()[0]} 
- progress_bar.set_postfix(**logs) 
- accelerator.log(logs, step=global_step)

+    logs = {"loss": loss.detach().item(), "lr": lr_scheduler.get_last_lr()[0]} 
+    progress_bar.set_postfix(**logs)
+    accelerator.log(logs, step=global_step)

Could you please confirm if this is the intended behavior or if the indentation should be corrected? Thank you!

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in examples/dreambooth/train_dreambooth.py ungefähr bei den Zeilen 1346–1395 und prüfe, wie accelerator.sync_gradients global_step steuert. Prüfe, ob progress_bar.set_postfix und accelerator.log einmal pro Optimierungsschritt oder bei jedem Batch ausgeführt werden; abgeschlossen ist die Aufgabe, wenn das beabsichtigte Logging-Verhalten bestätigt und die Einrückung bei Bedarf korrigiert wurde.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
machine-learning
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
50/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.