SYSTEM NOTICE

Auto translation by AI. Be sure, accuracy, nuances and authorial intent may not be fully reflected.
見出し画像

Trying out FLUX.1 on Google Colab

I tried out "FLUX.1" on "Google Colab" and have summarized it here.

[Note] Verified on Google Colab Pro/Pro+ using an A100.


1. FLUX.1

"FLUX.1" is the latest image generation AI model announced by "Black Forest Labs," which was founded by the developers of "Stable Diffusion."

・FLUX.1 [pro]: The highest quality model available via API.
・FLUX.1 [dev]: An open guidance-distilled model for non-commercial applications.
・FLUX.1 [schnell]: The fastest timestep-distilled model.

2. FLUX.1 [dev]

The procedure for running FLUX.1 [dev] (guidance-distilled model) on "Google Colab" is as follows.

・Guidance-distilled models require about 50 steps for high-quality generation
・There are no restrictions regarding max_sequence_length

(1) Install packages.

# パッケージのインストール
!pip install git+https://github.com/huggingface/diffusers.git

(2) Model cardClick "Agree and access repository" on the.

(3) Log in to HuggingFace.

!huggingface-cli login

Follow the instructions to enter the following information.

・Enter your token (input will not be visible) : HuggingFace token
・Add token as git credential? (Y/n) : n (Whether to save as authentication credentials)

(4) Prepare the pipeline.
Download "black-forest-labs/FLUX.1-dev".

import torch
from diffusers import  FluxPipeline

# パイプラインの準備
pipe = FluxPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-dev", 
    torch_dtype=torch.bfloat16
)
pipe.enable_model_cpu_offload()

(5) Prepare the prompt and execute image generation.

# プロンプトの準備
prompt = "cute cat ear maid of japanese anime style"

# 画像生成の実行
out = pipe(
    prompt=prompt, 
    guidance_scale=3.5, 
    width=1024, 
    height=1024, 
    num_inference_steps=50,
    max_sequence_length=256,
).images[0]
out.save("image.png")

It took 56 seconds for 50 steps. The memory consumption is as follows.

3. FLUX.1 [schnell]

The procedure for running FLUX.1 [schnell] (timestep-distilled model) on "Google Colab" is as follows.

・max_sequence_length cannot exceed 256
・guidance_scale must be 0
・Since it is a timestep-distilled model, fewer steps are advantageous

(1) Install packages.

# パッケージのインストール
!pip install git+https://github.com/huggingface/diffusers.git

(2) Preparing the pipeline.
Download "black-forest-labs/FLUX.1-schnell".

import torch
from diffusers import  FluxPipeline

# パイプラインの準備
pipe = FluxPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-schnell", 
    torch_dtype=torch.bfloat16
)
pipe.enable_model_cpu_offload()

(3) Preparing the prompt and executing image generation.

# プロンプトの準備
prompt = "cute cat ear maid of japanese anime style"

# 画像生成の実行
out = pipe(
    prompt=prompt, 
    guidance_scale=0., 
    width=1024, 
    height=1024, 
    num_inference_steps=4, 
    max_sequence_length=256,
).images[0]
out.save("image.png")

It took 34 seconds for 4 steps. The memory consumption is as follows.

4. Comfy UI

For how to use "Comfy UI" with "FLUX.1", the following article was helpful.

[Note]The solution for the issue where only noisy images are produced on Mac is here. An example of the corresponding command in "
Stability Matrix" is as follows.

cd "/Users/<ユーザー名>/Library/Application Support/StabilityMatrix/Packages/ComfyUI"
source venv/bin/activate
pip install torch==2.3.1 torchaudio==2.3.1 torchvision==0.18.1

Next time



いいなと思ったら応援しよう!