Deploy your QwQ-32B model

Updated at:

Deploy the QwQ-32B reasoning model on Elastic Container Instance (ECI) with DataCache to eliminate model download time during instance startup. This tutorial walks you through creating a DataCache for the QwQ-32B model, deploying the inference service on a GPU-powered ECI instance, and testing the service endpoint.

Deploying a containerized large language model inference service involves creating and starting the container, pulling the image, downloading the model files, and loading the model into memory. Because both the container image and the model files are large, pulling them consumes significant time and network bandwidth. The DataCache feature of ECI allows you to pre-load model data into a cache and mount it directly when you create an instance, which removes the wait for the model download. The image cache feature works the same way for container images. For more information about ECI, see Benefits.

Prerequisites

  • A virtual private cloud (VPC) is configured with Internet access. The VPC must be associated with an Internet NAT gateway with an SNAT entry configured so that resources in the VPC or its vSwitches can access the Internet. If the VPC is not associated with a NAT gateway, you can associate elastic IP addresses (EIPs) when you create the DataCache and deploy the application to pull data over the Internet.

  • Sufficient quota for GPU instances in the target region. The deployment requires a GPU instance type with at least four A10 GPUs.

  • Resource Access Management (RAM) permissions to create ECI instances and manage DataCaches.

Important

Deploying the QwQ-32B inference service (Step 2) requires specifying a GPU driver version, which the console does not currently support. You must use the API to complete the deployment.

Prepare the runtime environment

Recommended instance types

Use one of the following GPU instance types, or a higher-specification GPU instance type with at least four A10 GPUs:

Software environment

Large language model deployment depends on many libraries and settings. vLLM is a mainstream large language model inference engine, and this tutorial uses vLLM to deploy the inference service. ECI provides a public container image that you can use directly or extend as a base image:

  • Image address (public endpoint):registry.cn-beijing.aliyuncs.com/eci_open/vllm-openai:v0.7.2

  • Image address (VPC endpoint):registry-vpc.cn-beijing.aliyuncs.com/eci_open/vllm-openai:v0.7.2

  • Image size: approximately 16.5 GiB

    Use the VPC endpoint when pulling the image from within an ECI instance. The public endpoint is suitable for non-VPC environments such as DataCache data source pulls.

Step 1: Create your DataCache for QwQ-32B

Create a DataCache to pre-load the QwQ-32B model data. Use the console for a quick setup or the OpenAPI for automation and integration with your existing workflows.

Console

  1. Go to ModelScope and get the model ID.

    This tutorial uses the master version of the QwQ-32B model. After you find the model on ModelScope, copy the model ID from the top of the model details page.

  2. Log on to the Elastic Container Instance console.

  3. In the upper-left corner of the top menu bar, select a region.

  4. In the left-side navigation pane, choose Data Cache.

  5. Click Create Data Cache.

  6. Configure the DataCache parameters.

    The following table lists the configuration items used in this tutorial. The cache data source is the fixed configuration for pulling the QwQ-32B model. The other parameters can be customized. For more information, see Create a data cache.

    Configuration item

    Example value

    Cache Bucket

    default

    Cache Directory

    /models/qwq-32b

    Cache Name

    qwq-32b

    Cache Size

    70GiB

    Cache Data Source

    • Type: URL

    • Parameters

    • repoSource: ModelScope/Model

    • repoId: Qwen/QwQ-32B

  7. Click OK.

  8. View the cache status.

    Refresh the Data Cache page to view the cache status. A status of Available indicates that the cached data is ready to use. Alibaba Cloud provides hot loading for the QwQ-32B model, so the DataCache is created within seconds.

OpenAPI

  1. Go to ModelScope and get the model ID.

    This tutorial uses the master version of the QwQ-32B model. After you find the model on ModelScope, copy the model ID from the top of the model details page.

  2. Create a DataCache for QwQ-32B.

    Call the CreateDataCache operation. Use a software development kit (SDK).

    The following Java SDK example pulls the specified model data from ModelScope and saves it to the /models/qwq-32b directory of the bucket named default.

    CreateDataCacheRequest request = new CreateDataCacheRequest();
    request.setName("qwq-32b");
    request.setBucket("default");
    request.setPath("/models/qwq-32b");
    request.setVSwitchId("vsw-2ze*********");
    request.setSecurityGroupId("sg-2ze*********");
    CreateDataCacheRequest.DataSource dataSource = new CreateDataCacheRequest.DataSource();
    dataSource.setType("URL");
    HashMap<String, String> options = new HashMap<>();
    options.put("repoId", "Qwen/QwQ-32B");
    options.put("repoSource", "ModelScope/Model");
    dataSource.setOptions(options);
    request.setDataSource(dataSource);
  3. Query the cache status.

    Use the returned DataCache ID to call the DescribeDataCaches operation to query DataCache information. When the status of the DataCache (DataCaches.Status) is Available, the DataCache is ready to use.

Step 2: Deploy your QwQ-32B inference service

This step requires the API. The console does not support specifying a GPU driver version, which is required for QwQ-32B deployment.

  1. Create an ECI instance with the DataCache mounted.

    The following example shows the parameters used to call the CreateContainerGroup operation. The instance uses a GPU instance type and mounts the QwQ-32B model from the DataCache. After the container starts, it runs vllm serve /models/QwQ-32B --port 8000 --trust-remote-code --served-model-name qwq-32b --tensor-parallel=4 --max-model-len 8192 --gpu-memory-utilization 0.95 --enforce-eager to start the vLLM inference engine.

    Note

    In the following example, the system automatically creates an EIP and associates it with the ECI instance. If the VPC is already associated with an Internet NAT gateway, you do not need to associate an EIP when you create the ECI instance. After the instance is created, you can configure DNAT entries to allow external access to the ECI instance.

    The InstanceType field in this example lists multiple instance types separated by commas. Specify one of these types based on availability in your region.

    {
      "RegionId": "cn-beijing",
      "SecurityGroupId": "sg-2ze**************",
      "VSwitchId": "vsw-2ze**************",
      "ContainerGroupName": "qwq-32b-server",
      "InstanceType": "ecs.gn7i-4x.8xlarge,ecs.gn7i-4x.16xlarge,ecs.gn7i-c32g1.32xlarge",
      "DataCacheBucket": "default",
      "GpuDriverVersion": "tesla=535.161.08",
      "EphemeralStorage": 20,
      "Container": [
        {
          "Arg": [
            "-c",
            "vllm serve /models/QwQ-32B --port 8000 --trust-remote-code --served-model-name qwq-32b --tensor-parallel=4 --max-model-len 8192 --gpu-memory-utilization 0.95 --enforce-eager"
          ],
          "Command": [
            "/bin/sh"
          ],
          "Gpu": 4,
          "Name": "vllm",
          "Image": "registry-vpc.cn-beijing.aliyuncs.com/eci_open/vllm-openai:v0.7.2",
          "VolumeMount": [
            {
              "Name": "llm-model",
              "MountPath": "/models/QwQ-32B"
            },
            {
              "Name": "dshm",
              "MountPath": "/dev/shm"
            }
          ]
        }
      ],
      "Volume": [
        {
          "Type": "HostPathVolume",
          "HostPathVolume.Path": "/models/qwq-32b",
          "Name": "llm-model"
        },
        {
          "Type": "EmptyDirVolume",
          "Name": "dshm",
          "EmptyDirVolume.Medium": "Memory",
          "EmptyDirVolume.SizeLimit": "30Gi"
        }
      ],
      "DataCacheProvisionedIops": 15000,
      "DataCacheBurstingEnabled": true,
      "AutoCreateEip": true
    }
  2. Confirm the deployment status.

    Use the returned instance ID to call the DescribeContainerGroupStatus operation to query the instance status and the container status. When the instance status (Status) and the container status (ContainerStatuses.State) are both Running, the instance is created and the container is running.

  3. Query the EIP address of the instance.

    Use the returned instance ID to call the DescribeContainerGroups operation to query the instance details. The EIP address of the instance is available in the InternetIp field.

Step 3: Test the inference service

  1. Add an inbound rule to the security group of the ECI instance to allow traffic on port 8000.

  2. Send a model inference request to the inference service.

    The QwQ-32B instance deployed in this tutorial is associated with an EIP. Replace XX.XX.XX.XX in the sample code with the actual EIP address.

    curl -X POST http://XX.XX.XX.XX:8000/v1/chat/completions \
         -H "Content-Type: application/json" \
         -d '{
               "model": "qwq-32b",
               "messages": [
                   {
                       "role": "user",
                       "content": "Briefly describe cloud computing in one sentence"
                   }
               ],
               "temperature": 0.6,
               "max_tokens": 3000
             }' \
         --verbose
    {
      "id": "chatcmpl-7678099ec2b24852bc5b96b1227b0010",
      "object": "chat.completion",
      "model": "qwq-32b",
      "choices": [
        {
          "index": 0,
          "message": {
            "role": "assistant",
            "content": "Cloud computing is a model that delivers elastically scalable computing resources, such as servers, storage, networks, and applications, over the Internet, so that you access them on demand and pay only for what you use, without building your own infrastructure."
          },
          "finish_reason": "stop"
        }
      ],
      "usage": {
        "prompt_tokens": 15,
        "total_tokens": 450,
        "completion_tokens": 435
      }
    }

    The <think> block that may precede the final answer in the full response contains the internal reasoning steps that the model performs before it generates the final answer. These steps are not part of the final output.

    The final answer is as follows:

    Cloud computing is a model that delivers elastically scalable computing resources, such as servers, storage, networks, and applications, over the Internet, so that you access them on demand and pay only for what you use, without building your own infrastructure.

Clean up

After you finish testing, release the following resources to avoid ongoing charges:

  • The ECI instance created in Step 2

  • The DataCache created in Step 1

    For instructions on how to release these resources, see the relevant API reference or console documentation.