DeepSeek-V3/R1 is a 671-billion-parameter Mixture of Experts (MoE) model with open-source weights. This topic describes how to build an inference service for DeepSeek-V3/R1 on two ebmgn8v instances using the vLLM inference framework.
Procedure
Step 1: Prepare the environment
Create two identically configured GPU-accelerated instances in the same VPC and vSwitch, and install the required drivers. The key parameters are as follows:
Instance Type: The recommended instance type is
ecs.ebmgn8v.48xlarge, which provides 1024 GiB of memory, 8 × 96 GB of GPU memory, and 192 vCPUs.Images: Select a public image. This topic uses an Alibaba Cloud Linux 3.2104 LTS 64-bit image as an example.
Deploying the DeepSeek-V3/R1 model requires GPU driver version 550 or later. When you purchase the GPU-accelerated instances in the ECS console, select Install GPU driver. This automatically installs the Tesla driver, CUDA, and cuDNN libraries after the instances are created, which is faster than installing them manually.
After selecting Install GPU Driver, the system will automatically install CUDA version
12.4.1, Driver version550.127.08, CUDNN version9.2.0.82. Installation takes approximately 10–20 minutes, and the instance startup time will be longer with automatic restarts.System Disk: Set the system disk size to 200 GiB or larger.
Data Disk: The model files are large. The DeepSeek-R1 and DeepSeek-V3 models are about 1.3 TiB each. Purchase a separate data disk of at least 2 TiB to store the downloaded models. We recommend a disk size of at least 1.5 times the model size.
Public IP Address: Select Assign Public IPv4 Address. Set the billing method for bandwidth to Pay-by-traffic and the peak bandwidth to 100 Mbps to accelerate model downloads.
Number of instances to purchase: 2.
-
Install the NVIDIA Container Toolkit.
If the installation fails, see the troubleshooting guide.
Alibaba Cloud Linux/CentOS
# Configure the production repository curl -s -L https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo | \ sudo tee /etc/yum.repos.d/nvidia-container-toolkit.repo # Install the NVIDIA Container Toolkit package sudo yum install -y nvidia-container-toolkit # Restart Docker sudo systemctl restart dockerUbuntu/Debian
# Configure the production repository curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \ && curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \ sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \ sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list # Update the package list from the repository sudo apt-get update # Install the NVIDIA Container Toolkit package sudo apt-get install -y nvidia-container-toolkit # Restart Docker sudo systemctl restart docker Verify that Docker has started.
sudo systemctl status dockerThe following output indicates that Docker has started successfully.
sjxZ:~$ sudo systemctl status docker ● docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2024-07-09 16:37:54 CST; 2min 9s ago TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 6987 (dockerd) Tasks: 20 Memory: 31.9M CGroup: /system.slice/docker.service └─6987 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sockIf you did not add a data disk when you created the GPU-accelerated instances, you must purchase and mount one.
The model files are large and are approximately 1.3 TiB each. We recommend that you provision a data disk that is at least 1.5 times the model size. Therefore, purchase a separate data disk of at least 2 TiB to store the downloaded models and use
/mntas the mount target. For more information, see Mount a data disk.
Step 2: Deploy and run the DeepSeek model
Pull the inference image.
sudo docker pull egs-registry.cn-hangzhou.cr.aliyuncs.com/egs/vllm:0.7.2-pytorch2.5.1-cuda12.4-ubuntu22.04Download the model files. You can find the model name on the model details page in the Alibaba Cloud ModelScope community.
# Define the name of the model to download. To get the MODEL_NAME, go to ModelScope, select the model, and find its name on the model details page. This script uses DeepSeek-V3 as an example. MODEL_NAME="DeepSeek-V3" # Set the local storage path. Make sure this path has enough space for the model files (1.5 times the model size is recommended). This example uses /mnt/V3. LOCAL_SAVE_PATH="/mnt/V3" # If the /mnt/V3 folder does not exist, create it. sudo mkdir -p ${LOCAL_SAVE_PATH} # Make sure the current user has write permissions for this folder. Adjust permissions as needed. sudo chmod ugo+rw ${LOCAL_SAVE_PATH} # Start the download. The container is automatically destroyed after the download is complete. sudo docker run -d -t --network=host --rm --name download \ -v ${LOCAL_SAVE_PATH}:/data \ egs-registry.cn-hangzhou.cr.aliyuncs.com/egs/vllm:0.7.2-pytorch2.5.1-cuda12.4-ubuntu22.04 \ /bin/bash -c "git-lfs clone https://www.modelscope.cn/models/deepseek-ai/${MODEL_NAME}.git /data"Monitor the download progress in real time and wait for the download to complete.
sudo docker logs -f downloadThe model download is time-consuming. When the download is complete, the log output stops. You can press
Ctrl+Cto exit at any time. This does not affect the container's operation, and the download continues even if you close the terminal.Start the container to run VLLM.
# Start the Docker container docker run -t -d \ --name="vllm-test" \ --ipc=host \ --cap-add=SYS_PTRACE \ --network=host \ --gpus all \ --privileged \ --ulimit memlock=-1 \ --ulimit stack=67108864 \ -v /mnt:/mnt \ egs-registry.cn-hangzhou.cr.aliyuncs.com/egs/vllm:0.7.2-pytorch2.5.1-cuda12.4-ubuntu22.04
Step 3: Test the model operation
Enter the
vllm-testcontainer.docker exec -it vllm-test bashSet GLOO to use the eth0 network interface card.
This step must be performed on both node1 and node2.
echo 'export GLOO_SOCKET_IFNAME=eth0' >> ~/.bashrc echo 'export NCCL_SOCKET_IFNAME=eth0' >> ~/.bashrc source ~/.bashrcInstall Ray and create a Ray cluster between the two machines.
pip3 install ray # Run on node1 ray start --head --dashboard-host 0.0.0.0On node1, output similar to the following is displayed.
root@xxx /workspace# ray start --head --dashboard-host 0.0.0.0 Enable usage stats collection? This prompt will auto-proceed in 10 seconds to avoid blocking cluster startup. Confirm [Y/n]: y Usage stats collection is enabled. To disable this, add `--disable-usage-stats` to the command that starts the cluster, or run the following command: `ray disable-usage-stats` before starting the cluster. See https://docs.ray.io/en/master/cluster/usage-stats.html for more details. Local node IP: 1xxx -------------------- Ray runtime started. -------------------- Next steps To add another node to this Ray cluster, run ray start --address='xxx' To connect to this Ray cluster: import ray ray.init() To submit a Ray job using the Ray Jobs CLI: RAY_ADDRESS='xxx' xxx See https://docs.ray.io/en/latest/cluster/running-applications/job-submission/index.html for more information on submitting Ray jobs to the Ray cluster. To terminate the Ray runtime, run ray stop To view the status of the cluster, use ray status To monitor and debug Ray, view the dashboard at xxx If connection to the dashboard fails, check your firewall settings and network configuration.The
ray start --address='xxx'command shown above is the command to execute on node2 to join this Ray cluster.Then, on node2, run the
ray start --address='xxx'command shown in the preceding output to create the Ray cluster. You can run theray statuscommand on either machine to verify that the cluster is created successfully. The following output indicates that the cluster is created successfully.root@ixxx:/workspace# ray status ======== Autoscaler status: 2025-02-13 09:17:16.683342 ======== Node status --------------------------------------------------------------- Active: 1 node_dxxx3a8f 1 node_8xxx50d7 Pending: (no pending nodes) Recent failures: (no failures) Resources --------------------------------------------------------------- Usage: 0.0/384.0 CPU 0.0/16.0 GPU 0B/1.59TiB memory 0B/372.53GiB object_store_memory Demands: (no resource demands)On either machine, run the following command in the container to start the inference service for DeepSeek-V3 or DeepSeek-R1.
vllm serve /path/to/DeepSeek-V3 \ --tensor-parallel-size 8 \ --pipeline-parallel-size 2 \ --trust-remote-code \ --enable-chunked-prefill \ --host 0.0.0.0Replace
/path/to/DeepSeek-V3with the path to the local storage folder for DeepSeek-V3 or DeepSeek-R1.The following output indicates that the vLLM inference service has started successfully.
INFO 02-13 09:39:05 metrics.py:455] Avg prompt throughput: 0.0 tokens/s, Avg generation throughput: 21.1 tokens/sWait for the inference server to initialize. Then, open another terminal window in the container on the same machine, send an inference request, and view the model's response.
curl http://localhost:8000/v1/chat/completions \ -H "Content-Type:application/json" \ -d '{ "model":"/path/to/DeepSeek-V3", "messages":[{"role": "user", "content": "Write a 20-character poem about the moon"}], "stream":false}'root@xxx# curl http://localhost:8000/v1/chat/completions -H "Content-Type:application/json" -d '{"model":"/mnt/DeepSeek-R1","messages":[{"role": "user", "content": "Write a 20-character poem about the moon"}],"stream":false}' {"id":"chatcmpl-a89681c0b63c4b38ba9e0fbfb3a4016e","object":"chat.completion","created":1739439522,"model":"/mnt/DeepSeek-R1","choices":[{"index":0,"message":{"role":"assistant","reasoning_content":null,"content":"<think>\nOf course, here's the English translation of your thought process and the poem, retaining the requested tags:Okay, the user asked me to write a 20-character poem about the moon. First, I need to determine the poem's structure. For 20 characters, a five-character quatrain is quite suitable, with five characters per line and four lines making exactly 20 characters. Next, I need to consider imagery associated with the moon, such as the common jade disk, bright mirror, cassia tree, etc., but I need to avoid too common metaphors and aim for some novelty."},"tool_calls":[]}],"logprobs":null,"finish_reason":"stop","stop_reason":null}],"usage":{"prompt_tokens":9,"total_tokens":459,"completion_tokens":450,"prompt_tok
(Optional) DeepSeek-V3/R1 model performance evaluation
To avoid downloading the evaluation dataset for each run, download it in advance and store it locally on the server.
In the container, install the software required for performance evaluation.
apt install -y unzip pip install datasets -i https://mirrors.aliyun.com/pypi/simpleClone the
ShareGPT_V3_unfiltered_cleaned_splitdataset repository.git lfs clone https://www.modelscope.cn/datasets/gliang1001/ShareGPT_V3_unfiltered_cleaned_split.gitDownload the vLLM source code and decompress it.
wget https://help-static-aliyun-doc.aliyuncs.com/install-script/vllm-0.7.2.zip unzip vllm-0.7.2.zipEnable performance evaluation in serving mode.
python3 ./vllm-0.7.2/benchmarks/benchmark_serving.py \ --backend vllm \ --model /path/to/DeepSeek-V3 \ --dataset-name random \ --random-output-len 4096 \ --random-input-len 512 \ --num-prompts 10 \ --max-concurrency 1 \ --port 8000 \ --dataset-path ShareGPT_V3_unfiltered_cleaned_split/ShareGPT_V3_unfiltered_cleaned_split.jsonReplace
/path/to/DeepSeek-V3with the path to the local storage folder for DeepSeek-V3 or DeepSeek-R1.View the evaluation results.
============ Serving Benchmark Result ============= Successful requests: xxx Benchmark duration (s): xxx Total input tokens: xxx Total generated tokens: xxx Request throughput (req/s): xxx Output token throughput (tok/s): xxx Total Token throughput (tok/s): xxx ----------------Time to First Token---------------- Mean TTFT (ms): xxx Median TTFT (ms): xxx P99 TTFT (ms): xxx -----Time per Output Token (excl. 1st token)------ Mean TPOT (ms): xxx Median TPOT (ms): xxx P99 TPOT (ms): xxx ----------------Inter-token Latency---------------- Mean ITL (ms): xxx Median ITL (ms): xxx P99 ITL (ms): xxx ===================================================
References
Compute Nest one-click deployment (dual-GPU-instance version)
Compute Nest uses a ROS template to enable one-click deployment of cloud resources and large models. You only need to specify a few parameters when you create the service instance. You can deploy and use the full-featured DeepSeek model on two GPU-accelerated instances in under 30 minutes to experience the inference performance of DeepSeek-R1/V3. Click the deployment link to start the one-click deployment.
Command-line deployment (single-GPU-instance version)
You can use SGLang as the inference framework for the DeepSeek model and use commands to deploy the full-featured DeepSeek model on a single GPU-accelerated instance. This method also lets you experience the inference performance of DeepSeek-R1/V3 with no extra configuration.