Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/docs/concepts/gateways.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ router:
* `round_robin` — Cycles through workers in order.


> Currently, services using this type of gateway must run standard SGLang workers. See the [example](../../examples/inference/sglang/index.md).
> Services using this type of gateway can run PD-disaggregated inference. To run PD disaggregation inference, refer to the [SGLang PD-Disaggregation](../../examples/inference/sglang/index.md#pd-disaggregation) example.
>
> Support for prefill/decode disaggregation and auto-scaling based on inter-token latency is coming soon.
> Support for auto-scaling based on TTFT and ITL is coming soon.

### Public IP

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/concepts/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ Setting the minimum number of replicas to `0` allows the service to scale down t
> Properties such as `regions`, `port`, `image`, `env` and some other cannot be configured per replica group. This support is coming soon.

??? info "Disaggregated serving"
Native support for disaggregated prefill and decode, allowing both worker types to run within a single service, is coming soon.
Replica groups support disaggregated prefill and decode, allowing both worker types to run within a single service. To run PD disaggregated inference, refer to the [SGLang PD-Disaggregation](../../examples/inference/sglang/index.md#pd-disaggregation) example.

### Authorization

Expand Down
80 changes: 78 additions & 2 deletions examples/inference/sglang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,86 @@ curl http://127.0.0.1:3000/proxy/services/main/deepseek-r1/v1/chat/completions \

> If a [gateway](https://dstack.ai/docs/concepts/gateways/) is configured (e.g. to enable auto-scaling or HTTPs, rate-limits, etc), the service endpoint will be available at `https://deepseek-r1.<gateway domain>/`.

## PD-Disaggregation

To run PD-Disaggregated inference using SGLang Model Gateway.

Create a SGLang-enabled gateway in the same network where prefill and decode workers will be deployed. Here we are using a Kubernetes cluster to ensure the gateway and workers share the same network.

```yaml
type: gateway
name: gateway-name

backend: kubernetes
region: any

# This domain will be used to access the endpoint
domain: example.com
router:
type: sglang
```

After the gateway is ready, create a node group with at least two instances—one for the Prefill worker and one for the Decode worker—within the same Kubernetes cluster where the gateway is running. Then apply below service configuration to the GPU nodes.

```yaml
type: service
name: prefill-decode
image: lmsysorg/sglang:latest

env:
- HF_TOKEN
- MODEL_ID=zai-org/GLM-4.5-Air-FP8

replicas:
- count: 1..4
scaling:
metric: rps
target: 3
commands:
- |
python -m sglang.launch_server \
--model-path $MODEL_ID \
--disaggregation-mode prefill \
--disaggregation-transfer-backend mooncake \
--host 0.0.0.0 \
--port 8000 \
--disaggregation-bootstrap-port 8998
resources:
gpu: H200

- count: 1..8
scaling:
metric: rps
target: 2
commands:
- |
python -m sglang.launch_server \
--model-path $MODEL_ID \
--disaggregation-mode decode \
--disaggregation-transfer-backend mooncake \
--host 0.0.0.0 \
--port 8000
resources:
gpu: H200

port: 8000
model: zai-org/GLM-4.5-Air-FP8

# Custom probe is required for PD disaggregation
probes:
- type: http
url: /health_generate
interval: 15s

router:
type: sglang
pd_disaggregation: true
```

## Source code

The source-code of this example can be found in
[`examples/llms/deepseek/sglang`](https://github.com/dstackai/dstack/blob/master/examples/llms/deepseek/sglang).
The source-code of these examples can be found in
[`examples/llms/deepseek/sglang`](https://github.com/dstackai/dstack/blob/master/examples/llms/deepseek/sglang) and [`examples/inference/sglang`](https://github.com/dstackai/dstack/blob/master/examples/inference/sglang).

## What's next?

Expand Down
51 changes: 51 additions & 0 deletions examples/inference/sglang/pd.dstack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
type: service
name: prefill-decode
image: lmsysorg/sglang:latest

env:
- HF_TOKEN
- MODEL_ID=zai-org/GLM-4.5-Air-FP8

replicas:
- count: 1..4
scaling:
metric: rps
target: 3
commands:
- |
python -m sglang.launch_server \
--model-path $MODEL_ID \
--disaggregation-mode prefill \
--disaggregation-transfer-backend mooncake \
--host 0.0.0.0 \
--port 8000 \
--disaggregation-bootstrap-port 8998
resources:
gpu: 1

- count: 1..8
scaling:
metric: rps
target: 2
commands:
- |
python -m sglang.launch_server \
--model-path $MODEL_ID \
--disaggregation-mode decode \
--disaggregation-transfer-backend mooncake \
--host 0.0.0.0 \
--port 8000
resources:
gpu: 1

port: 8000
model: zai-org/GLM-4.5-Air-FP8

probes:
- type: http
url: /health_generate
interval: 15s

router:
type: sglang
pd_disaggregation: true