当前位置:   article > 正文

mac m1 代码调用 huggingface Stable Diffusion(diffusers 方式)Stable Diffusion xl_mac huggingface

mac huggingface

Stable Diffusion

  1. from diffusers import DiffusionPipeline
  2. import torch
  3. pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
  4. pipe = pipe.to("mps")
  5. # Recommended if your computer has < 64 GB of RAM
  6. pipe.enable_attention_slicing()
  7. prompt = "便利店开业"
  8. # First-time "warmup" pass if PyTorch version is 1.13 (see explanation above)
  9. _ = pipe(prompt, num_inference_steps=1)
  10. images = pipe(prompt=prompt).images[0]
  11. images.save("output1.png")

diffusers

 Hugging Face 平台提供了基础模型权重以及通用的模型训练框架 diffusers

参考

How to use Stable Diffusion in Apple Silicon (M1/M2)

stable-diffusion-xl

  1. from diffusers import StableDiffusionXLPipeline
  2. import torch
  3. # pipe = StableDiffusionXLPipeline.from_pretrained(
  4. # "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
  5. # )
  6. pipe = StableDiffusionXLPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0")
  7. # pipe.to("cuda")
  8. pipe = pipe.to("mps")
  9. # Recommended if your computer has < 64 GB of RAM
  10. pipe.enable_attention_slicing()
  11. prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
  12. # First-time "warmup" pass if PyTorch version is 1.13 (see explanation above)
  13. _ = pipe(prompt, num_inference_steps=1)
  14. image = pipe(prompt=prompt).images[0]
  15. image.save("sdxl.png")

https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/stable_diffusion_xl 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/680954
推荐阅读
相关标签
  

闽ICP备14008679号