Deploy a DeepSeek distilled model inference service on ACK

Updated at:

Use KServe in Container Service for Kubernetes (ACK) to deploy a production-ready DeepSeek model inference service.

Background

DeepSeek-R1 model

DeepSeek-R1 is the first-generation reasoning model released by DeepSeek. It is designed to improve the reasoning capability of large language models through large-scale reinforcement learning. Test results show that DeepSeek-R1 performs well on tasks such as mathematical reasoning and programming competitions. It outperforms other closed-source models and, on certain tasks, matches or surpasses the OpenAI-O1 series. DeepSeek-R1 also performs well on knowledge-based tasks and a wide range of other task types, including creative writing and general question answering. In addition, DeepSeek distills this reasoning capability into smaller models by fine-tuning existing models such as Qwen and Llama. The distilled 14B model significantly outperforms the existing open-source model QwQ-32B, and the distilled 32B and 70B models both set new records. For more information about DeepSeek models, see the DeepSeek AI GitHub repository.

KServe

KServe is an open-source, cloud-native model serving platform that simplifies deploying and running machine learning models on Kubernetes. It supports multiple machine learning frameworks and provides elastic scaling. KServe deploys models through a declarative API that you define in simple YAML files, which makes configuring and managing model services easier. For more information about the KServe open-source project, see KServe.

Arena

Arena is a lightweight Kubernetes-based machine learning solution that supports the complete lifecycle of data preparation, model development, model training, and model prediction. This improves the efficiency of data scientists. Arena is deeply integrated with underlying Alibaba Cloud services and supports services such as GPU sharing and Cloud Parallel File Storage (CPFS). You can run deep learning frameworks optimized by Alibaba Cloud to maximize the performance and cost benefits of Alibaba Cloud heterogeneous devices. For more information about Arena, see the Arena GitHub repository.

Prerequisites

GPU instance specifications and cost estimation

During inference, model parameters consume most of the GPU memory. You can calculate the required GPU memory by using the following formula.

Take a 7B model whose default precision is FP16 as an example. The number of model parameters is 7B (7 billion), and the number of bytes of the precision data type is: default precision of 16-bit floating-point / 8 bits per byte = 2 bytes.

In addition to the GPU memory used to load the model, you must also consider the size of the KV cache required for computation and GPU utilization. A portion of GPU memory is usually reserved as a buffer. Therefore, use a GPU instance with 24 GiB of GPU memory, such as ecs.gn7i-c8g1.2xlarge or ecs.gn7i-c16g1.4xlarge. For more information, see Recommended instance types. For more information about GPU instance types and billing, see GPU-accelerated compute-optimized instance families and Billing for Elastic GPU Service.

Model deployment

Step 1: Prepare the DeepSeek-R1-Distill-Qwen-7B model files

  1. Run the following commands to download the DeepSeek-R1-Distill-Qwen-7B model from ModelScope.

    Note

    Make sure that the git-lfs plugin is installed. If it is not installed, run yum install git-lfs or apt-get install git-lfs to install it. For more installation methods, see Install git-lfs.

    git lfs install
    GIT_LFS_SKIP_SMUDGE=1 git clone https://www.modelscope.cn/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B.git
    cd DeepSeek-R1-Distill-Qwen-7B/
    git lfs pull
  2. Create a directory in Object Storage Service (OSS) and upload the model to OSS.

    Note

    For more information about how to install and use ossutil, see Install ossutil.

    ossutil mkdir oss://<your-bucket-name>/models/DeepSeek-R1-Distill-Qwen-7B
    ossutil cp -r ./DeepSeek-R1-Distill-Qwen-7B oss://<your-bucket-name>/models/DeepSeek-R1-Distill-Qwen-7B
  3. Create a Persistent Volume (PV) and a Persistent Volume Claim (PVC). For the target cluster, configure a PV named llm-model and a PVC. For more information, see Use an ossfs 1.0 static volume.

    Console

    The following table describes the basic configurations of the sample PV:

    Parameter

    Description

    PV type

    OSS

    Name

    llm-model

    Access certificate

    The AccessKey ID and AccessKey secret that are used to access OSS.

    Bucket ID

    Select the OSS bucket that you created in the previous step.

    OSS Path

    Select the path where the model is stored, such as /models/DeepSeek-R1-Distill-Qwen-7B.

    The following table describes the basic configurations of the sample PVC:

    Parameter

    Description

    PVC type

    OSS

    Name

    llm-model

    Allocation mode

    Select an existing PV.

    Existing volumes

    Click the Select Existing Volume link and select the PV that you created.

    kubectl

    Sample YAML file:

    apiVersion: v1
    kind: Secret
    metadata:
      name: oss-secret
    stringData:
      akId: <your-oss-ak> # The credential used to access OSS: AccessKey ID
      akSecret: <your-oss-sk> # The credential used to access OSS: AccessKey Secret
    ---
    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: llm-model
      labels:
        alicloud-pvname: llm-model
    spec:
      capacity:
        storage: 30Gi 
      accessModes:
        - ReadOnlyMany
      persistentVolumeReclaimPolicy: Retain
      csi:
        driver: ossplugin.csi.alibabacloud.com
        volumeHandle: llm-model
        nodePublishSecretRef:
          name: oss-secret
          namespace: default
        volumeAttributes:
          bucket: <your-bucket-name> # bucket name
          url: <your-bucket-endpoint> # Endpoint information, such as oss-cn-hangzhou-internal.aliyuncs.com
          otherOpts: "-o umask=022 -o max_stat_cache_size=0 -o allow_other"
          path: <your-model-path> # In this example, the path is /models/DeepSeek-R1-Distill-Qwen-7B/
    ---
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: llm-model
    spec:
      accessModes:
        - ReadOnlyMany
      resources:
        requests:
          storage: 30Gi
      selector:
        matchLabels:
          alicloud-pvname: llm-model

Step 2: Deploy the inference service

  1. Run the following command to start an inference service named deepseek.

    arena serve kserve \
        --name=deepseek \
        --image=kube-ai-registry.cn-shanghai.cr.aliyuncs.com/kube-ai/vllm:v0.6.6 \
        --gpus=1 \
        --cpu=4 \
        --memory=12Gi \
        --data=llm-model:/models/DeepSeek-R1-Distill-Qwen-7B \
        "vllm serve /models/DeepSeek-R1-Distill-Qwen-7B --port 8080 --trust-remote-code --served-model-name deepseek-r1 --max-model-len 32768 --gpu-memory-utilization 0.95 --enforce-eager"

    The following table describes the parameters.

    Parameter

    Required

    Description

    --name

    Yes

    The name of the inference service that you submit. The name must be globally unique.

    --image

    Yes

    The image address of the inference service.

    --gpus

    No

    The number of GPUs required by the inference service. Default value: 0.

    --cpu

    No

    The number of CPUs required by the inference service.

    --memory

    No

    The amount of memory required by the inference service.

    --data

    No

    The model address of the inference service. In this topic, the model is the llm-model PV that you created in the previous step, which is mounted to the /models/ directory in the container.

    Expected output:

    inferenceservice.serving.kserve.io/deepseek created
    INFO[0003] The Job deepseek has been submitted successfully
    INFO[0003] You can run `arena serve get deepseek --type kserve -n default` to check the job status

Step 3: Verify the inference service

  1. Run the following command to view the deployment status of the KServe inference service.

    arena serve get deepseek

    Expected output:

    Name:       deepseek
    Namespace:  default
    Type:       KServe
    Version:    1
    Desired:    1
    Available:  1
    Age:        3m
    Address:    http://deepseek-default.example.com
    Port:       :80
    GPU:        1
    Instances:
      NAME                                 STATUS   AGE  READY  RESTARTS  GPU  NODE
      ----                                 ------   ---  -----  --------  ---  ----
      deepseek-predictor-7cd4d568fd-fznfg  Running  3m   1/1    0         1    cn-beijing.172.16.1.77

    The output indicates that the KServe inference service is deployed.

  2. Run the following commands to access the inference service by using the obtained Nginx Ingress gateway address.

    # Get the IP address of the Nginx Ingress.
    NGINX_INGRESS_IP=$(kubectl -n kube-system get svc nginx-ingress-lb -ojsonpath='{.status.loadBalancer.ingress[0].ip}')
    # Get the hostname of the inference service.
    SERVICE_HOSTNAME=$(kubectl get inferenceservice deepseek -o jsonpath='{.status.url}' | cut -d "/" -f 3)
    # Send a request to access the inference service.
    curl -H "Host: $SERVICE_HOSTNAME" -H "Content-Type: application/json" http://$NGINX_INGRESS_IP:80/v1/chat/completions -d '{"model": "deepseek-r1", "messages": [{"role": "user", "content": "Say this is a test!"}], "max_tokens": 512, "temperature": 0.7, "top_p": 0.9, "seed": 10}'

    Expected output:

    {"id":"chatcmpl-0fe3044126252c994d470e84807d4a0a","object":"chat.completion","created":1738828016,"model":"deepseek-r1","choices":[{"index":0,"message":{"role":"assistant","content":"<think>\n\n</think>\n\nIt seems like you're testing or sharing some information. How can I assist you further? If you have any questions or need help with something, feel free to ask!","tool_calls":[]},"logprobs":null,"finish_reason":"stop","stop_reason":null}],"usage":{"prompt_tokens":9,"total_tokens":48,"completion_tokens":39,"prompt_tokens_details":null},"prompt_logprobs":null}

Observability

Observability is critical for large language model (LLM) inference services in a production environment because it helps you detect and locate faults in advance. The vLLM framework provides many LLM inference metrics. For more information about the metrics, see the Metrics documentation. KServe also provides metrics to help you monitor the performance and health of model services. These capabilities are integrated into Arena. When you submit the application, you need only add the --enable-prometheus=true parameter.

arena serve kserve \
    --name=deepseek \
    --image=kube-ai-registry.cn-shanghai.cr.aliyuncs.com/kube-ai/vllm:v0.6.6 \
    --gpus=1 \
    --cpu=4 \
    --memory=12Gi \
    --enable-prometheus=true \
    --data=llm-model:/models/DeepSeek-R1-Distill-Qwen-7B \
    "vllm serve /models/DeepSeek-R1-Distill-Qwen-7B --port 8080 --trust-remote-code --served-model-name deepseek-r1 --max-model-len 32768 --gpu-memory-utilization 0.95 --enforce-eager"

You can use a Grafana dashboard to observe the LLM inference service that is deployed based on vLLM. First, import the vLLM Grafana JSON model into Grafana, and then create an observability dashboard for the LLM inference service. For more information about the JSON model to import, see the vLLM official website. For more information about how to import a dashboard, see Export and import Grafana dashboards. The following figure shows the dashboard after configuration:

image

Import a Grafana dashboard

Import the dashboard

  1. Log on to the ARMS console.

  2. In the navigation pane on the left, click Integration Management.

  3. On the Integrated Environments tab, select Container Environment, search for an environment by ACK cluster name, and then click the target environment.

  4. On the Component Management tab, copy and save the Cluster ID, and then click Dashboard Directory.

    In the Basic Information section at the top of the page, you can find the Cluster ID field and the Dashboard Directory field. The dashboard directory name contains the cluster ID.

  5. On the right side of the Dashboards tab, click Import.

  6. Copy the grafana.json file contents and paste them into the Import via panel json text box, and then click Load.

    Note

    You can also import the dashboard by uploading a JSON file.

  7. Keep the default settings and click Import. The observability dashboard for the LLM inference service is imported.

Verify the dashboard data

  1. Search for a data source by using the saved cluster ID or the Prometheus instance ID, and then select the target data source.

    image

  2. Send several requests to access the inference service, which simulates inference traffic. Then, verify the observability dashboard data of the LLM inference service, such as Token Throughput.

    image

Auto scaling

When you deploy and manage KServe model services, you may encounter dynamic load fluctuations. KServe uses the Horizontal Pod Autoscaler (HPA) feature of Kubernetes and the ack-alibaba-cloud-metrics-adapter add-on of ACK. It automatically adjusts the number of pods for a model service based on CPU utilization, memory utilization, GPU utilization, and custom performance metrics to keep the service stable and efficient. For more information, see Configure auto scaling for a service.

Model acceleration

As technology evolves, the model data of AI applications keeps growing. However, pulling these large files from storage services such as OSS and NAS may cause long delays and cold start issues. You can use Fluid to significantly accelerate model loading and improve the performance of inference services, especially KServe-based inference services. For more information, see Accelerate models using Fluid.

Canary release

Publishing application updates is the most common operation in a production environment. To keep your business stable and reduce change risks, a canary release is essential. ACK supports multiple canary release strategies, such as canary releases based on a traffic percentage or on request headers. For more information, see Implement a phased release for an inference service.

GPU sharing inference

The DeepSeek-R1-Distill-Qwen-7B model requires only 14 GB of GPU memory. If you use a GPU instance type with higher specifications, you can use GPU sharing inference to improve GPU utilization. GPU sharing partitions a single GPU so that multiple inference services share it, which improves GPU utilization. For more information, see Deploy GPU-shared Inference Services.

References