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 精细不少。文中使用到的文件已经上传到资源中,有兴趣的同学可以下载。

Logo

ModelScope旨在打造下一代开源的模型即服务共享平台,为泛AI开发者提供灵活、易用、低成本的一站式模型服务产品,让模型应用更简单!

更多推荐