huggingface / huggingface/diffusers
Potential incorrect indentation for logging in train_dreambooth.py
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 34.5k
- Forks
- 7.3k
- Merge medio
- 3 d 3 h
- PR fusionados (30 d)
- 91
Descripción
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:
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!
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en examples/dreambooth/train_dreambooth.py alrededor de las líneas 1346-1395 e inspecciona cómo accelerator.sync_gradients controla global_step. Comprueba si progress_bar.set_postfix y accelerator.log se ejecutan una vez por paso de optimización o en cada batch; la tarea está terminada cuando se haya confirmado el comportamiento de logging previsto y se haya corregido la indentación si es necesario.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- machine-learning
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 50/100