Updated on 2024-07-25 GMT+08:00

Creating a Training Job

Model training continuously iterates and optimizes model weights. ModelArts training management allows you to create training jobs, view training status, and manage training versions. Through model training, you can test various combinations of model structures, data, and hyperparameters to obtain the optimal model structure and weight.

Prerequisites

  • The data used for training has been uploaded to an OBS directory.
  • At least one empty folder has been created in OBS for storing the training output.

    OBS buckets are not encrypted. ModelArts does not support encrypted OBS buckets. When creating an OBS bucket, do not enable bucket encryption.

  • The account is not in arrears because resources are consumed when training jobs are running.
  • The OBS directory you use and ModelArts are in the same region.
  • Access authorization has been configured. For details, see Configuring Access Authorization (Global Configuration).
  • (Optional) An algorithm is available in Algorithm Management if you want to use it to create a training job. For details, see Introduction to Algorithm Preparation.
  • (Optional) A custom image has been uploaded to SWR if you want to use it to create a training job. For details, see How Can I Log In to SWR and Upload Images to It?

Operation Procedure

To create a training job, follow these steps:

  1. Access the page for creating a training job. For details, see Accessing the Page for Creating a Training Job.
  2. Configure basic information about the training job. For details, see Configuring Basic Information About a Training Job.
  3. Select an algorithm type for creating the training job.

  4. Configure training parameters, including the input, output, hyperparameters, and environment variables. For details, see Configuring Training Parameters.
  5. Select a resource pool as required. A dedicated resource pool is recommended. For details about the differences between dedicated resource pools and public resource pools, see Differences Between Dedicated Resource Pools and Public Resource Pools.

  6. Set tags if you want to manage training jobs by group. For details, see (Optional) Setting Tags.
  7. Perform follow-up procedure. For details, see Follow-Up Procedure.

Accessing the Page for Creating a Training Job

  1. Log in to the ModelArts console.
  2. In the navigation pane, choose Training Management > Training Jobs. The training job list is displayed.
  3. Click Create Training Job. The Create Training Job page is displayed.

Configuring Basic Information About a Training Job

On the Create Training Job page, set parameters.

Table 1 Basic information for creating a training job

Parameter

Description

Name

Name of a training job, which is mandatory.

The system automatically generates a name. You can rename it based on the following naming rules:

  • The name contains 1 to 64 characters.
  • Letters, digits, hyphens (-), and underscores (_) are allowed.

Description

Job description, which helps you learn about the job information in the training job list.

Choosing a Boot Mode (Preset Image)

If you use a preset image to create a training job, select a boot mode by referring to Table 2.
Table 2 Creating a training job using a preset image

Parameter

Description

Algorithm Type

Select Custom algorithm. This parameter is mandatory.

Boot Mode

Select Preset image and select the preset image engine and engine version to be used by the training job.

If you select Customize for the engine version, select a custom image from Image.

Image

This parameter is displayed and mandatory only when the preset image version is set to Customize.

You can set the container image path in either of the following ways:
  • To select your image or an image shared by others, click Select on the right and select a container image for training. The required image must be uploaded to SWR beforehand.
  • To select a public image, enter the address of the public image in SWR. Enter the image path in the format of "Organization name/Image name:Version name". Do not contain the domain name (swr.<region>.myhuaweicloud.com) in the path because the system will automatically add the domain name to the path. For example, if the SWR address of a public image is swr.<region>.myhuaweicloud.com/test-image/tensorflow2_1_1:1.1.1, enter test-images/tensorflow2_1_1:1.1.1.

Code Directory

Select the OBS directory where the training code file is stored. This parameter is mandatory.

  • Upload code to the OBS bucket beforehand. The total size of files in the directory cannot exceed 5 GB, the number of files cannot exceed 1000, and the folder depth cannot exceed 32.
  • The training code file is automatically downloaded to the ${MA_JOB_DIR}/demo-code directory of the training container when the training job is started. demo-code is the last-level OBS directory for storing the code. For example, if Code Directory is set to /test/code, the training code file is downloaded to the ${MA_JOB_DIR}/code directory of the training container.

Boot File

Select the Python boot script of the training job in the code directory. This parameter is mandatory.

ModelArts supports only the boot file written in Python. Therefore, the boot file must end with .py.

Local Code Directory

Specify the local directory of a training container. When a training starts, the system automatically downloads the code directory to this directory.

The default local code directory is /home/ma-user/modelarts/user-job-dir. This parameter is optional.

Work Directory

During training, the system automatically runs the cd command to execute the boot file in this directory.

Choosing a Boot Mode (Custom Image)

If you use a custom image to create a training job, select a boot mode by referring to Table 3.
Table 3 Creating a training job using a custom image

Parameter

Description

Algorithm Type

Select Custom algorithm. This parameter is mandatory.

Boot Mode

Select Custom image. This parameter is mandatory.

Image

Container image path. This parameter is mandatory.

You can set the container image path in either of the following ways:
  • To select your image or an image shared by others, click Select on the right and select a container image for training. The required image must be uploaded to SWR beforehand.
  • To select a public image, enter the address of the public image in SWR. Enter the image path in the format of "Organization name/Image name:Version name". Do not contain the domain name (swr.<region>.myhuaweicloud.com) in the path because the system will automatically add the domain name to the path. For example, if the SWR address of a public image is swr.<region>.myhuaweicloud.com/test-image/tensorflow2_1_1:1.1.1, enter test-images/tensorflow2_1_1:1.1.1.

Code Directory

Select the OBS directory where the training code file is stored. If the custom image does not contain training code, you need to set this parameter. If the custom image contains training code, you do not need to set this parameter.

  • Upload code to the OBS bucket beforehand. The total size of files in the directory cannot exceed 5 GB, the number of files cannot exceed 1000, and the folder depth cannot exceed 32.
  • The training code file is automatically downloaded to the ${MA_JOB_DIR}/demo-code directory of the training container when the training job is started. demo-code is the last-level OBS directory for storing the code. For example, if Code Directory is set to /test/code, the training code file is downloaded to the ${MA_JOB_DIR}/code directory of the training container.

User ID

User ID for running the container. The default value 1000 is recommended.

If the UID needs to be specified, its value must be within the specified range. The UID ranges of different resource pools are as follows:

  • Public resource pool: 1000 to 65535
  • Dedicated resource pool: 0 to 65535

Boot Command

Command for booting an image. This parameter is mandatory.

When a training job is running, the boot command is automatically executed after the code directory is downloaded.
  • If the training boot script is a .py file, train.py for example, the boot command is as follows.
    python ${MA_JOB_DIR}/demo-code/train.py
  • If the training boot script is a .sh file, main.sh for example, the boot command is as follows.
    bash ${MA_JOB_DIR}/demo-code/main.sh

You can use semicolons (;) and ampersands (&&) to combine multiple commands. demo-code in the command is the last-level OBS directory where the code is stored. Replace it with the actual one.

Local Code Directory

Specify the local directory of a training container. When a training starts, the system automatically downloads the code directory to this directory.

The default local code directory is /home/ma-user/modelarts/user-job-dir. This parameter is optional.

Work Directory

During training, the system automatically runs the cd command to execute the boot file in this directory.

Choosing an Algorithm Type (My Algorithm)

Set Algorithm Type to My algorithm and select an algorithm from the algorithm list. If no algorithm meets the requirements, you can create an algorithm. For details, see Creating an Algorithm.

Configuring Training Parameters

Data is obtained from an OBS bucket or dataset for model training. The training output is also stored in an OBS bucket. When creating a training job, you can configure parameters such as input, output, hyperparameters, and environment variables by referring to Table 4.

The input, output, and hyperparameter parameters of a training job vary depending on the algorithm type selected during training job creation. If a parameter value is dimmed, the parameter has been configured in the algorithm code and cannot be modified.

Table 4 Parameters for creating a training job

Parameter

Sub-Parameter

Description

Input

Parameter name

The algorithm code reads the training input data based on the input parameter name.

The recommended value is data_url. The training input parameters must match the input parameters of the selected algorithm. For details, see Table 2.

Dataset

Click Dataset and select the target dataset and its version in the ModelArts dataset list.

When the training job is started, ModelArts automatically downloads the data in the input path to the training container.

NOTE:

ModelArts data management is being upgraded and is invisible to users who have not used data management. It is recommended that new users store their training data in OBS buckets.

Data path

Click Data path and select the storage path to the training input data from an OBS bucket.

When the training job is started, ModelArts automatically downloads the data in the input path to the training container.

Obtained from

The following uses training input data_path as an example.

  • If you select Hyperparameters, use this code to obtain the data:
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('--data_path')
    args, unknown = parser.parse_known_args()
    data_path = args.data_path 
  • If you select Environment variables, use this code to obtain the data:
    import os
    data_path = os.getenv("data_path", "")

Output

Parameter name

The algorithm code reads the training output data based on the output parameter name.

The recommended value is train_url. The training output parameters must match the output parameters of the selected algorithm. For details, see Table 3.

Data path

Click Data path and select the storage path to the training output data from an OBS bucket. During training, the system automatically synchronizes files from the local code directory of the training container to the data path.

NOTE:

The data path can only be an OBS path. To prevent any issues with data storage, choose an empty directory as the data path.

Obtained from

The following uses the training output train_url as an example.

  • If you select Hyperparameters, use this code to obtain the data:
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument('--train_url')
    args, unknown = parser.parse_known_args()
    train_url = args.train_url 
  • If you select Environment variables, use this code to obtain the data:
    import os
    train_url = os.getenv("train_url", "")

Predownload

Indicates whether to pre-download the files in the output directory to a local directory.

  • If you set Predownload to No, the system does not download the files in the training output data path to a local directory of the training container when the training job is started.
  • If you set Predownload to Yes, the system automatically downloads the files in the training output data path to a local directory of the training container when the training job is started. The larger the file size, the longer the download time. To avoid excessive training time, remove any unneeded files from the local code directory of the training container as soon as possible. If you want to use resumable training and incremental training, you must select Yes.

Hyperparameter

N/A

Used for training tuning. This parameter is determined by the selected algorithm. If hyperparameters have been defined in the algorithm, all hyperparameters in the algorithm are displayed.

Hyperparameters can be modified and deleted. The status depends on the hyperparameter constraint settings in the algorithm. For details, see Defining Hyperparameters.

Environment Variable

N/A

Add environment variables based on service requirements. For details about the environment variables preset in the training container, see Viewing Environment Variables of a Training Container.

Auto Restart

N/A

Once this function is enabled, you can set the number of restarts and whether to enable Unconditional auto restart.

After you enable auto restart, ModelArts will handle any exceptions caused by environmental issues during a training job. It will either automatically handle the exception or isolate the faulty node and then restart the job, which helps to increase the success rate of the training. To avoid losing training progress and make full use of compute power, ensure that your code logic supports resumable training before enabling this function. For details, see Resumable Training and Incremental Training.

The value ranges from 1 to 128. The default value is 3. The value cannot be changed once the training job is created. Set this parameter based on your needs.

If Unconditional auto restart is selected, the training job will be restarted unconditionally once the system detects a training exception. To prevent invalid restarts, it supports a maximum of three consecutive unconditional restarts.

If auto restart is triggered during training, the system records the restart information. You can check the fault recovery details on the training job details page. For details, see Viewing Fault Recovery Details.

Configuring a Public Resource Pool

To configure a public resource pool, refer to Table 5.
Table 5 Configuring a public resource pool for a training job

Parameter

Description

Resource Pool

Select Public resource pool.

Resource Type

Select the resource type required for training. This parameter is mandatory. If a resource type has been defined in the training code, select a proper resource type based on algorithm constraints. For example, if the resource type defined in the training code is CPU and you select other types, the training fails. If some resource types are invisible or unavailable for selection, they are not supported.

Specifications

Select the required resource specifications based on the resource type.

If Data path is selected for Input, you can click Check Input Size on the right to ensure the storage is larger than the input data size.

NOTICE:

The resource flavor GPU:n*tnt004 (n indicates a specific number) does not support multi-process training.

Compute Nodes

Select the number of compute nodes as required. The default value is 1.

  • If only one compute node is used, a single-node training job is created. ModelArts starts one training container on this node. The training container exclusively uses the compute resources of the selected flavor.
  • If more than one compute nodes are used, a distributed training job is created. For more information about distributed training configurations, see Distributed Training Functions.

Persistent Log Saving

If you select CPU or GPU flavors, Persistent Log Saving is available for you to set.

  • This function is disabled by default. ModelArts automatically stores the logs for 30 days. You can download all logs on the job details page to a local path.
  • After this function is enabled, set Job Log Path. The system permanently stores training logs to the specified OBS path.

Job Log Path

When enabling Persistent Log Saving, select an empty OBS directory for Job Log Path to store log files generated by the training job.

Ensure that you have read and write permissions to the selected OBS directory.

Event Notification

Indicates whether to enable event notification.

  • This function is disabled by default, which means SMN is disabled.
  • After this function is enabled, you will be notified of specific events, such as job status changes or suspected suspensions, via an SMS or email. Notifications will be billed based on SMN pricing. In this case, you must configure the topic name and events.
    • Topic: topic of event notifications. Click Create Topic to create a topic on the SMN console.
    • Event: events you want to subscribe to. Examples: JobStarted, JobCompleted, JobFailed, JobTerminated, and JobHanged.
NOTE:
  • After you create a topic on the SMN console, add a subscription to the topic, and confirm the subscription. Then, you will be notified of events. For details, see Adding a Subscription.
  • SMN charges you for the number of notification messages. For details, see Billing.
  • Only training jobs using GPUs support JobHanged events.

Auto Stop

When using paid resources, you can determine whether to enable auto stop.

  • This function is disabled by default, the training job keeps running until the training is completed.
  • If this function is enabled, configure the auto stop time. The value can be 1 hour, 2 hours, 4 hours, 6 hours, or Customize. The customized time must range from 1 hour to 720 hours. When you enable this function, the training stops automatically when the time limit is reached. The time limit does not count down when the training is paused.

Configuring a Dedicated Resource Pool

To configure a dedicated resource pool, refer to Table 6.
Table 6 Configuring a dedicated resource pool for a training job

Parameter

Description

Resource Pool

Select a dedicated resource pool.

If you select a dedicated resource pool, you can view the status, node specifications, number of idle/fragmented nodes, number of available/total nodes, and number of cards of the resource pool. Hover over View in the Idle/Fragmented Nodes column to check fragment details and check whether the resource pool meets the training requirements.

Specifications

Select the required resource specifications based on the resource type.

If Data path is selected for Input, you can click Check Input Size on the right to ensure the storage is larger than the input data size.

NOTICE:

The resource flavor GPU:n*tnt004 (n indicates a specific number) does not support multi-process training.

Customized Specifications

Indicates whether to enable customized specifications. You can customize resource specifications for training jobs based on dedicated resource pool specifications to improve resource pool utilization.

  • This function is disabled by default, which means the dedicated resource pool specifications are used.
  • When you enable this function, jobs run with custom specifications. The custom specifications should not exceed the node specifications of the dedicated resource pool that you set. For CPU specifications, you can only customize the number of vCPUs and memory. For GPU specifications, you can customize the number of vCPUs, memory, and cards.
NOTE:

If customized specifications are enabled, the Specifications parameter is invalid.

Compute Nodes

Select the number of compute nodes as required. The default value is 1.

  • If only one compute node is used, a single-node training job is created. ModelArts starts one training container on this node. The training container exclusively uses the compute resources of the selected flavor.
  • If more than one compute nodes are used, a distributed training job is created. For more information about distributed training configurations, see Distributed Training Functions.

Job Priority

When using a dedicated resource pool, you can set the priority of the training job. The value ranges from 1 to 3. The default priority is 1, and the highest priority is 3.

  • By default, the job priority can be set to 1 or 2. After the permission to set the highest job priority is configured, the priority can be set to 1 to 3.
  • If a training job is in the Pending state for a long time, you can change the job priority to reduce the queuing duration. For details, see Priority of a Training Job.

SFS Turbo

When ModelArts and SFS Turbo are directly connected, multiple SFS Turbo file systems can be mounted to a training job to store training data. Click Add Mount Configuration and set the following parameters:

  • File System: Select an SFS Turbo file system.
  • Mount Path: Enter the SFS Turbo mounting path in the training container.
  • Storage Location: Specify the SFS Turbo storage location. If you have configured the folder control permission, select a storage location. If you have not configured the folder control permission, retain the default value / or customize a location.
  • Mounting Mode: Permission on the mounted SFS Turbo file system. This parameter is displayed as Read/Write or Read-only based on the permission of the SFS Turbo storage location. If you have not configured the folder control permission, this parameter is unavailable.
NOTE:
  • A file system can be mounted only once and to only one path. Each mount path must be unique. A maximum of 8 disks can be mounted to a training job.
  • To mount an SFS Turbo file system to a training job, you need to configure network passthrough between ModelArts and the SFS Turbo file system. For details, see ModelArts Network.
  • The mounting path cannot be a / directory or a default mounting path, such as /cache and /home/ma-user/modelarts.
  • For details about how to set permissions for SFS Turbo folders, see Permissions Management.

Persistent Log Saving

If you select CPU or GPU flavors, Persistent Log Saving is available for you to set.

  • This function is disabled by default. ModelArts automatically stores the logs for 30 days. You can download all logs on the job details page to a local path.
  • After this function is enabled, set Job Log Path. The system permanently stores training logs to the specified OBS path.

Job Log Path

When enabling Persistent Log Saving, select an empty OBS directory for Job Log Path to store log files generated by the training job.

Ensure that you have read and write permissions to the selected OBS directory.

Event Notification

Indicates whether to enable event notification.

  • This function is disabled by default, which means SMN is disabled.
  • After this function is enabled, you will be notified of specific events, such as job status changes or suspected suspensions, via an SMS or email. Notifications will be billed based on SMN pricing. In this case, you must configure the topic name and events.
    • Topic: topic of event notifications. Click Create Topic to create a topic on the SMN console.
    • Event: events you want to subscribe to. Examples: JobStarted, JobCompleted, JobFailed, JobTerminated, and JobHanged.
NOTE:
  • After you create a topic on the SMN console, add a subscription to the topic, and confirm the subscription. Then, you will be notified of events. For details, see Adding a Subscription.
  • SMN charges you for the number of notification messages. For details, see Billing.
  • Only training jobs using GPUs support JobHanged events.

Auto Stop

When using paid resources, you can determine whether to enable auto stop.

  • This function is disabled by default, the training job keeps running until the training is completed.
  • If this function is enabled, configure the auto stop time. The value can be 1 hour, 2 hours, 4 hours, 6 hours, or Customize. The customized time must range from 1 hour to 720 hours. When you enable this function, the training stops automatically when the time limit is reached. The time limit does not count down when the training is paused.

(Optional) Setting Tags

If you want to manage training jobs by group using tags, select Configure Now for Advanced Configuration to set tags for training jobs. For details about how to use tags, see How Does ModelArts Use Tags to Manage Resources by Group?

Follow-Up Procedure

After parameter setting for creating a training job, click Submit. On the Confirm dialog box, click OK.

A training job runs for a period of time. You can go to the training job list to view the basic information about the training job.

  • In the training job list, Status of a newly created training job is Pending.
  • When the status of a training job changes to Completed, the training job is finished, and the generated model is stored in the corresponding output path.
  • If the status is Failed or Abnormal, click the job name to go to the job details page and view logs for troubleshooting.

You are billed for the resources you choose when your training job runs.