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

Example: Creating a Training Job Using a Custom Image

Updated on 2023-09-06 GMT+08:00
NOTE:

This section describes how to use a custom image to train a model based on the training module of the old version. The training module of the old version is only available for its existing users. For details about how to use custom images in training of the new version, see Using a Custom Image to Train Models (New-Version Training).

The files required in this example are stored in GitHub. This example uses the MNIST dataset downloaded from the MNIST official website.

  • mnist_softmax.py: standalone training script

Creating and Uploading a Custom Image

In this example, the Dockerfile file is used to customize an image.

A Linux x86_x64 host is used here. You can purchase an ECS of the same specifications or use an existing local host to create a custom image.

  1. Install Docker. For details, see https://docs.docker.com/engine/install/binaries/#install-static-binaries.

    The following uses the Linux x86_64 OS as an example to describe how to obtain the Docker installation package. Run the following command to install the Docker software:

    curl -fsSL get.docker.com -o get-docker.sh
    sh get-docker.sh

    If the docker images command is successfully executed, Docker has been installed. In this case, skip this step.

  2. Obtain a basic image.

    A custom image used for a training job must be compiled based on a basic image. For details about the formats of basic image names, see Overview of a Basic Image Package. Run the following command to obtain a basic image for custom images:

    docker pull swr.<region>.myhuaweicloud.com/<image org>/<image name>

    In addition, you can run the docker images command to view the local image list.

  3. Compile a Dockerfile for building a custom image.

    This example uses a TensorFlow 1.13.2 image. The file name is tf-1.13.2.dockerfile. Run the vi tf-1.13.2.dockerfile command to switch to the Dockerfile.

    For details about how to compile Dockerfile, see Dockerfile Reference.

    FROM swr.cn-north-4.myhuaweicloud.com/modelarts-job-dev-image/custom-base-cuda10.0-cp36-ubuntu18.04-x86:1.1
    # Configure the HUAWEI CLOUD source and install TensorFlow.
    RUN cp -a /etc/apt/sources.list /etc/apt/sources.list.bak && \
    sed -i "s@http://.*archive.ubuntu.com@http://repo.myhuaweicloud.com@g"  /etc/apt/sources.list && \
    sed -i "s@http://.*security.ubuntu.com@http://repo.myhuaweicloud.com@g"  /etc/apt/sources.list && \
    pip install  --trusted-host https://repo.huaweicloud.com -i https://repo.huaweicloud.com/repository/pypi/simple  tensorflow==1.13.2
    # Configure environment variables.
    ENV PATH=/root/miniconda3/bin/:$PATH
  4. Create a custom image.

    In the following example, the image is in the cn-north-4 region and belongs to the deep-learning-diy organization. Run the following command in the directory where the tf-1.13.2.dockerfile file resides:

    1
    docker build -f tf-1.13.2.dockerfile . -t swr.cn-north-4.myhuaweicloud.com/deep-learning-diy/tf-1.13.2:latest
    
  5. Push the image to SWR. For details about how to upload an image, see Software Repository for Container User Guide.

    The prerequisite is that you have created an organization and obtained the SWR login command. In the following example, the image is in the cn-north-4 region and belongs to the deep-learning-diy organization. Run the following command to push the image to SWR:

    1
    docker push swr.cn-north-4.myhuaweicloud.com/deep-learning-diy/tf-1.13.2:latest
    

    swr.cn-north-4.myhuaweicloud.com/deep-learning-diy/tf-1.13.2:latest is the SWR URL of the custom image.

Standalone Training

  1. Upload training code mnist_softmax.py and training data to OBS. Store the code and data in the code root directory so that they can be directly downloaded to the container.

    The root directory obs://deep-learning/new/mnist/ is used as an example.

    The training code file is obs://deep-learning/new/mnist/.

    The data is stored in obs://deep-learning/new/mnist/mnist_data.

  2. Create a training job using a custom image. Set Data Storage Location and Training Output Path based on site requirements. Set Image Path, Code Directory, and Boot Command as follows:
    • Image Path: Enter the SWR URL of the uploaded image.
    • Code Directory: Enter the OBS path for storing the training code, that is, the code root directory in 1.

      Before a training job is started, ModelArts automatically recursively downloads all content in the code directory to the local path of the container. The local path of the container is /home/work/user-job-dir/${Last level of the code root directory}/. For example, if Code Directory is set to obs://deep-learning/new/mnist, the local path is /home/work/user-job-dir/mnist/, and the code boot file is /home/work/user-job-dir/mnist/mnist_softmax.py.

    • Boot Command: bash /home/work/run_train.sh python /home/work/user-job-dir/mnist/mnist_softmax.py --data_url /home/work/user-job-dir/mnist/mnist_data

      /home/work/user-job-dir/mnist/mnist_softmax.py is the code boot file, and --data_url /home/work/user-job-dir/mnist/mnist_data is the data storage path.

  3. After the training job is created, the code directory is downloaded, the custom image is reviewed, and the training job is completed in the background. Generally, training jobs run for a period of time, which may be several minutes or tens of minutes depending on the amount of data and resources you select. After the program is executed successfully, the log similar to the following is outputted:
    Figure 1 Run log information

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