Skip to content

StableDiffusionPipeline produces nans for SD2.1 (Mac, cpu device) #6136

Description

@UmerHA

Describe the bug

StableDiffusionPipeline produces nans for SD2.1.

CleanShot 2023-12-11 at 14 27 56@2x

The issue seems to be in the pipe.unet.conv_in. Printing the mean / std for sample before and after conv_in gives:

m,s = tensor(0.005) tensor(0.996)
m,s = tensor(15962061100191580160., grad_fn=<MeanBackward0>) tensor(16510648845702789070848., grad_fn=<StdBackward0>)

Reproduction

Make sure I'm using the latest official diffusers version

# uninstall local, editable version
!pip uninstall diffusers -y -qq
# install official version
!pip install diffusers -qq
# restart notebook now

Code to reproduce

from diffusers import StableDiffusionPipeline
pipe = StableDiffusionPipeline.from_pretrained('stabilityai/stable-diffusion-2-1')
result = pipe('the sun', output_type='pt')
result.images[0]

Output:

tensor([[[nan, nan, nan,  ..., nan, nan, nan],
         [nan, nan, nan,  ..., nan, nan, nan],
         [nan, nan, nan,  ..., nan, nan, nan],
...

Logs

No response

System Info

  • diffusers version: 0.24.0
  • Platform: macOS-14.1.2-arm64-arm-64bit
  • Python version: 3.11.6
  • PyTorch version (GPU?): 2.1.1 (False)
  • Huggingface_hub version: 0.19.4
  • Transformers version: 4.35.2
  • Accelerate version: 0.25.0
  • xFormers version: not installed
  • Using GPU in script?: no
  • Using distributed or parallel set-up in script?: no

Who can help?

Questions on pipelines > Stable Diffusion: @yiyixuxu @DN6 @sayakpaul @patrickvonplaten

Activity

  1. DN6 commented on Dec 12, 2023

    @DN6
    Collaborator

    Hi @UmerHA I was able to reproduce this. Using the MPS backend seems to resolve the issue pipe.to("mps"). Although I will look into why this is happening on CPU.

  2. DN6 commented on Dec 12, 2023

    @DN6
    Collaborator
  3. pcuenca commented on Dec 12, 2023

    @pcuenca
    Member

    Hi @UmerHA you are right, the pipeline is unstable using CPU. I tried to isolate a minimal reproduction snippet but couldn't. In the meantime, is there any reason why you are using the cpu instead of the mps device?

  4. UmerHA commented on Dec 12, 2023

    @UmerHA
    ContributorAuthor

    Hi @pcuenca, for educational purposes only. I created a very slim version of diffusers without all optimizations and wanted to compare results with the original diffusers.

  5. pcuenca commented on Dec 12, 2023

    @pcuenca
    Member

    Understood. What I saw is that calling self.conv_in(sample) produced different results after moving sample and conv_in to mps. However, attempting to reproduce the same case in an isolated script worked fine, using the same convolution weights (I saved them to a numpy array).

  6. github-actions commented on Jan 10, 2024

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

    Please note that issues that do not follow the contributing guidelines are likely to be ignored.

  7. pcuenca commented on Jan 18, 2024

    @pcuenca
    Member

    This is not fixed yet, keeping open in case someone from the community can come up with a workaround.

  8. changed the title [-]`StableDiffusionPipeline` produces `nans` for SD2.1[/-] [+]`StableDiffusionPipeline` produces `nans` for SD2.1 (Mac, cpu device)[/+] on Jan 18, 2024
  9. removed
    staleIssues that haven't received updates
    on Jan 18, 2024
  10. github-actions commented on Feb 12, 2024

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

    Please note that issues that do not follow the contributing guidelines are likely to be ignored.

  11. 2 remaining items

  12. github-actions commented on Mar 17, 2024

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

    Please note that issues that do not follow the contributing guidelines are likely to be ignored.

  13. removed
    staleIssues that haven't received updates
    on Mar 17, 2024
  14. sayakpaul commented on Mar 17, 2024

    @sayakpaul
    Member

    On the latest diffusers, on Mac M2 and M3, I didn't experience this.

  15. UmerHA commented on Mar 18, 2024

    @UmerHA
    ContributorAuthor

    I still experience this on an M2 with the latest diffusers (0.27)

    CleanShot 2024-03-18 at 12 16 55@2x

  16. sayakpaul commented on Mar 18, 2024

    @sayakpaul
    Member

    Will keep this open as it seems to be an edge case.

  17. github-actions commented on Apr 11, 2024

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

    Please note that issues that do not follow the contributing guidelines are likely to be ignored.

  18. a-r-r-o-w commented on Nov 19, 2024

    @a-r-r-o-w
    Contributor

    Gentle bump requesting status of this Issue. Got my M3 recently so can try and help out with some of the Mac issues :)

  19. removed
    staleIssues that haven't received updates
    on Nov 19, 2024
  20. github-actions commented on Dec 13, 2024

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

    Please note that issues that do not follow the contributing guidelines are likely to be ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcontributions-welcomehelp wantedExtra attention is neededstaleIssues that haven't received updates

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions