Skip to content
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 mixed precision torch compile bug #75

Merged
merged 1 commit into from
Oct 8, 2023

Conversation

Skylion007
Copy link
Contributor

@Skylion007 Skylion007 commented Oct 7, 2023

This is solves the bug that torch compile encountered. It didn't know the module was in fp16 until it hit weights in the backward pass because it does not know that .half() has side-effects. Making the program adhere to a more functional paradigm completely solves this bug (by invalidating the dtype cache of the nn Module).

This is solves the bug that torch compile encountered. It didn't know the module was in fp16 until it hit weights in the backward pass because it does not know that .half() has side-effects. Making the program more functional completely solves this bug
Copy link
Collaborator

@mvpatel2000 mvpatel2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!!

@Skylion007 Skylion007 merged commit 3365aec into main Oct 8, 2023
7 checks passed
@jon-chuang
Copy link

@Skylion007 could you give more context on:

  1. Where the torch.compile was invoked?

@jon-chuang
Copy link

Something that I find extremely suspicious about this fix is the following:

self.text_encoder.requires_grad_(False)
self.vae.requires_grad_(False)
if self.encode_latents_in_fp16:
    self.text_encoder = self.text_encoder.half()
    self.vae = self.vae.half()

Since vae does not require grad, how can it throw an error:

RuntimeError: attempting to assign a gradient with dtype 'float' to a tensor with dtype 'c10::Half'. Please ensure that the gradient and the tensor have the same dtype

About the dtype of its grad?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants