在 Mac 上从 2-1 升级到 Stable Diffusion 3

问题描述 投票:0回答:1

我正在将稳定扩散从 2-1 升级到 stable-diffusion-3-medium-diffusers

这是我的代码,适用于版本 2-1

# source venv/bin/activate

from diffusers import DiffusionPipeline

pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1")
pipe = pipe.to("mps")

pipe.enable_attention_slicing()

print("Starting Process")

steps = 200
query = "Stormy Weather in Monte Carlo"

image = pipe(query, num_inference_steps=steps).images[0]

image.save("oneOffImage.jpg")

print("Successfully Created Image as oneOffImage.jpg")

我升级了

diffusers
,在 Hugging Face 上注册以访问门控存储库,创建 HF_TOKEN 并将其添加到我的 .env,然后运行此代码

# source venv/bin/activate

from diffusers import StableDiffusion3Pipeline
from dotenv import load_dotenv
import os

load_dotenv()

print("Starting Process")

pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers")
pipe = pipe.to("mps")

# pipe.set_progress_bar_config(disable=True)
pipe.enable_attention_slicing()

print("Starting Process")

steps = 200
query = "Stormy Weather in Monte Carlo"

image = pipe(query, num_inference_steps=steps).images[0]

image.save("oneOffImage.jpg")

print("Successfully Created Image as oneOffImage.jpg")

我能够下载模型,我还记录了令牌并确认它在环境变量中,我尝试添加火炬并设置

, torch_dtype=torch.float16)
但这没有任何作用,而且我认为这就是cuda,我还尝试添加一个身份验证标签但是那什么也没做,我升级了我的变形金刚,但我什至不知道它做了什么。我已经没有主意了。

这是当前错误

(venv) mikeland@mikes-mac-mini WeatherWindow % python3 oneOffGenStableDiffusion.py 
/Users/mikeland/WeatherWindow/venv/lib/python3.9/site-packages/diffusers/models/transformers/transformer_2d.py:34: FutureWarning: `Transformer2DModelOutput` is deprecated and will be removed in version 1.0.0. Importing `Transformer2DModelOutput` from `diffusers.models.transformer_2d` is deprecated and this will be removed in a future version. Please use `from diffusers.models.modeling_outputs import Transformer2DModelOutput`, instead.
  deprecate("Transformer2DModelOutput", "1.0.0", deprecation_message)
Starting Process
Loading pipeline components...:   0%|                                                                                  | 0/9 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "/Users/mikeland/WeatherWindow/oneOffGenStableDiffusion.py", line 15, in <module>
    pipe = StableDiffusion3Pipeline.from_pretrained("stabilityai/stable-diffusion-3-medium-diffusers")
  File "/Users/mikeland/WeatherWindow/venv/lib/python3.9/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn
    return fn(*args, **kwargs)
  File "/Users/mikeland/WeatherWindow/venv/lib/python3.9/site-packages/diffusers/pipelines/pipeline_utils.py", line 881, in from_pretrained
    loaded_sub_model = load_sub_model(
  File "/Users/mikeland/WeatherWindow/venv/lib/python3.9/site-packages/diffusers/pipelines/pipeline_loading_utils.py", line 703, in load_sub_model
    loaded_sub_model = load_method(os.path.join(cached_folder, name), **loading_kwargs)
  File "/Users/mikeland/WeatherWindow/venv/lib/python3.9/site-packages/transformers/modeling_utils.py", line 3122, in from_pretrained
    raise ImportError(
ImportError: Using `low_cpu_mem_usage=True` or a `device_map` requires Accelerate: `pip install accelerate`

我现在只是在寻找可以在 Mac 上工作的任何示例。

python macos stable-diffusion mps
1个回答
0
投票

这就是最终为我工作的

# source venv/bin/activate

from diffusers import StableDiffusion3Pipeline
import torch

from dotenv import load_dotenv
import os

load_dotenv()

os.environ["PYTORCH_MPS_HIGH_WATERMARK_RATIO"] = "0.0"

print("Starting Process")

pipe = StableDiffusion3Pipeline.from_pretrained(
        "stabilityai/stable-diffusion-3-medium-diffusers", 
        low_cpu_mem_usage=False,
        torch_dtype=torch.float16,
        variant="fp16",
        use_safttensors=True
        ).to("mps")


pipe.enable_attention_slicing()

print("Starting Process")

steps = 40
query = "Rain Weather in New York City, New York"

image = pipe(query, num_inference_steps=steps).images[0]

image.save("oneOffImage.jpg")

print("Successfully Created Image as oneOffImage.jpg")
© www.soinside.com 2019 - 2024. All rights reserved.