有一台配有Apple Silicon 系列芯片(M系列芯片)的Mac电脑
这个条件如果满足,就可以继续看下去了!
只需要无脑按照提示运行命令,你的Mac就可以玩SD了!
如果还不会!拉到最底下进**流!
下载和安装Miniconda的命令如下:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-arm64.sh chmod +x Miniconda3-latest-MacOSX-arm64.sh ./Miniconda3-latest-MacOSX-arm64.sh安装完成后,创建一个虚拟环境,通过检查platform.uname()[4] 是不是为arm64 来检查Python的架构,检查命令如下:
conda config --env --set always_yes trueconda create -n try-mps python=3.8conda activate try-mpspython -c "import platform; print(platform.uname()[4])"如果最后一句命令的输出为arm64 ,说明Python版本搞定,可以继续下一步了
第三步,安装nightly版本的Pytorch,在开启的虚拟环境中进行下面的操作:
python -m pip install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu执行完成后通过下面的命令检查MPS后端是否可用:
python -c "import torch;print(torch.backends.mps.is_built())"依次运行以下命令行:
pip install accelerateconda install -c conda-forge diffuserspip install transformers运行以下代码开始跑图:
import timeimport torchfrom diffusers import DiffusionPipeline, LCMSchedulerpipe = DiffusionPipeline.from_pretrained( "runwayml/stable-diffusion-v1-5", variant="fp16", torch_dtype=torch.float16,).to("mps")# set schedulerpipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)# load LCM-LoRApipe.load_lora_weights("latent-consistency/lcm-lora-sdv1-5")prompt = "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k"start = time.time()generator = torch.manual_seed(42)image = pipe( prompt=prompt, num_inference_steps=4, generator=generator, guidance_scale=1.0).images[0]image.save("1.png")end = time.time()print(end-start)关注「开源AI项目落地」公众号
Copyright © 2025 AI图片论坛 版权所有. 站点地图