downshift-server 0.5.0__tar.gz → 0.5.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {downshift_server-0.5.0 → downshift_server-0.5.1}/.github/workflows/ci.yml +13 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/.gitignore +1 -0
- downshift_server-0.5.1/AGENTS.md +49 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/CHANGELOG.md +22 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/PKG-INFO +10 -4
- {downshift_server-0.5.0 → downshift_server-0.5.1}/README.md +8 -2
- {downshift_server-0.5.0 → downshift_server-0.5.1}/docs/code-docs/README.md +2 -2
- {downshift_server-0.5.0 → downshift_server-0.5.1}/docs/code-docs/cli.md +6 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/docs/code-docs/http-api.md +24 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/docs/code-docs/python-api.md +16 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/docs/code-docs/serving.md +2 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/docs/production.md +37 -4
- downshift_server-0.5.1/llms.txt +60 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/pyproject.toml +2 -2
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/_version.py +1 -1
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/adapters/embedding.py +13 -5
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/adapters/registry.py +4 -1
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/adapters/text.py +3 -2
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/cli/main.py +50 -26
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/cli/options.py +17 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/cli/render.py +12 -8
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/cli/runtime.py +37 -1
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/core/export_cache.py +5 -2
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/hf_repo.py +2 -1
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/serve/app.py +32 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/serve/engine.py +4 -1
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/serve/schemas.py +15 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/settings.py +7 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/conftest.py +39 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_cli.py +55 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_serve.py +18 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_serve_boot.py +40 -1
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_serve_hardening.py +5 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/.gitattributes +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/.github/workflows/compatibility-matrix.yml +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/.github/workflows/release.yml +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/LICENSE +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/BLOG_APPENDIX_v0.4.0.md +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/README.md +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/REPORT_v0.4.0.md +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/__init__.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/_path.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/cases.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/factories.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/hf_models.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/inproc.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/large/__init__.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/large/bert_small.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/large/cnn_large.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/large/mlp_large.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/loadgen.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/naive_hf_server.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/report.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/results/v0.5.0/REPORT.md +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/results/v0.5.0/chart_runs.csv +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/results/v0.5.0/chart_stages.csv +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/results/v0.5.0/results.json +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/results/v0.5.0/results_hf.json +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/results_hf_tuned_minilm_v0.4.0.json +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/results_hf_tuned_pg_v0.4.0.json +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/results_hf_v0.4.0.json +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/results_v0.4.0.json +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/run.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/bench/servers.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/docs/code-docs/adapters.md +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/docs/compatibility.md +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/examples/__init__.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/examples/clean_mlp.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/examples/data_dependent_branch.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/examples/scatter_include_self_false.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/scripts/gen_matrix.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/__init__.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/__main__.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/_imports.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/adapters/__init__.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/adapters/_flatten.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/adapters/base.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/adapters/generic.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/adapters/hf.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/adapters/pooling.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/adapters/pyg.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/cli/__init__.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/core/__init__.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/core/axes.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/core/capture.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/core/feeds.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/core/inputs.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/core/manifest.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/core/memo.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/core/phase.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/core/prevalidated.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/core/shapes.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/core/verdict.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/core/verify.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/loading.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/logs.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/py.typed +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/serve/__init__.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/serve/backends.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/serve/codec.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/serve/describe.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/serve/graphs.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/serve/middleware.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/serve/options.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/serve/predict.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/serve/reuse.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/src/downshift/sources.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/__init__.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/__init__.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/bf16_weights.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/broken_factory.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/clean_mlp.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/custom_autograd.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/data_dependent_branch.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/dict_input.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/dropout_model.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/dynamic_batch_cnn.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/gnn_gat.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/gnn_gcn.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/gnn_output_kinds.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/gnn_sage.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/hf_repo.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/scatter_include_self_false.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/tied_weights.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/models/tiny_bert.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_adapter_discovery_gating.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_adapters.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_axes.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_binary_io.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_capture.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_cli_startup.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_demo.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_describe.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_embedding.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_engine.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_export.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_export_cache.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_export_pyg.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_fixtures.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_gen_matrix.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_graph_batching.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_hf.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_hf_text.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_inputs.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_loading.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_logs.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_main_module.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_manifest.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_memo.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_package.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_path_privacy.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_prevalidated.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_render.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_review3_misc.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_schemas.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_settings.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_shapes.py +0 -0
- {downshift_server-0.5.0 → downshift_server-0.5.1}/tests/test_verify_internals.py +0 -0
|
@@ -20,6 +20,10 @@ jobs:
|
|
|
20
20
|
cache: pip
|
|
21
21
|
- run: pip install torch --index-url https://download.pytorch.org/whl/cpu
|
|
22
22
|
- run: pip install -e ".[dev,gnn,hf,fast]"
|
|
23
|
+
# The HTTPS tests make a throwaway certificate with the openssl command (tests/conftest.py).
|
|
24
|
+
# The runner images have it. The install is only a fallback.
|
|
25
|
+
- name: openssl
|
|
26
|
+
run: command -v openssl || (sudo apt-get update && sudo apt-get install -y openssl); openssl version
|
|
23
27
|
- run: ruff check .
|
|
24
28
|
- run: ruff format --check .
|
|
25
29
|
- run: mypy src
|
|
@@ -45,6 +49,10 @@ jobs:
|
|
|
45
49
|
# last release with which this job passed.
|
|
46
50
|
- run: pip install "onnx==1.16.0" "onnxruntime==1.17.0" "onnxscript==0.5.0" "numpy<2" "transformers==5.17.0"
|
|
47
51
|
- run: pip install -e ".[dev,gnn,hf,fast]"
|
|
52
|
+
# The HTTPS tests make a throwaway certificate with the openssl command (tests/conftest.py).
|
|
53
|
+
# The runner images have it. The install is only a fallback.
|
|
54
|
+
- name: openssl
|
|
55
|
+
run: command -v openssl || (sudo apt-get update && sudo apt-get install -y openssl); openssl version
|
|
48
56
|
- run: ruff check .
|
|
49
57
|
- run: ruff format --check .
|
|
50
58
|
- run: mypy src
|
|
@@ -70,6 +78,11 @@ jobs:
|
|
|
70
78
|
cache: pip
|
|
71
79
|
- run: pip install torch --index-url https://download.pytorch.org/whl/cpu
|
|
72
80
|
- run: pip install -e ".[dev,gnn,hf,fast]"
|
|
81
|
+
# The HTTPS tests make a throwaway certificate with the openssl command (tests/conftest.py).
|
|
82
|
+
# The runner image has it. The install is only a fallback.
|
|
83
|
+
- name: openssl
|
|
84
|
+
shell: bash
|
|
85
|
+
run: command -v openssl || choco install openssl -y --no-progress; openssl version
|
|
73
86
|
- run: ruff check .
|
|
74
87
|
- run: ruff format --check .
|
|
75
88
|
- run: mypy src
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# AGENTS.md
|
|
2
|
+
|
|
3
|
+
This file is for coding agents that work in this repository. To use downshift as a package, read [llms.txt](llms.txt).
|
|
4
|
+
|
|
5
|
+
## Set up
|
|
6
|
+
|
|
7
|
+
1. Install a CPU build of torch: `pip install torch --index-url https://download.pytorch.org/whl/cpu`.
|
|
8
|
+
2. Install the package in editable mode: `pip install -e ".[dev,gnn,hf,fast]"`.
|
|
9
|
+
3. If a non-editable `downshift-server` is also installed, set `PYTHONPATH=src`. If you do not, the tests import the installed copy and not your changes.
|
|
10
|
+
|
|
11
|
+
The project needs Python 3.12 to 3.14. The tests run on the CPU. A GPU is not necessary. The HTTPS tests need the `openssl` command on `PATH`. They make a throwaway certificate with it. Without `openssl`, they skip. In CI, they fail.
|
|
12
|
+
|
|
13
|
+
## Check a change
|
|
14
|
+
|
|
15
|
+
CI runs these commands. Run them before you finish:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
ruff check .
|
|
19
|
+
ruff format --check .
|
|
20
|
+
mypy src
|
|
21
|
+
pytest -q
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
CI requires 95% line coverage (`--cov-fail-under=95`). Add a test for each new code path.
|
|
25
|
+
|
|
26
|
+
While you work, run only the test files that apply to the change. Run the full suite one time, at the end.
|
|
27
|
+
|
|
28
|
+
## Layout
|
|
29
|
+
|
|
30
|
+
| Path | Contents |
|
|
31
|
+
|---|---|
|
|
32
|
+
| `src/downshift/core/` | Export, verification, the verdict, the export cache. |
|
|
33
|
+
| `src/downshift/adapters/` | The model families: generic, pyg, hf, onnx. |
|
|
34
|
+
| `src/downshift/serve/` | The FastAPI app, the backends, the request path. |
|
|
35
|
+
| `src/downshift/cli/` | The `check`, `export` and `serve` commands. |
|
|
36
|
+
| `src/downshift/settings.py` | The defaults and the `DOWNSHIFT_*` environment variables. |
|
|
37
|
+
| `tests/` | pytest. `tests/models/` has small models with known verdicts. |
|
|
38
|
+
| `docs/` | The user documentation. |
|
|
39
|
+
| `examples/` | The models of the README commands. |
|
|
40
|
+
|
|
41
|
+
## Rules
|
|
42
|
+
|
|
43
|
+
- Keep the CLI modules free of torch at import time. `downshift --help` and `--version` must stay fast. Import heavy modules inside the function bodies.
|
|
44
|
+
- Per-request speed has priority over boot time. Do not add work to the request path without a measurement.
|
|
45
|
+
- Keep the code simple. Prefer a plain function or a small dataclass to a new class hierarchy, registry or wrapper.
|
|
46
|
+
- Give each usage error a next step. A `ValueError` from a command is exit code `4`. Its message must say what to change.
|
|
47
|
+
- Write docs, comments, CLI help and error messages in ASD-STE100 Simplified Technical English. Use short sentences and one meaning for each word. Write steps as commands. Put conditions first.
|
|
48
|
+
- Add a new `serve` option in these places: `settings.py`, `cli/options.py`, `serve_cmd`, `docs/code-docs/cli.md` and `docs/production.md`. Refer to "Add a `serve` option" in `docs/code-docs/cli.md`.
|
|
49
|
+
- Record each change that a user can see in `CHANGELOG.md`.
|
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
All notable changes to this project are documented here. Format follows
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
5
5
|
|
|
6
|
+
## 0.5.1 - 2026-10-11
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- HTTPS. `serve --ssl-certfile PATH --ssl-keyfile PATH` (or `DOWNSHIFT_SSL_CERTFILE` and `DOWNSHIFT_SSL_KEYFILE`) serves HTTPS with your certificate. For an encrypted key, set `DOWNSHIFT_SSL_KEYFILE_PASSWORD`. Downshift loads the files before the model. A bad file is a usage error (exit code `4`) with a next step. Downshift uses the TLS settings of `ssl.create_default_context`: TLS 1.2 or later and the cipher list of the standard library. The default of uvicorn also enables NULL and anonymous ciphers. `--workers N` works with HTTPS. The banner, the `will listen on` line and `example_curl` in `/schema` show `https://`. The `serving with:` block has a `tls` row. Refer to "HTTPS" in `docs/production.md`.
|
|
11
|
+
- `GET /`. It gives the service name, the version, `ready`, the model, all routes, and the next step (`GET /schema`). A client that knows only the base URL can find the input format. If the API key is active, this route needs the key.
|
|
12
|
+
- `llms.txt` and `AGENTS.md` at the root of the repo. `llms.txt` tells an LLM agent how to call a server and how to host a model. `AGENTS.md` tells a coding agent how to set up, test and change this repo.
|
|
13
|
+
- `--help` of `check`, `export` and `serve` shows the exit codes and an example.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- More usage errors give a next step. These errors changed:
|
|
18
|
+
- A missing adapter file.
|
|
19
|
+
- A missing or read-only `--export-cache-dir`.
|
|
20
|
+
- `export` of a `.onnx` file.
|
|
21
|
+
- `--backend torch` with no PyTorch model.
|
|
22
|
+
- A repo with `auto_map`.
|
|
23
|
+
- A pooling recipe that downshift cannot apply.
|
|
24
|
+
|
|
25
|
+
A client or script that matches the old text must change.
|
|
26
|
+
- The `400` for text that is too long had a doubled word. The message now also gives the next step: send shorter text, or split the text into more rows.
|
|
27
|
+
|
|
6
28
|
## 0.5.0 - 2026-10-10
|
|
7
29
|
|
|
8
30
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: downshift-server
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: Serve PyTorch models over HTTP through ONNX Runtime. Downshift verifies each export against PyTorch before it serves, and it falls back to eager PyTorch.
|
|
5
5
|
Project-URL: Homepage, https://github.com/uNRealCoder/downshift-server
|
|
6
6
|
Project-URL: Repository, https://github.com/uNRealCoder/downshift-server
|
|
@@ -38,7 +38,7 @@ Requires-Dist: httpx>=0.24; extra == 'dev'
|
|
|
38
38
|
Requires-Dist: mypy>=1.0; extra == 'dev'
|
|
39
39
|
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
40
40
|
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
41
|
-
Requires-Dist: ruff
|
|
41
|
+
Requires-Dist: ruff==0.17.0; extra == 'dev'
|
|
42
42
|
Requires-Dist: safetensors>=0.4; extra == 'dev'
|
|
43
43
|
Provides-Extra: fast
|
|
44
44
|
Requires-Dist: pybase64>=1.4; extra == 'fast'
|
|
@@ -137,10 +137,11 @@ downshift serve my_pkg.models:build --port 8000
|
|
|
137
137
|
|
|
138
138
|
With `--workers N`, the parent process does these steps before uvicorn binds the port. Each worker needs the export that the parent makes. The routes are the same for all backends.
|
|
139
139
|
|
|
140
|
-
[docs/production.md](docs/production.md) describes how to run downshift in a real deployment. It covers probes, sizing, Kubernetes, the optional API key and
|
|
140
|
+
[docs/production.md](docs/production.md) describes how to run downshift in a real deployment. It covers probes, sizing, Kubernetes, the optional API key and HTTPS. To serve HTTPS, give `--ssl-certfile` and `--ssl-keyfile`. If you set `DOWNSHIFT_SERVER_API_KEY`, every route except `/health` and `/ready` needs the header `Authorization: Bearer <key>`. If you do not set it, the server logs one warning at startup. The warning says that the endpoints are unauthenticated.
|
|
141
141
|
|
|
142
142
|
| Route | What it does |
|
|
143
143
|
|---|---|
|
|
144
|
+
| `GET /` | The index. It gives the version, the model, whether the model is ready, and all routes. Start here if you know only the base URL. |
|
|
144
145
|
| `POST /predict` | Takes named tensor inputs for any model. Returns `503` (with `Retry-After`) until the model is ready. |
|
|
145
146
|
| `POST /predict/graph` | Takes one graph: `x`, `edge_index` and optional `edge_attr`. Returns the same `503` until ready. |
|
|
146
147
|
| `GET /health` | Liveness. Returns `200` when the process is up, also during the load. |
|
|
@@ -308,6 +309,7 @@ These options change what downshift serves:
|
|
|
308
309
|
- `--force-onnx` serves a DEGRADED graph through ONNX Runtime. The banner shows this.
|
|
309
310
|
- `--reference model` verifies a pre-built `.onnx` file against a PyTorch model. Without it, the verdict is UNVERIFIED. This option is only numeric. If the `.onnx` file also needs a tokenizer, add `--tokenizer-from`.
|
|
310
311
|
- `--tokenizer-from dir/` loads the tokenizer, the pooling recipe and the label metadata from a Hugging Face repo directory. It works for a `.onnx` file or a PyTorch model. With it, `{"text": ...}` works without a new export. The graph is served as it is. The option does not add pooling to a bare encoder. `/schema` reports the recipe only if the output is already pooled. The option does not depend on `--reference`, and it does not change verification. Both options can name the same directory or different directories. Refer to [Accepted model forms](#accepted-model-forms).
|
|
312
|
+
- `--ssl-certfile cert.pem --ssl-keyfile key.pem` (env `DOWNSHIFT_SSL_CERTFILE`, `DOWNSHIFT_SSL_KEYFILE`) serves HTTPS with your certificate. For an encrypted key, set `DOWNSHIFT_SSL_KEYFILE_PASSWORD`. Refer to [HTTPS](docs/production.md#https).
|
|
311
313
|
- `--middleware pkg.module:Attr` (repeatable) adds a middleware. It can be a class (pure ASGI, for example `starlette.middleware.gzip:GZipMiddleware`, or a `BaseHTTPMiddleware` subclass) or an `async (request, call_next)` function. If you add no middleware, there is no overhead.
|
|
312
314
|
- `--output-encoding json|base64` (env `DOWNSHIFT_OUTPUT_ENCODING`, default `json`) sets the response encoding for requests that do not send `output_encoding`.
|
|
313
315
|
- `--max-input-bytes N` (env `DOWNSHIFT_MAX_INPUT_BYTES`, default 256 MiB) sets the maximum decoded size of one base64 input. A larger input gets a `400`.
|
|
@@ -622,7 +624,11 @@ pytest
|
|
|
622
624
|
python scripts/gen_matrix.py # regenerates docs/compatibility.md and this README's table
|
|
623
625
|
```
|
|
624
626
|
|
|
625
|
-
A plain `pytest` run has no coverage gate on your machine. CI runs it with `--cov-fail-under=95`.
|
|
627
|
+
A plain `pytest` run has no coverage gate on your machine. CI runs it with `--cov-fail-under=95`. The HTTPS tests make a temporary certificate with the `openssl` command. If `openssl` is not on `PATH`, these tests skip.
|
|
628
|
+
|
|
629
|
+
### For LLM agents
|
|
630
|
+
|
|
631
|
+
[`llms.txt`](llms.txt) tells an agent how to call a downshift server and how to host a model. [`AGENTS.md`](AGENTS.md) tells a coding agent how to set up, test and change this repo.
|
|
626
632
|
|
|
627
633
|
## Changelog
|
|
628
634
|
|
|
@@ -87,10 +87,11 @@ downshift serve my_pkg.models:build --port 8000
|
|
|
87
87
|
|
|
88
88
|
With `--workers N`, the parent process does these steps before uvicorn binds the port. Each worker needs the export that the parent makes. The routes are the same for all backends.
|
|
89
89
|
|
|
90
|
-
[docs/production.md](docs/production.md) describes how to run downshift in a real deployment. It covers probes, sizing, Kubernetes, the optional API key and
|
|
90
|
+
[docs/production.md](docs/production.md) describes how to run downshift in a real deployment. It covers probes, sizing, Kubernetes, the optional API key and HTTPS. To serve HTTPS, give `--ssl-certfile` and `--ssl-keyfile`. If you set `DOWNSHIFT_SERVER_API_KEY`, every route except `/health` and `/ready` needs the header `Authorization: Bearer <key>`. If you do not set it, the server logs one warning at startup. The warning says that the endpoints are unauthenticated.
|
|
91
91
|
|
|
92
92
|
| Route | What it does |
|
|
93
93
|
|---|---|
|
|
94
|
+
| `GET /` | The index. It gives the version, the model, whether the model is ready, and all routes. Start here if you know only the base URL. |
|
|
94
95
|
| `POST /predict` | Takes named tensor inputs for any model. Returns `503` (with `Retry-After`) until the model is ready. |
|
|
95
96
|
| `POST /predict/graph` | Takes one graph: `x`, `edge_index` and optional `edge_attr`. Returns the same `503` until ready. |
|
|
96
97
|
| `GET /health` | Liveness. Returns `200` when the process is up, also during the load. |
|
|
@@ -258,6 +259,7 @@ These options change what downshift serves:
|
|
|
258
259
|
- `--force-onnx` serves a DEGRADED graph through ONNX Runtime. The banner shows this.
|
|
259
260
|
- `--reference model` verifies a pre-built `.onnx` file against a PyTorch model. Without it, the verdict is UNVERIFIED. This option is only numeric. If the `.onnx` file also needs a tokenizer, add `--tokenizer-from`.
|
|
260
261
|
- `--tokenizer-from dir/` loads the tokenizer, the pooling recipe and the label metadata from a Hugging Face repo directory. It works for a `.onnx` file or a PyTorch model. With it, `{"text": ...}` works without a new export. The graph is served as it is. The option does not add pooling to a bare encoder. `/schema` reports the recipe only if the output is already pooled. The option does not depend on `--reference`, and it does not change verification. Both options can name the same directory or different directories. Refer to [Accepted model forms](#accepted-model-forms).
|
|
262
|
+
- `--ssl-certfile cert.pem --ssl-keyfile key.pem` (env `DOWNSHIFT_SSL_CERTFILE`, `DOWNSHIFT_SSL_KEYFILE`) serves HTTPS with your certificate. For an encrypted key, set `DOWNSHIFT_SSL_KEYFILE_PASSWORD`. Refer to [HTTPS](docs/production.md#https).
|
|
261
263
|
- `--middleware pkg.module:Attr` (repeatable) adds a middleware. It can be a class (pure ASGI, for example `starlette.middleware.gzip:GZipMiddleware`, or a `BaseHTTPMiddleware` subclass) or an `async (request, call_next)` function. If you add no middleware, there is no overhead.
|
|
262
264
|
- `--output-encoding json|base64` (env `DOWNSHIFT_OUTPUT_ENCODING`, default `json`) sets the response encoding for requests that do not send `output_encoding`.
|
|
263
265
|
- `--max-input-bytes N` (env `DOWNSHIFT_MAX_INPUT_BYTES`, default 256 MiB) sets the maximum decoded size of one base64 input. A larger input gets a `400`.
|
|
@@ -572,7 +574,11 @@ pytest
|
|
|
572
574
|
python scripts/gen_matrix.py # regenerates docs/compatibility.md and this README's table
|
|
573
575
|
```
|
|
574
576
|
|
|
575
|
-
A plain `pytest` run has no coverage gate on your machine. CI runs it with `--cov-fail-under=95`.
|
|
577
|
+
A plain `pytest` run has no coverage gate on your machine. CI runs it with `--cov-fail-under=95`. The HTTPS tests make a temporary certificate with the `openssl` command. If `openssl` is not on `PATH`, these tests skip.
|
|
578
|
+
|
|
579
|
+
### For LLM agents
|
|
580
|
+
|
|
581
|
+
[`llms.txt`](llms.txt) tells an agent how to call a downshift server and how to host a model. [`AGENTS.md`](AGENTS.md) tells a coding agent how to set up, test and change this repo.
|
|
576
582
|
|
|
577
583
|
## Changelog
|
|
578
584
|
|
|
@@ -25,7 +25,7 @@ Each page starts with one sentence that says what it covers. Use it to go to the
|
|
|
25
25
|
|---|---|
|
|
26
26
|
| [`python-api.md`](python-api.md) | Every name in `downshift.__all__`: `check`, `export`, `intake`, `build_verdict`, `prepare_model`, `app_for`, the types `ExportVerdict`, `NumericsReport`, `Adapter`, `Prepared` and `OnnxRuntimeError`, and `__version__`. It also describes the lazy-import behaviour of `import downshift`. |
|
|
27
27
|
| [`cli.md`](cli.md) | `downshift check`, `downshift export` and `downshift serve`. For each flag: the environment variable and the default, if it has them. Also logging, the table of environment variables, and the process exit codes. |
|
|
28
|
-
| [`http-api.md`](http-api.md) | Every HTTP route
|
|
28
|
+
| [`http-api.md`](http-api.md) | Every HTTP route. `GET /` gives the index of routes. `GET /schema` gives what to POST, with an example body. HTTPS. The request and response schemas, the status codes, the nested-list and base64 wire formats, the headers, and `curl` examples. |
|
|
29
29
|
| [`serving.md`](serving.md) | The programmatic serving layer under `serve`: `ServeOptions`, `ServingState`, `prepare_serving`, `build_app`, the selection of the backend, and the `Backend` implementations. |
|
|
30
30
|
| [`adapters.md`](adapters.md) | The `Adapter` protocol, how downshift registers and resolves adapters, and how to write a custom adapter. |
|
|
31
31
|
|
|
@@ -44,7 +44,7 @@ All modules are in `src/downshift/`. Some leaf modules use only the standard lib
|
|
|
44
44
|
| `hf_repo.py` | Reads a downloaded Hugging Face repo: `load_config`, `load_pretrained` (with its task head), the pooling recipe, and the tokenizer and labels for text input. Downshift imports it only if transformers is installed. |
|
|
45
45
|
| `cli/main.py` | The three commands: `check`, `export` and `serve`. |
|
|
46
46
|
| `cli/options.py` | The typer option types (`Annotated` aliases and `LogLevel`). |
|
|
47
|
-
| `cli/runtime.py` | `ServeArgs`, `_collect_serve_args
|
|
47
|
+
| `cli/runtime.py` | `ServeArgs`, `_collect_serve_args`, the `--workers` handoff, and `_tls_config` (the TLS settings of `serve`). |
|
|
48
48
|
| `cli/render.py` | The banner, the reports, the warnings and the errors. All are logged as plain text. |
|
|
49
49
|
| `core/` | The gate. `verdict.py` has `check`, `prepare_model` and `build_verdict`. The other files are `capture.py`, `verify.py`, `prevalidated.py` (`intake`), `manifest.py`, `shapes.py`, `inputs.py` and `phase.py`. `phase.py` has the `Phase` enum (`load`, `export`, `verify`, `session`, `warmup`). The enum drives the `Boot` timings, `/ready` and the banner. |
|
|
50
50
|
| `adapters/` | `base.py` has the `Adapter` protocol, `Prepared` and `Family`. The other files are `registry.py`, `generic.py`, `pyg.py` and `hf.py`. The Hugging Face parts are `text.py` (tokenizing and class probabilities), `pooling.py` (the `--pooling` choices) and `embedding.py` (the pooling recipe and the graph that applies it). |
|
|
@@ -137,6 +137,8 @@ The adapter and verification flags of `check` also apply to `serve`, with the sa
|
|
|
137
137
|
| `--workers INT` | `DOWNSHIFT_WORKERS` | `1` | The number of uvicorn worker processes. The parent exports and verifies once. Each worker builds its own session over that graph (or reloads the model for torch) and warms up. The parent frees its copy of the model before the workers start. If a worker fails to load, the whole server stops with the startup-failure exit code of uvicorn. Downshift does not start the worker again. |
|
|
138
138
|
| `--log-level debug\|info\|warning\|error` | - | `warning` | Refer to "Logging" below. |
|
|
139
139
|
| `--access-log` / `--no-access-log` | - | on | The log line for each request (`downshift.access`). The access log of uvicorn is always off. |
|
|
140
|
+
| `--ssl-certfile PATH` | `DOWNSHIFT_SSL_CERTFILE` | none | A PEM certificate or certificate chain. If you give it, the server uses HTTPS. If you do not give it, the server uses plain HTTP. |
|
|
141
|
+
| `--ssl-keyfile PATH` | `DOWNSHIFT_SSL_KEYFILE` | none | The PEM private key of the certificate. If the certificate file contains the key, you do not need this flag. For an encrypted key, set `DOWNSHIFT_SSL_KEYFILE_PASSWORD`. |
|
|
140
142
|
|
|
141
143
|
```bash
|
|
142
144
|
downshift serve my_pkg.models:build --port 8000 --output-encoding base64
|
|
@@ -148,6 +150,8 @@ downshift serve my_pkg.models:build --port 8000 --output-encoding base64
|
|
|
148
150
|
- A crash during the boot (`5`).
|
|
149
151
|
- A normal shutdown of the process.
|
|
150
152
|
|
|
153
|
+
Downshift loads the TLS files before it loads the model. If a TLS file is bad, `serve` stops with a usage error (`4`). Examples are a missing file, a wrong key and a wrong password. The error message gives the cause and the next step.
|
|
154
|
+
|
|
151
155
|
## Logging
|
|
152
156
|
|
|
153
157
|
All output of the CLI and the server goes through Python `logging` to one plain-text handler on stdout (`downshift/logs.py`, `setup_logging`). This includes:
|
|
@@ -187,6 +191,8 @@ Each line has the form `time LEVEL logger: message`. If the line belongs to a re
|
|
|
187
191
|
| `DOWNSHIFT_EXECUTION`, `DOWNSHIFT_PREP_THREADS` | `threadpool`, `min(4, usable CPUs)` | `--execution`, `--prep-threads` |
|
|
188
192
|
| `DOWNSHIFT_WORKERS` | `1` | `--workers` (CLI only) |
|
|
189
193
|
| `DOWNSHIFT_SERVER_API_KEY` | unset | Requires `Authorization: Bearer <key>` on every route except `/health` and `/ready`. If it is unset or empty, downshift logs one startup warning that the endpoints are unauthenticated. There is no flag, because the key is a secret. `build_app(api_key=...)` and `app_for(api_key=...)` read it by default. |
|
|
194
|
+
| `DOWNSHIFT_SSL_CERTFILE`, `DOWNSHIFT_SSL_KEYFILE` | unset | `--ssl-certfile`, `--ssl-keyfile` (CLI only) |
|
|
195
|
+
| `DOWNSHIFT_SSL_KEYFILE_PASSWORD` | unset | The password of an encrypted key. There is no flag, because the password is a secret. |
|
|
190
196
|
| `DOWNSHIFT_TOL_{FLOAT32,FLOAT64,FLOAT16,BFLOAT16}_{ATOL,RTOL}` | see `check` above | The default tolerances. |
|
|
191
197
|
|
|
192
198
|
The library functions `check()`, `export()` and `intake()` use the constant `8` as the default for `k`. They do not use `DOWNSHIFT_SAMPLES`. Only `ServeOptions.k` (and so `app_for()`) and the CLI flag read that variable.
|
|
@@ -6,6 +6,7 @@ This page describes every route that `build_app` registers: the request and resp
|
|
|
6
6
|
|
|
7
7
|
| Method | Path | Purpose |
|
|
8
8
|
|---|---|---|
|
|
9
|
+
| `GET` | `/` | The index: the service, the version, the model, and the routes. Start here if you know only the base URL. |
|
|
9
10
|
| `GET` | `/health` | Liveness. |
|
|
10
11
|
| `GET` | `/ready` | Readiness. |
|
|
11
12
|
| `GET` | `/metadata` | Model, backend, verdict, limits, boot timings and warmup statistics. |
|
|
@@ -22,6 +23,10 @@ Each served model comes from this machine. It is one of these:
|
|
|
22
23
|
|
|
23
24
|
The `source` block of `/schema` shows which one applies to each server. Downshift fetches nothing to answer a request.
|
|
24
25
|
|
|
26
|
+
## HTTPS
|
|
27
|
+
|
|
28
|
+
If `serve` starts with `--ssl-certfile`, all routes use HTTPS on the same port. The routes, the bodies and the status codes do not change. A plain HTTP request to that port gets no HTTP response. Refer to [HTTPS in production.md](../production.md#https).
|
|
29
|
+
|
|
25
30
|
## Authentication
|
|
26
31
|
|
|
27
32
|
Authentication is optional. It uses one shared key. The key is active when `DOWNSHIFT_SERVER_API_KEY` is set. It is also active when you give a value to `build_app(..., api_key=...)` or `app_for(..., api_key=...)`. Both default to the variable. When the key is active, every route except `/health` and `/ready` needs `Authorization: Bearer <key>`.
|
|
@@ -42,6 +47,25 @@ The rest of this page does not repeat the `401` for each route.
|
|
|
42
47
|
curl -s localhost:8000/schema -H "Authorization: Bearer $DOWNSHIFT_SERVER_API_KEY"
|
|
43
48
|
```
|
|
44
49
|
|
|
50
|
+
### `GET /`
|
|
51
|
+
|
|
52
|
+
This route always returns `200`, also while the model loads. It tells a client where to start. The response model is `IndexResponse`:
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{"service": "downshift", "version": "0.5.1", "ready": true, "model": "clean_mlp",
|
|
56
|
+
"routes": {"index": "GET /", "health": "GET /health", "ready": "GET /ready",
|
|
57
|
+
"metadata": "GET /metadata", "schema": "GET /schema",
|
|
58
|
+
"predict": "POST /predict", "predict_graph": "POST /predict/graph",
|
|
59
|
+
"openapi": "GET /openapi.json", "docs": "GET /docs"},
|
|
60
|
+
"next_step": "Send GET /schema. The response gives the inputs and an example_request body. POST that body to /predict without a change"}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`model` is `null` until the model is ready. Downshift reads `routes` from the app, so the list is always correct. If the app is mounted under a prefix, each path includes the prefix. `routes` includes `/predict/graph` also for a model that is not a graph model. To find the predict route for this model, read `endpoint` and `graph_endpoint` in `/schema`. If the API key is active, this route needs the key.
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
curl -s localhost:8000/
|
|
67
|
+
```
|
|
68
|
+
|
|
45
69
|
### `GET /health`
|
|
46
70
|
|
|
47
71
|
This route returns `200` when the process is up and the event loop runs. It also returns `200` while a model is still loading. The route runs directly on the event loop (`async def`). A predict never blocks it. The response model is `HealthResponse`:
|
|
@@ -198,6 +198,22 @@ def app_for(
|
|
|
198
198
|
- `api_key`: if you set it, every route except `/health` and `/ready` needs `Authorization: Bearer <api_key>`. Without it, the route answers `401`. If you do not pass it, downshift uses the `DOWNSHIFT_SERVER_API_KEY` environment variable. Pass a value to override it for this app. If the key is unset or empty, downshift logs one `WARNING` that the endpoints are unauthenticated.
|
|
199
199
|
- `options`: downshift forwards these as `ServeOptions` fields (`backend=`, `warmup=`, `max_concurrency=`, and others). [`serving.md`](serving.md) has the full list of fields. Every default comes from `downshift.settings`. The `DOWNSHIFT_*` environment variables therefore also apply here, not only to the CLI. Downshift reads them once, when `downshift` is imported. A keyword argument has priority. `check()`, `export()` and `intake()` are an exception for `k`. They use the constant `8` as the default and not `DOWNSHIFT_SAMPLES`.
|
|
200
200
|
|
|
201
|
+
### HTTPS with `app_for`
|
|
202
|
+
|
|
203
|
+
`app_for` returns a FastAPI app. The app has no TLS settings. Your server sets TLS. To serve the app over HTTPS with uvicorn, give uvicorn the certificate and the key:
|
|
204
|
+
|
|
205
|
+
```python
|
|
206
|
+
import uvicorn
|
|
207
|
+
from downshift import app_for
|
|
208
|
+
|
|
209
|
+
app = app_for("model.onnx")
|
|
210
|
+
uvicorn.run(
|
|
211
|
+
app, host="0.0.0.0", port=8443, ssl_certfile="cert.pem", ssl_keyfile="key.pem", ssl_ciphers=None
|
|
212
|
+
)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
Use `ssl_ciphers=None`. With `None`, uvicorn keeps the cipher list of the Python standard library. The default of uvicorn (`"TLSv1"`) also enables NULL ciphers and anonymous ciphers. `downshift serve --ssl-certfile` uses the same settings. Refer to [HTTPS in production.md](../production.md#https).
|
|
216
|
+
|
|
201
217
|
## Types
|
|
202
218
|
|
|
203
219
|
### `ExportVerdict`
|
|
@@ -251,6 +251,8 @@ You must give exactly one of `state` and `loader`. Otherwise, `build_app` raises
|
|
|
251
251
|
- **`state=`** is for library use, `app_for` and tests. The app serves `state` immediately. There is no `503` window on `/ready`. The gate and the warmup already ran, synchronously, before the call to `build_app`.
|
|
252
252
|
- **`loader=`** is for `downshift serve` with one worker. The app binds with no `ServingState`. `/health` returns `200` immediately. `/ready`, `/metadata`, `/schema` and both predict routes return `503` until `loader` returns a `ServingState`. The lifespan of the app starts `loader` on a background thread when uvicorn starts to serve. It does not start when `build_app` is called. The returned `ServingState` goes to `app.state.serving`. During this time, `phase` on `/ready` says which `Phase` the loader is in. If `loader` raises an error, `app.state.serving` stays `None` for this function. `serve_cmd` holds the `uvicorn.Server` and sets `should_exit` itself when the loader fails. The process then exits and does not serve `503` forever.
|
|
253
253
|
|
|
254
|
+
In both modes, `GET /` returns `200`. The response gives `ready`, the model (when the model is ready) and the routes. `_routes` in `serve/app.py` reads the routes from `app.routes` for each request. The list therefore always agrees with the app. Each path includes the mount prefix (`root_path`).
|
|
255
|
+
|
|
254
256
|
`middleware` is a sequence of `pkg.module:Attr` specs (`--middleware`, repeatable). `load_middleware` (`serve/middleware.py`) attaches them in order. Each spec must resolve to one of these:
|
|
255
257
|
|
|
256
258
|
- A middleware class that is built as `cls(app)`: pure ASGI, or a subclass of `starlette.middleware.base.BaseHTTPMiddleware`.
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
- It warms up the backend.
|
|
8
8
|
- It answers `/predict`.
|
|
9
9
|
|
|
10
|
-
It has one fixed API key for authentication. It has no
|
|
10
|
+
It has one fixed API key for authentication and optional HTTPS with your certificate. It has no rate limiting and no process supervision. A real deployment adds these around downshift. This page describes how to do that.
|
|
11
11
|
|
|
12
|
-
## Authentication: one API key, no
|
|
12
|
+
## Authentication: one API key, no rate limiting
|
|
13
13
|
|
|
14
14
|
Set `DOWNSHIFT_SERVER_API_KEY`. Every route except `/health` and `/ready` then needs `Authorization: Bearer <key>`. The comparison takes constant time. Any other request gets a `401` with `WWW-Authenticate: Bearer` and this body: `{"detail": "Authorization header is not set or incorrect"}`. The two probes stay open, so Kubernetes never needs the key.
|
|
15
15
|
|
|
@@ -24,9 +24,9 @@ If the variable is unset or empty, the server logs one `WARNING` at startup. The
|
|
|
24
24
|
|
|
25
25
|
`app_for()` and `build_app(..., api_key=...)` read the same variable by default. To override it for one app, pass `api_key=`. To turn it off, pass `api_key=None`.
|
|
26
26
|
|
|
27
|
-
One key is not a user system. It is a shared secret that travels in a header. Use it only
|
|
27
|
+
One key is not a user system. It is a shared secret that travels in a header. Use it only with TLS: either the `--ssl-certfile` of downshift (refer to [HTTPS](#https)) or a proxy. A proxy layer does the other jobs better than downshift can. Put a reverse proxy in front of downshift. Examples are nginx, Envoy, the load balancer of your cloud, and a service mesh sidecar. Configure these items in the proxy:
|
|
28
28
|
|
|
29
|
-
- TLS termination.
|
|
29
|
+
- TLS termination, with automatic renewal of the certificate.
|
|
30
30
|
- Authentication that is more than one shared key (mTLS, keys for each client, OAuth).
|
|
31
31
|
- Rate limiting and IP allow-lists.
|
|
32
32
|
- Limits on request size that are lower than `--max-body-bytes`. Use them to reject oversized bodies before they reach this process.
|
|
@@ -39,6 +39,36 @@ If you need something in the process, use `--middleware pkg.module:Attr` (repeat
|
|
|
39
39
|
|
|
40
40
|
Downshift attaches them in the order that you give. Your middleware runs inside the key check. It sees only authenticated requests. A `401` never reaches it.
|
|
41
41
|
|
|
42
|
+
## HTTPS
|
|
43
|
+
|
|
44
|
+
Downshift can serve HTTPS with a certificate that you supply. To serve HTTPS, do these steps:
|
|
45
|
+
|
|
46
|
+
1. Get a PEM certificate and its PEM private key. For a public name, get the two files from a certificate authority, for example Let's Encrypt. For a private network, use the certificate authority of your organization.
|
|
47
|
+
2. Give the two files to `serve`:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
downshift serve my_pkg.models:build --host 0.0.0.0 --port 8443 \
|
|
51
|
+
--ssl-certfile /etc/downshift/cert.pem --ssl-keyfile /etc/downshift/key.pem
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
3. If the key is encrypted, set `DOWNSHIFT_SSL_KEYFILE_PASSWORD`. There is no flag for the password, because a flag shows in the process list.
|
|
55
|
+
4. Make sure that the banner shows `https://` in the `Endpoint` row.
|
|
56
|
+
|
|
57
|
+
Downshift loads the files before it loads the model. If a file is bad, `serve` stops with exit code `4`. Examples are a missing file, a key that does not agree with the certificate, and a wrong password. The error message gives the next step. Downshift never asks for a password on the terminal.
|
|
58
|
+
|
|
59
|
+
Downshift uses the TLS settings of `ssl.create_default_context` in the Python standard library. The minimum protocol is TLS 1.2. The cipher list is the list of the standard library. The default cipher string of uvicorn (`"TLSv1"`) also enables NULL ciphers and anonymous ciphers. Downshift does not use that default.
|
|
60
|
+
|
|
61
|
+
`--workers N` works with HTTPS. Each worker reads the same files.
|
|
62
|
+
|
|
63
|
+
These items are not in downshift. If you need one of them, use a proxy:
|
|
64
|
+
|
|
65
|
+
- Automatic renewal of the certificate. Downshift reads the files one time, at startup. After you renew the certificate, restart the process.
|
|
66
|
+
- ACME (Let's Encrypt) requests.
|
|
67
|
+
- Client certificates (mTLS).
|
|
68
|
+
- HTTP and HTTPS on the same port, or a redirect from HTTP to HTTPS.
|
|
69
|
+
|
|
70
|
+
If a proxy terminates TLS, do not give `--ssl-certfile` to downshift. Keep downshift on plain HTTP behind the proxy, on `127.0.0.1` or on a private network.
|
|
71
|
+
|
|
42
72
|
## `/health` and `/ready`
|
|
43
73
|
|
|
44
74
|
- **`/health`** is the liveness probe. It returns `200` when the process is up and the event loop runs, with or without a loaded model. It never shows readiness or load. It never waits for predicts that are running. `/health` and `/ready` are `async def` routes. They run directly on the event loop and do not share a thread pool with predicts. Use it to decide "restart this container". Do not use it to decide "send traffic to it".
|
|
@@ -184,6 +214,7 @@ Downshift reads each `DOWNSHIFT_*` variable once, when `downshift` is imported.
|
|
|
184
214
|
- `DOWNSHIFT_MAX_INPUT_BYTES`, `DOWNSHIFT_MAX_BODY_BYTES`
|
|
185
215
|
- `DOWNSHIFT_MAX_CONCURRENCY`, `DOWNSHIFT_MAX_QUEUE`, `DOWNSHIFT_REQUEST_TIMEOUT`
|
|
186
216
|
- `DOWNSHIFT_WORKERS`, `DOWNSHIFT_SERVER_API_KEY`
|
|
217
|
+
- `DOWNSHIFT_SSL_CERTFILE`, `DOWNSHIFT_SSL_KEYFILE`, `DOWNSHIFT_SSL_KEYFILE_PASSWORD`
|
|
187
218
|
- The `DOWNSHIFT_TOL_*` variables for each dtype.
|
|
188
219
|
|
|
189
220
|
They apply to library use (`app_for()` and `ServeOptions()`) and to the CLI. A flag or a keyword argument has priority over the variable. The variable has priority over the default. To change a variable, restart the process that reads it.
|
|
@@ -246,3 +277,5 @@ resources:
|
|
|
246
277
|
```
|
|
247
278
|
|
|
248
279
|
Read the `Boot` row from a real run of the model that you deploy. Set `initialDelaySeconds` a little above it, on both probes in this mode. The pod does not listen at all until the export of the parent finishes.
|
|
280
|
+
|
|
281
|
+
If `serve` uses `--ssl-certfile`, add `scheme: HTTPS` to the `httpGet` of both probes. The kubelet does not check the certificate.
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# downshift
|
|
2
|
+
|
|
3
|
+
> Serve a model that is already on this machine over HTTP, with one command. Before the first request, downshift exports the model to ONNX and compares the ONNX graph with PyTorch. If the numbers are wrong, downshift serves eager PyTorch. Package: `pip install downshift-server`. Command: `downshift` (or `python -m downshift`).
|
|
4
|
+
|
|
5
|
+
This file is for LLM agents. It gives the shortest correct path. The full documentation is in the links below.
|
|
6
|
+
|
|
7
|
+
## Call a running server
|
|
8
|
+
|
|
9
|
+
Do these steps in this sequence:
|
|
10
|
+
|
|
11
|
+
1. `GET /`. It gives the version, the model, `ready`, and the routes.
|
|
12
|
+
2. Poll `GET /ready` until it gives `200`. A `503` with `{"ready": false, "phase": ...}` means that the model loads. Do not restart the server.
|
|
13
|
+
3. `GET /schema`. Read `inputs` (name, dtype, shape, bounds) and `example_request`.
|
|
14
|
+
4. `POST /predict` with `example_request`. The server gives `200`. Then change the values. Keep the names, the dtypes and the shapes.
|
|
15
|
+
|
|
16
|
+
Rules for request bodies:
|
|
17
|
+
|
|
18
|
+
- A list of integers becomes `int64`. All other lists become `float32`.
|
|
19
|
+
- To set the dtype, send `{"data": [...], "dtype": "float16", "shape": [1, 16]}` in place of a list.
|
|
20
|
+
- If an axis is outside `bounds`, the server gives a `400` that names the axis and the range.
|
|
21
|
+
- If the server gives `503` with `Retry-After`, wait for that number of seconds and send again.
|
|
22
|
+
- If `DOWNSHIFT_SERVER_API_KEY` is set on the server, send `Authorization: Bearer <key>`. `/health` and `/ready` do not need the key.
|
|
23
|
+
- For a text model, `/schema` has `text_input`. Send `{"text": ["..."]}`. The server rejects text that is longer than the model accepts. It does not cut the text.
|
|
24
|
+
|
|
25
|
+
## Host a model
|
|
26
|
+
|
|
27
|
+
Do these steps in this sequence:
|
|
28
|
+
|
|
29
|
+
1. Download the model first. Downshift fetches nothing. It rejects a Hugging Face hub id. Use `huggingface-cli download <id> --local-dir ./<name>`, then give the directory.
|
|
30
|
+
2. Run `downshift check MODEL --json`. Read `status`. The exit code is the verdict.
|
|
31
|
+
3. Run `downshift serve MODEL`. The port opens immediately. Poll `/ready`.
|
|
32
|
+
4. Read the boot banner. The `Endpoint` row gives the URL. The `ready in N s` line shows when `/ready` gives `200`.
|
|
33
|
+
|
|
34
|
+
MODEL is one of these:
|
|
35
|
+
|
|
36
|
+
- A `.onnx` file.
|
|
37
|
+
- A PyTorch checkpoint: `.pt`, `.pth`, `.bin` or `.ckpt`.
|
|
38
|
+
- A downloaded Hugging Face repo directory with a `config.json`.
|
|
39
|
+
- `package.module:attr`: an `nn.Module`, or a function that returns one.
|
|
40
|
+
|
|
41
|
+
Exit codes of `check` and `export`: `0` CLEAN, `1` FAILED, `2` DEGRADED, `3` UNVERIFIED, `4` usage error, `5` crash. `serve` exits with `4` or `5` only before the server is ready. `serve` serves all four verdicts.
|
|
42
|
+
|
|
43
|
+
Known problems and their fixes:
|
|
44
|
+
|
|
45
|
+
- A model with only bfloat16 weights: ONNX Runtime has no bf16 kernels on the CPU. `--backend auto` serves torch. Do not give `--backend onnxruntime`.
|
|
46
|
+
- A `DEGRADED` verdict with `--backend onnxruntime`: this is a usage error. Remove `--backend onnxruntime`, or add `--force-onnx` if you accept wrong numbers.
|
|
47
|
+
- A `.pt` file that is a state dict: give `--model-class package.module:Class`.
|
|
48
|
+
- A `.pt` file with a pickled module: give `--unsafe-load` only if you trust the file.
|
|
49
|
+
- A `.onnx` file with `--backend torch`: give `--reference` with the PyTorch model.
|
|
50
|
+
- HTTPS: give `--ssl-certfile cert.pem --ssl-keyfile key.pem`. For an encrypted key, set `DOWNSHIFT_SSL_KEYFILE_PASSWORD`.
|
|
51
|
+
|
|
52
|
+
## Docs
|
|
53
|
+
|
|
54
|
+
- [README](README.md): install, serve, the gate, and examples.
|
|
55
|
+
- [HTTP API](docs/code-docs/http-api.md): all routes, bodies, status codes and wire formats.
|
|
56
|
+
- [CLI](docs/code-docs/cli.md): all commands, flags, environment variables and exit codes.
|
|
57
|
+
- [Python API](docs/code-docs/python-api.md): `check()`, `export()`, `app_for()` and `build_app()`.
|
|
58
|
+
- [Production](docs/production.md): HTTPS, the API key, probes, sizing and Kubernetes.
|
|
59
|
+
- [Adapters](docs/code-docs/adapters.md): add a model family.
|
|
60
|
+
- OpenAPI: `GET /openapi.json` on a running server.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "downshift-server"
|
|
7
|
-
version = "0.5.
|
|
7
|
+
version = "0.5.1"
|
|
8
8
|
description = "Serve PyTorch models over HTTP through ONNX Runtime. Downshift verifies each export against PyTorch before it serves, and it falls back to eager PyTorch."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12,<3.15"
|
|
@@ -41,7 +41,7 @@ dependencies = [
|
|
|
41
41
|
dev = [
|
|
42
42
|
"pytest>=7.0",
|
|
43
43
|
"pytest-cov>=5.0",
|
|
44
|
-
"ruff
|
|
44
|
+
"ruff==0.17.0", # pinned: CI and local runs must format the same way (0.17 also formats Markdown code blocks)
|
|
45
45
|
"mypy>=1.0",
|
|
46
46
|
"httpx>=0.24", # FastAPI TestClient
|
|
47
47
|
"safetensors>=0.4", # reference reader/writer for the binary wire format tests
|
|
@@ -106,12 +106,15 @@ def _prompts(root: Path) -> tuple[dict[str, str], str | None]:
|
|
|
106
106
|
def _pooling_mode(directory: Path) -> str:
|
|
107
107
|
config = _read_json(directory / "config.json")
|
|
108
108
|
if not isinstance(config, dict):
|
|
109
|
-
raise RecipeError(
|
|
109
|
+
raise RecipeError(
|
|
110
|
+
f"modules.json names a Pooling module but {directory} has no config.json. "
|
|
111
|
+
"The download is not complete. Download the repo again"
|
|
112
|
+
)
|
|
110
113
|
modes = [mode for flag, mode in _POOLING_FLAGS.items() if config.get(flag)]
|
|
111
114
|
if len(modes) != 1:
|
|
112
115
|
raise RecipeError(
|
|
113
116
|
f"{directory.name}/config.json enables {len(modes)} pooling modes. "
|
|
114
|
-
"Downshift applies exactly one"
|
|
117
|
+
"Downshift applies exactly one. Pass --pooling to select it"
|
|
115
118
|
)
|
|
116
119
|
return str(modes[0])
|
|
117
120
|
|
|
@@ -125,7 +128,9 @@ def read_recipe(path: Path) -> EmbeddingRecipe | None:
|
|
|
125
128
|
if modules is None:
|
|
126
129
|
return None
|
|
127
130
|
if not isinstance(modules, list):
|
|
128
|
-
raise RecipeError(
|
|
131
|
+
raise RecipeError(
|
|
132
|
+
"modules.json is not a list of modules. Pass --pooling to set the pooling"
|
|
133
|
+
)
|
|
129
134
|
pooling: str | None = None
|
|
130
135
|
normalize = False
|
|
131
136
|
transformer_dir = path
|
|
@@ -145,7 +150,10 @@ def read_recipe(path: Path) -> EmbeddingRecipe | None:
|
|
|
145
150
|
"serve the encoder's token-level output instead."
|
|
146
151
|
)
|
|
147
152
|
if pooling is None:
|
|
148
|
-
raise RecipeError(
|
|
153
|
+
raise RecipeError(
|
|
154
|
+
"modules.json has no Pooling module. Pass --pooling to set one, or "
|
|
155
|
+
"--pooling none to serve token vectors"
|
|
156
|
+
)
|
|
149
157
|
prompts, default_prompt = _prompts(path)
|
|
150
158
|
return EmbeddingRecipe(
|
|
151
159
|
pooling,
|
|
@@ -177,7 +185,7 @@ def resolve_recipe(
|
|
|
177
185
|
if pooling is not None or normalize is not None:
|
|
178
186
|
raise RecipeError(
|
|
179
187
|
"--pooling/--normalize apply to encoder-only repos. "
|
|
180
|
-
"This repo has a classification head"
|
|
188
|
+
"This repo has a classification head. Remove --pooling and --normalize"
|
|
181
189
|
)
|
|
182
190
|
return None
|
|
183
191
|
root = Path(path)
|
|
@@ -59,7 +59,10 @@ def load_from_file(path_str: str, attr: str = "ADAPTER") -> Adapter:
|
|
|
59
59
|
"""
|
|
60
60
|
path = Path(path_str)
|
|
61
61
|
if not path.is_file():
|
|
62
|
-
raise LoadError(
|
|
62
|
+
raise LoadError(
|
|
63
|
+
f"adapter file {path} does not exist. Give the path of a .py file, or one "
|
|
64
|
+
f"of these names: {', '.join(available())}"
|
|
65
|
+
)
|
|
63
66
|
spec = importlib.util.spec_from_file_location(f"downshift._custom_adapter_{path.stem}", path)
|
|
64
67
|
if spec is None or spec.loader is None:
|
|
65
68
|
raise LoadError(f"cannot import {path} as a Python module")
|
|
@@ -40,8 +40,9 @@ class TextIO:
|
|
|
40
40
|
if over:
|
|
41
41
|
rows = ", ".join(f"row {i}: {n}" for i, n in over.items())
|
|
42
42
|
raise ValueError(
|
|
43
|
-
f"text longer than this model reads ({self.max_length} tokens, from the "
|
|
44
|
-
f"
|
|
43
|
+
f"text longer than this model reads ({self.max_length} tokens, a limit from the "
|
|
44
|
+
f"model files) is refused and not cut. Token counts: {rows}. Send shorter "
|
|
45
|
+
"text, or split it into more rows"
|
|
45
46
|
)
|
|
46
47
|
padded = self.tokenizer.pad(encoded, return_tensors="np")
|
|
47
48
|
return {name: np.asarray(value) for name, value in padded.items()}
|