1206 字
6 分钟

Mac ARM 平台手动部署 ComfyUI 指南

对于 Mac 用户主要推荐使用 ComfyUI Desktop 版本,你可以访问ComfyUI Desktop 版本安装教程来使用 ComfyUI,之所以选择手动安装 ComfyUI 是因为在 Mac ARM Silicon 平台的 BUG 较多而桌面版(稳定版)的更新较为缓慢,使用手动安装的方式(可以自由的切换版本)获得最及时的问题修复以及新的功能支持,同时能做到让 ComfyUI 静默的运行,是我认为较为舒服的方式。

1、创建虚拟环境#

Install Miniconda. 这将帮助您安装 ComfyUI 所需的正确版本的 Python 和其他库。使用 Conda 创建一个环境。

conda create -n comfyenv
conda activate comfyenv

2、克隆代码仓库#

你需要保证你的系统上已经安装了 Git, 首先你需要打开终端(命令行),然后克隆代码仓库。

打开终端应用程序

git clone git@github.com:comfyanonymous/ComfyUI.git

3、安装GPU 及 ComfyUI 依赖#

1、安装 GPU 依赖

Mac ARM Silicon 平台执行

Terminal window
conda install pytorch-nightly::pytorch torchvision torchaudio -c pytorch-nightly

2、安装 ComfyUI 依赖

Terminal window
cd ~/ComfyUI
pip install -r requirements.txt

3、安装插件管理器(ComfyUI-Manager)

cd ~/ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Manager.git
cd ComfyUI-Manager && pip install -r requirements.txt

4、安装汉化插件(装上后还是可以选择使用英文界面,可在设置中进行切换)

cd ~/ComfyUI/custom_nodes
git clone https://github.com/AIGODLIKE/AIGODLIKE-COMFYUI-TRANSLATION.git

3、启动 ComfyUI

Terminal window
cd ~/ComfyUI
python main.py

4、添加外部模型路径(可选)#

如果想要共用 ComfyUI/models​ 模型,通过 extra_model_paths.yaml 配置文件来添加额外模型搜索路径。

可以在 ComfyUI 的根目录下找到 extra_model_paths.yaml.example 的示例文件

ComfyUI/extra_model_paths.yaml.example

复制并重命名为 extra_model_paths.yaml​ 来使用, 并保持在 ComfyUI 的根目录下, 路径应该是 ComfyUI/extra_model_paths.yaml

参考配置如下:

Terminal window
#Rename this to extra_model_paths.yaml and ComfyUI will load it
#config for comfyui
#your base path should be either an existing comfy install or a central folder where you store all of your models, loras, etc.
comfyui:
base_path: /Users/gowah_yue/Documents/AIGC/ComfyUI/
# # You can use is_default to mark that these folders should be listed first, and used as the default dirs for eg downloads
# #is_default: true
animatediff_models: models/animatediff_models
animatediff_motion_lora: models/animatediff_motion_lora
animatediff_video_formats: models/animatediff_video_formats
blip: models/blip
checkpoints: models/checkpoints
clip: models/clip
clip_vision: models/clip_vision
CogVideo: models/CogVideo
configs: models/configs
controlnet: models/controlnet
diffusers: models/diffusers
diffusion_models: models/diffusion_models
embeddings: models/embeddings
gligen: models/gligen
hypernetworks: models/hypernetworks
insightface: models/insightface
Joy_caption: models/Joy_caption
layerstyle: models/layerstyle
liveportrait: models/liveportrait
LLM: models/LLM
loras: models/loras
model_patches: models/model_patches
photomaker: models/photomaker
style_models: models/style_models
text_encoders: models/text_encoders
unet: models/unet
upscale_models: models/upscale_models
vae: models/vae
vae_approx: models/vae_approx
xlabs: models/xlabs
#config for a1111 ui
#all you have to do is uncomment this (remove the #) and change the base_path to where yours is installed
#a111:
# base_path: path/to/stable-diffusion-webui/
# checkpoints: models/Stable-diffusion
# configs: models/Stable-diffusion
# vae: models/VAE
# loras: |
# models/Lora
# models/LyCORIS
# upscale_models: |
# models/ESRGAN
# models/RealESRGAN
# models/SwinIR
# embeddings: embeddings
# hypernetworks: models/hypernetworks
# controlnet: models/ControlNet
# For a full list of supported keys (style_models, vae_approx, hypernetworks, photomaker,
# model_patches, audio_encoders, classifiers, etc.) see folder_paths.py.
#other_ui:
# base_path: path/to/ui
# checkpoints: models/checkpoints
# gligen: models/gligen
# custom_nodes: path/custom_nodes

这里我将之前桌面端使用过程留存的 models​ 文件夹迁移至 /Users/gowah_yue/Documents/AIGC/ComfyUI/​ 并作为 base_path 目录,各个模型文件夹分别使用相对路径。

如果想要和桌面端共存的朋友,可以在 macOS ComfyUI 桌面端 ~/Library/Application Support/ComfyUI/extra_models_config.yaml 做出相应的修改。

4、为 ComfyUI 服务创建自启动脚本#

~/Library/LaunchAgents​ 路径下创建 local.startup.comfyui.plist 文件参考如下:

Terminal window
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.startup.comfyui</string>
<key>EnvironmentVariables</key>
<dict>
<key>PYTORCH_ENABLE_MPS_FALLBACK</key>
<string>1</string>
<key>PYTORCH_MPS_HIGH_WATERMARK_RATIO</key>
<string>1.0</string>
<key>PYTORCH_MPS_LOW_WATERMARK_RATIO</key>
<string>0.9</string>
</dict>
<key>WorkingDirectory</key>
<string>/Users/gowah_yue/ComfyUI</string>
<key>ProgramArguments</key>
<array>
<string>/opt/miniconda3/envs/comfyenv/bin/python3</string>
<string>main.py</string>
<string>--listen</string>
<string>0.0.0.0</string>
<string>--port</string>
<string>8188</string>
<string>--cache-classic</string>
<string>--use-split-cross-attention</string>
<string>--normalvram</string>
<string>--output-directory</string>
<string>/Users/gowah_yue/Documents/AIGC/ComfyUI/data/output</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>StandardOutPath</key>
<string>/tmp/local.startup.comfyui.stdout.log</string>
<key>StandardErrorPath</key>
<string>/tmp/local.startup.comfyui.stderr.log</string>
</dict>
</plist>

脚本介绍:#

1、WorkingDirectory​ 的值(即 /path/to/your/app​)必须是你存放 main.py​ 文件和该文件所需所有其他资源文件的实际目录的绝对路径。

2、使用 ProgramArguments​ 实现 Python 运行,需要在之前创建 ComfyUI 的虚拟环境下(也就是需要运行 conda activate comfyenv​ 激活虚拟环境后)运行 which python3​ 获取在该环境下 python3​ 命令的实际路径,并写入到脚本文件的 <string> 中。

3、脚本同时加入了优化 Pytorch 环境变量 PYTORCH_ENABLE_MPS_FALLBACK​ 和 PYTORCH_MPS_HIGH_WATERMARK_RATIO​ 确保 PyTorch 不支持的情况不会立即报错或崩溃,而是会自动将该操作转移到 CPU 上执行,同时确保 PyTorch 将 内存缓存 限制在总 GPU 可用内存的 80%

日常维护#

Terminal window
# 1. 卸载旧配置
launchctl unload ~/Library/LaunchAgents/local.startup.comfyui.plist
# 2. 重新加载新配置
launchctl load ~/Library/LaunchAgents/local.startup.comfyui.plist
# 3. 立即启动新服务
launchctl start local.startup.comfyui

5、如何更新 ComfyUI#

1、拉取最新代码

使用命令行进入 ComfyUI 的安装路径,然后拉取最新代码。

cd <安装路径>/ComfyUI
git pull

2、安装依赖

使用命令行进入 ComfyUI 的安装路径,然后安装依赖。

你需要确保当前的 Python 环境是 ComfyUI 的虚拟环境,否则依赖会安装到系统级 Python 环境,污染系统级 Python 环境。

pip install -r requirements.txt

6、进阶优化#

  1. 外置硬盘部署:(上述的开机脚本需要修改其中的路径)
    手动安装版本可将整个 ComfyUI 文件夹拷贝至外置 SSD,启动时指定路径:

    cd /Volumes/SSD/ComfyUI && source venv/bin/activate && python main.py
  2. 性能调优​:
    编辑 ~/.bash_profile 添加环境变量提升推理速度:

    export PYTORCH_ENABLE_MPS_FALLBACK=1
    export PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.8

    应用环境变量

    Terminal window
    source ~/.bash_profile

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或赞助支持!

赞助
Mac ARM 平台手动部署 ComfyUI 指南
https://blog.moewah.com/posts/mac-arm-comfyui-manual-installation-guide/
作者
GoWah
发布于
2025-03-11
许可协议
CC BY-NC-SA 4.0
Profile Image of the Author
GoWah
Hello, I'm GoWah.
分类
标签
站点统计
文章
160
分类
9
标签
350
总字数
301,106
运行时长
0
最后活动
0 天前

目录