Skip to content

Commit 1232f7e

Browse files
authored
Update dev container config to support live code sync and improve docker setup guide (sgl-project#6018)
Signed-off-by: Lifu Huang <[email protected]>
1 parent 3008db9 commit 1232f7e

File tree

2 files changed

+71
-9
lines changed

2 files changed

+71
-9
lines changed

.devcontainer/devcontainer.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,11 @@
2020
"runArgs": [
2121
"--gpus",
2222
"all"
23-
]
23+
],
24+
// The two lines below ensures that your local changes in the sglang
25+
// repo is automatically synced to the sglang pip package installed
26+
// in the dev docker container. You can remove / comment out these
27+
// two lines if you prefer to sync code changes manually.
28+
"workspaceMount": "source=${localWorkspaceFolder},target=/sgl-workspace/sglang,type=bind",
29+
"workspaceFolder": "/sgl-workspace/sglang"
2430
}

docs/developer/development_guide_using_docker.md

+64-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# Development Guide Using Docker
22

3-
## Setup VSCode
3+
## Setup VSCode on a Remote Host
4+
(Optional - you can skip this step if you plan to run sglang dev container locally)
45

5-
Download `code` from `Https://code.visualstudio.com/docs/?dv=linux64cli`
6+
1. In the remote host, download `code` from [Https://code.visualstudio.com/docs/?dv=linux64cli](https://code.visualstudio.com/download) and run `code tunnel` in a shell.
67

8+
Example
79
```bash
810
wget https://vscode.download.prss.microsoft.com/dbazure/download/stable/fabdb6a30b49f79a7aba0f2ad9df9b399473380f/vscode_cli_alpine_x64_cli.tar.gz
911
tar xf vscode_cli_alpine_x64_cli.tar.gz
@@ -12,29 +14,83 @@ tar xf vscode_cli_alpine_x64_cli.tar.gz
1214
./code tunnel
1315
```
1416

17+
2. In your local machine, press F1 in VSCode and choose "Remote Tunnels: Connect to Tunnel".
18+
1519
## Setup Docker Container
1620

21+
### Option 1. Use the default dev container automatically from VSCode
22+
There is a `.devcontainer` folder in the sglang repository root folder to allow VSCode to automatically start up within dev container. You can read more about this VSCode extension in VSCode official document [Developing inside a Container](https://code.visualstudio.com/docs/devcontainers/containers).
23+
![image](https://github.com/user-attachments/assets/6a245da8-2d4d-4ea8-8db1-5a05b3a66f6d)
24+
(*Figure 1: Diagram from VSCode official documentation [Developing inside a Container](https://code.visualstudio.com/docs/devcontainers/containers).*)
25+
26+
To enable this, you only need to:
27+
1. Start Visual Studio Code and install [VSCode dev container extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers).
28+
2. Press F1, type and choose "Dev Container: Open Folder in Container.
29+
3. Input the `sglang` local repo path in your machine and press enter.
30+
31+
The first time you open it in dev container might take longer due to docker pull and build. Once it's successful, you should set on your status bar at the bottom left displaying that you are in a dev container:
32+
33+
![image](https://github.com/user-attachments/assets/650bba0b-c023-455f-91f9-ab357340106b)
34+
35+
Now when you run `sglang.launch_server` in the VSCode terminal or start debugging using F5, sglang server will be started in the dev container with all your local changes applied automatically:
36+
37+
![image](https://github.com/user-attachments/assets/748c85ba-7f8c-465e-8599-2bf7a8dde895)
38+
39+
40+
### Option 2. Start up containers manually (advanced)
41+
1742
The following startup command is an example for internal development by the SGLang team. You can **modify or add directory mappings as needed**, especially for model weight downloads, to prevent repeated downloads by different Docker containers.
1843

1944
❗️ **Note on RDMA**
2045

2146
1. `--network host` and `--privileged` are required by RDMA. If you don't need RDMA, you can remove them but keeping them there does not harm. Thus, we enable these two flags by default in the commands below.
2247
2. You may need to set `NCCL_IB_GID_INDEX` if you are using RoCE, for example: `export NCCL_IB_GID_INDEX=3`.
2348

24-
### H100
25-
2649
```bash
2750
# Change the name to yours
51+
docker run -itd --shm-size 32g --gpus all -v <volumes-to-mount> --ipc=host --network=host --privileged --name sglang_dev lmsysorg/sglang:dev /bin/zsh
52+
docker exec -it sglang_dev /bin/zsh
53+
```
54+
Some useful volumes to mount are:
55+
1. **Huggingface model cache**: mounting model cache can avoid re-download everytime docker restarts. Default location on Linux is `~/.cache/huggingface/`.
56+
2. **SGLang repository**: code changes in the SGLang local repository will be automatically synced to the .devcontainer.
57+
58+
Example 1: Monting local cache folder `/opt/dlami/nvme/.cache` but not the SGLang repo. Use this when you prefer to manually transfer local code changes to the devcontainer.
59+
```bash
2860
docker run -itd --shm-size 32g --gpus all -v /opt/dlami/nvme/.cache:/root/.cache --ipc=host --network=host --privileged --name sglang_zhyncs lmsysorg/sglang:dev /bin/zsh
2961
docker exec -it sglang_zhyncs /bin/zsh
3062
```
31-
32-
### H200
33-
63+
Example 2: Mounting both HuggingFace cache and local SGLang repo. Local code changes are automatically synced to the devcontainer as the SGLang is installed in editable mode in the dev image.
3464
```bash
35-
docker run -itd --shm-size 32g --gpus all -v /mnt/co-research/shared-models:/root/.cache/huggingface --ipc=host --network=host --privileged --name sglang_zhyncs lmsysorg/sglang:dev /bin/zsh
65+
docker run -itd --shm-size 32g --gpus all -v $HOME/.cache/huggingface/:/root/.cache/huggingface -v $HOME/src/sglang:/sgl-workspace/sglang --ipc=host --network=host --privileged --name sglang_zhyncs lmsysorg/sglang:dev /bin/zsh
3666
docker exec -it sglang_zhyncs /bin/zsh
3767
```
68+
## Debug SGLang with VSCode Debugger
69+
1. (Create if not exist) open `launch.json` in VSCode.
70+
2. Add the following config and save. Please note that you can edit the script as needed to apply different parameters or debug a different program (e.g. benchmark script).
71+
```JSON
72+
{
73+
"version": "0.2.0",
74+
"configurations": [
75+
{
76+
"name": "Python Debugger: launch_server",
77+
"type": "debugpy",
78+
"request": "launch",
79+
"module": "sglang.launch_server",
80+
"console": "integratedTerminal",
81+
"args": [
82+
"--model-path", "meta-llama/Llama-3.2-1B",
83+
"--host", "0.0.0.0",
84+
"--port", "30000",
85+
"--trust-remote-code",
86+
],
87+
"justMyCode": false
88+
}
89+
]
90+
}
91+
```
92+
93+
3. Press "F5" to start. VSCode debugger will ensure that the program will pause at the breakpoints even if the program is running at remote SSH/Tunnel host + dev container.
3894

3995
## Profile
4096

0 commit comments

Comments
 (0)