[Apple Silicon] [MLX] MLX decode partial overlap scheduling for generation (async eval) (#22416)
Co-authored-by: R0CKSTAR <yeahdongcn@gmail.com> Co-authored-by: Alex Nails <alex.nails@radixark.ai>
This commit is contained in:
co-authored by
R0CKSTAR
Alex Nails
parent
d4040e7010
commit
3272af2f00
@@ -1,6 +1,6 @@
|
||||
# Apple Silicon with Metal
|
||||
# Apple Silicon with Metal (MLX)
|
||||
|
||||
This document describes how run SGLang on Apple Silicon using [Metal](https://developer.apple.com/metal/). If you encounter issues or have questions, please [open an issue](https://github.com/sgl-project/sglang/issues).
|
||||
This document describes how run SGLang on Apple Silicon using [Metal (MLX)](https://opensource.apple.com/projects/mlx/). If you encounter issues or have questions, please [open an issue](https://github.com/sgl-project/sglang/issues).
|
||||
|
||||
## Install SGLang
|
||||
|
||||
@@ -18,3 +18,57 @@ pip install --upgrade pip
|
||||
rm -f python/pyproject.toml && mv python/pyproject_other.toml python/pyproject.toml
|
||||
uv pip install -e "python[all_mps]"
|
||||
```
|
||||
|
||||
## Launch of the Serving Engine
|
||||
|
||||
Launch the server with:
|
||||
|
||||
```bash
|
||||
SGLANG_USE_MLX=1 python -m sglang.launch_server \
|
||||
--model <MODEL_ID_OR_PATH> \
|
||||
--disable-cuda-graph \
|
||||
--host 0.0.0.0
|
||||
```
|
||||
|
||||
**Key Parameters Explained:**
|
||||
|
||||
1. `SGLANG_USE_MLX=1` - Enables the use of MLX as the SGLang runtime backend (if disabled, SGLang will fall back to `torch.mps`, which has less support)
|
||||
2. `--disable-cuda-graph` - Disables usage of CUDA graph, which is not relevant for Apple Metal.
|
||||
3. `--disable-overlap-schedule` - Disables overlap scheduling (enabled/not present by default) achieved using MLX's `async_eval()`
|
||||
|
||||
|
||||
## Benchmarking with Requests
|
||||
|
||||
`sglang.benchmark_one_batch` calls the synchronous prefill/decode methods directly without going through the scheduler and the overlap code path.
|
||||
|
||||
`sglang.benchmark_offline_throughput` can toggle overlap scheduling as it uses the scheduler and the overlap code path by using the flag `--disable-overlap-schedule`.
|
||||
|
||||
### Throughput Testing
|
||||
|
||||
Basic synchronous one batch throughput:
|
||||
```bash
|
||||
SGLANG_USE_MLX=1 python -m sglang.bench_one_batch \
|
||||
--model-path <MODEL_ID_OR_PATH> \
|
||||
--disable-cuda-graph \
|
||||
--tp-size 1 \
|
||||
--batch-size 1 \
|
||||
--input-len 60 \
|
||||
--output-len 10
|
||||
```
|
||||
|
||||
Synchronous offline throughput:
|
||||
```bash
|
||||
SGLANG_USE_MLX=1 python -m sglang.bench_offline_throughput \
|
||||
--model-path <MODEL_ID_OR_PATH> \
|
||||
--disable-cuda-graph \
|
||||
--num-prompts 1 \
|
||||
--disable-overlap-schedule
|
||||
```
|
||||
|
||||
Asynchronous offline throughput:
|
||||
```bash
|
||||
SGLANG_USE_MLX=1 python -m sglang.bench_offline_throughput \
|
||||
--model-path <MODEL_ID_OR_PATH> \
|
||||
--disable-cuda-graph \
|
||||
--num-prompts 1
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user