huggingface / huggingface/diffusers

[Training] Resume checkpoint global step inconsistent/confusion across scripts

Đang mở
#8,296 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug stale
Ngôn ngữ chính
Python
Star
34.5k
Fork
7.3k
Merge trung bình
3 ngày 3 giờ
Pull request đã merge (30 ngày)
91

Mô tả

### Describe the bug

Hi,
I have been working on training scripts for multiple models (T2I, IP2P) and found the different logic to calculate `step` and `epoch` while resuming training different across scripts.
In `train_text_to_image.py` script [link](https://github.com/huggingface/diffusers/blob/fe5f035f797a5fa663a98030c9d0ec2f982cd09d/examples/text_to_image/train_text_to_image.py#L902)
```
accelerator.print(f"Resuming from checkpoint {path}")
accelerator.load_state(os.path.join(args.output_dir, path))
global_step = int(path.split("-")[1])
initial_global_step = global_step
first_epoch = global_step // num_update_steps_per_epoch
```
In `train_instruct_pix2pix.py` script [link](https://github.com/huggingface/diffusers/blob/fe5f035f797a5fa663a98030c9d0ec2f982cd09d/examples/instruct_pix2pix/train_instruct_pix2pix.py#L825)
```
accelerator.print(f"Resuming from checkpoint {path}")
accelerator.load_state(os.path.join(args.output_dir, path))
global_step = int(path.split("-")[1])

resume_global_step = global_step * args.gradient_accumulation_steps
first_epoch = global_step // num_update_steps_per_epoch
resume_step = resume_global_step % (num_update_steps_per_epoch * args.gradient_accumulation_steps)
```
In the similar [issue](https://github.com/huggingface/diffusers/issues/5005), some changes are made for the progress bar inconsistency but I am bit confused with the following things:-
1. The multiplication of `args.gradient_accumulation_steps` in `train_instruct_pix2pix.py` script
2. In general, when does global-step indicate and how does it's being updated, in both the scripts I can see the following code but couldn't understand it from `accelerate` documentation
```
if accelerator.sync_gradients:
if args.use_ema:
ema_unet.step(unet.parameters())
progress_bar.update(1)
global_step += 1
accelerator.log({"train_loss": train_loss}, step=global_step)
train_loss = 0.0
```
If we are using multiple GPUs with gradient accumulation, at what event `global_step` is updated- is it being updated independently by each GPU (since the code is not wrapped with `accelerator.is_main_process`), also how accumulation affecting the tracking here?

### Reproduction

-

### Logs

_No response_

### System Info

-

### Who can help?

@sayakpaul

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu bằng cách so sánh logic resume trong examples/text_to_image/train_text_to_image.py và examples/instruct_pix2pix/train_instruct_pix2pix.py, sau đó đọc khối accelerator.sync_gradients cập nhật global_step. Theo dõi cách tích lũy gradient và nhiều tiến trình ảnh hưởng đến các giá trị này, đồng thời xác định hành vi nhất quán cho resume và việc theo dõi tiến độ trên cả hai script.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python, pytorch
Lĩnh vực
machine-learning
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
28/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.