DEV Community

Cover image for How to Run Flux 1 Schnell and Pro Image Generator in the Cloud
Ayush kumar for NodeShift

Posted on

How to Run Flux 1 Schnell and Pro Image Generator in the Cloud

FluxAI, developed by Black Forest Labs—a team of former Stable Diffusion experts—is revolutionizing open-source AI image generation.

By combining state-of-the-art techniques in natural language processing, computer vision, and deep learning, FluxAI aims to democratize access to high-quality, realistic image synthesis while fostering a vibrant community of developers, researchers, and artists.

Launched on August 1, Flux 1 is available in three different versions. The Pro version of the AI model is the high-end one designed for commercial use. Meanwhile, the Dev version has open weights and is built for non-commercial use. The faster version of Flux 1 with open weights is called Schnell.

Image description

Flux 1 Pro: The powerhouse of the Flux family, crafted for commercial and enterprise use. This model delivers top-tier performance, exceptional image quality, and a nuanced understanding of prompts, making it the go-to choice for those needing the absolute best.

Flux 1 Dev: The open-source variant that serves as the backbone of the Flux AI community, allowing developers, researchers, and enthusiasts to explore, modify, and contribute to the model’s codebase.

Flux 1 Schnell: This optimized model prioritizes speed and efficiency without compromising image quality. It is open-source and available on platforms like Hugging Face, making it ideal for real-time or near-real-time generation applications. It strikes a delicate balance between quick processing and high-quality output, perfect for personal projects or integrations with tools like Diffusers and Comfy UI.

Image description

What sets FluxAI apart from its predecessors is its unique hybrid architecture that combines the strengths of Transformer networks for text understanding with the power of diffusion models for image generation. This approach enables FluxAI to excel in prompt interpretation and high-quality image synthesis, producing results that closely align with the provided textual descriptions.

In this blog, we'll show you how you can Run Flux 1 Schnell and Pro Image Generator and test the AI image generator's visual quality with a sample text prompt.

Step-by-Step Process to Run Flux 1 Schnell and Pro Image Generator

For the purpose of this tutorial, we will use a GPU-powered Virtual Machine offered by NodeShift; however, you can replicate the same steps with any other cloud provider of your choice.

Step 1: Sign Up and Set Up a NodeShift Cloud Account

Visit the NodeShift Cloud website (https://app.nodeshift.com/) and create an account. Once you've signed up, log into your account.

Follow the account setup process and provide the necessary details and information.

Image description

Step 2: Create a GPU Virtual Machine

NodeShift GPUs offer flexible and scalable on-demand resources like NodeShift Virtual Machines (VMs) equipped with diverse GPUs ranging from H100s to A100s. These GPU-powered VMs provide enhanced environmental control, allowing configuration adjustments for GPUs, CPUs, RAM, and Storage based on specific requirements.

Image description
Navigate to the menu on the left side. Select the GPU VMs option, create a GPU VM in the Dashboard, click the Create GPU VM button, and create your first deployment.

Step 3: Select a Model, Region, and Storage

In the "GPU VMs" tab, select a GPU Model and Storage according to your needs and the geographical region where you want to launch your model.

Image description

Image description

Image description

  • Flux1-dev requires more than 12GB VRAM.
  • Flux1-schnell can run on 12GB VRAM
  • If you have less than 32GB of System RAM, use the t5xxl_fp8_e4m3fn text encoder instead of the t5xxl_fp16 version.

We use 1x H100 SXM GPU for this tutorial to achieve the fastest performance. However, you can opt for a more affordable GPU with lesser VRAM if that suits your requirements.

Step 4: Select Authentication Method

There are two authentication methods available: Password and SSH Key. SSH keys are a more secure option; in order to create them, head over to our official documentation: (https://docs.nodeshift.com/gpus/create-gpu-deployment)

Image description

Step 5: Choose an Image

Next, you will need to choose an image for your VM. We will deploy Flux 1 Schnell and Pro Image Generator on an NVIDIA Cuda Virtual Machine. This proprietary, closed-source parallel computing platform will allow you to install Flux 1 Schnell and Pro Image Generator on your GPU VM.

Image description

After choosing the image, click the ‘Create’ button, and your VM will be deployed.

Image description

Step 6: Virtual Machine Successfully Deployed

You will get visual confirmation that your machine is up and running.

Image description

Step 7: Connect to GPUs using SSH

NodeShift GPUs can be connected to and controlled through a terminal using the SSH key provided during GPU creation.

Once your GPU VM deployment is successfully created and has reached the 'RUNNING' status, you can navigate to the page of your GPU Deployment Instance. Then, click the 'Connect' button in the top right corner.

Image description

Now open your terminal and paste the proxy SSH IP.

Image description

Next, If you want to check the GPU details, run the command below:

nvidia-smi

Image description

Step 8: Install Miniconda & Packages

After completing the steps above, install Miniconda.

Miniconda is a free minimal installer for conda. It allows the management and installation of Python packages.

Anaconda has over 1,500 pre-installed packages, making it a comprehensive solution for data science projects. On the other hand, Miniconda allows you to install only the packages you need, reducing unnecessary clutter in your environment.

We highly recommend installing Python using Miniconda. Miniconda comes with Python and a small number of essential packages. Additional packages can be installed using the package management systems Mamba or Conda.

For Linux/macOS:

Download the Miniconda installer script:

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh

For Windows:

  • Download the Windows Miniconda installer from the official website.
  • Run the installer and follow the installation prompts.

Image description

Run the installer script:

bash Miniconda3-latest-Linux-x86_64.sh

Image description

Image description

After Installing Miniconda, you will see the following message:

Thank you for installing Miniconda 3! This means Miniconda is installed in your working directory or on your operating system.

Check the screenshot below for proof:

Image description

Step 9: Activate Conda and perform a version check

After the installation process, activate Conda using the following command:

conda init
source ~/.bashrc

Also, check the version of Conda using the following command:

conda --version

Image description

Step 10: Create and activate your environment

Create a Conda Environment using the following command:

conda create -n fal python=3.10 -y

  • conda create: This command is used to create a new Conda environment.
  • n fal: The -n flag specifies the name of the environment. Here fal is the name of the environment you're creating. You can name it anything you like.
  • python=3.10: This specifies the version of Python you want to install in the environment. In this case, it's Python 3.10.
  • y: This flag automatically answers "yes" to all prompts during the creation process, so the environment is created without asking for further confirmation.

Image description

Activating the Conda Environment

Run the following command to activate the Conda Environment:

conda activate fal

conda activate fal: This command activates the environment you just created. Once activated, any Python-related commands or installations will be isolated to this environment, which won’t affect other environments or your global Python installation.

Image description

Role of Fal here

Fal is a tool that integrates with dbt (Data Build Tool) to run Python scripts within your dbt project. It allows you to execute Python code alongside your dbt models, which can be helpful for tasks such as:

  • Post-processing data after it has been transformed by dbt.
  • Running machine learning models or other advanced analytics on your data.
  • Automating workflows that require both SQL (handled by dbt) and Python.

When you name a Conda environment fal, you are likely setting up a dedicated environment to work with Fal and its dependencies. By having this environment, you ensure that all necessary libraries and tools are available and isolated from other projects.

Step 11: Install Torch, Transformers and Huggingface

After activating the Conda environment, install Torch, Transformers and Huggingface.

Run the following command to install the packages:

pip install torch
pip install --upgrade transformers
pip install accelerate huggingface_hub

Image description

Image description

Image description

Step 12: Download the Flux Model and Install Requirements

Next, you need to download the Flux model from GitHub. Run the following command to download the model.

git clone https://github.com/black-forest-labs/flux && cd flux

Flux GitHub Repo Link: https://github.com/black-forest-labs/flux

Check Flux Repo for more info.

Image description

Run the following command to install the required dependencies:

pip install -e ".[all]"

After running this command, all the packages, environments, and dependencies are set up. Now, you can run the model and generate images.

Image description

Step 13: Run the Flux Model

When you check the Flux GitHub repo, you will see multiple methods on how to use the Flux model. We will proceed with the Streamlit method.

Image description

Run the following command to run the model:

streamlit run demo_st.py

Now, you can check the screenshot below for proof. When you run the command, it will give the following output: You can view your Streamlit app in your browser.

Image description

Now, open your preferred browser, copy the localhost address, and paste it into the browser.

Load and choose the model, then generate images from the model.

Image description

We have tried some images; check the output below.

Image description

Image description

Image description

Image description

Conclusion

In this guide, we've walked through the process of setting up and running Flux 1 Schnell and Pro Image Generators on a GPU-powered virtual machine. With FluxAI, you now have the tools to create stunning, high-quality images, whether for commercial projects or personal exploration. By following these steps, you have the power of advanced AI image generation, all while enjoying the flexibility and efficiency that Flux AI offers.

For more information about NodeShift:
Website
Docs
LinkedIn
X
Discord
Blogs
dailydev

Top comments (0)