readme.md 1.91 KB
Newer Older
1
2
# SGLang Engine

3
SGLang provides a direct inference engine without the need for an HTTP server. There are generally these use cases:
4

5
6
7
8
9
- [Offline Batch Inference](#offline-batch-inference)
- [Embedding Generation](#embedding-generation)
- [Custom Server](#custom-server)
- [Token-In-Token-Out for RLHF](#token-in-token-out-for-rlhf)
- [Inference Using FastAPI](#inference-using-fastapi)
10
11
12

## Examples

13
### [Offline Batch Inference](./offline_batch_inference.py)
14
15
16

In this example, we launch an SGLang engine and feed a batch of inputs for inference. If you provide a very large batch, the engine will intelligently schedule the requests to process efficiently and prevent OOM (Out of Memory) errors.

17
### [Embedding Generation](./embedding.py)
James Xu's avatar
James Xu committed
18
19
20

In this example, we launch an SGLang engine and feed a batch of inputs for embedding generation.

21
### [Custom Server](./custom_server.py)
22
23
24

This example demonstrates how to create a custom server on top of the SGLang Engine. We use [Sanic](https://sanic.dev/en/) as an example. The server supports both non-streaming and streaming endpoints.

25
#### Steps
26
27
28

1. Install Sanic:

29
30
31
   ```bash
   pip install sanic
   ```
32
33
34

2. Run the server:

35
36
37
   ```bash
   python custom_server
   ```
38
39
40

3. Send requests:

41
42
43
44
   ```bash
   curl -X POST http://localhost:8000/generate  -H "Content-Type: application/json"  -d '{"prompt": "The Transformer architecture is..."}'
   curl -X POST http://localhost:8000/generate_stream  -H "Content-Type: application/json"  -d '{"prompt": "The Transformer architecture is..."}' --no-buffer
   ```
45

46
   This will send both non-streaming and streaming requests to the server.
47

48
### [Token-In-Token-Out for RLHF](../token_in_token_out)
49
50

In this example, we launch an SGLang engine, feed tokens as input and generate tokens as output.
51
52
53
54

### [Inference Using FastAPI](fastapi_engine_inference.py)

This example demonstrates how to create a FastAPI server that uses the SGLang engine for text generation.