zdd

zdd

如何在Apple M1 上玩转stable-diffusion

被 AIGC 浪潮一遍遍的拍打,Midjourney 免费的 25 张还没能让我学会 “魔法咒语”,没有外币结算的信用卡,充值太麻烦了;所以又到了感谢开源万岁的时候了,继续 stable-diffusion 练习魔法咒语;Apple 的 M 系列芯片有强大的算力,结合统一内存的技术,我们可以在 M 系列的 Mac 上玩转 SD,当然,前提是至少得 16G 内存哦!

https://oss.productnose.com/assets/stable-diffusion-demo-2.jpg|inline

本着命令行能不用就不用的原则,选择https://github.com/AUTOMATIC1111/stable-diffusion-webui 开源项目来折腾,并且整个搭建的流程非常自动化;对 Apple 的 ARM 芯片的自动安装脚本。

基础环境准备#

你需要有 python、rust 等基础的运行环境,如果已经安装 homebrew, 可以使用下面这条命令安装:

brew install cmake protobuf rust [email protected] git wget

下载项目#

首先进这个项目地址:https://github.com/AUTOMATIC1111/stable-diffusion-webui

如果会使用 git,你可以直接 clone 项目;

git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui

不会也没事儿,你可以直接下载项目代码的压缩包;

[https://github.com/AUTOMATIC1111/stable-diffusion-webui/archive/refs/heads/master.zip](https://github.com/AUTOMATIC1111/stable-diffusion-webui/archive/refs/heads/master.zip)

下载模型#

项目代码中是不包含模型的,需要额外去 官方模型库 或者Hugging Face 下载大佬们训练好的模型,图像生成的模型大小一般都挺大,网络不好下载需要一些时间;

一些受欢迎的官方稳定模型:

Hugging Face 中你选择 Text-to-Image 可以查找受欢迎的模型

https://oss.productnose.com/assets/huggingface.png|inline

最后,将下载好的模型,放在刚刚项目的这个目录下

stable-diffusion-webui/models/Stable-diffusion

Let's begin#

进入项目根目录的终端,执行下面代码,等待运行提示完成,即可在浏览器访问127.0.0.1:7860开始魔法啦;

./webui.sh

在 txt2img 菜单下,输入你的魔法咒语就可以开始啦;下面各项属性可以调整生成图片的分辨率、、数量等等;我们会在后面的文章中来学习该怎么玩;(我也得学习一下,有点复杂,哈哈哈哈)

https://oss.productnose.com/assets/20230323160108.png|inline

关于体验#

关于生成图像的速度,基于我的 MacBookPro M1 Pro 32G 的体验来看,512 分辨率的图像速度还是挺快的,一般在 15s 以内可以完成;当然随着你 Sampling steps、批量生成数量的增加时间也会增加;玩了大概半小时,可以摸到 MBP 的温度升上来了。

官方在 Apple ARM 上使用问题有一些情况说明;目前我使用中还没有遇到(主要是一些高级玩法还没使用)

Currently most functionality in the web UI works correctly on macOS, with the most notable exceptions being CLIP interrogator and training. Although training does seem to work, it is incredibly slow and consumes an excessive amount of memory. CLIP interrogator can be used but it doesn't work correctly with the GPU acceleration macOS uses so the default configuration will run it entirely via CPU (which is slow).

Most samplers are known to work with the only exception being the PLMS sampler when using the Stable Diffusion 2.0 model. Generated images with GPU acceleration on macOS should usually match or almost match generated images on CPU with the same settings and seed.

目前,Web UI 中的大多数功能在 macOS 上都能正常工作,最显著的例外是 CLIP 询问器和训练。虽然训练似乎可以工作,但速度非常慢,并且消耗过多的内存。CLIP 询问器可以使用,但它不能正确地与 macOS 使用的 GPU 加速配合使用,因此默认配置将完全通过 CPU 运行(这很慢)。

大多数采样器都已知可用,唯一的例外是在使用 Stable Diffusion 2.0 模型时使用 PLMS 采样器。在 macOS 上启用 GPU 加速生成图像应该通常与相同设置和种子下 CPU 生成图像匹配或几乎匹配。

后续#

近期,我想要用 AIGC 帮我生成好看的 Logo,没有美术设计背景画的 Logo 真的惨不忍睹;后续我也会将过程实践中学到的使用教程整理分享出来,之后见啦!

参考来源:

https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Installation-on-Apple-Silicon#downloading-stable-diffusion-models

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。