Flux.1-dev: Run a top text-to-image model on Modal
What is Flux.1-dev?
Flux.1-dev is a powerful text-to-image model from Black Forest Labs. Together with Stable Diffusion 3.5, it is one of the best text-to-image models on the market.
Why should you run Flux.1-dev on Modal?
If you are looking to run Flux.1-dev, you will need access to a GPU in order for the inference times to be fast. There are several ways to get a GPU, but the easiest way is to use Modal.
Modal is a cloud platform designed specifically for running machine learning workloads. Unlike traditional cloud services that require complex infrastructure management, Modal provides a serverless environment where you can deploy AI models with just a few lines of Python code.
Example code for running the Flux.1-dev model on Modal
To run the following code, you will need to:
- Create an account at modal.com
- Run
pip install modalto install the modal Python package - Run
modal setupto authenticate (if this doesn’t work, trypython -m modal setup) - Copy the code below into a file called
app.py - Run
modal run app.py
Please note that this code is not optimized. For a more detailed example of how to run Flux fast with torch.compile, refer here.
Performance Considerations
The model generates images up to 1024x1024 resolution, with generation time typically ranging from 2-4 seconds on an H100 GPU. Batch processing can significantly improve throughput for bulk image generation tasks.