litserve 0.2.7__tar.gz → 0.2.8.dev0__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.
- {litserve-0.2.7/src/litserve.egg-info → litserve-0.2.8.dev0}/PKG-INFO +72 -70
- {litserve-0.2.7 → litserve-0.2.8.dev0}/README.md +68 -67
- {litserve-0.2.7 → litserve-0.2.8.dev0}/requirements.txt +1 -1
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/__about__.py +1 -1
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/loops/base.py +12 -32
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/loops/continuous_batching_loop.py +6 -5
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/loops/loops.py +4 -11
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/loops/simple_loops.py +17 -16
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/loops/streaming_loops.py +19 -18
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/server.py +59 -45
- litserve-0.2.8.dev0/src/litserve/transport/__init__.py +4 -0
- litserve-0.2.8.dev0/src/litserve/transport/base.py +20 -0
- litserve-0.2.8.dev0/src/litserve/transport/factory.py +38 -0
- litserve-0.2.8.dev0/src/litserve/transport/process_transport.py +44 -0
- {litserve-0.2.7/src/litserve → litserve-0.2.8.dev0/src/litserve/transport}/zmq_queue.py +1 -1
- litserve-0.2.8.dev0/src/litserve/transport/zmq_transport.py +42 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/utils.py +2 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0/src/litserve.egg-info}/PKG-INFO +72 -70
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve.egg-info/SOURCES.txt +7 -2
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve.egg-info/requires.txt +1 -1
- {litserve-0.2.7 → litserve-0.2.8.dev0}/LICENSE +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/MANIFEST.in +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/setup.cfg +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/setup.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/__init__.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/__main__.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/api.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/callbacks/__init__.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/callbacks/base.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/callbacks/defaults/__init__.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/callbacks/defaults/metric_callback.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/cli.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/connector.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/docker_builder.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/loggers.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/loops/__init__.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/middlewares.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/python_client.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/schema/__init__.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/schema/image.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/specs/__init__.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/specs/base.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/specs/openai.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/specs/openai_embedding.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/test_examples/__init__.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/test_examples/openai_embedding_spec_example.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/test_examples/openai_spec_example.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve/test_examples/simple_example.py +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve.egg-info/dependency_links.txt +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve.egg-info/entry_points.txt +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve.egg-info/not-zip-safe +0 -0
- {litserve-0.2.7 → litserve-0.2.8.dev0}/src/litserve.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: litserve
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.8.dev0
|
|
4
4
|
Summary: Lightweight AI server.
|
|
5
5
|
Home-page: https://github.com/Lightning-AI/litserve
|
|
6
6
|
Download-URL: https://github.com/Lightning-AI/litserve
|
|
@@ -30,7 +30,7 @@ License-File: LICENSE
|
|
|
30
30
|
Requires-Dist: fastapi>=0.100
|
|
31
31
|
Requires-Dist: uvicorn[standard]>=0.29.0
|
|
32
32
|
Requires-Dist: pyzmq>=22.0.0
|
|
33
|
-
Requires-Dist: starlette
|
|
33
|
+
Requires-Dist: starlette
|
|
34
34
|
Provides-Extra: test
|
|
35
35
|
Requires-Dist: asgi-lifespan; extra == "test"
|
|
36
36
|
Requires-Dist: coverage[toml]>=7.5.3; extra == "test"
|
|
@@ -62,6 +62,7 @@ Dynamic: download-url
|
|
|
62
62
|
Dynamic: home-page
|
|
63
63
|
Dynamic: keywords
|
|
64
64
|
Dynamic: license
|
|
65
|
+
Dynamic: license-file
|
|
65
66
|
Dynamic: project-url
|
|
66
67
|
Dynamic: provides-extra
|
|
67
68
|
Dynamic: requires-dist
|
|
@@ -89,10 +90,11 @@ LitServe is at least [2x faster](#performance) than plain FastAPI due to AI-spec
|
|
|
89
90
|
<div align='center'>
|
|
90
91
|
|
|
91
92
|
<pre>
|
|
92
|
-
✅ (2x)+ faster serving ✅ Easy to use
|
|
93
|
-
✅ Bring your own model ✅ PyTorch/JAX/TF/...
|
|
94
|
-
✅ GPU autoscaling ✅ Batching, Streaming
|
|
95
|
-
✅ Compound AI ✅ Integrate with vLLM
|
|
93
|
+
✅ (2x)+ faster serving ✅ Easy to use ✅ LLMs, non LLMs and more
|
|
94
|
+
✅ Bring your own model ✅ PyTorch/JAX/TF/... ✅ Built on FastAPI
|
|
95
|
+
✅ GPU autoscaling ✅ Batching, Streaming ✅ Self-host or ⚡️ managed
|
|
96
|
+
✅ Compound AI ✅ Integrate with vLLM, etc ✅ Serverless
|
|
97
|
+
|
|
96
98
|
</pre>
|
|
97
99
|
|
|
98
100
|
<div align='center'>
|
|
@@ -169,12 +171,23 @@ if __name__ == "__main__":
|
|
|
169
171
|
server.run(port=8000)
|
|
170
172
|
```
|
|
171
173
|
|
|
172
|
-
Now run the server via the command-line
|
|
174
|
+
Now run the server anywhere (local or cloud) via the command-line.
|
|
173
175
|
|
|
174
176
|
```bash
|
|
177
|
+
# Deploy to the cloud of your choice via Lightning AI (serverless, autoscaling, etc.)
|
|
178
|
+
lightning serve server.py
|
|
179
|
+
|
|
180
|
+
# Or run locally (self host anywhere)
|
|
181
|
+
lightning serve server.py --local
|
|
182
|
+
```
|
|
183
|
+
Learn more about managed hosting on [Lightning AI](#hosting-options).
|
|
184
|
+
|
|
185
|
+
You can also run the server manually:
|
|
186
|
+
|
|
187
|
+
```bash
|
|
175
188
|
python server.py
|
|
176
189
|
```
|
|
177
|
-
|
|
190
|
+
|
|
178
191
|
### Test the server
|
|
179
192
|
Run the auto-generated test client:
|
|
180
193
|
```bash
|
|
@@ -198,7 +211,7 @@ litgpt serve microsoft/phi-2
|
|
|
198
211
|
- LitAPI lets you easily build complex AI systems with one or more models ([docs](https://lightning.ai/docs/litserve/api-reference/litapi)).
|
|
199
212
|
- Use the setup method for one-time tasks like connecting models, DBs, and loading data ([docs](https://lightning.ai/docs/litserve/api-reference/litapi#setup)).
|
|
200
213
|
- LitServer handles optimizations like batching, GPU autoscaling, streaming, etc... ([docs](https://lightning.ai/docs/litserve/api-reference/litserver)).
|
|
201
|
-
- Self host on your
|
|
214
|
+
- Self host on your machines or create a fully managed deployment with Lightning ([learn more](https://lightning.ai/docs/litserve/features/deploy-on-cloud)).
|
|
202
215
|
|
|
203
216
|
[Learn how to make this server 200x faster](https://lightning.ai/docs/litserve/home/speed-up-serving-by-200x).
|
|
204
217
|
|
|
@@ -206,14 +219,7 @@ litgpt serve microsoft/phi-2
|
|
|
206
219
|
|
|
207
220
|
# Featured examples
|
|
208
221
|
Use LitServe to deploy any model or AI service: (Compound AI, Gen AI, classic ML, embeddings, LLMs, vision, audio, etc...)
|
|
209
|
-
|
|
210
|
-
<div align='center'>
|
|
211
|
-
<div width='200px'>
|
|
212
|
-
<video src="https://github.com/user-attachments/assets/5e73549a-bc0f-47a9-9d9c-5b54389be5de" width='200px' controls></video>
|
|
213
|
-
</div>
|
|
214
|
-
</div>
|
|
215
|
-
|
|
216
|
-
## Examples
|
|
222
|
+
|
|
217
223
|
<pre>
|
|
218
224
|
<strong>Toy model:</strong> <a target="_blank" href="#define-a-server">Hello world</a>
|
|
219
225
|
<strong>LLMs:</strong> <a target="_blank" href="https://lightning.ai/lightning-ai/studios/deploy-llama-3-2-vision-with-litserve">Llama 3.2</a>, <a target="_blank" href="https://lightning.ai/lightning-ai/studios/openai-fault-tolerant-proxy-server">LLM Proxy server</a>, <a target="_blank" href="https://lightning.ai/lightning-ai/studios/deploy-ai-agent-with-tool-use">Agent with tool use</a>
|
|
@@ -233,31 +239,59 @@ Use LitServe to deploy any model or AI service: (Compound AI, Gen AI, classic ML
|
|
|
233
239
|
|
|
234
240
|
|
|
235
241
|
|
|
236
|
-
# Features
|
|
237
|
-
State-of-the-art features:
|
|
238
242
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
✅ [Worker autoscaling](https://lightning.ai/docs/litserve/features/autoscaling)
|
|
246
|
-
✅ [Self-host on your machines](https://lightning.ai/docs/litserve/features/hosting-methods#host-on-your-own)
|
|
247
|
-
✅ [Host fully managed on Lightning AI](https://lightning.ai/docs/litserve/features/hosting-methods#host-on-lightning-studios)
|
|
248
|
-
✅ [Serve all models: (LLMs, vision, etc.)](https://lightning.ai/docs/litserve/examples)
|
|
249
|
-
✅ [Scale to zero (serverless)](https://lightning.ai/docs/litserve/features/streaming)
|
|
250
|
-
✅ [Supports PyTorch, JAX, TF, etc...](https://lightning.ai/docs/litserve/features/full-control)
|
|
251
|
-
✅ [OpenAPI compliant](https://www.openapis.org/)
|
|
252
|
-
✅ [Open AI compatibility](https://lightning.ai/docs/litserve/features/open-ai-spec)
|
|
253
|
-
✅ [Authentication](https://lightning.ai/docs/litserve/features/authentication)
|
|
254
|
-
✅ [Dockerization](https://lightning.ai/docs/litserve/features/dockerization-deployment)
|
|
243
|
+
# Hosting options
|
|
244
|
+
Self host LitServe anywhere or deploy to your favorite cloud via [Lightning AI](http://lightning.ai/deploy).
|
|
245
|
+
|
|
246
|
+
https://github.com/user-attachments/assets/ff83dab9-0c9f-4453-8dcb-fb9526726344
|
|
247
|
+
|
|
248
|
+
Self-hosting is ideal for hackers, students, and DIY developers while fully managed hosting is ideal for enterprise developers needing easy autoscaling, security, release management, and 99.995% uptime and observability.
|
|
255
249
|
|
|
250
|
+
To host on [Lightning AI](https://lightning.ai/deploy), simply add the `--cloud` arg, login and choose the cloud of your choice.
|
|
251
|
+
```bash
|
|
252
|
+
lightning serve api server.py --cloud
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
|
|
256
256
|
|
|
257
|
+
<div align='center'>
|
|
257
258
|
|
|
258
|
-
[
|
|
259
|
+
| [Feature](https://lightning.ai/docs/litserve/features) | Self Managed | [Fully Managed on Lightning](https://lightning.ai/deploy) |
|
|
260
|
+
|----------------------------------------------------------------------|-----------------------------------|------------------------------------|
|
|
261
|
+
| Docker-first deployment | ✅ DIY | ✅ One-click deploy |
|
|
262
|
+
| Cost | ✅ Free (DIY) | ✅ Generous [free tier](https://lightning.ai/pricing) with pay as you go |
|
|
263
|
+
| Full control | ✅ | ✅ |
|
|
264
|
+
| Use any engine (vLLM, etc.) | ✅ | ✅ vLLM, Ollama, LitServe, etc. |
|
|
265
|
+
| Own VPC | ✅ (manual setup) | ✅ Connect your own VPC |
|
|
266
|
+
| [(2x)+ faster than plain FastAPI](#performance) | ✅ | ✅ |
|
|
267
|
+
| [Bring your own model](https://lightning.ai/docs/litserve/features/full-control) | ✅ | ✅ |
|
|
268
|
+
| [Build compound systems (1+ models)](https://lightning.ai/docs/litserve/home) | ✅ | ✅ |
|
|
269
|
+
| [GPU autoscaling](https://lightning.ai/docs/litserve/features/gpu-inference) | ✅ | ✅ |
|
|
270
|
+
| [Batching](https://lightning.ai/docs/litserve/features/batching) | ✅ | ✅ |
|
|
271
|
+
| [Streaming](https://lightning.ai/docs/litserve/features/streaming) | ✅ | ✅ |
|
|
272
|
+
| [Worker autoscaling](https://lightning.ai/docs/litserve/features/autoscaling) | ✅ | ✅ |
|
|
273
|
+
| [Serve all models: (LLMs, vision, etc.)](https://lightning.ai/docs/litserve/examples) | ✅ | ✅ |
|
|
274
|
+
| [Supports PyTorch, JAX, TF, etc...](https://lightning.ai/docs/litserve/features/full-control) | ✅ | ✅ |
|
|
275
|
+
| [OpenAPI compliant](https://www.openapis.org/) | ✅ | ✅ |
|
|
276
|
+
| [Open AI compatibility](https://lightning.ai/docs/litserve/features/open-ai-spec) | ✅ | ✅ |
|
|
277
|
+
| [Authentication](https://lightning.ai/docs/litserve/features/authentication) | ❌ DIY | ✅ Token, password, custom |
|
|
278
|
+
| GPUs | ❌ DIY | ✅ 8+ GPU types, H100s from $1.75 |
|
|
279
|
+
| Load balancing | ❌ | ✅ Built-in |
|
|
280
|
+
| Scale to zero (serverless) | ❌ | ✅ No machine runs when idle |
|
|
281
|
+
| Autoscale up on demand | ❌ | ✅ Auto scale up/down |
|
|
282
|
+
| Multi-node inference | ❌ | ✅ Distribute across nodes |
|
|
283
|
+
| Use AWS/GCP credits | ❌ | ✅ Use existing cloud commits |
|
|
284
|
+
| Versioning | ❌ | ✅ Make and roll back releases |
|
|
285
|
+
| Enterprise-grade uptime (99.95%) | ❌ | ✅ SLA-backed |
|
|
286
|
+
| SOC2 / HIPAA compliance | ❌ | ✅ Certified & secure |
|
|
287
|
+
| Observability | ❌ | ✅ Built-in, connect 3rd party tools|
|
|
288
|
+
| CI/CD ready | ❌ | ✅ Lightning SDK |
|
|
289
|
+
| 24/7 enterprise support | ❌ | ✅ Dedicated support |
|
|
290
|
+
| Cost controls & audit logs | ❌ | ✅ Budgets, breakdowns, logs |
|
|
291
|
+
| Debug on GPUs | ❌ | ✅ Studio integration |
|
|
292
|
+
| [20+ features](https://lightning.ai/docs/litserve/features) | - | - |
|
|
259
293
|
|
|
260
|
-
|
|
294
|
+
</div>
|
|
261
295
|
|
|
262
296
|
|
|
263
297
|
|
|
@@ -276,40 +310,8 @@ These results are for image and text classification ML tasks. The performance re
|
|
|
276
310
|
|
|
277
311
|
***💡 Note on LLM serving:*** For high-performance LLM serving (like Ollama/vLLM), integrate [vLLM with LitServe](https://lightning.ai/lightning-ai/studios/deploy-a-private-llama-3-2-rag-api), use [LitGPT](https://github.com/Lightning-AI/litgpt?tab=readme-ov-file#deploy-an-llm), or build your custom vLLM-like server with LitServe. Optimizations like kv-caching, which can be done with LitServe, are needed to maximize LLM performance.
|
|
278
312
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
# Hosting options
|
|
282
|
-
LitServe can be hosted independently on your own machines or fully managed via Lightning Studios.
|
|
283
|
-
|
|
284
|
-
Self-hosting is ideal for hackers, students, and DIY developers, while fully managed hosting is ideal for enterprise developers needing easy autoscaling, security, release management, and 99.995% uptime and observability.
|
|
285
|
-
|
|
286
313
|
|
|
287
314
|
|
|
288
|
-
<div align="center">
|
|
289
|
-
<a target="_blank" href="https://lightning.ai/lightning-ai/studios/litserve-hello-world">
|
|
290
|
-
<img src="https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/app-2/host-on-lightning.svg" alt="Host on Lightning"/>
|
|
291
|
-
</a>
|
|
292
|
-
</div>
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
<div align='center'>
|
|
297
|
-
|
|
298
|
-
| Feature | Self Managed | Fully Managed on Studios |
|
|
299
|
-
|----------------------------------|-----------------------------------|-------------------------------------|
|
|
300
|
-
| Deployment | ✅ Do it yourself deployment | ✅ One-button cloud deploy |
|
|
301
|
-
| Load balancing | ❌ | ✅ |
|
|
302
|
-
| Autoscaling | ❌ | ✅ |
|
|
303
|
-
| Scale to zero | ❌ | ✅ |
|
|
304
|
-
| Multi-machine inference | ❌ | ✅ |
|
|
305
|
-
| Authentication | ❌ | ✅ |
|
|
306
|
-
| Own VPC | ❌ | ✅ |
|
|
307
|
-
| AWS, GCP | ❌ | ✅ |
|
|
308
|
-
| Use your own cloud commits | ❌ | ✅ |
|
|
309
|
-
|
|
310
|
-
</div>
|
|
311
|
-
|
|
312
|
-
|
|
313
315
|
|
|
314
316
|
# Community
|
|
315
317
|
LitServe is a [community project accepting contributions](https://lightning.ai/docs/litserve/community) - Let's make the world's most advanced AI inference engine.
|
|
@@ -19,10 +19,11 @@ LitServe is at least [2x faster](#performance) than plain FastAPI due to AI-spec
|
|
|
19
19
|
<div align='center'>
|
|
20
20
|
|
|
21
21
|
<pre>
|
|
22
|
-
✅ (2x)+ faster serving ✅ Easy to use
|
|
23
|
-
✅ Bring your own model ✅ PyTorch/JAX/TF/...
|
|
24
|
-
✅ GPU autoscaling ✅ Batching, Streaming
|
|
25
|
-
✅ Compound AI ✅ Integrate with vLLM
|
|
22
|
+
✅ (2x)+ faster serving ✅ Easy to use ✅ LLMs, non LLMs and more
|
|
23
|
+
✅ Bring your own model ✅ PyTorch/JAX/TF/... ✅ Built on FastAPI
|
|
24
|
+
✅ GPU autoscaling ✅ Batching, Streaming ✅ Self-host or ⚡️ managed
|
|
25
|
+
✅ Compound AI ✅ Integrate with vLLM, etc ✅ Serverless
|
|
26
|
+
|
|
26
27
|
</pre>
|
|
27
28
|
|
|
28
29
|
<div align='center'>
|
|
@@ -99,12 +100,23 @@ if __name__ == "__main__":
|
|
|
99
100
|
server.run(port=8000)
|
|
100
101
|
```
|
|
101
102
|
|
|
102
|
-
Now run the server via the command-line
|
|
103
|
+
Now run the server anywhere (local or cloud) via the command-line.
|
|
103
104
|
|
|
104
105
|
```bash
|
|
106
|
+
# Deploy to the cloud of your choice via Lightning AI (serverless, autoscaling, etc.)
|
|
107
|
+
lightning serve server.py
|
|
108
|
+
|
|
109
|
+
# Or run locally (self host anywhere)
|
|
110
|
+
lightning serve server.py --local
|
|
111
|
+
```
|
|
112
|
+
Learn more about managed hosting on [Lightning AI](#hosting-options).
|
|
113
|
+
|
|
114
|
+
You can also run the server manually:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
105
117
|
python server.py
|
|
106
118
|
```
|
|
107
|
-
|
|
119
|
+
|
|
108
120
|
### Test the server
|
|
109
121
|
Run the auto-generated test client:
|
|
110
122
|
```bash
|
|
@@ -128,7 +140,7 @@ litgpt serve microsoft/phi-2
|
|
|
128
140
|
- LitAPI lets you easily build complex AI systems with one or more models ([docs](https://lightning.ai/docs/litserve/api-reference/litapi)).
|
|
129
141
|
- Use the setup method for one-time tasks like connecting models, DBs, and loading data ([docs](https://lightning.ai/docs/litserve/api-reference/litapi#setup)).
|
|
130
142
|
- LitServer handles optimizations like batching, GPU autoscaling, streaming, etc... ([docs](https://lightning.ai/docs/litserve/api-reference/litserver)).
|
|
131
|
-
- Self host on your
|
|
143
|
+
- Self host on your machines or create a fully managed deployment with Lightning ([learn more](https://lightning.ai/docs/litserve/features/deploy-on-cloud)).
|
|
132
144
|
|
|
133
145
|
[Learn how to make this server 200x faster](https://lightning.ai/docs/litserve/home/speed-up-serving-by-200x).
|
|
134
146
|
|
|
@@ -136,14 +148,7 @@ litgpt serve microsoft/phi-2
|
|
|
136
148
|
|
|
137
149
|
# Featured examples
|
|
138
150
|
Use LitServe to deploy any model or AI service: (Compound AI, Gen AI, classic ML, embeddings, LLMs, vision, audio, etc...)
|
|
139
|
-
|
|
140
|
-
<div align='center'>
|
|
141
|
-
<div width='200px'>
|
|
142
|
-
<video src="https://github.com/user-attachments/assets/5e73549a-bc0f-47a9-9d9c-5b54389be5de" width='200px' controls></video>
|
|
143
|
-
</div>
|
|
144
|
-
</div>
|
|
145
|
-
|
|
146
|
-
## Examples
|
|
151
|
+
|
|
147
152
|
<pre>
|
|
148
153
|
<strong>Toy model:</strong> <a target="_blank" href="#define-a-server">Hello world</a>
|
|
149
154
|
<strong>LLMs:</strong> <a target="_blank" href="https://lightning.ai/lightning-ai/studios/deploy-llama-3-2-vision-with-litserve">Llama 3.2</a>, <a target="_blank" href="https://lightning.ai/lightning-ai/studios/openai-fault-tolerant-proxy-server">LLM Proxy server</a>, <a target="_blank" href="https://lightning.ai/lightning-ai/studios/deploy-ai-agent-with-tool-use">Agent with tool use</a>
|
|
@@ -163,31 +168,59 @@ Use LitServe to deploy any model or AI service: (Compound AI, Gen AI, classic ML
|
|
|
163
168
|
|
|
164
169
|
|
|
165
170
|
|
|
166
|
-
# Features
|
|
167
|
-
State-of-the-art features:
|
|
168
171
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
✅ [Worker autoscaling](https://lightning.ai/docs/litserve/features/autoscaling)
|
|
176
|
-
✅ [Self-host on your machines](https://lightning.ai/docs/litserve/features/hosting-methods#host-on-your-own)
|
|
177
|
-
✅ [Host fully managed on Lightning AI](https://lightning.ai/docs/litserve/features/hosting-methods#host-on-lightning-studios)
|
|
178
|
-
✅ [Serve all models: (LLMs, vision, etc.)](https://lightning.ai/docs/litserve/examples)
|
|
179
|
-
✅ [Scale to zero (serverless)](https://lightning.ai/docs/litserve/features/streaming)
|
|
180
|
-
✅ [Supports PyTorch, JAX, TF, etc...](https://lightning.ai/docs/litserve/features/full-control)
|
|
181
|
-
✅ [OpenAPI compliant](https://www.openapis.org/)
|
|
182
|
-
✅ [Open AI compatibility](https://lightning.ai/docs/litserve/features/open-ai-spec)
|
|
183
|
-
✅ [Authentication](https://lightning.ai/docs/litserve/features/authentication)
|
|
184
|
-
✅ [Dockerization](https://lightning.ai/docs/litserve/features/dockerization-deployment)
|
|
172
|
+
# Hosting options
|
|
173
|
+
Self host LitServe anywhere or deploy to your favorite cloud via [Lightning AI](http://lightning.ai/deploy).
|
|
174
|
+
|
|
175
|
+
https://github.com/user-attachments/assets/ff83dab9-0c9f-4453-8dcb-fb9526726344
|
|
176
|
+
|
|
177
|
+
Self-hosting is ideal for hackers, students, and DIY developers while fully managed hosting is ideal for enterprise developers needing easy autoscaling, security, release management, and 99.995% uptime and observability.
|
|
185
178
|
|
|
179
|
+
To host on [Lightning AI](https://lightning.ai/deploy), simply add the `--cloud` arg, login and choose the cloud of your choice.
|
|
180
|
+
```bash
|
|
181
|
+
lightning serve api server.py --cloud
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
|
|
186
185
|
|
|
186
|
+
<div align='center'>
|
|
187
187
|
|
|
188
|
-
[
|
|
188
|
+
| [Feature](https://lightning.ai/docs/litserve/features) | Self Managed | [Fully Managed on Lightning](https://lightning.ai/deploy) |
|
|
189
|
+
|----------------------------------------------------------------------|-----------------------------------|------------------------------------|
|
|
190
|
+
| Docker-first deployment | ✅ DIY | ✅ One-click deploy |
|
|
191
|
+
| Cost | ✅ Free (DIY) | ✅ Generous [free tier](https://lightning.ai/pricing) with pay as you go |
|
|
192
|
+
| Full control | ✅ | ✅ |
|
|
193
|
+
| Use any engine (vLLM, etc.) | ✅ | ✅ vLLM, Ollama, LitServe, etc. |
|
|
194
|
+
| Own VPC | ✅ (manual setup) | ✅ Connect your own VPC |
|
|
195
|
+
| [(2x)+ faster than plain FastAPI](#performance) | ✅ | ✅ |
|
|
196
|
+
| [Bring your own model](https://lightning.ai/docs/litserve/features/full-control) | ✅ | ✅ |
|
|
197
|
+
| [Build compound systems (1+ models)](https://lightning.ai/docs/litserve/home) | ✅ | ✅ |
|
|
198
|
+
| [GPU autoscaling](https://lightning.ai/docs/litserve/features/gpu-inference) | ✅ | ✅ |
|
|
199
|
+
| [Batching](https://lightning.ai/docs/litserve/features/batching) | ✅ | ✅ |
|
|
200
|
+
| [Streaming](https://lightning.ai/docs/litserve/features/streaming) | ✅ | ✅ |
|
|
201
|
+
| [Worker autoscaling](https://lightning.ai/docs/litserve/features/autoscaling) | ✅ | ✅ |
|
|
202
|
+
| [Serve all models: (LLMs, vision, etc.)](https://lightning.ai/docs/litserve/examples) | ✅ | ✅ |
|
|
203
|
+
| [Supports PyTorch, JAX, TF, etc...](https://lightning.ai/docs/litserve/features/full-control) | ✅ | ✅ |
|
|
204
|
+
| [OpenAPI compliant](https://www.openapis.org/) | ✅ | ✅ |
|
|
205
|
+
| [Open AI compatibility](https://lightning.ai/docs/litserve/features/open-ai-spec) | ✅ | ✅ |
|
|
206
|
+
| [Authentication](https://lightning.ai/docs/litserve/features/authentication) | ❌ DIY | ✅ Token, password, custom |
|
|
207
|
+
| GPUs | ❌ DIY | ✅ 8+ GPU types, H100s from $1.75 |
|
|
208
|
+
| Load balancing | ❌ | ✅ Built-in |
|
|
209
|
+
| Scale to zero (serverless) | ❌ | ✅ No machine runs when idle |
|
|
210
|
+
| Autoscale up on demand | ❌ | ✅ Auto scale up/down |
|
|
211
|
+
| Multi-node inference | ❌ | ✅ Distribute across nodes |
|
|
212
|
+
| Use AWS/GCP credits | ❌ | ✅ Use existing cloud commits |
|
|
213
|
+
| Versioning | ❌ | ✅ Make and roll back releases |
|
|
214
|
+
| Enterprise-grade uptime (99.95%) | ❌ | ✅ SLA-backed |
|
|
215
|
+
| SOC2 / HIPAA compliance | ❌ | ✅ Certified & secure |
|
|
216
|
+
| Observability | ❌ | ✅ Built-in, connect 3rd party tools|
|
|
217
|
+
| CI/CD ready | ❌ | ✅ Lightning SDK |
|
|
218
|
+
| 24/7 enterprise support | ❌ | ✅ Dedicated support |
|
|
219
|
+
| Cost controls & audit logs | ❌ | ✅ Budgets, breakdowns, logs |
|
|
220
|
+
| Debug on GPUs | ❌ | ✅ Studio integration |
|
|
221
|
+
| [20+ features](https://lightning.ai/docs/litserve/features) | - | - |
|
|
189
222
|
|
|
190
|
-
|
|
223
|
+
</div>
|
|
191
224
|
|
|
192
225
|
|
|
193
226
|
|
|
@@ -206,40 +239,8 @@ These results are for image and text classification ML tasks. The performance re
|
|
|
206
239
|
|
|
207
240
|
***💡 Note on LLM serving:*** For high-performance LLM serving (like Ollama/vLLM), integrate [vLLM with LitServe](https://lightning.ai/lightning-ai/studios/deploy-a-private-llama-3-2-rag-api), use [LitGPT](https://github.com/Lightning-AI/litgpt?tab=readme-ov-file#deploy-an-llm), or build your custom vLLM-like server with LitServe. Optimizations like kv-caching, which can be done with LitServe, are needed to maximize LLM performance.
|
|
208
241
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
# Hosting options
|
|
212
|
-
LitServe can be hosted independently on your own machines or fully managed via Lightning Studios.
|
|
213
|
-
|
|
214
|
-
Self-hosting is ideal for hackers, students, and DIY developers, while fully managed hosting is ideal for enterprise developers needing easy autoscaling, security, release management, and 99.995% uptime and observability.
|
|
215
|
-
|
|
216
242
|
|
|
217
243
|
|
|
218
|
-
<div align="center">
|
|
219
|
-
<a target="_blank" href="https://lightning.ai/lightning-ai/studios/litserve-hello-world">
|
|
220
|
-
<img src="https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/app-2/host-on-lightning.svg" alt="Host on Lightning"/>
|
|
221
|
-
</a>
|
|
222
|
-
</div>
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
<div align='center'>
|
|
227
|
-
|
|
228
|
-
| Feature | Self Managed | Fully Managed on Studios |
|
|
229
|
-
|----------------------------------|-----------------------------------|-------------------------------------|
|
|
230
|
-
| Deployment | ✅ Do it yourself deployment | ✅ One-button cloud deploy |
|
|
231
|
-
| Load balancing | ❌ | ✅ |
|
|
232
|
-
| Autoscaling | ❌ | ✅ |
|
|
233
|
-
| Scale to zero | ❌ | ✅ |
|
|
234
|
-
| Multi-machine inference | ❌ | ✅ |
|
|
235
|
-
| Authentication | ❌ | ✅ |
|
|
236
|
-
| Own VPC | ❌ | ✅ |
|
|
237
|
-
| AWS, GCP | ❌ | ✅ |
|
|
238
|
-
| Use your own cloud commits | ❌ | ✅ |
|
|
239
|
-
|
|
240
|
-
</div>
|
|
241
|
-
|
|
242
|
-
|
|
243
244
|
|
|
244
245
|
# Community
|
|
245
246
|
LitServe is a [community project accepting contributions](https://lightning.ai/docs/litserve/community) - Let's make the world's most advanced AI inference engine.
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
12
|
# See the License for the specific language governing permissions and
|
|
13
13
|
# limitations under the License.
|
|
14
|
-
__version__ = "0.2.
|
|
14
|
+
__version__ = "0.2.8.dev0"
|
|
15
15
|
__author__ = "Lightning-AI et al."
|
|
16
16
|
__author_email__ = "community@lightning.ai"
|
|
17
17
|
__license__ = "Apache-2.0"
|
|
@@ -15,7 +15,6 @@ import asyncio
|
|
|
15
15
|
import inspect
|
|
16
16
|
import logging
|
|
17
17
|
import pickle
|
|
18
|
-
import signal
|
|
19
18
|
import sys
|
|
20
19
|
import time
|
|
21
20
|
from abc import ABC
|
|
@@ -27,12 +26,14 @@ from starlette.formparsers import MultiPartParser
|
|
|
27
26
|
from litserve import LitAPI
|
|
28
27
|
from litserve.callbacks import CallbackRunner
|
|
29
28
|
from litserve.specs.base import LitSpec
|
|
29
|
+
from litserve.transport.base import MessageTransport
|
|
30
30
|
from litserve.utils import LitAPIStatus
|
|
31
|
-
from litserve.zmq_queue import Producer
|
|
32
31
|
|
|
33
32
|
logger = logging.getLogger(__name__)
|
|
34
33
|
# FastAPI writes form files to disk over 1MB by default, which prevents serialization by multiprocessing
|
|
35
34
|
MultiPartParser.max_file_size = sys.maxsize
|
|
35
|
+
# renamed in PR: https://github.com/encode/starlette/pull/2780
|
|
36
|
+
MultiPartParser.spool_max_size = sys.maxsize
|
|
36
37
|
|
|
37
38
|
|
|
38
39
|
def _inject_context(context: Union[List[dict], dict], func, *args, **kwargs):
|
|
@@ -152,7 +153,7 @@ class _BaseLoop(ABC):
|
|
|
152
153
|
device: str,
|
|
153
154
|
worker_id: int,
|
|
154
155
|
request_queue: Queue,
|
|
155
|
-
|
|
156
|
+
transport: MessageTransport,
|
|
156
157
|
max_batch_size: int,
|
|
157
158
|
batch_timeout: float,
|
|
158
159
|
stream: bool,
|
|
@@ -164,9 +165,7 @@ class _BaseLoop(ABC):
|
|
|
164
165
|
|
|
165
166
|
async def _wrapper():
|
|
166
167
|
logger.info("Running LitLoop in a asyncio event loop")
|
|
167
|
-
future = self.schedule_task(
|
|
168
|
-
lit_api, lit_spec, request_queue, max_batch_size, batch_timeout, response_queues
|
|
169
|
-
)
|
|
168
|
+
future = self.schedule_task(lit_api, lit_spec, request_queue, max_batch_size, batch_timeout, transport)
|
|
170
169
|
_ = event_loop.create_task(future)
|
|
171
170
|
while True:
|
|
172
171
|
try:
|
|
@@ -176,7 +175,7 @@ class _BaseLoop(ABC):
|
|
|
176
175
|
device,
|
|
177
176
|
worker_id,
|
|
178
177
|
request_queue,
|
|
179
|
-
|
|
178
|
+
transport,
|
|
180
179
|
max_batch_size,
|
|
181
180
|
batch_timeout,
|
|
182
181
|
stream,
|
|
@@ -196,7 +195,7 @@ class _BaseLoop(ABC):
|
|
|
196
195
|
device,
|
|
197
196
|
worker_id,
|
|
198
197
|
request_queue,
|
|
199
|
-
|
|
198
|
+
transport,
|
|
200
199
|
max_batch_size,
|
|
201
200
|
batch_timeout,
|
|
202
201
|
stream,
|
|
@@ -211,7 +210,7 @@ class _BaseLoop(ABC):
|
|
|
211
210
|
device: str,
|
|
212
211
|
worker_id: int,
|
|
213
212
|
request_queue: Queue,
|
|
214
|
-
|
|
213
|
+
transport: MessageTransport,
|
|
215
214
|
max_batch_size: int,
|
|
216
215
|
batch_timeout: float,
|
|
217
216
|
stream: bool,
|
|
@@ -223,9 +222,7 @@ class _BaseLoop(ABC):
|
|
|
223
222
|
|
|
224
223
|
class LitLoop(_BaseLoop):
|
|
225
224
|
def __init__(self):
|
|
226
|
-
self.producer: Optional[Producer] = None
|
|
227
225
|
self._context = {}
|
|
228
|
-
self._setup_signal_handlers()
|
|
229
226
|
|
|
230
227
|
def get_batch_requests(self, lit_api: LitAPI, request_queue: Queue, max_batch_size: int, batch_timeout: float):
|
|
231
228
|
batches, timed_out_uids = collate_requests(
|
|
@@ -247,32 +244,15 @@ class LitLoop(_BaseLoop):
|
|
|
247
244
|
lit_spec.populate_context(self._context, request)
|
|
248
245
|
|
|
249
246
|
def put_response(
|
|
250
|
-
self,
|
|
247
|
+
self, transport: MessageTransport, response_queue_id: int, uid: str, response_data: Any, status: LitAPIStatus
|
|
251
248
|
) -> None:
|
|
252
|
-
|
|
253
|
-
self.producer.put((uid, (response_data, status)), consumer_id=response_queue_id)
|
|
254
|
-
else:
|
|
255
|
-
response_queues[response_queue_id].put((uid, (response_data, status)), block=False)
|
|
249
|
+
transport.send((uid, (response_data, status)), consumer_id=response_queue_id)
|
|
256
250
|
|
|
257
251
|
def put_error_response(
|
|
258
|
-
self,
|
|
252
|
+
self, transport: MessageTransport, response_queue_id: int, uid: str, error: Exception
|
|
259
253
|
) -> None:
|
|
260
254
|
error = pickle.dumps(error)
|
|
261
|
-
self.put_response(
|
|
262
|
-
|
|
263
|
-
def __del__(self):
|
|
264
|
-
if self.producer:
|
|
265
|
-
self.producer.close()
|
|
266
|
-
|
|
267
|
-
def _setup_signal_handlers(self):
|
|
268
|
-
def cleanup_handler(signum=None, frame=None):
|
|
269
|
-
logging.debug("Worker process received shutdown signal")
|
|
270
|
-
if self.producer:
|
|
271
|
-
self.producer.close()
|
|
272
|
-
sys.exit(0)
|
|
273
|
-
|
|
274
|
-
signal.signal(signal.SIGINT, cleanup_handler)
|
|
275
|
-
signal.signal(signal.SIGTERM, cleanup_handler)
|
|
255
|
+
self.put_response(transport, response_queue_id, uid, error, LitAPIStatus.ERROR)
|
|
276
256
|
|
|
277
257
|
|
|
278
258
|
class DefaultLoop(LitLoop):
|
|
@@ -23,6 +23,7 @@ from litserve import LitAPI
|
|
|
23
23
|
from litserve.callbacks import CallbackRunner
|
|
24
24
|
from litserve.loops.base import LitLoop
|
|
25
25
|
from litserve.specs.base import LitSpec
|
|
26
|
+
from litserve.transport.base import MessageTransport
|
|
26
27
|
from litserve.utils import LitAPIStatus
|
|
27
28
|
|
|
28
29
|
logger = logging.getLogger(__name__)
|
|
@@ -185,7 +186,7 @@ requires the lit_api to have a has_finished method. Please implement the has_fin
|
|
|
185
186
|
device: str,
|
|
186
187
|
worker_id: int,
|
|
187
188
|
request_queue: Queue,
|
|
188
|
-
|
|
189
|
+
transport: MessageTransport,
|
|
189
190
|
max_batch_size: int,
|
|
190
191
|
batch_timeout: float,
|
|
191
192
|
stream: bool,
|
|
@@ -214,19 +215,19 @@ requires the lit_api to have a has_finished method. Please implement the has_fin
|
|
|
214
215
|
|
|
215
216
|
response_data = lit_api.format_encoded_response(response_data)
|
|
216
217
|
if status == LitAPIStatus.ERROR:
|
|
217
|
-
self.put_error_response(
|
|
218
|
+
self.put_error_response(transport, response_queue_id, uid, response_data)
|
|
218
219
|
self.mark_completed(uid)
|
|
219
220
|
elif status == LitAPIStatus.FINISH_STREAMING:
|
|
220
|
-
self.put_response(
|
|
221
|
+
self.put_response(transport, response_queue_id, uid, response_data, status)
|
|
221
222
|
self.mark_completed(uid)
|
|
222
223
|
else:
|
|
223
|
-
self.put_response(
|
|
224
|
+
self.put_response(transport, response_queue_id, uid, response_data, status)
|
|
224
225
|
|
|
225
226
|
except Exception as e:
|
|
226
227
|
logger.exception(f"Error in continuous batching loop: {e}")
|
|
227
228
|
# Handle any errors by sending error responses for all tracked requests
|
|
228
229
|
for uid, response_queue_id in self.response_queue_ids.items():
|
|
229
|
-
self.put_error_response(
|
|
230
|
+
self.put_error_response(transport, response_queue_id, uid, e)
|
|
230
231
|
self.response_queue_ids.clear()
|
|
231
232
|
self.active_sequences.clear()
|
|
232
233
|
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
import logging
|
|
15
15
|
from queue import Queue
|
|
16
|
-
from typing import Dict,
|
|
16
|
+
from typing import Dict, Optional, Union
|
|
17
17
|
|
|
18
18
|
from litserve import LitAPI
|
|
19
19
|
from litserve.callbacks import CallbackRunner, EventTypes
|
|
@@ -21,8 +21,8 @@ from litserve.loops.base import _BaseLoop
|
|
|
21
21
|
from litserve.loops.simple_loops import BatchedLoop, SingleLoop
|
|
22
22
|
from litserve.loops.streaming_loops import BatchedStreamingLoop, StreamingLoop
|
|
23
23
|
from litserve.specs.base import LitSpec
|
|
24
|
+
from litserve.transport.base import MessageTransport
|
|
24
25
|
from litserve.utils import WorkerSetupStatus
|
|
25
|
-
from litserve.zmq_queue import Producer
|
|
26
26
|
|
|
27
27
|
logger = logging.getLogger(__name__)
|
|
28
28
|
|
|
@@ -45,15 +45,13 @@ def inference_worker(
|
|
|
45
45
|
device: str,
|
|
46
46
|
worker_id: int,
|
|
47
47
|
request_queue: Queue,
|
|
48
|
-
|
|
48
|
+
transport: MessageTransport,
|
|
49
49
|
max_batch_size: int,
|
|
50
50
|
batch_timeout: float,
|
|
51
51
|
stream: bool,
|
|
52
52
|
workers_setup_status: Dict[int, str],
|
|
53
53
|
callback_runner: CallbackRunner,
|
|
54
54
|
loop: Union[str, _BaseLoop],
|
|
55
|
-
use_zmq: bool,
|
|
56
|
-
zmq_addr: Optional[str],
|
|
57
55
|
):
|
|
58
56
|
callback_runner.trigger_event(EventTypes.BEFORE_SETUP, lit_api=lit_api)
|
|
59
57
|
try:
|
|
@@ -76,18 +74,13 @@ def inference_worker(
|
|
|
76
74
|
if loop == "auto":
|
|
77
75
|
loop = get_default_loop(stream, max_batch_size)
|
|
78
76
|
|
|
79
|
-
if use_zmq:
|
|
80
|
-
producer = Producer(address=zmq_addr)
|
|
81
|
-
producer.wait_for_subscribers(timeout=5)
|
|
82
|
-
loop.producer = producer
|
|
83
|
-
|
|
84
77
|
loop(
|
|
85
78
|
lit_api,
|
|
86
79
|
lit_spec,
|
|
87
80
|
device,
|
|
88
81
|
worker_id,
|
|
89
82
|
request_queue,
|
|
90
|
-
|
|
83
|
+
transport,
|
|
91
84
|
max_batch_size,
|
|
92
85
|
batch_timeout,
|
|
93
86
|
stream,
|