-
Couldn't load subscription status.
- Fork 6.5k
fix the in-place modification in unet condition when using controlnet #2586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix the in-place modification in unet condition when using controlnet #2586
Conversation
…, which will cause backprop errors when training
|
The documentation is not available anymore as the PR was closed or merged. |
|
Yes, this makes sense indeed! cc @williamberman can you check? |
|
hey! hmm, in all honesty I'm not super familiar with the restrictions around how modifying tensors in place effects errors during back propagation. My understanding from a (quick) googling is that tensor variables which are stored for the backward pass have the underlying tensors they point to modified, torch throws an error. It isn't immediately clear to me if torch always throws this error or if it requires some extra config. While training controlnet, I'm not getting the in place modification error. Assuming torch throws the error by default, I'd rather not introduce an unnecessary copy. Am I off base here with if torch always throw the error or not? |
|
Hi William, Thanks for your feedback! Your understanding of in-place tensor modification is correct. But note Pytorch will throw an error only if the gradient of the tensor is being calculated during back prop. In the vanilla case, the down_block_res_sample does not require grad calculation, so you don't find an error. However, as long as you want to also fine-tune the UNet (either full fine-tuning or using LoRA), Pytorch will throw an error. So I think it makes sense to add a copy here in case anyone wants to train ControlNet with UNet together. |
|
FWIW I got this error as well, not during training, but when using 'Null-Text Inversion', which requires backprop. |
|
@williamberman can you double check here? I'm in favor of going ahead with this PR as it has no drawbacks as far as I can see |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
…huggingface#2586) * fix the in-place modification in unet condition when using controlnet, which will cause backprop errors when training * add clone to mid block * fix-copies --------- Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> Co-authored-by: William Berman <WLBberman@gmail.com>
…huggingface#2586) * fix the in-place modification in unet condition when using controlnet, which will cause backprop errors when training * add clone to mid block * fix-copies --------- Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> Co-authored-by: William Berman <WLBberman@gmail.com>
…huggingface#2586) * fix the in-place modification in unet condition when using controlnet, which will cause backprop errors when training * add clone to mid block * fix-copies --------- Co-authored-by: Patrick von Platen <patrick.v.platen@gmail.com> Co-authored-by: William Berman <WLBberman@gmail.com>
Just adding a clone operation. The original code will cause backprop errors when training the controlnet.