Skip to content

Instantly share code, notes, and snippets.

@lucataco
Created November 29, 2023 20:32
Show Gist options
  • Save lucataco/da6b3c752230ce7a8ece90d0658e01da to your computer and use it in GitHub Desktop.
Save lucataco/da6b3c752230ce7a8ece90d0658e01da to your computer and use it in GitHub Desktop.
Benchmark SDXL speed
import io
import time
import json
import base64
import requests
from PIL import Image
# Start SDXL locally:
# docker run -d -p 5000:5000 --gpus=all r8.im/stability-ai/sdxl@sha256:39ed52f2a78e934b3ba6e2a89f5b1c712de7dfea535525255b1aa35c5565e08b
url = "http://localhost:5000/predictions"
headers = {
"Content-Type": "application/json"
}
data = {
"input": {
"prompt": "An astronaut riding a rainbow unicorn, cinematic, dramatic",
"width": 768,
"height": 768,
"num_inference_steps": 25
}
}
t1 = time.time()
for _ in range(1):
response = requests.post(url, headers=headers, data=json.dumps(data))
t2 = time.time()
# Save response as an image
resp = response.json()
output = resp["output"][0]
img = Image.open(io.BytesIO(base64.b64decode(output.split(",")[1])))
img.save("output.png")
# Print the time difference
print("Time taken: ", t2 - t1)
print("Done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment