昇腾社区首页
中文
注册
开发者
下载

ComfyUI迁移

ComfyUI是一个基于节点的Stable Diffusion用户界面,用户能够通过连接节点来构建复杂的图像生成工作流。ComfyUI中可以通过构建自定义加速节点替换工作流中的原有节点实现加速。

操作步骤

  1. 使用以下命令下载ComfyUI官方代码仓。
    git clone https://github.com/comfyanonymous/ComfyUI
  2. 进入/ComfyUI目录并下载相关依赖。
    cd ComfyUI 
    pip install -r requirements.txt
  3. 下载MindIE SD加速插件并导入ComfyUI。
    git clone https://modelers.cn/MindIE/stable_audio_open_1.0.git cp -r stable_audio_open_1.0/StableAudio_Comfyui_Plugin /{ComfyUI下载路径}/ComfyUI/custom_nodes/

    另一种获取加速节点方式:基于MindIE SD优化后的模型自定义加速节点,操作步骤如下所示。

    1. 加载MindIE代码仓中优化后模型的Transformer模型。
      unet_path = os.path.join(MODEL_FOLDER_PATH, unet_name)
      unet = UnetAdapter(unet_path, use_attentioncache, start_step, attentioncache_interval, end_step)
    2. 加载ComfyUI中对应模型的Transformer模型。
      conf = comfy.supported_models.StableAudio( {"audio_model": "dit1.0"})
      conf.unet_config["disable_unet_model_creation"] = True
      conf.unet_config = {
          "audio_model": "dit1.0",
      }
      embedder_weights_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "seconds_embedder_weights")
      seconds_start_embedder_weights = torch.load(os.path.join(embedder_weights_path, "seconds_start_embedder_weights.pt"))
      seconds_total_embedder_weights = torch.load(os.path.join(embedder_weights_path, "seconds_total_embedder_weights.pt"))
      model = comfy.model_base.StableAudio1(conf, seconds_start_embedder_weights, seconds_total_embedder_weights)
    3. 使用优化后的Transformer模型替换ComfyUI的Transformer模型。
      model.diffusion_model = unet
      model.memory_required = lambda *args, **kwargs: 0
  4. 安装相关依赖。
    cd /PATH/TO/ComfyUI/custom_nodes/StableAudio_Comfyui_Plugin/ 
    pip3 install -r requirements.txt 
    apt-get update 
    apt-get install libsndfile1
  5. 下载权重。
    • 下载text_encode权重,保存为t5_base.safetensors ,并将其放在ComfyUI/models/text_encoders/路径下。
      https://huggingface.co/google-t5/t5-base/blob/main/model.safetensors
    • 下载diffusion_model权重,保存为stable_audio_open_1.0.safetensors,并将其放在ComfyUI/models/checkpoints/路径下。
      https://huggingface.co/stabilityai/stable-audio-open-1.0/tree/main
    • 下载transformers权重,在ComfyUI/models/目录下新建mindiesd/stable-audio-open-1.0/transformer目录,并保存在该路径下(包含config.json)。
      https://huggingface.co/stabilityai/stable-audio-open-1.0/tree/main/transformer
  6. 执行以下命令启动ComfyUI。
    python main.py --gpu-only --listen

    参数说明:

    • --gpu-only:表示只在Device(GPU/NPU)上执行推理 。
    • --listen:服务器管控的IP地址,默认为0.0.0.0 。
    打印以下内容则表示启动成功:
    To seethe GUI go to: http://0.0.0.0:8188 
    To seethe GUI go to: http://[::]:8188
  7. 打开本地计算机的代理设置,对当前服务器IP设置为不进行代理。 本地浏览器访问http://xxx.xxx.xxx.xxx:8188(xxx.xxx.xxx.xxx为容器所在服务器IP),即可访问容器内开启的ComfyUI服务,如图1所示。
    图1 ComfyUI
  8. 加载工作流,代码仓中提供stable_audio_open_1.0的加速工作流,在ComfyUI页面加载该工作流,即可执行推理。或者下载ComfyUI官方提供的StableAudio工作流,在ComfyUI页面加载后,右键添加节点,选择MindIE SD/StableAudio类别下的加速节点,手动替换官方工作流中模型。
    https://comfyanonymous.github.io/ComfyUI_examples/audio/stable_audio_example.flac
  9. 单击ComfyUI页面下方的“Queue”按钮,运行推理。