Metadata-Version: 2.5
Name: jbr-inference
Version: 0.1.0
Summary: Local inference service: one OpenAI-compatible API in front of GPU (llama.cpp) and NPU (OpenVINO) backends.
Project-URL: Homepage, https://github.com/jbr589/jbr-inference
Project-URL: Repository, https://github.com/jbr589/jbr-inference
Project-URL: Issues, https://github.com/jbr589/jbr-inference/issues
Author: Joffray Braga
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Requires-Python: >=3.11
Requires-Dist: fastapi>=0.115
Requires-Dist: httpx>=0.28.1
Requires-Dist: pydantic>=2.9
Requires-Dist: uvicorn>=0.32
Provides-Extra: all
Requires-Dist: llama-cpp-python[server]==0.3.34; extra == 'all'
Requires-Dist: nncf>=2.15; extra == 'all'
Requires-Dist: optimum-intel[openvino]>=1.24; extra == 'all'
Requires-Dist: protobuf>=5.28; extra == 'all'
Requires-Dist: sentencepiece>=0.2.2; extra == 'all'
Requires-Dist: torch>=2.5; extra == 'all'
Requires-Dist: transformers<5,>=4.46; extra == 'all'
Provides-Extra: gpu
Requires-Dist: llama-cpp-python[server]==0.3.34; extra == 'gpu'
Provides-Extra: npu
Requires-Dist: nncf>=2.15; extra == 'npu'
Requires-Dist: optimum-intel[openvino]>=1.24; extra == 'npu'
Requires-Dist: protobuf>=5.28; extra == 'npu'
Requires-Dist: sentencepiece>=0.2.2; extra == 'npu'
Requires-Dist: torch>=2.5; extra == 'npu'
Requires-Dist: transformers<5,>=4.46; extra == 'npu'
Description-Content-Type: text/markdown

# jbr-inference

A local inference service that exposes one OpenAI-compatible API and routes each model to its own backend: a GPU
backend (llama.cpp server, CUDA) or an NPU backend (OpenVINO), plus an in-memory fake backend for development and tests.

## Why

Running several local models on different accelerators usually means one server and one client convention per
backend. jbr-inference puts a single HTTP contract in front of them: a registry maps each model id to a backend,
a router dispatches the request, and a backend that is not running answers `503` instead of crashing the service.
Mixed GPU and NPU use is not a coded feature: it follows from the registry, each backend staying in its own process
and its own virtual environment.

## Install

```sh
python -m venv .venv && . .venv/bin/activate
pip install jbr-inference
```

The base package only needs FastAPI, Uvicorn, HTTPX and Pydantic. The real backends are optional extras
(`jbr-inference[gpu]`, `jbr-inference[npu]`) and are meant to live in separate virtual environments.

## Quick start

Runs as-is after the install above, without cloning this repository:

```sh
# Start the service with the built-in fake backend (no GPU, no NPU, no model weights)
python -m uvicorn jbr_inference.serving.app:app --host 127.0.0.1 --port 8000 &
sleep 3

# List the registered models
curl -s http://127.0.0.1:8000/v1/models

# Chat through the fake backend (deterministic answer, no network access)
curl -s http://127.0.0.1:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "fake-chat-7b", "messages": [{"role": "user", "content": "hello"}]}'

kill $!
```

The registry also lists GPU and NPU models: they are routable, but answer `503 backend_unavailable` until the
matching backend server is running.

## Architecture

- `jbr_inference/serving/`: the common contract (API, router, error envelope) and the fake backend.
- `jbr_inference/models/`: the model-to-backend registry (`registry.toml`) and quantization policies.
- `jbr_inference/backends/gpu/`: adapter and lifecycle manager for a local llama.cpp server.
- `jbr_inference/backends/npu/`: OpenVINO service for a static-shape encoder, and its conversion script.
- `jbr_inference/bench/`: a benchmark harness that calls the common API, never a backend directly.

The service listens on loopback only. The management API (`/admin/*`) is only active when
`JBR_INFERENCE_ENABLE_ADMIN=1`: otherwise its router is not mounted, and a request to `/admin/*` without a loopback
`Origin` header is refused with `403` (with one, it gets a plain `404`). When enabled, every `/admin/*` request
still has to carry a loopback `Origin` header.

## Measurements

One small run drives the common API against a real GPU model and a real NPU model, with invented prompts and texts
(3 requests each, 0 errors); the two figures measure different tasks and are not comparable with each other
([details](https://github.com/jbr589/jbr-inference/blob/main/docs/bench/results/2026-07-21.md)).

## Limitations

- The GPU and NPU backends were exercised on a single machine (an NVIDIA GPU under WSL2, an Intel NPU through a
  native Windows OpenVINO service). Other hardware and operating systems are untested.
- The NPU backend needs static input shapes (a fixed sequence length chosen at export time).
- The `usage` token counters returned by the real backends are zero: they are not wired yet.
- The GPU throughput in the benchmark is an estimate (about 4 characters per token), not a tokenizer count.
- Model weights are never shipped: they are fetched by the user, as described in the backend READMEs of the
  source tree.

## Language and contributions

Internal docs and code comments are in French. The README, package metadata and changelog are in English.

This is a mirror repository: contributions are reviewed and ported by hand. Issues are welcome;
pull requests are read but not merged as such, and a change that is accepted lands in a later release.
Security reports: see [SECURITY.md](https://github.com/jbr589/jbr-inference/blob/main/SECURITY.md).

## License

Apache License 2.0, see [LICENSE](https://github.com/jbr589/jbr-inference/blob/main/LICENSE) and [NOTICE](https://github.com/jbr589/jbr-inference/blob/main/NOTICE).
