Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page
Help Center/ ModelArts/ ModelArts User Guide (Lite Cluster)/ Using Lite Cluster Resources/ Using Snt9B for Inference in a Lite Cluster Resource Pool

Using Snt9B for Inference in a Lite Cluster Resource Pool

Updated on 2024-12-31 GMT+08:00

Description

This case outlines the process of using the Deployment mechanism to deploy a real-time inference service in the Snt9B environment. Create a pod to host the service, log in to the pod container to deploy the real-time service, and create a terminal as the client to access the service to test its functions.

Figure 1 Task diagram

Procedure

  1. Pulls the image. The test image is bert_pretrain_mindspore:v1, which contains the test data and code.

    docker pull swr.cn-southwest-2.myhuaweicloud.com/os-public-repo/bert_pretrain_mindspore:v1
    docker tag swr.cn-southwest-2.myhuaweicloud.com/os-public-repo/bert_pretrain_mindspore:v1 bert_pretrain_mindspore:v1

  2. Create the config.yaml file on the host.

    Configure Pods using this file. For debugging, start a Pod with the sleep command. Alternatively, replace the command with the boot command for your job (for example, python inference.py). The job will run once the container starts.

    The file content is as follows:
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: yourapp
      labels:
          app: infers
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: infers
      template:
        metadata: 
          labels:
             app: infers
        spec:
          schedulerName: volcano
          nodeSelector:
            accelerator/huawei-npu: ascend-1980
          containers:
          - image: bert_pretrain_mindspore:v1                  # Inference image name
            imagePullPolicy: IfNotPresent
            name: mindspore
            command:
            - "sleep"
            - "1000000000000000000"
            resources:
              requests:
    huawei.com/ascend-1980: "1"      # Number of required NPUs. The maximum value is 16. You can add lines below to configure resources such as memory and CPU. The key remains unchanged.
              limits:
    huawei.com/ascend-1980: "1"        # Limits the number of cards. The key remains unchanged. The value must be consistent with that in requests.
            volumeMounts:
              - name: ascend-driver               # Mount driver. Retain the settings.
              mountPath: /usr/local/Ascend/driver
              - name: ascend-add-ons           # Mount driver. Retain the settings.
              mountPath: /usr/local/Ascend/add-ons
              - name: hccn                             # HCCN configuration of the driver. Retain the settings.
              mountPath: /etc/hccn.conf
            - name: npu-smi                             #npu-smi
              mountPath: /usr/local/sbin/npu-smi
            - name: localtime                       #The container time must be the same as the host time.
              mountPath: /etc/localtime
          volumes:
          - name: ascend-driver
            hostPath:
              path: /usr/local/Ascend/driver
          - name: ascend-add-ons
            hostPath:
              path: /usr/local/Ascend/add-ons
          - name: hccn
            hostPath:
              path: /etc/hccn.conf
          - name: npu-smi
            hostPath:
              path: /usr/local/sbin/npu-smi
          - name: localtime
            hostPath:
              path: /etc/localtime

  3. Create a pod based on the config.yaml file.

    kubectl apply -f config.yaml

  4. Run the following command to check the pod startup status. If 1/1 running is displayed, the startup is successful.

    kubectl get pod -A

  5. Go to the container, replace {pod_name} with your pod name (displayed by the get pod command), and replace {namespace} with your namespace (default).

    kubectl exec -it {pod_name} bash -n {namespace}

  6. Activate the conda mode.

    su - ma-user //Switch the user identity.
    conda activate MindSpore //Activate the MindSpore environment.

  7. Create test code test.py.

    from flask import Flask, request
    import json 
    app = Flask(__name__)
    
    @app.route('/greet', methods=['POST'])
    def say_hello_func():
        print("----------- in hello func ----------")
        data = json.loads(request.get_data(as_text=True))
        print(data)
        username = data['name']
        rsp_msg = 'Hello, {}!'.format(username)
        return json.dumps({"response":rsp_msg}, indent=4)
    
    @app.route('/goodbye', methods=['GET'])
    def say_goodbye_func():
        print("----------- in goodbye func ----------")
        return '\nGoodbye!\n'
    
    
    @app.route('/', methods=['POST'])
    def default_func():
        print("----------- in default func ----------")
        data = json.loads(request.get_data(as_text=True))
        return '\n called default func !\n {} \n'.format(str(data))
    
    # host must be "0.0.0.0", port must be 8080
    if __name__ == '__main__':
        app.run(host="0.0.0.0", port=8080)
    Execute the code. After the code is executed, a real-time service is deployed. The container is the server.
    python test.py
    Figure 2 Deploying a real-time service

  8. Open a terminal in XShell and access the container (client) by referring to steps 5 to 7. Run the following commands to test the functions of the three APIs of the custom image. If the following information is displayed, the service is successfully invoked.

    curl -X POST -H "Content-Type: application/json" --data '{"name":"Tom"}'  127.0.0.1:8080/
    curl -X POST -H "Content-Type: application/json" --data '{"name":"Tom"}' 127.0.0.1:8080/greet
    curl -X GET 127.0.0.1:8080/goodbye
    Figure 3 Accessing a real-time service
    NOTE:

    Set limit and request to proper values to restrict the number of CPUs and memory size. A single Snt9B node is equipped with eight Snt9B cards and 192u1536g. Properly plan the CPU and memory allocations to avoid task failures due to insufficient CPU and memory limits.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback