Menu

1 / 3

downshift-server: Serve a pytorch / HF-embedding model in 3 steps

DEV Community: pytorch·Nikhil Ranjan·10 days ago
#2aEsiXdP
#devtopytorch#devto#dev#model#downshift
Long article (734 words) — no AI summary yet.
Reading 0:00
15s threshold

Quick Setup

A hands-on walkthrough of downshift-server 1.0: an embedding model behind the OpenAI route, your own PyTorch model, and a check that catches a wrong ONNX export.

Step 1:Install torch (the CPU build is fine) and downshift with the Hugging Face extra:

pip install torch --index-url https://download.pytorch.org/whl/cpu pip install "downshift-server[hf]" openai

Enter fullscreen mode

Exit fullscreen mode

Step 2: Download an encoder type embedding model from HF

hf download BAAI/bge-small-en-v1.5 --local-dir ./bge-small-en-v1.5

Enter fullscreen mode

Exit fullscreen mode

Step 3: Serve it out!

downshift serve ./bge-small-en-v1.5 --port 8000

Enter fullscreen mode

Exit fullscreen mode

downshift-server exports the model to ONNX and checks it against the original weights to ensure that the model still performs the same.

What just happened?

You are now the creator of a tiny FastAPI server which is serving the model in an OpenAI compatible API.

from openai import OpenAI

client = OpenAI (…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.