Skip to main content

downshift

Downshift is verified export for a model you already have: CPU-first, one process for each model, and eager PyTorch when the export is not correct.

Serve a downloaded model over HTTP with one command. Before the first request, downshift exports the model to ONNX and compares the ONNX graph with PyTorch on inputs that the exporter did not see. If the graph gives wrong numbers, downshift serves eager PyTorch instead.

Everything that downshift serves is already on the machine: a PyTorch checkpoint, an ONNX file, a downloaded Hugging Face repo directory, or an nn.Module that Python can import. Downshift fetches nothing.

$ downshift serve examples.scatter_include_self_false:make_model

2026-10-20 16:20:33 WARNING downshift.serve: DOWNSHIFT_API_KEY is not set, so the endpoints (including /metadata) are unauthenticated. Set it to require a fixed API key, or add your own authentication middleware.
2026-10-20 16:20:33 INFO downshift.report: loading examples.scatter_include_self_false:make_model
2026-10-20 16:20:33 INFO downshift.report: will listen on http://127.0.0.1:8000 (not ready yet)
2026-10-20 16:20:36 INFO downshift.report: verify: sample 1/8, x [6, 8], segment_ids [6]
...
2026-10-20 16:20:36 INFO downshift.report: verify: sample 8/8, x [7, 8], segment_ids [7]
2026-10-20 16:20:36 INFO downshift.report: downshift v1.0.0
  Model          examples.scatter_include_self_false:make_model
  Family         generic
  Verdict        DEGRADED  (strict=False, opset 20)
  Numerics       max abs err 1.62e+00 over 8 samples  6/8 failed
                 ! numerics diverge on 6/8 samples (max abs err 1.62e+00)
  Override       --force-onnx to serve the ONNX graph anyway
  Tolerance      atol 1e-04, rtol 1e-03 (float32)
  Worst          output_0[3, 0]: torch 0.2167, onnxruntime 1.8388  (sample 2, x (7,8), segment_ids (7))
  Samples        x: (6,8) (12,8) (7,8) (7,8) (1,8) (12,8) (1,8) (7,8)
                 segment_ids: (6) (12) (7) (7) (1) (12) (1) (7)
  Rows           not checked (the numerics check failed)
  Cache          off (the numerics check failed)
  Warmup         3 inferences, 0.09 ms each
  Boot           2.9 s: load 0.0, export 2.8, verify 0.0, session 0.0, warmup 0.0
  Backend        torch (eager) | cpu  <- auto-selected
  Verified on    CPUExecutionProvider
  Dynamic dims   `dim0` (x[0])  sampled 1-12, serves 1-65536  ! unverified above 12
                 `dim0` (segment_ids[0])  sampled 1-12, serves 1-65536  ! unverified above 12
  Encoding       json  (clients override with output_encoding)
  Capacity       4 inferences at a time, 4 prep threads, 64 queued, 30 s timeout  (--max-concurrency, --prep-threads, --max-queue, --request-timeout)
  Execution      threadpool  (--execution)
  Endpoint       http://127.0.0.1:8000  (GET /schema for the input format)
2026-10-20 16:20:36 INFO downshift.report: ready in 2.9 s

This graph exported without an error, but it gives wrong numbers on 6 of 8 inputs. Downshift found the fault before the first request and serves PyTorch instead. The model is examples/scatter_include_self_false.py. To run the command, use a clone of this repo.

Install

If the machine has no GPU, install the CPU build of torch first. The default wheel is much larger.

pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install downshift-server            # core: any nn.Module, any .onnx
pip install "downshift-server[hf]"      # + Hugging Face repos, text input
pip install "downshift-server[gnn]"     # + PyTorch Geometric adapter
pip install "downshift-server[fast]"    # + pybase64, about 12x faster base64 tensors
pip install "downshift-server[all]"     # hf, gnn and fast

For a GPU, install a CUDA build of torch, and install onnxruntime-gpu in place of onnxruntime. Refer to docs/production.md.

Downshift needs Python 3.12 to 3.14. If the downshift command is not on PATH, use python -m downshift.

Quick start

To try downshift with no clone, write a file model.py:

import torch


def make_model():
    return torch.nn.Linear(4, 2).eval()


def make_inputs():
    return (torch.randn(1, 4),)

Check the model, then serve it:

downshift check model:make_model
downshift serve model:make_model --port 8000

The check prints the verdict. This is the output for model.py:

  Export          CLEAN  (strict=False, opset 20)
  Numerics        max abs err 1.19e-07 over 8 samples  OK
  Rows            independent
  Backend         onnxruntime

When GET /ready gives 200, send a request in a second terminal:

curl -s localhost:8000/predict -H 'content-type: application/json' \
  -d '{"inputs": {"input": [[1.0, 2.0, 3.0, 4.0]]}}'
{"outputs":{"output_0":[[-2.7712083,0.8470939]]},"shapes":{"output_0":[1,2]},"dtypes":{"output_0":"float32"}}

The numbers depend on the random weights of the layer. The steps below are for your own model.

  1. Start the server. The port opens at once. The gate runs in the background.

    downshift serve my_pkg.models:build --port 8000
    
  2. Wait until GET /ready gives 200. Until then, it gives 503 with the current phase.

  3. Ask the server what to send. GET /schema reads the input names, dtypes, shapes and bounds from the graph that runs. It also gives an example_request that you can send back unchanged.

    curl -s localhost:8000/schema | python -m json.tool
    
  4. Send a request:

    curl -s localhost:8000/predict -H 'content-type: application/json' \
      -d '{"inputs": {"x": [[0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2, 1.3, 1.4, 1.5]]}}'
    
    {"outputs": {"output_0": [[0.199, -0.206, 0.561, 0.405]]},
     "shapes": {"output_0": [1, 4]},
     "dtypes": {"output_0": "float32"}}
    

Integer lists become int64, and all other lists become float32. For large tensors, send base64 or a safetensors body. A Hugging Face repo with a tokenizer also takes {"text": [...]}. A graph model takes x and edge_index on POST /predict/graph. Refer to docs/http-api.md.

A text embedding model also has the OpenAI embeddings route. Change only base_url and api_key in the openai package. Refer to docs/openai.md.

from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1", api_key="not-used")
vectors = client.embeddings.create(model="bge-small", input=["hello"]).data[0].embedding
Route Purpose
GET / The version, the model, ready, and all routes. Start here if you know only the base URL.
GET /health Liveness. 200 while the process is up, also during the load.
GET /ready Readiness. 503 until the model is loaded, verified and warmed up.
GET /schema What to POST, with an example body.
GET /metadata The verdict, the backend, the limits and the boot timings.
POST /predict Named tensors, or text. JSON or safetensors.
POST /predict/graph One graph, or a batch of graphs.
POST /v1/embeddings The OpenAI embeddings route, for a text embedding model. Also GET /v1/models.

To mount the same app in your own FastAPI service, use downshift.serve.app_for(model, example_inputs). Refer to docs/python-api.md. To deploy, read docs/production.md.

The gate

A successful torch.onnx.export does not prove that the graph computes the same function as the model. Before downshift serves anything, it exports the model in memory. It then runs 8 samples by default through PyTorch and through ONNX Runtime, and it varies the dynamic axes, so some samples have shapes that the exporter did not see. The result is one of four verdicts, and the verdict selects the backend:

Verdict Meaning Served by
CLEAN The model exports, matches PyTorch on every sample, and works on shapes that the trace did not include. ONNX Runtime
DEGRADED The model exports, but the numbers differ by more than the tolerance on at least one sample. eager PyTorch (--force-onnx overrides)
FAILED The model does not export, or ONNX Runtime cannot load or run the graph. eager PyTorch
UNVERIFIED A .onnx file with no --reference model, or --no-verify. ONNX Runtime, labelled as never checked

The gate also runs alone:

downshift check my_pkg.models:build --json > verdict.json   # exit code = verdict: 0 CLEAN, 1 FAILED, 2 DEGRADED, 3 UNVERIFIED
downshift export my_pkg.models:build -o artifacts/            # writes the .onnx file and a manifest

check can gate CI. Exit code 4 is a usage error, and 5 is a crash. docs/cli.md describes each flag, the tolerances and the report.

Result cache

The result cache is on when the row check finds the rows independent. The row check uses two rows, so it cannot prove that a small effect is absent. On a server with more than one tenant, a hit is faster than a miss, and a client can see the difference. To turn the cache off, set --result-cache-rows 0. Refer to Result cache.

Accepted model forms

Argument Meaning
model.onnx A downloaded or already exported ONNX file. Served as it is. UNVERIFIED unless you give --reference model.
weights.pt A downloaded PyTorch checkpoint (state dict). Needs --model-class pkg.module:Class. .pth, .bin and .ckpt also work. Downshift loads it with weights_only=True. --unsafe-load allows a pickled module from a file that you trust.
path/to/repo/dir/ A downloaded Hugging Face repo: a directory with a config.json. Needs the [hf] extra.
pkg.module:attr An nn.Module, or a function that returns one. If the module has a make_inputs function, downshift uses it for the example inputs. Otherwise, give --inputs pkg.module:fn.

Downshift serves a Hugging Face repo the way its own files say:

  • A classifier (...ForSequenceClassification) loads with its head and also returns class probabilities.
  • A sentence-transformers repo (modules.json, 1_Pooling/) is pooled and normalised inside the exported graph, so the verification covers the embedding.
  • With tokenizer files, /predict takes {"text": ...}. A row that is longer than the model reads gets a 400. Downshift never cuts a row.

downshift serve model.onnx --tokenizer-from repo/ serves a graph that someone else exported (for example with optimum or Olive) and keeps text input, with the tokenizer and recipe of the repo.

Downshift never contacts the Hugging Face hub and rejects a hub id. Download the repo first:

huggingface-cli download bert-base-uncased --local-dir ./bert-base-uncased
downshift serve ./bert-base-uncased

Compatibility matrix

scripts/gen_matrix.py generates this table from the fixtures in tests/models/. Each fixture isolates one export hazard. To make the table again, run python scripts/gen_matrix.py. The full file, with versions, is docs/compatibility.md. The same page lists Tested real models: public Hugging Face, torchvision and PyG models that scripts/check_real_models.py checks.

Model Hazard Family Export Capture Numerics Shape-general Backend
bf16_weights bfloat16 weights: ONNX Runtime CPU has no bf16 Gemm kernel generic FAILED strict=False — — torch
broken_factory Not an export hazard fixture: raises as soon as it is instantiated — skipped (RuntimeError) — — — —
clean_mlp Control fixture: no export hazards generic CLEAN strict=False 1.2e-07 ✓ onnxruntime
custom_autograd custom autograd.Function with no symbolic override generic CLEAN strict=False 2.4e-07 ✓ onnxruntime
data_dependent_branch data-dependent control flow generic FAILED — — — torch
dict_input dataclass container input generic CLEAN strict=False 1.2e-07 ✓ onnxruntime
dropout_model stochastic layer generic CLEAN strict=False 2.4e-07 ✓ onnxruntime
dynamic_batch_cnn batch-dim generalization generic CLEAN strict=False 6.0e-08 ✓ onnxruntime
gnn_gat GNN fixture: 3-layer GAT node classifier pyg CLEAN strict=False 1.2e-07 ✓ onnxruntime
gnn_gcn GNN fixture: 2-layer GCN node classifier pyg CLEAN strict=False 1.2e-07 ✓ onnxruntime
gnn_sage GNN fixture: 2-layer GraphSAGE node classifier pyg CLEAN strict=False 2.1e-07 ✓ onnxruntime
scatter_include_self_false scatter_reduce(include_self=False) has no faithful ONNX translation generic DEGRADED strict=False 9.5e-01 — torch
tied_weights tied embedding/output weight (GPT-2/OPT-style) generic CLEAN strict=False 3.8e-06 ✓ onnxruntime
tiny_bert HF fixture: a BERT encoder with two layers and random initialization hf CLEAN strict=False 7.2e-07 ✓ onnxruntime

Read these rows carefully:

  • scatter_include_self_false exports without an error and returns wrong numbers. Only the numerics check stops this graph from reaching production.
  • bf16_weights exports without an error, but ONNX Runtime cannot run it, because bfloat16 has no CPU Gemm kernel. It is a FAILED verdict and serves on torch.
  • custom_autograd is CLEAN. torch.export traces through a Function.forward that has ordinary operations.

Scope and non-goals

Downshift serves models that give their answer in one forward pass: tensors in, tensors out. The gate compares one pass between the ONNX graph and PyTorch. GNNs, encoders, classifiers, embedders and your own nn.Module classes fit. A model that needs a loop around it does not fit.

  • No text generation. There is no KV cache or sampling loop. There are no chat or completions routes. (/v1/embeddings exists.) Use vLLM, TGI or llama.cpp. Downshift refuses a decoder-only repo (...ForCausalLM), unless it has an embedding recipe, as Qwen3-Embedding has.
  • No remote code. Downshift never sets trust_remote_code. A repo with an auto_map does not load. Export it to ONNX yourself and serve it with --tokenizer-from.
  • No multimodal Hugging Face models. Text in, one tensor out.
  • No quantization or graph optimization. Use Olive or onnxruntime.quantization, then serve the result with downshift serve model.onnx --reference model.pt, so downshift verifies it against the original weights. --fp16 changes the fp32 graph to fp16 weights, with fp32 inputs and outputs.
  • No dynamic request batching. One request makes one inference. /predict/graph joins a batch of graphs only when the outputs are for each node or each edge.
  • No container image in 1.0. Container images come in 1.1. Use pip and version pins until then.
  • No DGL adapter. PyG is the supported GNN family.

To add a model family, write an adapter. Refer to docs/adapters.md.

When not to use downshift

Your need Use
High-QPS embeddings at large batch sizes TEI or Infinity (dynamic batching)
Many models on a GPU fleet Triton Inference Server
Text generation vLLM

Documentation

Development

pip install -e ".[dev,all]"
ruff check .
ruff format --check .
mypy src
pytest
python scripts/gen_matrix.py     # makes docs/compatibility.md and the table above again

CI requires 95% line coverage (--cov-fail-under=95). The HTTPS tests make a temporary certificate with openssl. If openssl is not on PATH, these tests skip.

License

MIT.

Metadata

Release files for downshift-server 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for downshift-server 1.0.0
File Size Uploaded Provenance Actions
downshift_server-1.0.0.tar.gz 357.8 kB With provenance Details for downshift_server-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for downshift-server 1.0.0
File Interpreter ABI Platform Actions
downshift_server-1.0.0-py3-none-any.whl Python 3 none any Details for downshift_server-1.0.0-py3-none-any.whl

Total release size: 533.8 kB

Release files / downshift_server-1.0.0.tar.gz

Download URL downshift_server-1.0.0.tar.gz
Size 357.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4cb0646a4a137ff31c36791b175c1407fa36096818697b3755cdf11fada56856
BLAKE2b-256 checksum
How to use checksums
41c3a6bf0dd38f63c584e47c0d5b38da5211be61ea96cd2b342e4ca963d137bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / downshift_server-1.0.0-py3-none-any.whl

Download URL downshift_server-1.0.0-py3-none-any.whl
Size 176.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06cee5bcf33eb83b9c3cd166f5124c901420395ed98051aa93b88b9f19b84383
BLAKE2b-256 checksum
How to use checksums
019f8e67964e6348941a635bc71349189f2b4c5c6aacbfec04231305d90da147
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Security for downshift-server 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for downshift_server-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page