Tutorial

FLUX.1 Text-to-Image Generation on Cloud GPUs

Published on October 2, 2024

Technical Evangelist // AI Arcanist

FLUX.1 Text-to-Image Generation on Cloud GPUs

FLUX.1, an image generator, has gained dramatically in popularity since its release earlier in mid-2024. A step forward in terms of prompt understanding, scene creation, and text writing, FLUX.1 represents an obvious improvement over Stable Diffusion in every way. For these reasons, FLUX.1 is now an essential tool for any graphics designer, artist, or image creator working with AI.

In this article, we will show how to setup FLUX.1 with the ComfyUI from ComfyAnonymous. This is the premier GUI for running FLUX.1 and Stable Diffusion models. Readers can expect to leave this tutorial with a full understanding of how to use FLUX.1 on their own cloud GPU machines.

Prerequisites

  • Python: The content of this article is highly technical. We recommend this piece to readers experienced with both Python and basic concepts in Deep Learning. For new users, this article may be a good place to start.
  • Cloud GPU: Running FLUX.1 will require a sufficiently powerful GPU. We recommend at least 40 GB VRAM machines at the minimum.

Setting up the Local Machine

To follow along with this tutorial, you will need to use your own local computer. First, download Visual Studio Code, our preferred platform for local development, or your preferred code editor. This will make it possible to pipe our web UI onto our local browser. Open VS Code, and leave it for now.

Next, find the terminal on your computer, and open up a new window. We need to now setup our SSH Key to work with our Cloud GPU. Follow the instructions in this article to do so.

For now, we can move onto the Cloud GPU setup, but we will return to using the local later.

Setting up the Cloud GPU

For this tutorial, we are going to use a DigitalOcean GPU Droplet to run the tutorial. These are powered by NVIDIA H100 GPUs, and provide more than enough power to run FLUX.1 models. For more information about GPU Droplets, please check out the main GPU Droplet page, and sign up for GPU Droplets in your DigitalOcean account.

To set up the GPU, we recommend selecting the “AI/ML Ready” OS. Additionally, make sure you have setup your SSH key beforehand, so it can be added onto the GPU Droplet for easy access from your local machine. These are the only two essential settings, so we can now run our Droplet as is. Once it is spun up, copy the IP Address and paste into the following snippet in your terminal to SSH in.


ssh root@<your ip address>

From here, we can begin setting up the environment.

Setting up the Environment for ComfyUI

The AI/ML ready OS comes pre-installed with CUDA and other deep learning associated packages, but not the coding or Deep Learning packages, such as Python or Torch. Fortunately, setting up our environment is simple. Paste the following into your terminal window:


cd ../home
apt install python3-pip -y
git clone https://github.com/comfyanonymous/ComfyUI
cd ComfyUI
pip install -r requirements.txt

This will install all the required software. Next, we need to download all the relevant model files from HuggingFace, so we can actually use them on our Cloud GPU Droplet. Once again, paste the following into your terminal.


wget -O models/vae/ae.safetensors https://huggingface.co/second-state/FLUX.1-schnell-GGUF/resolve/main/ae.safetensors
wget -O models/diffusion_models/flux1-dev-fp8.safetensors https://huggingface.co/Comfy-Org/flux1-dev/resolve/main/flux1-dev-fp8.safetensors
wget -O mopels/clip/clip_l.safetensors https://huggingface.co/comfyanonymous/flux_text_encoders/resolve/main/clip_l.safetensors
wget -O models/clip/t5xxl_fp8_e4m3fn.safetensors https://huggingface.co/comfyanonymous/flux_text_encoders/resolve/main/t5xxl_fp8_e4m3fn.safetensors

Finally, we are going to download this workflow json file. Loading this into the UI will get us the layout required to use the models we just downloaded with zero additional setup.

Running the ComfyUI for FLUX.1 dev on your Local Machine using a Cloud GPU

Now that our Cloud GPU and our local are both setup, we can run the demo! Copy your SSH IP address (i.e. root @<your ip address here>, and open VS code on your local machine. Click ‘Connect To’ in the ‘Start’ section in the center of the window. At the top, now select ‘Connect to Host’, and then select ‘+ Add New SSH Host’. Paste in your code here to add the VS Code window to your cloud GPU access.

With that complete, we can run the demo. To start it, paste the following into your Cloud GPU terminal window:


python3 main.py

This will launch the Web UI for us. Copy the address printed after setup completes. Ours appeared like the following:


To see the GUI go to: http://127.0.0.1:8188

Take the URL, and go to your local machine VS Code window. There within, type “Command” + “Shift” + “p” at the same time, and then search for “Simple Browser: Show”. Click on it, and paste your URL into the search bar. Then click the outgoing button on the far right of the URL bar to open the window in your local browser.

If everything worked correctly, you will be brought to the ComfyUI home page. From here, we will load the JSON file we downloaded earlier in the tutorial by clicking the “Load” button on the far right of the screen in the command palette. This will complete setup.

image

Now, we can click “Queue” to run the generation. If we followed all the instructions, it will output this same image for us:

image

We can change the output of the image generation by changing the prompt, which is located in the “CLIP Text Encode (Positive Prompt)” modal. We suggest playing around with all sorts of ideas, as FLUX.1 is incredibly capable.

Closing Thoughts

Using FLUX.1 with the ComfyUI is a truly powerful experience. It makes it evident, in the same way that using the SOTA LLMs do, that AI is an incredibly potent new sector of technological growth that features a nearly limitless capability to create. We are excited to see what everyone generates with FLUX.1 on the Cloud!

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar

Technical Evangelist // AI Arcanist

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
Leave a comment


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more