Fusion of Engineering, Control, Coding, Machine Learning, and Science

Install and Run FLUX.1 [schnell] Text-to-Image model in Python on a Local Linux Computer

The YouTube tutorial given below explains how to install and run FLUX.1 -schnell text-to-image model in Python on a local Linux computer. Besides providing the tutorial, we also give codes for downloading the Flux. 1 schnell model files from the Hugging face website and for running the Flux. 1- schnell in Python. For the complete installation procedure see the YouTube video tutorial.

Install and Run FLUX.1-schnell text to Image Model in Python and Linux on Local Computer

Background Information about FLUX.1-schnell and Hardware Requirements

Flux.1 [schnell] is a rectified flow transformer that is used to generate images from text descriptions. The rectified flow transformer has around 12 billion parameters. It is released under Apache 2.0 license, which means that this model can be used for personal, scientific, and commercial purposes. In this tutorial, we explain how to correctly install and how to run Flux 1 [schnell] in Python on a local Linux machine.

Software/Hardware prerequisites:

Python Codes for Downloading the Model and Running FLUX. 1 Schnell Locally

Here is the Python code for downloading the model weights from the Huggingface website (see the YouTube tutorial):

from huggingface_hub import snapshot_download

snapshot_download(repo_id="black-forest-labs/FLUX.1-schnell",
                  local_dir="/home/aleksandar/codes/flux1schnell")

Here is the Python code for running FLUX. 1. schnell locally (see the YouTube tutorial):

import matplotlib.pyplot as plt
import torch
from diffusers import FluxPipeline

# here, adjust the path
pipe = FluxPipeline.from_pretrained("/home/aleksandar/codes/flux1schnell", 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
pipe.enable_sequential_cpu_offload() # offloads modules to CPU on a submodule level (rather than model level)

prompt = "Ancient greek soldier with a sword and a shield. Behind there are horses. In the background there is a mountain with snow."

image = pipe(
    prompt,
    guidance_scale=0.0,
    output_type="pil",
    num_inference_steps=4,
    max_sequence_length=256,
    generator=torch.Generator("cpu").manual_seed(0)
).images[0]


plt.imshow(image)
plt.show()
image.save("generated_imag.png")

Exit mobile version