black-forest-labs / flux

Official inference repo for FLUX.1 models
Apache License 2.0
14.74k stars 1.06k forks source link

FluxPipeline Hanging #122

Open leefernandes opened 1 month ago

leefernandes commented 1 month ago

Hi, I lack experience with all of this tooling. After following the README I've run the FluxPipeline example, and it appears to hang. I was anticipating that it would complete and write the file to disk in the cwd, but I'm not certain if that is how this works. But it looks stuck on | 0/4

Can someone clarify what the FluxPipeline does. Should one run it, expect a longish set of commands to run, and then a file to output? Should it take a long time?

If someone has downloaded the flux github repo and schnell hugging face repo and wants a quick "hello world" image generation. What is the recommended approach?

model_index.json: 100%|███████████████████████████████████████████████████████████████████████| 536/536 [00:00<?, ?B/s]
scheduler/scheduler_config.json: 100%|████████████████████████████████████████████████████████| 274/274 [00:00<?, ?B/s]
text_encoder_2/config.json: 100%|█████████████████████████████████████████████████████| 782/782 [00:00<00:00, 1.02MB/s]
(…)t_encoder_2/model.safetensors.index.json: 100%|████████████████████████████████████████| 19.9k/19.9k [00:00<?, ?B/s]
text_encoder/config.json: 100%|███████████████████████████████████████████████████████████████| 613/613 [00:00<?, ?B/s]
tokenizer/merges.txt: 100%|█████████████████████████████████████████████████████████| 525k/525k [00:00<00:00, 9.56MB/s]
tokenizer/tokenizer_config.json: 100%|████████████████████████████████████████████████████████| 705/705 [00:00<?, ?B/s]
tokenizer_2/special_tokens_map.json: 100%|████████████████████████████████████████| 2.54k/2.54k [00:00<00:00, 3.66MB/s]
tokenizer/special_tokens_map.json: 100%|██████████████████████████████████████████████████████| 588/588 [00:00<?, ?B/s]
tokenizer/vocab.json: 100%|███████████████████████████████████████████████████████| 1.06M/1.06M [00:00<00:00, 6.65MB/s]
tokenizer_2/tokenizer_config.json: 100%|██████████████████████████████████████████| 20.8k/20.8k [00:00<00:00, 21.5MB/s]
transformer/config.json: 100%|████████████████████████████████████████████████████████████████| 321/321 [00:00<?, ?B/s]
spiece.model: 100%|█████████████████████████████████████████████████████████████████| 792k/792k [00:00<00:00, 2.01MB/s]
tokenizer_2/tokenizer.json: 100%|█████████████████████████████████████████████████| 2.42M/2.42M [00:00<00:00, 4.51MB/s]
(…)ion_pytorch_model.safetensors.index.json: 100%|██████████████████████████████████| 121k/121k [00:00<00:00, 4.22MB/s]
vae/config.json: 100%|████████████████████████████████████████████████████████████████████████| 774/774 [00:00<?, ?B/s]
model.safetensors: 100%|████████████████████████████████████████████████████████████| 246M/246M [00:10<00:00, 23.8MB/s]
diffusion_pytorch_model.safetensors: 100%|██████████████████████████████████████████| 168M/168M [00:34<00:00, 4.84MB/s]
model-00002-of-00002.safetensors: 100%|███████████████████████████████████████████| 4.53G/4.53G [02:37<00:00, 28.7MB/s]
model-00001-of-00002.safetensors: 100%|███████████████████████████████████████████| 4.99G/4.99G [04:28<00:00, 18.6MB/s]
(…)pytorch_model-00003-of-00003.safetensors: 100%|████████████████████████████████| 3.87G/3.87G [04:52<00:00, 13.2MB/s]
(…)pytorch_model-00002-of-00003.safetensors: 100%|████████████████████████████████| 9.95G/9.95G [06:49<00:00, 24.3MB/s]
(…)pytorch_model-00001-of-00003.safetensors: 100%|████████████████████████████████| 9.96G/9.96G [06:58<00:00, 23.8MB/s]
Fetching 23 files: 100%|███████████████████████████████████████████████████████████████| 23/23 [06:59<00:00, 18.24s/it]
Loading checkpoint shards: 100%|█████████████████████████████████████████████████████████| 2/2 [00:00<00:00, 14.23it/s]
Loading pipeline components...:  57%|█████████████████████████████▋                      | 4/7 [00:02<00:02,  1.45it/s]You set `add_prefix_space`. The tokenizer needs to be converted from the slow tokenizers1G/9.96G [04:28<02:31, 36.1MB/s]
Loading pipeline components...: 100%|████████████████████████████████████████████████████| 7/7 [00:04<00:00,  1.55it/s]
  0%|                                                                                            | 0/4 [00:00<?, ?it/s]
(…)pytorch_model-00001-of-00003.safetensors: 100%|███████████████████████████████▉| 9.96G/9.96G [06:58<00:00, 75.9MB/s]

The script

import torch
from diffusers import FluxPipeline

model_id = "black-forest-labs/FLUX.1-schnell"

pipe = FluxPipeline.from_pretrained(model_id , torch_dtype=torch.bfloat16)
pipe.enable_model_cpu_offload() #save some VRAM by offloading the model to CPU. Remove this if you have enough GPU power

prompt = "A cat holding a sign that says hello world"
seed = 42
image = pipe(
    prompt,
    output_type="pil",
    num_inference_steps=4, #use a larger number if you are using [dev]
    generator=torch.Generator("cpu").manual_seed(seed)
).images[0]
image.save("flux-schnell.png")
WilTay1 commented 3 weeks ago

you need add pipe.to("cuda") after pipe = FluxPipeline.from_pretrained(model_id , torch_dtype=torch.bfloat16)