Skip to content

Commit 1ab6f87

Browse files
authored
Migrate to Ray Serve and capability-based inference API (#45)
1 parent 7251c47 commit 1ab6f87

127 files changed

Lines changed: 12559 additions & 4403 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env_example

Lines changed: 0 additions & 2 deletions
This file was deleted.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ dist/
1111
docs/build/*
1212
docs/source/generated/*
1313
.env
14+
site/
15+
CLAUDE.md
16+
celery_logs.log
17+
poc/

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232

3333
## Context
3434

35-
This library aims to provide a common ecosystem to launch inference for various Artificial Intelligence tasks from different providers (Open-AI, transformers, sam2, ...). It has first been implemented to work in par with the [Pixano](https://pixano.github.io/pixano/latest/) AI-powered annotation tool.
35+
This library provides a Ray Serve-based inference server for multimodal AI
36+
tasks. It was first built to support the
37+
[Pixano](https://pixano.github.io/pixano/latest/) AI-powered annotation tool
38+
and exposes typed deployment configs, a Python client, and a REST API for
39+
running deployed models.
3640

3741
## Installation
3842

deploy/sam2_example.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# =================================
2+
# Copyright: CEA-LIST/DIASI/SIALV
3+
# Author : pixano@cea.fr
4+
# License: CECILL-C
5+
# =================================
6+
7+
"""SAM2 deployment configuration for Pixano Inference.
8+
9+
Usage:
10+
pixano-inference --config deploy/sam2_example.py
11+
"""
12+
13+
from pixano_inference.configs import DeploymentConfig, ModelConfig, Sam2ImageParams, Sam2VideoParams
14+
from pixano_inference.impls.sam2.image import Sam2ImageModel
15+
from pixano_inference.impls.sam2.video import Sam2VideoModel
16+
17+
18+
models = [
19+
ModelConfig(
20+
name="sam2-image",
21+
model_class=Sam2ImageModel,
22+
model_params=Sam2ImageParams(path="facebook/sam2.1-hiera-tiny", torch_dtype="float32"),
23+
deployment=DeploymentConfig(num_gpus=0, min_replicas=0, max_replicas=1, max_batch_size=8),
24+
),
25+
ModelConfig(
26+
name="sam2-video",
27+
model_class=Sam2VideoModel,
28+
model_params=Sam2VideoParams(path="facebook/sam2.1-hiera-tiny", torch_dtype="float32"),
29+
deployment=DeploymentConfig(num_gpus=0, min_replicas=0, max_replicas=1, max_batch_size=1),
30+
),
31+
]

docs/README.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

docs/api-reference.md

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
<!---
2+
# =================================
3+
# Copyright: CEA-LIST/DIASI/SIALV
4+
# Author : pixano@cea.fr
5+
# License: CECILL-C
6+
# =================================
7+
--->
8+
9+
# Pixano Inference HTTP API
10+
11+
This document describes the HTTP API exposed by the Ray Serve-based Pixano
12+
Inference server.
13+
14+
**Base URL:** `http://<host>:<port>` with default `http://127.0.0.1:7463`
15+
16+
Start the server with a Python config file:
17+
18+
```bash
19+
pixano-inference --config models.py
20+
```
21+
22+
## Overview
23+
24+
- Models are loaded at startup from a Python `.py` config file passed to `--config`.
25+
- All inference routes are synchronous `POST` endpoints.
26+
- There are no runtime HTTP endpoints for deploying or undeploying models.
27+
- Every inference request includes a `model` field that must match a deployed model name.
28+
- Endpoint families are capability-based: segmentation, detection, tracking, and VLM.
29+
30+
## Service endpoints
31+
32+
| Method | Path | Purpose |
33+
| ------ | ---------------- | ------------------------------------ |
34+
| `GET` | `/` | Basic API metadata and docs link |
35+
| `GET` | `/health` | Liveness probe |
36+
| `GET` | `/ready` | Readiness summary |
37+
| `GET` | `/app/settings/` | Server settings and resource summary |
38+
| `GET` | `/app/models/` | List deployed models |
39+
40+
### `GET /app/settings/`
41+
42+
Example response:
43+
44+
```json
45+
{
46+
"app_name": "Pixano Inference",
47+
"app_version": "0.6.0",
48+
"app_description": "Pixano Inference API powered by Ray Serve",
49+
"num_cpus": 8,
50+
"num_gpus": 2,
51+
"num_nodes": 1,
52+
"gpus_used": 1.0,
53+
"gpu_to_model": {},
54+
"models": ["sam2-image"],
55+
"models_to_capability": {
56+
"sam2-image": "segmentation"
57+
}
58+
}
59+
```
60+
61+
### `GET /app/models/`
62+
63+
Returns a list of `ModelInfo` objects:
64+
65+
```json
66+
[
67+
{
68+
"name": "sam2-image",
69+
"capability": "segmentation",
70+
"model_path": "facebook/sam2-hiera-base-plus",
71+
"model_class": "Sam2ImageModel"
72+
}
73+
]
74+
```
75+
76+
## Inference endpoints
77+
78+
| Method | Path | Request schema | Response schema | Python client helper |
79+
| ------ | -------------------------- | --------------------- | ---------------------- | ----------------------- |
80+
| `POST` | `/inference/segmentation/` | `SegmentationRequest` | `SegmentationResponse` | `client.segmentation()` |
81+
| `POST` | `/inference/detection/` | `DetectionRequest` | `DetectionResponse` | `client.detection()` |
82+
| `POST` | `/inference/tracking/` | `TrackingRequest` | `TrackingResponse` | `client.tracking()` |
83+
| `POST` | `/inference/vlm/` | `VLMRequest` | `VLMResponse` | `client.vlm()` |
84+
85+
If a model exists but does not support the endpoint capability, the server
86+
returns `400`.
87+
88+
The request and response models are available from `pixano_inference.schemas`.
89+
90+
### Example: segmentation
91+
92+
```json
93+
{
94+
"model": "sam2-image",
95+
"image": "data:image/png;base64,...",
96+
"points": [[[200, 175]]],
97+
"labels": [[1]]
98+
}
99+
```
100+
101+
### Example: detection
102+
103+
```json
104+
{
105+
"model": "grounding-dino",
106+
"image": "http://images.cocodataset.org/val2017/000000039769.jpg",
107+
"classes": ["cat", "remote control"],
108+
"box_threshold": 0.3,
109+
"text_threshold": 0.2
110+
}
111+
```
112+
113+
## Response envelope
114+
115+
All inference endpoints return the same top-level envelope:
116+
117+
```json
118+
{
119+
"id": "ray-sam2-image-1739000000000",
120+
"status": "SUCCESS",
121+
"timestamp": "2026-01-01T12:00:00",
122+
"processing_time": 0.234,
123+
"metadata": {
124+
"model_name": "sam2-image",
125+
"capability": "segmentation",
126+
"model_class": "Sam2ImageModel"
127+
},
128+
"data": {}
129+
}
130+
```
131+
132+
| Field | Description |
133+
| ----------------- | ---------------------------------------------------------- |
134+
| `id` | Server-generated request identifier |
135+
| `status` | Inference status, typically `SUCCESS` |
136+
| `timestamp` | Response timestamp |
137+
| `processing_time` | End-to-end inference time in seconds |
138+
| `metadata` | Deployment metadata for the model that handled the request |
139+
| `data` | Capability-specific payload |
140+
141+
## Python client
142+
143+
```python
144+
import asyncio
145+
146+
from pixano_inference.client import PixanoInferenceClient
147+
from pixano_inference.schemas import SegmentationRequest
148+
149+
150+
async def main() -> None:
151+
client = PixanoInferenceClient.connect("http://localhost:7463")
152+
request = SegmentationRequest(
153+
model="sam2-image",
154+
image="data:image/png;base64,...",
155+
points=[[[200, 175]]],
156+
labels=[[1]],
157+
)
158+
response = await client.segmentation(request)
159+
print(response.processing_time)
160+
print(response.data.scores.to_numpy())
161+
162+
163+
asyncio.run(main())
164+
```
165+
166+
## Error responses
167+
168+
- `400` when the model exists but does not support the requested capability.
169+
- `404` when the requested model name is not deployed.
170+
- `422` when the request body fails schema validation.
171+
- `500` when inference fails inside the model deployment.
172+
173+
The Python client raises `fastapi.HTTPException` with the server error detail
174+
when a request is unsuccessful.

docs/api_reference/index.md

Lines changed: 20 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,58 +8,23 @@
88

99
# Pixano Inference API reference
1010

11-
## Client module
12-
13-
The client module contains the class for the API client. It is responsible for making requests to the API endpoints.
14-
15-
## Data module
16-
17-
The data module contains the functions to read (and later write) data from/to a database or file.
18-
19-
## Model registry module
20-
21-
The model registry module contains the functions to register a model to the application.
22-
23-
## Models module
24-
25-
The models module contains the inference models to perform the tasks Pixano Inference API is designed for.
26-
27-
The models include:
28-
29-
- `BaseInferenceModel`: Base class for all Pixano Inference API models.
30-
- `Sam2Model`: Model used to detect and segment objects in images and videos.
31-
- `TransformerModel`: Model instantiated from Transformers.
32-
- `VLLMModel`: Model instantiated from VLLM.
33-
34-
## Providers module
35-
36-
The providers module contains the functions to load a model and to perform inference either from a model provider or from an API provider.
37-
38-
The providers include:
39-
40-
- `BaseProvider`: Base class for all Pixano Inference API providers.
41-
- `Sam2Provider`: Provider used to instantiate a `Sam2Model` and call its methods.
42-
- `TransformersProvider`: Provider used to instantiate a `TransformerModel` and call its methods.
43-
- `VLLMProvider`: Provider used to instantiate a `VLLMModel` and call its methods.
44-
45-
## Pydantic module
46-
47-
The pydantic module contains the classes for data validation. It is used by the models, providers, and the application itself to validate the input/output of the API.
48-
49-
## Routers module
50-
51-
The routers module contains the routers for the API. Each router has a path prefix that defines the endpoint where it will be mounted in the API.
52-
53-
The routers swagger is accessible at at the `/docs` endpoint.
54-
55-
## Settings module
56-
57-
The settings module contains the configuration of the application.
58-
59-
## Tasks module
60-
61-
The tasks module contains the enums used to define the task that a model can perform.
62-
63-
## Utils module
64-
65-
The utils module contains the functions and classes used by the other modules.
11+
This section documents the public Python modules for the Ray Serve-based
12+
Pixano-Inference API.
13+
14+
## Public modules
15+
16+
- `pixano_inference.client`
17+
Python client for the HTTP API.
18+
- `pixano_inference.configs`
19+
Typed deployment configuration objects used in Python config files.
20+
- `pixano_inference.models`
21+
Base classes, I/O models, and `register_model` for custom deployments.
22+
- `pixano_inference.ray`
23+
Server bootstrap and Ray Serve integration.
24+
- `pixano_inference.schemas`
25+
HTTP-layer request/response schemas and shared helper types.
26+
- `pixano_inference.settings`
27+
Runtime settings exposed by the server.
28+
Task enums and task-string helpers.
29+
- `pixano_inference.utils`
30+
Shared helper utilities.

0 commit comments

Comments
 (0)