You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Tracker] fix training resuming problem when using FP16 in the examples #6552
File "/content/train_text_to_image_lora_sdxl.py", line 1261, in<module>
main(args)
File "/content/train_text_to_image_lora_sdxl.py", line 1077, in main
accelerator.clip_grad_norm_(params_to_optimize, args.max_grad_norm)
File "/usr/local/lib/python3.10/dist-packages/accelerate/accelerator.py", line 2040, in clip_grad_norm_
self.unscale_gradients()
File "/usr/local/lib/python3.10/dist-packages/accelerate/accelerator.py", line 2003, in unscale_gradients
self.scaler.unscale_(opt)
File "/usr/local/lib/python3.10/dist-packages/torch/cuda/amp/grad_scaler.py", line 307, in unscale_
optimizer_state["found_inf_per_device"] = self._unscale_grads_(
File "/usr/local/lib/python3.10/dist-packages/torch/cuda/amp/grad_scaler.py", line 229, in _unscale_grads_
raise ValueError("Attempting to unscale FP16 gradients.")
#6514 introduces a fix for the SDXL DreamBooth LoRA training script. #6553 is a follow-up that cleans things up a bit. However, it would be nice to extend them for the other scripts too. This issue tracks the integration:
Feel free to claim any of these and submit PRs. Do tag me in those PRs and focus on fixing only one script at a time. I know that @linoytsaban is already working on the last one.
While submitting the PRs, please also provide example commands as I did in #6514 (comment) so as to quickly test the validity.
So just an FYI i did a quick port of those changes to the Advanced LoRa trainer. I received the following error after resuming training from a checkpoint and running inference on the generated model.
Loading adapter weights from state_dict led to unexpected keys not found in the model: ['down_blocks.1.attentions.0.transformer_blocks.0.attn1.to_q.lora_A_1.default_0.weight', 'down_blocks.1.attentions.0.transformer_blocks.0.attn1.to_q.lora_B_1.default_0.weight',
....
Update:
I can see in the logs that once training finishes the same error is raised.
Tested training a model with train_dreambooth_lora_sdxl.py script and the following error was returned after saving a checkpoint and trying to resume from the checkpoint.
Resuming from checkpoint checkpoint-10
01/12/2024 16:42:50 - INFO - accelerate.accelerator - Loading states from father_lora_v22/checkpoint-10
Traceback (most recent call last):
File "/home/steve/projects/training/scripts/train_dreambooth_lora_sdxl.py", line 1762, in <module>
main(args)
File "/home/steve/projects/training/scripts/train_dreambooth_lora_sdxl.py", line 1383, in main
accelerator.load_state(os.path.join(args.output_dir, path))
File "/home/steve/.local/lib/python3.10/site-packages/accelerate/accelerator.py", line 2849, in load_state
hook(models, input_dir)
File "/home/steve/projects/training/scripts/train_dreambooth_lora_sdxl.py", line 1078, in load_model_hook
_set_state_dict_into_text_encoder(
File "/home/steve/.local/lib/python3.10/site-packages/diffusers/training_utils.py", line 140, in _set_state_dict_into_text_encoder
set_peft_model_state_dict(text_encoder, text_encoder_state_dict, adapter_name="default")
File "/home/steve/.local/lib/python3.10/site-packages/peft/utils/save_and_load.py", line 201, in set_peft_model_state_dict
load_result = model.load_state_dict(peft_model_state_dict, strict=False)
File "/home/steve/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 2152, in load_state_dict
raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for CLIPTextModel:
size mismatch for text_model.encoder.layers.0.self_attn.k_proj.lora_A.default.weight: copying a param with shape torch.Size([32, 1280]) from checkpoint, the shape in current model is torch.Size([32, 768]).
size mismatch for text_model.encoder.layers.0.self_attn.k_proj.lora_B.default.weight: copying a param with shape torch.Size([1280, 32]) from checkpoint, the shape in current model is torch.Size([768, 32]).
...
changed the title [-][Examples] fix training resuming problem when using FP16[/-][+][Tracker] fix training resuming problem when using FP16 in the examples[/+]on Jan 29, 2024
I believe that the fix has been propagated to Advanced LoRA trainer SD v1.5 in PR 7018 which is the final script in the tracker. Are there more scripts in the examples folder that need the fix to be applied?
Activity
a-r-r-o-w commentedon Jan 12, 2024
Hi Sayak, I'll take up DreamBooth LoRA SD. Opening a PR shortly, thanks.
steverhoades commentedon Jan 12, 2024
So just an FYI i did a quick port of those changes to the Advanced LoRa trainer. I received the following error after resuming training from a checkpoint and running inference on the generated model.
Update:
I can see in the logs that once training finishes the same error is raised.
steverhoades commentedon Jan 13, 2024
Tested training a model with
train_dreambooth_lora_sdxl.pyscript and the following error was returned after saving a checkpoint and trying to resume from the checkpoint.resulted in:
sayakpaul commentedon Jan 13, 2024
@linoytsaban ^
steverhoades commentedon Jan 13, 2024
I was able to get a working example running, still learning this code base but gave a crack at a PR #6566.
I tested both
train_text_encoderandtrain_text_encoder_tiwhich completed successfully.[-][Examples] fix training resuming problem when using FP16[/-][+][Tracker] fix training resuming problem when using FP16 in the examples[/+]pedrogengo commentedon Jan 30, 2024
Hey hey! I will take Text-to-image LoRA SD fix. Should open a PR today or tomorrow!
sriagastya commentedon Feb 4, 2024
Hello HuggingFace Team, Can I work on SDXL Consistency Distillation?
sayakpaul commentedon Feb 4, 2024
Please feel free to.
ParagEkbote commentedon May 9, 2025
Has this issue been resolved or are there any pending scripts I could contribute to fix?
cc: @sayakpaul
sayakpaul commentedon May 10, 2025
You can take an example where the fix hasn't been propagated yet and open a PR.
ParagEkbote commentedon May 10, 2025
I believe that the fix has been propagated to Advanced LoRA trainer SD v1.5 in PR 7018 which is the final script in the tracker. Are there more scripts in the examples folder that need the fix to be applied?
cc: @sayakpaul
sayakpaul commentedon May 10, 2025
How about https://github.com/huggingface/diffusers/blob/main/examples/advanced_diffusion_training/train_dreambooth_lora_sd15_advanced.py?
ParagEkbote commentedon May 10, 2025
So, PR 7018 did not propagate the fix and the script is still open for contribution, right?
sayakpaul commentedon May 10, 2025
My bad, sorry. It did propagate it. Closing this issue.