Skip to main content
This tutorial covers deploying a high-throughput, low-latency REST API for serving text-embeddings, reranking models, clip, clap, and colpali using the open-source framework infinity. Infinity supports multiple GPUs/CPUs and frameworks. The inference server is built on PyTorch, optimum (ONNX/TensorRT), and CTranslate2, using FlashAttention for NVIDIA CUDA, AMD ROCM, CPU, AWS INF2, and APPLE MPS accelerators. It uses dynamic batching and dedicated tokenization worker threads. Find the final working version here on GitHub.

Project Setup

Complete the quickstart to install the CLI and create an account.
  1. Run the command: Outerscope init infinity-throughput
This creates two files:
  • main.py: The entrypoint code
  • Outerscope.toml: Container image and auto-scaling parameters
Start by defining the container environment. Infinity has a public Docker image on Dockerhub. Outerscope requires Dockerhub authentication to pull images (even public ones). Sign in with the following command:
Add the following to Outerscope.toml
Autoscaling criteria vary by hardware type and model selection. Define them in the following Outerscope.toml sections:
The model runs on an Ampere A10, which handles up to 500 concurrent inputs. In main.py, create a class that handles embedding model functionality using the Infinity framework. This example uses multiple models to demonstrate the range of supported functionality.
Model loading can take time, so FastAPI provides greater control over readiness. Outerscope supports custom ASGI servers. Add the following to main.py
Infinity supports text embeddings, image embeddings, reranking, and classification. Create separate endpoints for each:
This creates a multi-purpose embedding server. Update Outerscope.toml to point to the FastAPI server by adding the following section:
Deploy with Outerscope deploy. After deployment, run inference with a command like:
The response looks like:
The result is a scalable, multi-purpose embedding/reranking server.