ModelScope 部署 Flux 模型

Flux 文生图模型,是 Black Forest Labs 最近发布的模型,图片生成清晰度很高,模型可以在 ModelScope 上进行下载,本文将在本地环境中部署 Flex。使用环境如下

  • 2080 TI 22G
  • Ubuntu 22
  • Amd R7 2700 / 128G

启动 Model Scope 容器

ModelScope 1.16 版本

docker run --rm --runtime=nvidia  --shm-size=32g --gpus all  -p 8890:8888 -p 8891-8895:8891-8895 \
-v /opt/modelscope/models:/mnt/workspace/.cache \
-v /opt/modelscope/notebook:/notebook \
 -it    registry.cn-beijing.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.1.0-py310-torch2.3.0-tf2.16.1-1.16.0 /bin/bash

通过 Notebook 启动 ComfyUI

安装 ComfyUI

from pathlib import Path

OPTIONS = {}

UPDATE_COMFY_UI = True  #@param {type:"boolean"}
WORKSPACE = 'ComfyUI'
OPTIONS['UPDATE_COMFY_UI'] = UPDATE_COMFY_UI

WORKSPACE = "./ComfyUI"


![ ! -d $WORKSPACE ] && echo -= Initial setup ComfyUI =- && git clone https://github.com/comfyanonymous/ComfyUI
%cd $WORKSPACE

if OPTIONS['UPDATE_COMFY_UI']:
  !echo -= Updating ComfyUI =-
  !git pull

!echo -= Install dependencies =-
!pip install -r requirements.txt

下载模型


### FLUX1-DEV
!modelscope download --model AI-ModelScope/FLUX.1-dev --local_dir ./models/unet/ flux1-dev.safetensors
!modelscope download --model AI-ModelScope/flux-fp8 --local_dir ./models/unet/ flux1-dev-fp8.safetensors


### Download text encoder model
!modelscope download --model AI-ModelScope/flux_text_encoders --local_dir ./models/clip/ t5xxl_fp16.safetensors
!modelscope download --model AI-ModelScope/flux_text_encoders --local_dir ./models/clip/ clip_l.safetensors
!modelscope download --model AI-ModelScope/flux_text_encoders --local_dir ./models/clip/ t5xxl_fp8_e4m3fn.safetensors


# ### vae
!modelscope download --model AI-ModelScope/FLUX.1-dev --local_dir ./models/vae/ ae.safetensors

安装 Cloudflared

!wget "https://modelscope.oss-cn-beijing.aliyuncs.com/resource/cloudflared-linux-amd64.deb"
!dpkg -i cloudflared-linux-amd64.deb

启动 ComfyUI

import subprocess
import threading
import time
import socket
import urllib.request

def iframe_thread(port):
  while True:
      time.sleep(0.5)
      sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
      result = sock.connect_ex(('127.0.0.1', port))
      if result == 0:
        break
      sock.close()
  print("\nComfyUI finished loading, trying to launch cloudflared (if it gets stuck here cloudflared is having issues)\n")

  p = subprocess.Popen(["cloudflared", "tunnel", "--url", "http://127.0.0.1:{}".format(port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  for line in p.stderr:
    l = line.decode()
    if "trycloudflare.com " in l:
      print("This is the URL to access ComfyUI:", l[l.find("http"):], end='')
    #print(l, end='')


threading.Thread(target=iframe_thread, daemon=True, args=(8892,)).start()


!python main.py --dont-print-server --port 8892 --listen 0.0.0.0

创建工作流

在这里插入图片描述

生成图片

A transparent glass of very very small slim capsule is being held by fingers, inside the capsule there is a nuclear explosion, there is smoke and fire, the background of a cozy room

在这里插入图片描述

Chinese ink painting, a girl, long hair, colorful hair, shining eyes

在这里插入图片描述

总结

比之前部署的 SD 精细不少。文中使用到的文件已经上传到资源中,有兴趣的同学可以下载。

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值