mship 0.7.3__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.
Files changed (74) hide show
  1. mship-0.7.3/PKG-INFO +319 -0
  2. mship-0.7.3/README.md +233 -0
  3. mship-0.7.3/modelship/__init__.py +0 -0
  4. mship-0.7.3/modelship/deploy/__init__.py +0 -0
  5. mship-0.7.3/modelship/deploy/actor_options.py +186 -0
  6. mship-0.7.3/modelship/deploy/config.py +109 -0
  7. mship-0.7.3/modelship/deploy/effective_config.py +101 -0
  8. mship-0.7.3/modelship/deploy/serve_utils.py +468 -0
  9. mship-0.7.3/modelship/deploy/strategy.py +244 -0
  10. mship-0.7.3/modelship/driver.py +366 -0
  11. mship-0.7.3/modelship/infer/base_infer.py +467 -0
  12. mship-0.7.3/modelship/infer/base_serving.py +21 -0
  13. mship-0.7.3/modelship/infer/custom/custom_infer.py +89 -0
  14. mship-0.7.3/modelship/infer/custom/openai/serving_speech.py +56 -0
  15. mship-0.7.3/modelship/infer/custom/openai/serving_transcription.py +83 -0
  16. mship-0.7.3/modelship/infer/deploy_coordinator.py +204 -0
  17. mship-0.7.3/modelship/infer/diffusers/diffusers_infer.py +171 -0
  18. mship-0.7.3/modelship/infer/diffusers/openai/serving_image.py +230 -0
  19. mship-0.7.3/modelship/infer/image_serving_common.py +83 -0
  20. mship-0.7.3/modelship/infer/infer_config.py +621 -0
  21. mship-0.7.3/modelship/infer/llama_server/llama_server_infer.py +854 -0
  22. mship-0.7.3/modelship/infer/model_deployment.py +454 -0
  23. mship-0.7.3/modelship/infer/model_resolver.py +249 -0
  24. mship-0.7.3/modelship/infer/replica_coordinator.py +158 -0
  25. mship-0.7.3/modelship/infer/stable_diffusion_cpp/openai/serving_image.py +181 -0
  26. mship-0.7.3/modelship/infer/stable_diffusion_cpp/stable_diffusion_cpp_infer.py +138 -0
  27. mship-0.7.3/modelship/infer/vllm/capabilities.py +20 -0
  28. mship-0.7.3/modelship/infer/vllm/engine_ops.py +632 -0
  29. mship-0.7.3/modelship/infer/vllm/openai/serving_speech.py +6 -0
  30. mship-0.7.3/modelship/infer/vllm/parsing/__init__.py +6 -0
  31. mship-0.7.3/modelship/infer/vllm/parsing/detect.py +252 -0
  32. mship-0.7.3/modelship/infer/vllm/vllm_infer.py +863 -0
  33. mship-0.7.3/modelship/launcher.py +163 -0
  34. mship-0.7.3/modelship/logging.py +229 -0
  35. mship-0.7.3/modelship/metrics.py +409 -0
  36. mship-0.7.3/modelship/openai/api.py +1074 -0
  37. mship-0.7.3/modelship/openai/auth.py +186 -0
  38. mship-0.7.3/modelship/openai/compaction_crypto.py +99 -0
  39. mship-0.7.3/modelship/openai/protocol/__init__.py +169 -0
  40. mship-0.7.3/modelship/openai/protocol/audio.py +170 -0
  41. mship-0.7.3/modelship/openai/protocol/base.py +21 -0
  42. mship-0.7.3/modelship/openai/protocol/chat.py +194 -0
  43. mship-0.7.3/modelship/openai/protocol/embeddings.py +43 -0
  44. mship-0.7.3/modelship/openai/protocol/error.py +67 -0
  45. mship-0.7.3/modelship/openai/protocol/images.py +115 -0
  46. mship-0.7.3/modelship/openai/protocol/raw.py +57 -0
  47. mship-0.7.3/modelship/openai/protocol/responses/__init__.py +73 -0
  48. mship-0.7.3/modelship/openai/protocol/responses/adapter.py +361 -0
  49. mship-0.7.3/modelship/openai/protocol/responses/schemas.py +227 -0
  50. mship-0.7.3/modelship/openai/protocol/responses/streaming.py +393 -0
  51. mship-0.7.3/modelship/openai/protocol/usage.py +26 -0
  52. mship-0.7.3/modelship/openai/state/__init__.py +22 -0
  53. mship-0.7.3/modelship/openai/state/responses.py +119 -0
  54. mship-0.7.3/modelship/openai/utils/__init__.py +4 -0
  55. mship-0.7.3/modelship/openai/utils/chat.py +293 -0
  56. mship-0.7.3/modelship/openai/utils/responses.py +333 -0
  57. mship-0.7.3/modelship/plugins/base_plugin.py +147 -0
  58. mship-0.7.3/modelship/preflight/__init__.py +38 -0
  59. mship-0.7.3/modelship/preflight/base.py +501 -0
  60. mship-0.7.3/modelship/preflight/llama_cpp.py +531 -0
  61. mship-0.7.3/modelship/preflight/stable_diffusion_cpp.py +42 -0
  62. mship-0.7.3/modelship/preflight/vllm.py +896 -0
  63. mship-0.7.3/modelship/state/__init__.py +161 -0
  64. mship-0.7.3/modelship/state/base.py +83 -0
  65. mship-0.7.3/modelship/state/memory.py +208 -0
  66. mship-0.7.3/modelship/state/redis.py +129 -0
  67. mship-0.7.3/modelship/utils/__init__.py +113 -0
  68. mship-0.7.3/modelship/utils/accelerator.py +29 -0
  69. mship-0.7.3/modelship/utils/audio.py +69 -0
  70. mship-0.7.3/modelship/utils/cache.py +18 -0
  71. mship-0.7.3/modelship/utils/cli.py +250 -0
  72. mship-0.7.3/modelship/utils/ray_auth.py +25 -0
  73. mship-0.7.3/modelship/utils/request_id.py +23 -0
  74. mship-0.7.3/pyproject.toml +204 -0
mship-0.7.3/PKG-INFO ADDED
@@ -0,0 +1,319 @@
1
+ Metadata-Version: 2.3
2
+ Name: mship
3
+ Version: 0.7.3
4
+ Summary: The production backend for self-hosted agents — the OpenAI Responses API with server-side conversation state (durable with Redis), universal tool calling, and reasoning, alongside embeddings, speech, and image generation, behind one OpenAI-compatible endpoint. Built on Ray Serve.
5
+ Keywords: ai,inference,vllm,ray,ray-serve,openai,llm,agentic,tool-calling,reasoning,responses-api,multimodal,tts,stt,embeddings,image-generation,diffusers,self-hosted
6
+ Author: Alex Margarit
7
+ License: Apache-2.0
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Topic :: Home Automation
12
+ Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
13
+ Requires-Dist: argparse>=1.4.0
14
+ Requires-Dist: asyncio>=4.0.0
15
+ Requires-Dist: cryptography>=43.0.0
16
+ Requires-Dist: fastapi>=0.116.1
17
+ Requires-Dist: httpx>=0.28.1
18
+ Requires-Dist: huggingface-hub>=1.12.0
19
+ Requires-Dist: numpy>=2.2.6
20
+ Requires-Dist: pydantic>=2.12.0
21
+ Requires-Dist: pydantic-yaml>=1.6.0
22
+ Requires-Dist: python-multipart>=0.0.20
23
+ Requires-Dist: ray[data,default,serve-grpc]>=2.54.0
24
+ Requires-Dist: requests>=2.32.5
25
+ Requires-Dist: pip>=25.0
26
+ Requires-Dist: psutil>=5.9
27
+ Requires-Dist: gguf>=0.18.0
28
+ Requires-Dist: redis>=8.0.0
29
+ Requires-Dist: torch>=2.10.0 ; extra == 'cpu'
30
+ Requires-Dist: torchvision>=0.25.0 ; extra == 'cpu'
31
+ Requires-Dist: transformers>=5.5.3 ; extra == 'cpu'
32
+ Requires-Dist: stable-diffusion-cpp-python>=0.4.7 ; extra == 'cpu'
33
+ Requires-Dist: onnxruntime>=1.20.1 ; extra == 'cpu'
34
+ Requires-Dist: vllm==0.24.0 ; extra == 'cpu'
35
+ Requires-Dist: vllm[audio]==0.24.0 ; extra == 'cpu'
36
+ Requires-Dist: librosa>=0.11.0 ; extra == 'cpu'
37
+ Requires-Dist: scipy>=1.16.1 ; extra == 'cpu'
38
+ Requires-Dist: soundfile>=0.13.0 ; extra == 'cpu'
39
+ Requires-Dist: torch>=2.10.0 ; extra == 'cuda'
40
+ Requires-Dist: torchvision>=0.25.0 ; extra == 'cuda'
41
+ Requires-Dist: transformers>=5.5.3 ; extra == 'cuda'
42
+ Requires-Dist: flashinfer-python>=0.6.1 ; extra == 'cuda'
43
+ Requires-Dist: vllm==0.24.0 ; extra == 'cuda'
44
+ Requires-Dist: vllm[audio]==0.24.0 ; extra == 'cuda'
45
+ Requires-Dist: bitsandbytes>=0.49.0 ; extra == 'cuda'
46
+ Requires-Dist: diffusers>=0.31.0 ; extra == 'cuda'
47
+ Requires-Dist: stable-diffusion-cpp-python>=0.4.7 ; extra == 'cuda'
48
+ Requires-Dist: onnxruntime-gpu>=1.20.1 ; extra == 'cuda'
49
+ Requires-Dist: nvidia-ml-py ; extra == 'cuda'
50
+ Requires-Dist: librosa>=0.11.0 ; extra == 'cuda'
51
+ Requires-Dist: scipy>=1.16.1 ; extra == 'cuda'
52
+ Requires-Dist: soundfile>=0.13.0 ; extra == 'cuda'
53
+ Requires-Dist: ruff>=0.11.0 ; extra == 'dev'
54
+ Requires-Dist: pyright>=1.1.400 ; extra == 'dev'
55
+ Requires-Dist: pytest>=8.0.0 ; extra == 'dev'
56
+ Requires-Dist: pytest-asyncio>=0.25.0 ; extra == 'dev'
57
+ Requires-Dist: pre-commit>=4.0.0 ; extra == 'dev'
58
+ Requires-Dist: fakeredis>=2.36.2 ; extra == 'dev'
59
+ Requires-Dist: mkdocs-material>=9.6.0 ; extra == 'docs'
60
+ Requires-Dist: kokoroonnx ; extra == 'kokoroonnx'
61
+ Requires-Dist: librosa>=0.11.0 ; extra == 'metal'
62
+ Requires-Dist: scipy>=1.16.1 ; extra == 'metal'
63
+ Requires-Dist: soundfile>=0.13.0 ; extra == 'metal'
64
+ Requires-Dist: onnxruntime>=1.20.1 ; extra == 'metal'
65
+ Requires-Dist: stable-diffusion-cpp-python>=0.4.7 ; extra == 'metal'
66
+ Requires-Dist: orpheus ; extra == 'orpheus'
67
+ Requires-Dist: opentelemetry-sdk>=1.20.0 ; extra == 'otel'
68
+ Requires-Dist: opentelemetry-exporter-otlp>=1.20.0 ; extra == 'otel'
69
+ Requires-Dist: whispercpp ; extra == 'whispercpp'
70
+ Requires-Python: ==3.12.10
71
+ Project-URL: Homepage, https://github.com/alez007/modelship
72
+ Project-URL: Documentation, https://docs.model-ship.ai/
73
+ Project-URL: Issues, https://github.com/alez007/modelship/issues
74
+ Project-URL: Changelog, https://github.com/alez007/modelship/blob/main/CHANGELOG.md
75
+ Provides-Extra: cpu
76
+ Provides-Extra: cuda
77
+ Provides-Extra: dev
78
+ Provides-Extra: docs
79
+ Provides-Extra: kokoroonnx
80
+ Provides-Extra: metal
81
+ Provides-Extra: orpheus
82
+ Provides-Extra: otel
83
+ Provides-Extra: thin
84
+ Provides-Extra: whispercpp
85
+ Description-Content-Type: text/markdown
86
+
87
+ <div align="center">
88
+ <picture>
89
+ <source media="(prefers-color-scheme: dark)" srcset="docs/assets/logo-dark.svg">
90
+ <source media="(prefers-color-scheme: light)" srcset="docs/assets/logo-light.svg">
91
+ <img alt="Modelship" src="docs/assets/logo-light.svg" width="160">
92
+ </picture>
93
+ </div>
94
+
95
+ # Modelship
96
+
97
+ [![CI](https://github.com/alez007/modelship/actions/workflows/ci.yml/badge.svg)](https://github.com/alez007/modelship/actions/workflows/ci.yml)
98
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
99
+ [![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
100
+ [![Docs](https://img.shields.io/badge/docs-docs.model--ship.ai-0E7C86.svg)](https://docs.model-ship.ai/)
101
+
102
+ Modelship runs the AI stack your agents call — chat, the **Responses API** with server-side conversation state (durable with Redis), universal **tool calling**, and **reasoning**, alongside embeddings, speech, and image generation — behind one OpenAI-compatible endpoint on your own GPUs (or CPU). Built on [Ray Serve](https://docs.ray.io/en/latest/serve/index.html): state is shared across gateway replicas, deploys are declarative, and everything is observable. Point the OpenAI SDK at it and your agent runs unchanged — private, with no per-token bill.
103
+
104
+ ## Why Modelship?
105
+
106
+ - **Agent state that isn't siloed per replica** — the `/v1/responses` API with reasoning, universal tool/function calling, and server-side conversation state (`previous_response_id`) live in one pluggable store shared by every gateway replica — in-memory by default, or Redis for durability across restarts and node failure. Works across both the vLLM and llama.cpp (`llama_server`) loaders.
107
+ - **Everything an agent app calls, one endpoint** — chat, embeddings for RAG, speech-to-text, text-to-speech, and image generation, all behind a single OpenAI-compatible `/v1` surface. No juggling separate services for each modality.
108
+ - **Drop-in OpenAI, on your hardware** — any OpenAI SDK client works out of the box. Point it at Modelship instead of the OpenAI API and your agent code doesn't change — it just runs privately, on infrastructure you control.
109
+ - **GPU memory control** — allocate exact GPU fractions per model (e.g. 70% for the LLM, 5% for TTS) so a full stack fits on hardware you already own
110
+ - **Mix and match backends** — vLLM for high-throughput GPU or CPU inference, llama.cpp for efficient quantized GGUF models, Diffusers for images, and a plugin system for custom backends — in the same deployment
111
+
112
+ ## Architecture
113
+
114
+ <picture>
115
+ <source media="(prefers-color-scheme: dark)" srcset="docs/assets/architecture-dark.svg">
116
+ <source media="(prefers-color-scheme: light)" srcset="docs/assets/architecture-light.svg">
117
+ <img alt="Modelship architecture: an agent app calls the Modelship gateway's OpenAI-compatible API, which exposes chat, embeddings, audio, and image endpoints plus a Responses API backed by a shared conversation-state store, routing round-robin to Ray Serve deployments across GPU and CPU cluster nodes." src="docs/assets/architecture-light.svg">
118
+ </picture>
119
+
120
+ Each model runs as an isolated [Ray Serve](https://docs.ray.io/en/latest/serve/index.html) deployment with its own lifecycle, health checks, and resource budget. Four inference backends are available:
121
+
122
+ | Backend | Best for | GPU required |
123
+ |---|---|---|
124
+ | **vLLM** | High-throughput chat, embeddings, transcription | No — installs on GPU or CPU |
125
+ | **llama.cpp** (`llama_server`) | High-efficiency quantized GGUF models (chat, embeddings, vision) | No |
126
+ | **Diffusers** | Image generation | Yes |
127
+ | **Custom (plugins)** | TTS backends (Kokoro ONNX, Orpheus), STT backends (whisper.cpp) | No |
128
+
129
+ Models can be deployed across multiple GPUs, run on CPU-only, or both — multiple deployments of the same model (e.g. one on GPU via vLLM, one on CPU via vLLM or llama.cpp) are load-balanced with round-robin routing. Each deployment can also scale horizontally with `num_replicas`.
130
+
131
+ ## Requirements
132
+
133
+ - **Docker** (or Python 3.12+ with `uv` for local development)
134
+ - **NVIDIA GPU** (optional) — 16 GB+ VRAM recommended for a full stack (LLM + TTS + STT + embeddings) via vLLM; 8 GB is sufficient for lighter setups. Not required when using the vLLM or llama.cpp backends on CPU
135
+ - **[NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html)** — required only when running GPU models in Docker
136
+ - **HuggingFace token** for gated models
137
+
138
+ ## Features
139
+
140
+ - **Multi-model, multi-GPU** — run chat, embedding, STT, TTS, and image generation models simultaneously across one or more GPUs with tunable per-model GPU memory allocation
141
+ - **CPU-only support** — run models without a GPU using the vLLM or llama.cpp (`llama_server`) backends (chat, embeddings, transcription, vision). Useful for development, testing, or small models that don't need GPU acceleration
142
+ - **Multiple inference backends** — vLLM for high-throughput GPU or CPU inference, llama.cpp for efficient quantized GGUF models on CPU or GPU, Diffusers for image generation, and a plugin system for custom backends
143
+ - **Zero-downtime hot-reloads** — modify your `models.yaml` and run a cluster reconcile; changes are applied incrementally without interrupting the API gateway or unchanged models
144
+ - **Advanced agentic capabilities** — native support for DeepSeek-style reasoning (`<think>` blocks parsed into `reasoning_content`) and universal tool/function calling across the vLLM and GGUF (`llama_server`) backends
145
+ - **Per-model isolated deployments** — each model runs in its own Ray Serve deployment with independent lifecycle, health checks, failure isolation, and configurable replica count
146
+ - **OpenAI-compatible API** — drop-in replacement for any OpenAI SDK client
147
+ - **Streaming** — SSE streaming for chat completions and TTS audio
148
+ - **Plugin system** — opt-in TTS and STT backends installed as isolated uv workspace packages
149
+ - **Multi-GPU & hybrid routing** — assign models to specific GPUs or run them on CPU-only; deploy the same model on both GPU and CPU and requests are load-balanced via round-robin; full tensor parallelism support for large models spanning multiple GPUs
150
+ - **Client disconnect detection** — cancels in-flight inference when the client disconnects, freeing GPU resources immediately
151
+ - **Security** — gateway API-key authentication (`MSHIP_API_KEYS`), Ray cluster token auth (`--ray-auth=token`), and configurable request payload/concurrency limits
152
+ - **Built-in observability** — Prometheus metrics, custom `modelship:*` metrics, vLLM engine stats, Ray cluster metrics, structured JSON logging, and OpenTelemetry log export; pre-built Grafana dashboard and alerting rules included
153
+
154
+ ## Supported OpenAI Endpoints
155
+
156
+ | Endpoint | Usecase |
157
+ |---|---|
158
+ | `POST /v1/chat/completions` | Chat / text generation (streaming and non-streaming) |
159
+ | `POST /v1/responses` | Responses API — text, reasoning, client-driven tool calls, and stored conversations (streaming and non-streaming) |
160
+ | `GET`/`DELETE /v1/responses/{id}` | Fetch or drop a stored response (`/input_items` lists its input) |
161
+ | `POST /v1/embeddings` | Text embeddings |
162
+ | `POST /v1/audio/transcriptions` | Speech-to-text |
163
+ | `POST /v1/audio/translations` | Audio translation |
164
+ | `POST /v1/audio/speech` | Text-to-speech (SSE streaming or single-response) |
165
+ | `POST /v1/images/generations` | Image generation |
166
+ | `GET /v1/models` | List available models |
167
+
168
+ ## Quick Start
169
+
170
+ The fastest way to try Modelship: run a tiny reasoning model on a laptop — no GPU required. Copy-paste this block and you'll have an OpenAI-compatible API on `http://localhost:8000` in a few minutes.
171
+
172
+ ```bash
173
+ mkdir -p models-cache && cat > models.yaml <<'EOF'
174
+ models:
175
+ - name: reasoning-qwen
176
+ model: "lmstudio-community/Qwen3-0.6B-GGUF:*Q4_K_M.gguf"
177
+ usecase: generate
178
+ loader: llama_server
179
+ num_cpus: 3
180
+ llama_server_config:
181
+ n_ctx: 4096 # Give reasoning space to think
182
+ EOF
183
+
184
+ docker run --rm --shm-size=8g \
185
+ -v ./models.yaml:/modelship/config/models.yaml \
186
+ -v ./models-cache:/.cache \
187
+ -p 8000:8000 \
188
+ ghcr.io/alez007/modelship:latest-cpu
189
+ ```
190
+
191
+ Images are multi-arch (amd64 + arm64), so this works on Apple Silicon and ARM Linux hosts too.
192
+
193
+ Once the server is up (look for `Deployed app 'modelship api' successfully`), call the **Responses API** and watch the model think:
194
+
195
+ ```bash
196
+ curl http://localhost:8000/v1/responses \
197
+ -H "Content-Type: application/json" \
198
+ -d '{
199
+ "model": "reasoning-qwen",
200
+ "input": "Which is larger, 9.11 or 9.9?"
201
+ }'
202
+ ```
203
+
204
+ The response includes both `output_text` and a first-class `reasoning` output item — the same server-side conversation state (`previous_response_id`) and tool-calling support work here as they do on GPU-backed models. `/v1/chat/completions` remains available too, if that's what your client speaks.
205
+
206
+ ### Apple Silicon (native, no Docker)
207
+
208
+ On a Mac, install `mship` directly and get full Metal GPU offload for GGUF models via `llama_server` (and image generation via `stable_diffusion_cpp`) — no container, no Linux VM. Install Xcode Command Line Tools first — `[metal]` compiles `stable-diffusion-cpp-python` from source on first install (a few minutes; `xcode-select -p` checks if you already have it):
209
+
210
+ ```bash
211
+ xcode-select --install # first-time only; skip if already installed
212
+ uv tool install "mship[metal]"
213
+ mship deploy --config models.yaml
214
+ ```
215
+
216
+ `uv tool install` auto-fetches the pinned Python 3.12.10 interpreter. `pip install "mship[metal]"` also works if you already have that exact version (same Xcode CLI Tools prerequisite applies). Bare `pip install mship`, `mship[cuda]`, or `mship[cpu]` are not supported install paths — those extras are for the Docker images only.
217
+
218
+ ### GPU (vLLM, Diffusers)
219
+
220
+ For high-throughput GPU inference, use the `-cuda` image and add `--gpus all`. You'll also need the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html) and an `HF_TOKEN` for gated models. Example `models.yaml` entries for vLLM, Diffusers, and multi-GPU setups live in [docs/model-configuration.md](docs/model-configuration.md); ready-to-run configs are in [config/examples/](config/examples/).
221
+
222
+ ```bash
223
+ docker run --rm --shm-size=8g --gpus all \
224
+ -e HF_TOKEN=your_token_here \
225
+ -v ./models.yaml:/modelship/config/models.yaml \
226
+ -v ./models-cache:/.cache \
227
+ -p 8000:8000 \
228
+ ghcr.io/alez007/modelship:latest-cuda
229
+ ```
230
+
231
+ > [!NOTE]
232
+ > `ghcr.io/alez007/modelship:latest` (bare tag, no suffix) is the **thin** control/coordinator image — no torch/vllm, for a driver/head role only. It cannot serve models by itself; always use `-cuda` or `-cpu` to actually run inference. See [docs/development.md](docs/development.md) for the full three-image breakdown.
233
+
234
+ > [!TIP]
235
+ > Always set `--shm-size=8g` (or higher) when running the docker container to prevent PyTorch from hitting shared memory limits during multi-process operations.
236
+
237
+ Hitting an error? Check [docs/troubleshooting.md](docs/troubleshooting.md).
238
+
239
+ ## Plugin Support
240
+
241
+ Modelship's TTS and STT systems are built around a plugin architecture — each backend is an opt-in package with its own isolated dependencies. Plugins ship inside this repo (`plugins/`) or can be installed from PyPI.
242
+
243
+ Built-in plugins:
244
+
245
+ - [Kokoro ONNX](plugins/kokoroonnx/README.md) — lightweight TTS via ONNX Runtime (CPU or GPU)
246
+ - [Orpheus](plugins/orpheus/README.md) — expressive TTS
247
+ - [whisper.cpp](plugins/whispercpp/README.md) — CPU-only STT via `pywhispercpp`
248
+
249
+ To enable plugins for local development, pass them as extras at sync time:
250
+
251
+ ```bash
252
+ uv sync --extra kokoroonnx
253
+ uv sync --extra kokoroonnx --extra whispercpp # multiple plugins
254
+ ```
255
+
256
+ For deployment, plugins are automatically loaded from standalone Python wheels via Ray's `runtime_env` when referenced in `models.yaml`. This ensures that complex backend dependencies don't pollute the main API gateway or other deployments.
257
+
258
+ For a full guide on writing your own plugin, see [Plugin Development](docs/plugins.md).
259
+
260
+ ## Documentation
261
+
262
+ Full docs are hosted at **[docs.model-ship.ai](https://docs.model-ship.ai/)**. The same source files are also browsable directly in this repo:
263
+
264
+ - [Development](docs/development.md) — dev environment setup, building, and running locally
265
+ - [Model Configuration](docs/model-configuration.md) — full `models.yaml` reference, GPU pinning, environment variables
266
+ - [Multi-node without Kubernetes](docs/multi-node-docker.md) — join VMs into one Ray cluster with plain `docker run`, no orchestrator
267
+ - [Architecture](docs/architecture.md) — system design, request lifecycle, plugin loading
268
+ - [Plugin Development](docs/plugins.md) — writing custom TTS/STT backends
269
+ - [Monitoring & Logging](docs/monitoring.md) — Prometheus metrics, Grafana dashboard, structured logging, health checks
270
+ - [Troubleshooting](docs/troubleshooting.md) — common first-run errors and fixes
271
+
272
+ ## Monitoring
273
+
274
+ Modelship exposes Prometheus metrics (Ray cluster, Ray Serve, vLLM, and custom `modelship:*` metrics) through a single scrape endpoint on port 8079. Metrics are **enabled by default** — set `MSHIP_METRICS=false` to disable. A pre-built [Grafana dashboard](docs/grafana-dashboard.json) and [Prometheus alerting rules](docs/prometheus-alerts.yml) are included in the repository.
275
+
276
+ Logging supports structured JSON output (`MSHIP_LOG_FORMAT=json`) and request ID correlation across Ray actor boundaries. Logs can be shipped to a remote syslog server (`--log-target syslog://host:514`) or an OpenTelemetry collector (`--otel-endpoint http://collector:4317`). Set `MSHIP_LOG_LEVEL` to `TRACE` for full request/response payloads, or `DEBUG` for detailed diagnostics without payloads.
277
+
278
+ See [Monitoring & Logging](docs/monitoring.md) for full details.
279
+
280
+ ## Production Readiness
281
+
282
+ Modelship is actively used and designed for stability in multi-tenant setups. Key guarantees include:
283
+
284
+ - **Mutex-backed deployments:** A cluster-wide deploy coordinator prevents VRAM exhaustion by ensuring models are never loaded concurrently if resources are tight.
285
+ - **Comprehensive HTTP-level tests:** The `tests/test_integration.py` suite validates chat, reasoning, tool-calling, and streaming across all loaders using real (small) models.
286
+ - **Security:** Gateway API-key auth, opt-in Ray cluster token auth, and payload/concurrency limits (`MSHIP_MAX_REQUEST_BODY_BYTES`) guard against unauthenticated or oversized requests.
287
+ - **Observability:** Deep integration with Prometheus, OpenTelemetry, and structured logging, with a pre-built Grafana dashboard and Prometheus alerting rules included.
288
+
289
+ We are currently hardening the Kubernetes/KubeRay path (a Helm chart ships in [`helm/`](helm/modelship/); GPU-aware probes and gateway-level rate-limiting are next). See the full [Production Readiness Plan](docs/production-readiness.md) for the scorecard and roadmap.
290
+
291
+ ## Open Responses Conformance
292
+
293
+ `/v1/responses` is also tested against the independent [Open Responses](https://github.com/openresponses/openresponses) compliance suite (`bun run test:compliance`), which exercises the endpoint over real HTTP against a live deployment rather than mocks.
294
+
295
+ **Latest result: 17/17** (`Qwen3-VL-8B-Instruct` AWQ, vLLM, 2026-07-24), including the full WebSocket transport suite:
296
+
297
+ | Test | Category | Status |
298
+ |---|---|---|
299
+ | Basic Text Response | Core | ✅ Pass |
300
+ | Assistant Message Phase | Core | ✅ Pass |
301
+ | Response Output Phase Schema | Core | ✅ Pass |
302
+ | Streaming Response | Core | ✅ Pass |
303
+ | System Prompt | Core | ✅ Pass |
304
+ | Multi-turn Conversation | Core | ✅ Pass |
305
+ | Tool Calling | Core | ✅ Pass |
306
+ | Compaction Endpoint | `/v1/responses/compact` | ✅ Pass |
307
+ | Compaction Missing Required Model | `/v1/responses/compact` | ✅ Pass |
308
+ | Image Input | Vision | ✅ Pass |
309
+ | WebSocket Response | WebSocket | ✅ Pass |
310
+ | WebSocket Sequential Responses | WebSocket | ✅ Pass |
311
+ | WebSocket Continuation | WebSocket | ✅ Pass |
312
+ | WebSocket Store False Reconnect Recovery | WebSocket | ✅ Pass |
313
+ | WebSocket Missing Previous Response | WebSocket | ✅ Pass |
314
+ | WebSocket Failed Continuation Evicts Cache | WebSocket | ✅ Pass |
315
+ | WebSocket Compact New Chain | WebSocket | ✅ Pass |
316
+
317
+ ## Contributing
318
+
319
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on setting up the dev environment, code style, and submitting pull requests.
mship-0.7.3/README.md ADDED
@@ -0,0 +1,233 @@
1
+ <div align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="docs/assets/logo-dark.svg">
4
+ <source media="(prefers-color-scheme: light)" srcset="docs/assets/logo-light.svg">
5
+ <img alt="Modelship" src="docs/assets/logo-light.svg" width="160">
6
+ </picture>
7
+ </div>
8
+
9
+ # Modelship
10
+
11
+ [![CI](https://github.com/alez007/modelship/actions/workflows/ci.yml/badge.svg)](https://github.com/alez007/modelship/actions/workflows/ci.yml)
12
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
13
+ [![Python 3.12+](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
14
+ [![Docs](https://img.shields.io/badge/docs-docs.model--ship.ai-0E7C86.svg)](https://docs.model-ship.ai/)
15
+
16
+ Modelship runs the AI stack your agents call — chat, the **Responses API** with server-side conversation state (durable with Redis), universal **tool calling**, and **reasoning**, alongside embeddings, speech, and image generation — behind one OpenAI-compatible endpoint on your own GPUs (or CPU). Built on [Ray Serve](https://docs.ray.io/en/latest/serve/index.html): state is shared across gateway replicas, deploys are declarative, and everything is observable. Point the OpenAI SDK at it and your agent runs unchanged — private, with no per-token bill.
17
+
18
+ ## Why Modelship?
19
+
20
+ - **Agent state that isn't siloed per replica** — the `/v1/responses` API with reasoning, universal tool/function calling, and server-side conversation state (`previous_response_id`) live in one pluggable store shared by every gateway replica — in-memory by default, or Redis for durability across restarts and node failure. Works across both the vLLM and llama.cpp (`llama_server`) loaders.
21
+ - **Everything an agent app calls, one endpoint** — chat, embeddings for RAG, speech-to-text, text-to-speech, and image generation, all behind a single OpenAI-compatible `/v1` surface. No juggling separate services for each modality.
22
+ - **Drop-in OpenAI, on your hardware** — any OpenAI SDK client works out of the box. Point it at Modelship instead of the OpenAI API and your agent code doesn't change — it just runs privately, on infrastructure you control.
23
+ - **GPU memory control** — allocate exact GPU fractions per model (e.g. 70% for the LLM, 5% for TTS) so a full stack fits on hardware you already own
24
+ - **Mix and match backends** — vLLM for high-throughput GPU or CPU inference, llama.cpp for efficient quantized GGUF models, Diffusers for images, and a plugin system for custom backends — in the same deployment
25
+
26
+ ## Architecture
27
+
28
+ <picture>
29
+ <source media="(prefers-color-scheme: dark)" srcset="docs/assets/architecture-dark.svg">
30
+ <source media="(prefers-color-scheme: light)" srcset="docs/assets/architecture-light.svg">
31
+ <img alt="Modelship architecture: an agent app calls the Modelship gateway's OpenAI-compatible API, which exposes chat, embeddings, audio, and image endpoints plus a Responses API backed by a shared conversation-state store, routing round-robin to Ray Serve deployments across GPU and CPU cluster nodes." src="docs/assets/architecture-light.svg">
32
+ </picture>
33
+
34
+ Each model runs as an isolated [Ray Serve](https://docs.ray.io/en/latest/serve/index.html) deployment with its own lifecycle, health checks, and resource budget. Four inference backends are available:
35
+
36
+ | Backend | Best for | GPU required |
37
+ |---|---|---|
38
+ | **vLLM** | High-throughput chat, embeddings, transcription | No — installs on GPU or CPU |
39
+ | **llama.cpp** (`llama_server`) | High-efficiency quantized GGUF models (chat, embeddings, vision) | No |
40
+ | **Diffusers** | Image generation | Yes |
41
+ | **Custom (plugins)** | TTS backends (Kokoro ONNX, Orpheus), STT backends (whisper.cpp) | No |
42
+
43
+ Models can be deployed across multiple GPUs, run on CPU-only, or both — multiple deployments of the same model (e.g. one on GPU via vLLM, one on CPU via vLLM or llama.cpp) are load-balanced with round-robin routing. Each deployment can also scale horizontally with `num_replicas`.
44
+
45
+ ## Requirements
46
+
47
+ - **Docker** (or Python 3.12+ with `uv` for local development)
48
+ - **NVIDIA GPU** (optional) — 16 GB+ VRAM recommended for a full stack (LLM + TTS + STT + embeddings) via vLLM; 8 GB is sufficient for lighter setups. Not required when using the vLLM or llama.cpp backends on CPU
49
+ - **[NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html)** — required only when running GPU models in Docker
50
+ - **HuggingFace token** for gated models
51
+
52
+ ## Features
53
+
54
+ - **Multi-model, multi-GPU** — run chat, embedding, STT, TTS, and image generation models simultaneously across one or more GPUs with tunable per-model GPU memory allocation
55
+ - **CPU-only support** — run models without a GPU using the vLLM or llama.cpp (`llama_server`) backends (chat, embeddings, transcription, vision). Useful for development, testing, or small models that don't need GPU acceleration
56
+ - **Multiple inference backends** — vLLM for high-throughput GPU or CPU inference, llama.cpp for efficient quantized GGUF models on CPU or GPU, Diffusers for image generation, and a plugin system for custom backends
57
+ - **Zero-downtime hot-reloads** — modify your `models.yaml` and run a cluster reconcile; changes are applied incrementally without interrupting the API gateway or unchanged models
58
+ - **Advanced agentic capabilities** — native support for DeepSeek-style reasoning (`<think>` blocks parsed into `reasoning_content`) and universal tool/function calling across the vLLM and GGUF (`llama_server`) backends
59
+ - **Per-model isolated deployments** — each model runs in its own Ray Serve deployment with independent lifecycle, health checks, failure isolation, and configurable replica count
60
+ - **OpenAI-compatible API** — drop-in replacement for any OpenAI SDK client
61
+ - **Streaming** — SSE streaming for chat completions and TTS audio
62
+ - **Plugin system** — opt-in TTS and STT backends installed as isolated uv workspace packages
63
+ - **Multi-GPU & hybrid routing** — assign models to specific GPUs or run them on CPU-only; deploy the same model on both GPU and CPU and requests are load-balanced via round-robin; full tensor parallelism support for large models spanning multiple GPUs
64
+ - **Client disconnect detection** — cancels in-flight inference when the client disconnects, freeing GPU resources immediately
65
+ - **Security** — gateway API-key authentication (`MSHIP_API_KEYS`), Ray cluster token auth (`--ray-auth=token`), and configurable request payload/concurrency limits
66
+ - **Built-in observability** — Prometheus metrics, custom `modelship:*` metrics, vLLM engine stats, Ray cluster metrics, structured JSON logging, and OpenTelemetry log export; pre-built Grafana dashboard and alerting rules included
67
+
68
+ ## Supported OpenAI Endpoints
69
+
70
+ | Endpoint | Usecase |
71
+ |---|---|
72
+ | `POST /v1/chat/completions` | Chat / text generation (streaming and non-streaming) |
73
+ | `POST /v1/responses` | Responses API — text, reasoning, client-driven tool calls, and stored conversations (streaming and non-streaming) |
74
+ | `GET`/`DELETE /v1/responses/{id}` | Fetch or drop a stored response (`/input_items` lists its input) |
75
+ | `POST /v1/embeddings` | Text embeddings |
76
+ | `POST /v1/audio/transcriptions` | Speech-to-text |
77
+ | `POST /v1/audio/translations` | Audio translation |
78
+ | `POST /v1/audio/speech` | Text-to-speech (SSE streaming or single-response) |
79
+ | `POST /v1/images/generations` | Image generation |
80
+ | `GET /v1/models` | List available models |
81
+
82
+ ## Quick Start
83
+
84
+ The fastest way to try Modelship: run a tiny reasoning model on a laptop — no GPU required. Copy-paste this block and you'll have an OpenAI-compatible API on `http://localhost:8000` in a few minutes.
85
+
86
+ ```bash
87
+ mkdir -p models-cache && cat > models.yaml <<'EOF'
88
+ models:
89
+ - name: reasoning-qwen
90
+ model: "lmstudio-community/Qwen3-0.6B-GGUF:*Q4_K_M.gguf"
91
+ usecase: generate
92
+ loader: llama_server
93
+ num_cpus: 3
94
+ llama_server_config:
95
+ n_ctx: 4096 # Give reasoning space to think
96
+ EOF
97
+
98
+ docker run --rm --shm-size=8g \
99
+ -v ./models.yaml:/modelship/config/models.yaml \
100
+ -v ./models-cache:/.cache \
101
+ -p 8000:8000 \
102
+ ghcr.io/alez007/modelship:latest-cpu
103
+ ```
104
+
105
+ Images are multi-arch (amd64 + arm64), so this works on Apple Silicon and ARM Linux hosts too.
106
+
107
+ Once the server is up (look for `Deployed app 'modelship api' successfully`), call the **Responses API** and watch the model think:
108
+
109
+ ```bash
110
+ curl http://localhost:8000/v1/responses \
111
+ -H "Content-Type: application/json" \
112
+ -d '{
113
+ "model": "reasoning-qwen",
114
+ "input": "Which is larger, 9.11 or 9.9?"
115
+ }'
116
+ ```
117
+
118
+ The response includes both `output_text` and a first-class `reasoning` output item — the same server-side conversation state (`previous_response_id`) and tool-calling support work here as they do on GPU-backed models. `/v1/chat/completions` remains available too, if that's what your client speaks.
119
+
120
+ ### Apple Silicon (native, no Docker)
121
+
122
+ On a Mac, install `mship` directly and get full Metal GPU offload for GGUF models via `llama_server` (and image generation via `stable_diffusion_cpp`) — no container, no Linux VM. Install Xcode Command Line Tools first — `[metal]` compiles `stable-diffusion-cpp-python` from source on first install (a few minutes; `xcode-select -p` checks if you already have it):
123
+
124
+ ```bash
125
+ xcode-select --install # first-time only; skip if already installed
126
+ uv tool install "mship[metal]"
127
+ mship deploy --config models.yaml
128
+ ```
129
+
130
+ `uv tool install` auto-fetches the pinned Python 3.12.10 interpreter. `pip install "mship[metal]"` also works if you already have that exact version (same Xcode CLI Tools prerequisite applies). Bare `pip install mship`, `mship[cuda]`, or `mship[cpu]` are not supported install paths — those extras are for the Docker images only.
131
+
132
+ ### GPU (vLLM, Diffusers)
133
+
134
+ For high-throughput GPU inference, use the `-cuda` image and add `--gpus all`. You'll also need the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html) and an `HF_TOKEN` for gated models. Example `models.yaml` entries for vLLM, Diffusers, and multi-GPU setups live in [docs/model-configuration.md](docs/model-configuration.md); ready-to-run configs are in [config/examples/](config/examples/).
135
+
136
+ ```bash
137
+ docker run --rm --shm-size=8g --gpus all \
138
+ -e HF_TOKEN=your_token_here \
139
+ -v ./models.yaml:/modelship/config/models.yaml \
140
+ -v ./models-cache:/.cache \
141
+ -p 8000:8000 \
142
+ ghcr.io/alez007/modelship:latest-cuda
143
+ ```
144
+
145
+ > [!NOTE]
146
+ > `ghcr.io/alez007/modelship:latest` (bare tag, no suffix) is the **thin** control/coordinator image — no torch/vllm, for a driver/head role only. It cannot serve models by itself; always use `-cuda` or `-cpu` to actually run inference. See [docs/development.md](docs/development.md) for the full three-image breakdown.
147
+
148
+ > [!TIP]
149
+ > Always set `--shm-size=8g` (or higher) when running the docker container to prevent PyTorch from hitting shared memory limits during multi-process operations.
150
+
151
+ Hitting an error? Check [docs/troubleshooting.md](docs/troubleshooting.md).
152
+
153
+ ## Plugin Support
154
+
155
+ Modelship's TTS and STT systems are built around a plugin architecture — each backend is an opt-in package with its own isolated dependencies. Plugins ship inside this repo (`plugins/`) or can be installed from PyPI.
156
+
157
+ Built-in plugins:
158
+
159
+ - [Kokoro ONNX](plugins/kokoroonnx/README.md) — lightweight TTS via ONNX Runtime (CPU or GPU)
160
+ - [Orpheus](plugins/orpheus/README.md) — expressive TTS
161
+ - [whisper.cpp](plugins/whispercpp/README.md) — CPU-only STT via `pywhispercpp`
162
+
163
+ To enable plugins for local development, pass them as extras at sync time:
164
+
165
+ ```bash
166
+ uv sync --extra kokoroonnx
167
+ uv sync --extra kokoroonnx --extra whispercpp # multiple plugins
168
+ ```
169
+
170
+ For deployment, plugins are automatically loaded from standalone Python wheels via Ray's `runtime_env` when referenced in `models.yaml`. This ensures that complex backend dependencies don't pollute the main API gateway or other deployments.
171
+
172
+ For a full guide on writing your own plugin, see [Plugin Development](docs/plugins.md).
173
+
174
+ ## Documentation
175
+
176
+ Full docs are hosted at **[docs.model-ship.ai](https://docs.model-ship.ai/)**. The same source files are also browsable directly in this repo:
177
+
178
+ - [Development](docs/development.md) — dev environment setup, building, and running locally
179
+ - [Model Configuration](docs/model-configuration.md) — full `models.yaml` reference, GPU pinning, environment variables
180
+ - [Multi-node without Kubernetes](docs/multi-node-docker.md) — join VMs into one Ray cluster with plain `docker run`, no orchestrator
181
+ - [Architecture](docs/architecture.md) — system design, request lifecycle, plugin loading
182
+ - [Plugin Development](docs/plugins.md) — writing custom TTS/STT backends
183
+ - [Monitoring & Logging](docs/monitoring.md) — Prometheus metrics, Grafana dashboard, structured logging, health checks
184
+ - [Troubleshooting](docs/troubleshooting.md) — common first-run errors and fixes
185
+
186
+ ## Monitoring
187
+
188
+ Modelship exposes Prometheus metrics (Ray cluster, Ray Serve, vLLM, and custom `modelship:*` metrics) through a single scrape endpoint on port 8079. Metrics are **enabled by default** — set `MSHIP_METRICS=false` to disable. A pre-built [Grafana dashboard](docs/grafana-dashboard.json) and [Prometheus alerting rules](docs/prometheus-alerts.yml) are included in the repository.
189
+
190
+ Logging supports structured JSON output (`MSHIP_LOG_FORMAT=json`) and request ID correlation across Ray actor boundaries. Logs can be shipped to a remote syslog server (`--log-target syslog://host:514`) or an OpenTelemetry collector (`--otel-endpoint http://collector:4317`). Set `MSHIP_LOG_LEVEL` to `TRACE` for full request/response payloads, or `DEBUG` for detailed diagnostics without payloads.
191
+
192
+ See [Monitoring & Logging](docs/monitoring.md) for full details.
193
+
194
+ ## Production Readiness
195
+
196
+ Modelship is actively used and designed for stability in multi-tenant setups. Key guarantees include:
197
+
198
+ - **Mutex-backed deployments:** A cluster-wide deploy coordinator prevents VRAM exhaustion by ensuring models are never loaded concurrently if resources are tight.
199
+ - **Comprehensive HTTP-level tests:** The `tests/test_integration.py` suite validates chat, reasoning, tool-calling, and streaming across all loaders using real (small) models.
200
+ - **Security:** Gateway API-key auth, opt-in Ray cluster token auth, and payload/concurrency limits (`MSHIP_MAX_REQUEST_BODY_BYTES`) guard against unauthenticated or oversized requests.
201
+ - **Observability:** Deep integration with Prometheus, OpenTelemetry, and structured logging, with a pre-built Grafana dashboard and Prometheus alerting rules included.
202
+
203
+ We are currently hardening the Kubernetes/KubeRay path (a Helm chart ships in [`helm/`](helm/modelship/); GPU-aware probes and gateway-level rate-limiting are next). See the full [Production Readiness Plan](docs/production-readiness.md) for the scorecard and roadmap.
204
+
205
+ ## Open Responses Conformance
206
+
207
+ `/v1/responses` is also tested against the independent [Open Responses](https://github.com/openresponses/openresponses) compliance suite (`bun run test:compliance`), which exercises the endpoint over real HTTP against a live deployment rather than mocks.
208
+
209
+ **Latest result: 17/17** (`Qwen3-VL-8B-Instruct` AWQ, vLLM, 2026-07-24), including the full WebSocket transport suite:
210
+
211
+ | Test | Category | Status |
212
+ |---|---|---|
213
+ | Basic Text Response | Core | ✅ Pass |
214
+ | Assistant Message Phase | Core | ✅ Pass |
215
+ | Response Output Phase Schema | Core | ✅ Pass |
216
+ | Streaming Response | Core | ✅ Pass |
217
+ | System Prompt | Core | ✅ Pass |
218
+ | Multi-turn Conversation | Core | ✅ Pass |
219
+ | Tool Calling | Core | ✅ Pass |
220
+ | Compaction Endpoint | `/v1/responses/compact` | ✅ Pass |
221
+ | Compaction Missing Required Model | `/v1/responses/compact` | ✅ Pass |
222
+ | Image Input | Vision | ✅ Pass |
223
+ | WebSocket Response | WebSocket | ✅ Pass |
224
+ | WebSocket Sequential Responses | WebSocket | ✅ Pass |
225
+ | WebSocket Continuation | WebSocket | ✅ Pass |
226
+ | WebSocket Store False Reconnect Recovery | WebSocket | ✅ Pass |
227
+ | WebSocket Missing Previous Response | WebSocket | ✅ Pass |
228
+ | WebSocket Failed Continuation Evicts Cache | WebSocket | ✅ Pass |
229
+ | WebSocket Compact New Chain | WebSocket | ✅ Pass |
230
+
231
+ ## Contributing
232
+
233
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on setting up the dev environment, code style, and submitting pull requests.
File without changes
File without changes