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 F.interpolate() for large batch sizes #1006

Merged
merged 2 commits into from
Oct 28, 2022

Conversation

NouamaneTazi
Copy link
Member

@NouamaneTazi NouamaneTazi commented Oct 26, 2022

Fixes #984.
It seems that F.interpolate(hidden_states, scale_factor=2.0, mode="nearest") breaks for batch sizes > 64 when hidden_states uses channels last format. See pytorch/pytorch#81665 and #984

This PR proposes to force a contiguous format for hidden states when bsz > 64. Credits to @pcuenca for the find.

The following now works (after applying the memory efficient PR + this PR)

pipe = StableDiffusionPipeline.from_pretrained(
    "CompVis/stable-diffusion-v1-4", 
    use_auth_token=True,
    revision="fp16",
    torch_dtype=torch.float16,
).to("cuda")

batch_size = 32

with torch.inference_mode():
    image = pipe([prompt] * batch_size, num_inference_steps=5).images[0]

cc @pcuenca @patrickvonplaten @patil-suraj

@NouamaneTazi NouamaneTazi changed the title fix F.interpolate() for large bsz fix F.interpolate() for large batch sizes Oct 26, 2022
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Oct 26, 2022

The documentation is not available anymore as the PR was closed or merged.

@NouamaneTazi
Copy link
Member Author

Wondering if I should apply the same fix for the following lines as well 🤔

        if self.upsample is not None:
            input_tensor = self.upsample(input_tensor)
            hidden_states = self.upsample(hidden_states)

Copy link
Contributor

@patil-suraj patil-suraj left a comment

Choose a reason for hiding this comment

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

Looks good to me!Maybe let's apply it before those two lines that you listed so it wilkl apply to all upsample ops.

@NouamaneTazi
Copy link
Member Author

Done @patil-suraj

@patil-suraj patil-suraj merged commit ab079f2 into huggingface:main Oct 28, 2022
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* fix `upsample_nearest_nhwc` for large bsz

* fix `upsample_nearest_nhwc` for large bsz
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.

F.interpolate(hidden_states, scale_factor=2.0, mode="nearest") breaks for large bsz
3 participants