How You Can Achieve Real-time Inference for Stable Diffusion

Oct 20, 2022


Stable Diffusion is making waves across the machine learning space with its new innovative approach for text-image generation. Stable Diffusion is a deep learning model released by StabilityAI in 2022, and it is mainly used for providing detailed images conditioned on text descriptions.

In this blog, we will walk you through how to deploy Stable Diffusion and run sub-1ms latency inference with a line of code!

How to Deploy Stable Diffusion

What You’ll Need

To deploy Stable Diffusion with almost real-time inference, you'll need a few things:

  1. Access the Stochastic GitHub Repository: X-Stable-Diffusion. Currently, the repository includes 4 optimization techniques with more in the pipeline
  2. Python and Docker installed on your system
  3. A Stochastic Account: If you don’t have a Stochastic Account, the CLI will prompt you to create one when accessing our library. It is free and just takes 1 minute Sign Up →
  4. A GPU

Getting Started

  1. Install the latest version of the stochasticx library
  2. pip install stochasticx

  3. Deploy the Stable Diffusion Model
  4. stochasticx stable-diffusion deploy --type aitemplate

  5. To infer with this deployed model:
  6. stochasticx stable-diffusion infer --prompt "Riding a horse"

  7. Check all the options of the infer command:
  8. stochasticx stable-diffusion infer --help

  9. You can get the logs of the deployment executing the following command:
  10. stochasticx stable-diffusion logs

  11. Stop and remove the deployment with this command:
  12. stochasticx stable-diffusion stop

Sample Images Generated Using Stable Diffusion

Stable Diffusion is very versatile in both the prompts it can accept and the images it can generate. Below are some images generated using Stable Diffusion with a given prompt, across different types of optimizations.

Prompt: “The Easter bunny riding a motorcycle in New York City”



Text-image generation is becoming a huge deal in the machine learning world, with Stable Diffusion as one of the models to access text-image capabilities. Fortunately, anyone can deploy Stable Diffusion with the Stochastic X library through a few lines of code.

Speeding up other models with Stochastic X is just as easy. The Stochastic X platform automatically speeds up your deep learning models for you. To learn more, view our other blog articles, or contact us.

Access our product here: Sign Up →

For enterprise solutions, reach out here: Enterprise Inquiries →