litserve 0.2.7.dev0__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.
Files changed (52) hide show
  1. {litserve-0.2.7.dev0/src/litserve.egg-info → litserve-0.2.8.dev0}/PKG-INFO +76 -73
  2. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/README.md +68 -67
  3. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/requirements.txt +1 -0
  4. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/setup.py +1 -3
  5. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/__about__.py +1 -1
  6. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/api.py +8 -3
  7. litserve-0.2.8.dev0/src/litserve/cli.py +17 -0
  8. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/loops/base.py +12 -32
  9. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/loops/continuous_batching_loop.py +6 -5
  10. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/loops/loops.py +4 -11
  11. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/loops/simple_loops.py +17 -16
  12. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/loops/streaming_loops.py +19 -18
  13. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/server.py +59 -45
  14. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/specs/openai.py +12 -2
  15. litserve-0.2.8.dev0/src/litserve/transport/__init__.py +4 -0
  16. litserve-0.2.8.dev0/src/litserve/transport/base.py +20 -0
  17. litserve-0.2.8.dev0/src/litserve/transport/factory.py +38 -0
  18. litserve-0.2.8.dev0/src/litserve/transport/process_transport.py +44 -0
  19. {litserve-0.2.7.dev0/src/litserve → litserve-0.2.8.dev0/src/litserve/transport}/zmq_queue.py +1 -1
  20. litserve-0.2.8.dev0/src/litserve/transport/zmq_transport.py +42 -0
  21. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/utils.py +2 -0
  22. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0/src/litserve.egg-info}/PKG-INFO +76 -73
  23. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve.egg-info/SOURCES.txt +8 -2
  24. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve.egg-info/entry_points.txt +1 -0
  25. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve.egg-info/requires.txt +1 -0
  26. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/LICENSE +0 -0
  27. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/MANIFEST.in +0 -0
  28. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/setup.cfg +0 -0
  29. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/__init__.py +0 -0
  30. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/__main__.py +0 -0
  31. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/callbacks/__init__.py +0 -0
  32. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/callbacks/base.py +0 -0
  33. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/callbacks/defaults/__init__.py +0 -0
  34. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/callbacks/defaults/metric_callback.py +0 -0
  35. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/connector.py +0 -0
  36. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/docker_builder.py +0 -0
  37. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/loggers.py +0 -0
  38. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/loops/__init__.py +0 -0
  39. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/middlewares.py +0 -0
  40. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/python_client.py +0 -0
  41. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/schema/__init__.py +0 -0
  42. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/schema/image.py +0 -0
  43. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/specs/__init__.py +0 -0
  44. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/specs/base.py +0 -0
  45. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/specs/openai_embedding.py +0 -0
  46. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/test_examples/__init__.py +0 -0
  47. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/test_examples/openai_embedding_spec_example.py +0 -0
  48. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/test_examples/openai_spec_example.py +0 -0
  49. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve/test_examples/simple_example.py +0 -0
  50. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve.egg-info/dependency_links.txt +0 -0
  51. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve.egg-info/not-zip-safe +0 -0
  52. {litserve-0.2.7.dev0 → litserve-0.2.8.dev0}/src/litserve.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: litserve
3
- Version: 0.2.7.dev0
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,10 +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
- Provides-Extra: perf
34
- Requires-Dist: jsonargparse; extra == "perf"
35
- Requires-Dist: tenacity; extra == "perf"
36
- Requires-Dist: uvloop; extra == "perf"
33
+ Requires-Dist: starlette
37
34
  Provides-Extra: test
38
35
  Requires-Dist: asgi-lifespan; extra == "test"
39
36
  Requires-Dist: coverage[toml]>=7.5.3; extra == "test"
@@ -52,6 +49,10 @@ Requires-Dist: python-multipart; extra == "test"
52
49
  Requires-Dist: requests; extra == "test"
53
50
  Requires-Dist: torch>2.0.0; extra == "test"
54
51
  Requires-Dist: transformers; extra == "test"
52
+ Provides-Extra: perf
53
+ Requires-Dist: jsonargparse; extra == "perf"
54
+ Requires-Dist: tenacity; extra == "perf"
55
+ Requires-Dist: uvloop; extra == "perf"
55
56
  Dynamic: author
56
57
  Dynamic: author-email
57
58
  Dynamic: classifier
@@ -61,6 +62,7 @@ Dynamic: download-url
61
62
  Dynamic: home-page
62
63
  Dynamic: keywords
63
64
  Dynamic: license
65
+ Dynamic: license-file
64
66
  Dynamic: project-url
65
67
  Dynamic: provides-extra
66
68
  Dynamic: requires-dist
@@ -88,10 +90,11 @@ LitServe is at least [2x faster](#performance) than plain FastAPI due to AI-spec
88
90
  <div align='center'>
89
91
 
90
92
  <pre>
91
- ✅ (2x)+ faster serving ✅ Easy to use ✅ LLMs, non LLMs and more
92
- ✅ Bring your own model ✅ PyTorch/JAX/TF/... ✅ Built on FastAPI
93
- ✅ GPU autoscaling ✅ Batching, Streaming ✅ Self-host or ⚡️ managed
94
- ✅ Compound AI ✅ Integrate with vLLM and more
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
+
95
98
  </pre>
96
99
 
97
100
  <div align='center'>
@@ -168,12 +171,23 @@ if __name__ == "__main__":
168
171
  server.run(port=8000)
169
172
  ```
170
173
 
171
- Now run the server via the command-line
174
+ Now run the server anywhere (local or cloud) via the command-line.
172
175
 
173
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
174
188
  python server.py
175
189
  ```
176
-
190
+
177
191
  ### Test the server
178
192
  Run the auto-generated test client:
179
193
  ```bash
@@ -197,7 +211,7 @@ litgpt serve microsoft/phi-2
197
211
  - LitAPI lets you easily build complex AI systems with one or more models ([docs](https://lightning.ai/docs/litserve/api-reference/litapi)).
198
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)).
199
213
  - LitServer handles optimizations like batching, GPU autoscaling, streaming, etc... ([docs](https://lightning.ai/docs/litserve/api-reference/litserver)).
200
- - Self host on your own machines or use Lightning Studios for a fully managed deployment ([learn more](#hosting-options)).
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)).
201
215
 
202
216
  [Learn how to make this server 200x faster](https://lightning.ai/docs/litserve/home/speed-up-serving-by-200x).
203
217
 
@@ -205,14 +219,7 @@ litgpt serve microsoft/phi-2
205
219
 
206
220
  # Featured examples
207
221
  Use LitServe to deploy any model or AI service: (Compound AI, Gen AI, classic ML, embeddings, LLMs, vision, audio, etc...)
208
-
209
- <div align='center'>
210
- <div width='200px'>
211
- <video src="https://github.com/user-attachments/assets/5e73549a-bc0f-47a9-9d9c-5b54389be5de" width='200px' controls></video>
212
- </div>
213
- </div>
214
-
215
- ## Examples
222
+
216
223
  <pre>
217
224
  <strong>Toy model:</strong> <a target="_blank" href="#define-a-server">Hello world</a>
218
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>
@@ -232,31 +239,59 @@ Use LitServe to deploy any model or AI service: (Compound AI, Gen AI, classic ML
232
239
 
233
240
  &nbsp;
234
241
 
235
- # Features
236
- State-of-the-art features:
237
242
 
238
- [(2x)+ faster than plain FastAPI](#performance)
239
- [Bring your own model](https://lightning.ai/docs/litserve/features/full-control)
240
- ✅ [Build compound systems (1+ models)](https://lightning.ai/docs/litserve/home)
241
- ✅ [GPU autoscaling](https://lightning.ai/docs/litserve/features/gpu-inference)
242
- ✅ [Batching](https://lightning.ai/docs/litserve/features/batching)
243
- [Streaming](https://lightning.ai/docs/litserve/features/streaming)
244
- ✅ [Worker autoscaling](https://lightning.ai/docs/litserve/features/autoscaling)
245
- ✅ [Self-host on your machines](https://lightning.ai/docs/litserve/features/hosting-methods#host-on-your-own)
246
- ✅ [Host fully managed on Lightning AI](https://lightning.ai/docs/litserve/features/hosting-methods#host-on-lightning-studios)
247
- ✅ [Serve all models: (LLMs, vision, etc.)](https://lightning.ai/docs/litserve/examples)
248
- ✅ [Scale to zero (serverless)](https://lightning.ai/docs/litserve/features/streaming)
249
- ✅ [Supports PyTorch, JAX, TF, etc...](https://lightning.ai/docs/litserve/features/full-control)
250
- ✅ [OpenAPI compliant](https://www.openapis.org/)
251
- ✅ [Open AI compatibility](https://lightning.ai/docs/litserve/features/open-ai-spec)
252
- ✅ [Authentication](https://lightning.ai/docs/litserve/features/authentication)
253
- ✅ [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.
254
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
+ &nbsp;
255
256
 
257
+ <div align='center'>
256
258
 
257
- [10+ features...](https://lightning.ai/docs/litserve/features)
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) | - | - |
258
293
 
259
- **Note:** We prioritize scalable, enterprise-level features over hype.
294
+ </div>
260
295
 
261
296
  &nbsp;
262
297
 
@@ -275,40 +310,8 @@ These results are for image and text classification ML tasks. The performance re
275
310
 
276
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.
277
312
 
278
- &nbsp;
279
-
280
- # Hosting options
281
- LitServe can be hosted independently on your own machines or fully managed via Lightning Studios.
282
-
283
- 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.
284
-
285
313
  &nbsp;
286
314
 
287
- <div align="center">
288
- <a target="_blank" href="https://lightning.ai/lightning-ai/studios/litserve-hello-world">
289
- <img src="https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/app-2/host-on-lightning.svg" alt="Host on Lightning"/>
290
- </a>
291
- </div>
292
-
293
- &nbsp;
294
-
295
- <div align='center'>
296
-
297
- | Feature | Self Managed | Fully Managed on Studios |
298
- |----------------------------------|-----------------------------------|-------------------------------------|
299
- | Deployment | ✅ Do it yourself deployment | ✅ One-button cloud deploy |
300
- | Load balancing | ❌ | ✅ |
301
- | Autoscaling | ❌ | ✅ |
302
- | Scale to zero | ❌ | ✅ |
303
- | Multi-machine inference | ❌ | ✅ |
304
- | Authentication | ❌ | ✅ |
305
- | Own VPC | ❌ | ✅ |
306
- | AWS, GCP | ❌ | ✅ |
307
- | Use your own cloud commits | ❌ | ✅ |
308
-
309
- </div>
310
-
311
- &nbsp;
312
315
 
313
316
  # Community
314
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 ✅ 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 and more
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 own machines or use Lightning Studios for a fully managed deployment ([learn more](#hosting-options)).
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
  &nbsp;
165
170
 
166
- # Features
167
- State-of-the-art features:
168
171
 
169
- [(2x)+ faster than plain FastAPI](#performance)
170
- [Bring your own model](https://lightning.ai/docs/litserve/features/full-control)
171
- ✅ [Build compound systems (1+ models)](https://lightning.ai/docs/litserve/home)
172
- ✅ [GPU autoscaling](https://lightning.ai/docs/litserve/features/gpu-inference)
173
- ✅ [Batching](https://lightning.ai/docs/litserve/features/batching)
174
- [Streaming](https://lightning.ai/docs/litserve/features/streaming)
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
+ &nbsp;
186
185
 
186
+ <div align='center'>
187
187
 
188
- [10+ features...](https://lightning.ai/docs/litserve/features)
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
- **Note:** We prioritize scalable, enterprise-level features over hype.
223
+ </div>
191
224
 
192
225
  &nbsp;
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
- &nbsp;
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
  &nbsp;
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
- &nbsp;
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
- &nbsp;
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.
@@ -1,3 +1,4 @@
1
1
  fastapi >=0.100
2
2
  uvicorn[standard] >=0.29.0
3
3
  pyzmq >=22.0.0
4
+ starlette
@@ -111,8 +111,6 @@ setup(
111
111
  "Programming Language :: Python :: 3.11",
112
112
  ],
113
113
  entry_points={
114
- "console_scripts": [
115
- "litserve=litserve.__main__:main",
116
- ],
114
+ "console_scripts": ["litserve=litserve.__main__:main", "lightning=litserve.cli:main"],
117
115
  },
118
116
  )
@@ -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.7.dev0"
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,7 @@ import json
15
15
  import warnings
16
16
  from abc import ABC, abstractmethod
17
17
  from queue import Queue
18
- from typing import Optional
18
+ from typing import Callable, Optional
19
19
 
20
20
  from pydantic import BaseModel
21
21
 
@@ -24,8 +24,8 @@ from litserve.specs.base import LitSpec
24
24
 
25
25
  class LitAPI(ABC):
26
26
  _stream: bool = False
27
- _default_unbatch: callable = None
28
- _spec: LitSpec = None
27
+ _default_unbatch: Optional[Callable] = None
28
+ _spec: Optional[LitSpec] = None
29
29
  _device: Optional[str] = None
30
30
  _logger_queue: Optional[Queue] = None
31
31
  request_timeout: Optional[float] = None
@@ -76,6 +76,11 @@ class LitAPI(ABC):
76
76
 
77
77
  def unbatch(self, output):
78
78
  """Convert a batched output to a list of outputs."""
79
+ if self._default_unbatch is None:
80
+ raise ValueError(
81
+ "Default implementation for `LitAPI.unbatch` method was not found. "
82
+ "Please implement the `LitAPI.unbatch` method."
83
+ )
79
84
  return self._default_unbatch(output)
80
85
 
81
86
  def encode_response(self, output, **kwargs):
@@ -0,0 +1,17 @@
1
+ import importlib.util
2
+ import subprocess
3
+ import sys
4
+
5
+
6
+ def _ensure_lightning_installed():
7
+ if not importlib.util.find_spec("lightning_sdk"):
8
+ print("Lightning CLI not found. Installing...")
9
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "-U", "lightning-sdk"])
10
+
11
+
12
+ def main():
13
+ _ensure_lightning_installed()
14
+
15
+ # Forward CLI arguments to the real lightning command
16
+ cli_args = sys.argv[1:]
17
+ subprocess.run(["lightning"] + cli_args)
@@ -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
- response_queues: List[Queue],
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
- response_queues,
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
- response_queues,
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
- response_queues: List[Queue],
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, response_queues: List[Queue], response_queue_id: int, uid: str, response_data: Any, status: LitAPIStatus
247
+ self, transport: MessageTransport, response_queue_id: int, uid: str, response_data: Any, status: LitAPIStatus
251
248
  ) -> None:
252
- if self.producer:
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, response_queues: List[Queue], response_queue_id: int, uid: str, error: Exception
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(response_queues, response_queue_id, uid, error, LitAPIStatus.ERROR)
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
- response_queues: List[Queue],
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(response_queues, response_queue_id, uid, response_data)
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(response_queues, response_queue_id, uid, response_data, status)
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(response_queues, response_queue_id, uid, response_data, status)
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(response_queues, response_queue_id, uid, e)
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