Giter Club home page Giter Club logo

sdxl_serverless_runpod's Introduction

SDXL_Serverless_Runpod

1. Introduction

This is a serverless application that uses Stable Diffusion XL to run a Text-to-Image task on RunPod.

See also AnimateDiff_Serverless_Runpod for Text-to-Video task.

Serverless means that you are only charged for the time you use the application, and you don't need to pay for the idle time, which is very suitable for this kind of application that is not used frequently but needs to respond quickly.

Theoretically, this application can be called by any other application. Here we provide two examples:

  1. A simple Python script
  2. A Telegram bot

See Usage below for more details.

Example Result:

Input Prompt:

A white cat, sitting next to a window, sun shining through the window.

Example Result: (40 steps, 1344x768, around 15 seconds on RTX 3090, 0.006$๐Ÿ˜ฑ on RunPod) Example Result

Time Measurement Explanation:

The time is measured from the moment the input prompt is sent to the moment the result image is received, including the time for all the following steps:

  • Receive the request from the client
  • Serverless container startup
  • Model loading
  • Inference
  • Sending the result image back to the client.

2. Dependencies

  • Python >= 3.9.7
  • Docker
  • Local GPU is necessary for testing but not necessary for deployment. (Recommended: RTX 3090)

If you don't have a GPU, you can modify and test the code on Google Colab and then build and deploy the application on RunPod.

3. Usage

1. Test on Local Machine

# Install dependencies
pip install -r requirements.txt

# Download models
python script/download.py

# Edit (or not) config to customize your inference
edit preset_prompts.json if your want to customize your prompt

# Run inference test
python inference_util.py

# Run server.py local test
python server.py

2. Deploy on RunPod

  1. First, make sure you have installed Docker and have accounts on both DockerHub and RunPod.

  2. Then, decide a name for your Docker image, e.g., "your_username/sdxl:v1" and set your image name in "./scripts/build.sh".

  3. Run the following commands to build and push your Docker image to DockerHub.

bash scripts/build.sh

  1. Finally, deploy your application on RunPod to create Template and Endpoint.

Sorry for not providing detailed instructions here as the author is quite busy recently. You can find many detailed instructions on Google about how to deploy a Docker image on RunPod.

Feel free to contact me if you encounter any problems after searching on Google.

3. Call the Application

Call from a Python script
# Make sure to set API key and endpoint ID before running the script.
python test_client.py
Showcase: Call from a Telegram bot

Example Result

4. TODO

  • Support custom models
  • Support low VRAM GPUs(8~12GB)
  • More detailed instructions
  • One-click deploy (If anyone is interested...)

4. Acknowledgement

Thanks to Stable Diffusion XL and RunPod.

sdxl_serverless_runpod's People

Contributors

sky24h avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.