Create a training job
PAI-DLC lets you quickly create single-node or distributed training jobs. Kubernetes automatically provisions compute nodes under the hood, eliminating the need to manually purchase machines or configure runtime environments. It supports TensorFlow, PyTorch, and other popular deep learning frameworks, with flexible resource configuration options.
Quick start
Using MNIST handwritten digit recognition as an example, this guide walks you through single-node, single-GPU training and multi-node, multi-GPU distributed training with DLC. For details, see Get started with Deep Learning Containers (DLC).
Console parameter reference
Basic information
Parameter | Description |
Job Name | Set an easily identifiable name for the job. |
Tag | Apply standardized tags to your jobs. Tags provide the foundation for archiving jobs by label, analyzing job distribution, and tracking resource consumption. The following constraints apply:
For guidance on standardized tagging, see Standardize tagging for DLC, DSW, and EAS. |
Task Description | Use this field to describe the purpose, background, or other context of the job. |
Environment information
Parameter | Description |
Image Configuration | In addition to the Alibaba Cloud Image, the following image types are supported:
|
Mount dataset | Datasets provide the data files needed for model training. The following two dataset types are supported:
Mount Path: The path where the dataset is mounted in the DLC container, for example Important If you use a CPFS dataset, you must configure a VPC for DLC that matches the CPFS VPC. Otherwise, the submitted job may remain in the Preparing environment state for an extended period. |
Mount storage | You can also mount data source paths directly to read required data or store intermediate and result files.
For more information, see Use cloud storage. |
Startup Command | Set the job startup command. Shell commands are supported. DLC automatically injects common PyTorch and TensorFlow environment variables such as
Important The mount path configured for code (such as /mnt/data) is the location of your code files within the DLC container. Your startup command must reference code files using this path. For example, if the code mount path is /mnt/data and your code file is train.py, the startup command should be: python /mnt/data/train.py |
Resource information
Parameter | Description |
Resource Type | Defaults to General Computing. Lingjun Intelligence Resources is available in the following regions: China (Ulanqab), Singapore, China (Shenzhen), China (Beijing), China (Shanghai), China (Hangzhou), China (Guangzhou), China (Hong Kong), Malaysia, Germany, and Atlanta. |
Source |
|
Framework | The following deep learning training frameworks and tools are supported: TensorFlow, PyTorch, ElasticBatch, XGBoost, OneFlow, MPIJob, Slurm, Ray, Custom, DataJuicer, and MPI. Note When Resource Quota is set to Lingjun resources, only TensorFlow, PyTorch, ElasticBatch, MPIJob, Slurm, and Ray jobs are supported. |
Job Resource | Based on the selected Framework, you can configure resources for Worker, PS, Chief, Evaluator, and GraphLearn node types. When using the Ray framework, you can click Add Role to customize Worker roles, enabling mixed execution of heterogeneous resources.
|
Scheduling Policy | You can customize the container resource scheduling strategy based on your business scenarios and job characteristics:
|
DLC does not support directly modifying the instance type of a submitted job. To change the instance type (for example, to switch to an instance that supports eRDMA high-performance networking, such as ecs.ebmgn8v.48xlarge), use the Clone Job feature to create a new job, select the target instance type, and submit it. The platform automatically enables high-performance networking and configures NCCL-related parameters. To change the NVIDIA driver and CUDA version of an instance, use the instance configuration feature to change the driver version (for example, to version 580). The platform automatically pulls the corresponding DLC image based on the new configuration to update the runtime environment, completing the driver change, CUDA upgrade, or GPU driver replacement.
VPC configuration
If no VPC is configured, the public network and public gateway are used. Because the public gateway has limited bandwidth, jobs may experience slowdowns or fail to run properly during execution.
Configuring a VPC and selecting the corresponding vSwitch and security group improves network bandwidth, stability, and security. The cluster running your jobs can also directly access services within this VPC.
ImportantWhen using a VPC, ensure that the job resource group instances, dataset storage (OSS), and code repository are all within the same VPC in the same region, and that network connectivity is established.
When using a CPFS dataset, you must configure a VPC that matches the CPFS VPC. Otherwise, the submitted DLC training job may remain in the Preparing environment state for an extended period.
When submitting DLC jobs using Lingjun spot resources, you must configure a VPC.
Additionally, you can configure Internet Access Gateway. The following two options are supported:
Public Gateway: Bandwidth is limited. During periods of high concurrency or when downloading large files, network speed may not meet demand.
Private Gateway: To overcome the public gateway bandwidth limitation, you can create a NAT gateway in the DLC VPC, associate an EIP, and configure SNAT entries. For details, see Improve internet access with a private gateway.
Fault tolerance and diagnostics
Parameter | Description |
Automatic Fault Tolerance | After enabling the Automatic Fault Tolerance feature and configuring the relevant parameters, the system provides job monitoring and control capabilities. It can detect algorithm-level errors in real time and take corrective action, improving GPU utilization. For details, see AIMaster: An elastic and automatic fault tolerance engine. Note When automatic fault tolerance is enabled, the system launches an AIMaster instance alongside the job instances, which consumes additional compute resources. AIMaster instance resource usage details:
|
Sanity Check | After enabling the Sanity Check feature, the health check thoroughly inspects the resources involved in training, automatically isolates faulty nodes, and triggers background automated operations. This effectively reduces the likelihood of issues during the early stages of training and improves the training success rate. For details, see SanityCheck: Compute health checks. Note The health check feature is supported only for PyTorch training jobs submitted with Lingjun resource quotas and when the GPU count is greater than 0. |
Roles and permissions
Instance RAM role configuration is described below. For details, see Configure a RAM role for DLC.
Instance RAM role | Description |
Default Role of PAI | Operates based on the service role AliyunPAIDLCDefaultRole, which has access only to MaxCompute and OSS, with more granular permissions. Temporary credentials issued based on the PAI default role:
|
Custom Role | Select or specify a custom RAM role. When accessing cloud services from within the instance using STS temporary credentials, the permissions are consistent with those of the custom role. |
Does Not Associate Role | No RAM role is associated with the DLC job. This is the default option. |
Related documentation
View job basic information, resource views, and operation logs. For details, see Training details.
View billing details for job execution. For details, see Billing details.
For common DLC job issues and solutions, see FAQ about DLC.
For DLC use cases, see DLC use cases.
FAQ
Q: What should I do if I get a BadRequest error about selecting a NAS data source with a mount target when creating a training job?
This error occurs when the NAS data source lacks a mount target. Create a new mount target in the NAS console, then select it as the data source in the Mount dataset or Mount storage configuration when creating the training job, and resubmit the job.
Q: Can DLC training jobs export metrics to Weights & Biases (W&B)?
Yes, DLC supports exporting training metrics to W&B, but the following prerequisites must be met:
Network connectivity: Ensure that PAI training nodes can access the public endpoint api.wandb.ai. If using a VPC, configure a NAT gateway.
Key management: Inject the W&B API key through environment variables. Do not hardcode it in your code.
Compliance: Upload only non-sensitive scalar metrics. Do not upload raw data or sensitive model details.
Q: Does a failed DLC job still appear in the job list?
Whether it appears depends on the failure reason:
Jobs that fail due to insufficient resources temporarily appear in the DLC console job list and are removed after deletion.
When the API returns an error directly (with a RequestID) due to invalid request parameters, no record is kept in the job list. The error message is displayed only on the operation page.
Q: What should I do if I see an "account security protection triggered" or "resource allocation suspended" message when creating a DLC job?
This message is typically triggered by account risk control policies. Use the Alibaba Cloud self-service diagnostic tool (https://smartservice.console.alibabacloud.com/service/self-service-center/search?questionId=27591) to diagnose why payment or resource allocation cannot proceed, and submit an appeal. Once the appeal is approved, you can retry creating the job.
Appendix
Create a job by using the SDK or CLI
Python SDK
Step 1: Install the Alibaba Cloud Credentials tool
When you call OpenAPI by using an Alibaba Cloud SDK to manage resources, you must install the Credentials tool to configure your credentials. Requirements:
Python version >= 3.7.
Use V2.0 Alibaba Cloud SDKs.
pip install alibabacloud_credentialsStep 2: Obtain the AccessKey of your account
This example uses AccessKey (AK) information to configure access credentials. To prevent credential leakage, we recommend that you store your AccessKey in environment variables. The environment variable names for the ID and secret are ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.
For information about how to obtain an AccessKey, see Create an AccessKey.
For information about how to configure environment variables, see Configure environment variables.
For other credential configuration methods, see Install the Credentials tool.
Step 3: Install the Python SDK
Install the workspace SDK.
pip install alibabacloud_aiworkspace20210204==3.0.1Install the DLC SDK.
pip install alibabacloud_pai_dlc20201203==1.4.17
Step 4: Submit a job
Submit a job by using public resources
The following sample code shows how to create and submit a job:
Submit a job by using a subscription resource quota
Log on to the PAI console.
View the workspace ID: In the left-side navigation pane, click Workspace List. Find the target workspace, click the ⓘ icon next to its name, and view and copy the Workspace ID in the information panel that appears.
View the resource quota ID of your dedicated resource group. In the left-side navigation pane, choose AI Computing Resources > Resource Quota. Click the General Computing Resources tab, and obtain the Quota ID of the target resource quota from the Name/ID column in the resource quota list.
Use the following code to create and submit a job. For the list of public images that you can use, see Step 2: Prepare an image.
from alibabacloud_pai_dlc20201203.client import Client from alibabacloud_credentials.client import Client as CredClient from alibabacloud_tea_openapi.models import Config from alibabacloud_pai_dlc20201203.models import ( CreateJobRequest, JobSpec, ResourceConfig, GetJobRequest ) # Initialize a Client to access the DLC API. region = 'cn-hangzhou' # The Alibaba Cloud account AccessKey has access permissions to all APIs. It is recommended to use RAM users for API access or daily operations and maintenance. # It is highly recommended not to save AccessKey ID and AccessKey Secret directly in the project code to prevent leak risks, which could threaten the security of all resources under your account. # This example uses the Credentials SDK to read the AccessKey from environment variables by default for identity authentication. cred = CredClient() client = Client( config=Config( credential=cred, region_id=region, endpoint=f'pai-dlc.{region}.aliyuncs.com', ) ) # Declare the resource configuration for the job. For image selection, refer to the public image list in the documentation, or you can pass in your own image address. spec = JobSpec( type='Worker', image=f'registry-vpc.cn-hangzhou.aliyuncs.com/pai-dlc/tensorflow-training:1.15-cpu-py36-ubuntu18.04', pod_count=1, resource_config=ResourceConfig(cpu='1', memory='2Gi') ) # Declare the execution content of the job. req = CreateJobRequest( resource_id='<Replace with your own resource quota ID>', workspace_id='<Replace with your own WorkspaceID>', display_name='sample-dlc-job', job_type='TFJob', job_specs=[spec], user_command='echo "Hello World"', ) # Submit the job. response = client.create_job(req) # Get the job ID. job_id = response.body.job_id # Query the job status. job = client.get_job(job_id, GetJobRequest()).body print('job status:', job.status) # View the command executed by the job. job.user_command
Submit a job by using spot resources
SpotDiscountLimit (Spot discount)
#!/usr/bin/env python3 from alibabacloud_tea_openapi.models import Config from alibabacloud_credentials.client import Client as CredClient from alibabacloud_pai_dlc20201203.client import Client as DLCClient from alibabacloud_pai_dlc20201203.models import CreateJobRequest region_id = '<region-id>' # The region ID where the DLC job is located, for example, cn-hangzhou for China (Hangzhou). cred = CredClient() workspace_id = '12****' # The workspace ID where the DLC job is located. dlc_client = DLCClient( Config(credential=cred, region_id=region_id, endpoint='pai-dlc.{}.aliyuncs.com'.format(region_id), protocol='http')) create_job_resp = dlc_client.create_job(CreateJobRequest().from_map({ 'WorkspaceId': workspace_id, 'DisplayName': 'sample-spot-job', 'JobType': 'PyTorchJob', 'JobSpecs': [ { "Type": "Worker", "Image": "dsw-registry-vpc.<region-id>.cr.aliyuncs.com/pai/pytorch-training:1.12-cpu-py39-ubuntu20.04", "PodCount": 1, "EcsSpec": 'ecs.g7.xlarge', "SpotSpec": { "SpotStrategy": "SpotWithPriceLimit", "SpotDiscountLimit": 0.4, } }, ], 'UserVpc': { "VpcId": "vpc-0jlq8l7qech3m2ta2****", "SwitchId": "vsw-0jlc46eg4k3pivwpz8****", "SecurityGroupId": "sg-0jl4bd9wwh5auei9****", }, "UserCommand": "echo 'Hello World' && ls -R /mnt/data/ && sleep 30 && echo 'DONE'", })) job_id = create_job_resp.body.job_id print(f'jobId is {job_id}')SpotPriceLimit (Spot price)
#!/usr/bin/env python3 from alibabacloud_tea_openapi.models import Config from alibabacloud_credentials.client import Client as CredClient from alibabacloud_pai_dlc20201203.client import Client as DLCClient from alibabacloud_pai_dlc20201203.models import CreateJobRequest # The region ID where the DLC job is located, for example, cn-hangzhou. region_id = '<region-id>' # Initialize the credentials client to handle authentication. cred = CredClient() # The workspace ID where the DLC job is located. workspace_id = '12****' # Initialize the DLC client with the required configuration. dlc_client = DLCClient( Config(credential=cred, region_id=region_id, endpoint='pai-dlc.{}.aliyuncs.com'.format(region_id), protocol='http')) # Create a DLC job with spot instance configuration (SpotWithPriceLimit). create_job_resp = dlc_client.create_job(CreateJobRequest().from_map({ 'WorkspaceId': workspace_id, 'DisplayName': 'sample-spot-job', 'JobType': 'PyTorchJob', 'JobSpecs': [ { "Type": "Worker", "Image": "dsw-registry-vpc.<region-id>.cr.aliyuncs.com/pai/pytorch-training:1.12-cpu-py39-ubuntu20.04", "PodCount": 1, "EcsSpec": 'ecs.g7.xlarge', "SpotSpec": { "SpotStrategy": "SpotWithPriceLimit", "SpotPriceLimit": 0.011, } }, ], 'UserVpc': { "VpcId": "vpc-0jlq8l7qech3m2ta2****", "SwitchId": "vsw-0jlc46eg4k3pivwpz8****", "SecurityGroupId": "sg-0jl4bd9wwh5auei9****", }, "UserCommand": "echo 'Hello World' && ls -R /mnt/data/ && sleep 30 && echo 'DONE'", })) # Get and print the created job ID. job_id = create_job_resp.body.job_id print(f'jobId is {job_id}')
The key configurations are described as follows:
Parameter | Description |
SpotStrategy | The bidding strategy. The bidding type takes effect only when this parameter is set toSpotWithPriceLimit. |
SpotDiscountLimit | Uses spot discount as the bidding method. Note
|
SpotPriceLimit | Uses spot price as the bidding method. |
UserVpc | Required when you submit a job by using Lingjun spot resources. Configure the VPC, vSwitch, and security groupID of the region where the job runs. |
When you create a DLC job by calling an API or using an SDK (createJob), you cannot directly upload local code files. Upload your code to one of the following locations first:
Git repository: Create a code configuration in AI Assets Management and link it to the Git repository URL.
OSS storage: After you upload the code to OSS, make it available to the job by mounting it as a dataset.
Custom image: Package the code into a Docker image.
Command line
Step 1: Download the client and complete user authentication
Download the Linux 64-bit or Mac client tool based on your operating system, and complete user authentication. For details, see Before you begin.
Step 2: Submit a job
Log on to the PAI console.
Follow these instructions to view your workspace ID (WorkspaceID) on the workspace list page.
In the left-side navigation pane, click Workspace List. Find the target workspace, click the ⓘ icon to the right of its name, and view the Workspace ID in the information panel that appears.
Follow these instructions to view your resource quota ID.
In the left-side navigation pane, choose AI Computing Resources > Resource Quota. Select the tab for your target resource type (such as General Computing Resources), and obtain the resource quota ID from the Name/ID column in the resource quota list.
Prepare a parameter file based on the following content
tfjob.params. For more information about how to configure the parameter file, see Commands used to submit jobs.name=test_cli_tfjob_001 workers=1 worker_cpu=4 worker_gpu=0 worker_memory=4Gi worker_shared_memory=4Gi worker_image=registry-vpc.cn-beijing.aliyuncs.com/pai-dlc/tensorflow-training:1.12.2PAI-cpu-py27-ubuntu16.04 command=echo good && sleep 120 resource_id=<your_resource_quota_id> workspace_id=<your_workspace_id>Use the following sample code to pass in the params_file parameter. This submits the DLC job to the specified workspace and resource quota.
./dlc submit tfjob --job_file ./tfjob.paramsUse the following command to view the DLC job you submitted.
./dlc get job <jobID>
Advanced parameter list
Parameter (key) | Supported framework types | Description | Parameter value |
| ALL | Configures a custom resource release policy. This parameter is optional. If you do not configure it, all Pod resources are released when the job ends. If you configure it, the only supported value is pod-exit, which releases the resources of a Pod when the Pod exits. | pod-exit |
| ALL | Specifies whether to enable jumbo frames. This parameter is supported only by AI Computing Resources - General Computing 2.0 The default value is false, which means disabled. |
|
| ALL | Specifies whether to enable IBGDA when the GPU driver is loaded. |
|
| ALL | Specifies whether to install the GDRCopy kernel module. The currently installed version is 2.4.4. |
|
| ALL | Specifies whether to enable NUMA. |
|
| ALL | When you submit a job, this parameter checks whether the total resources (node specifications) in the quota meet the specifications of all roles in the job. |
|
| PyTorch | Specifies whether to allow network connectivity between workers.
After this is enabled, the domain name of each worker is the worker name, such as |
|
| PyTorch | Allows you to define the network ports exposed on each worker. You can use this parameter together with If left unconfigured, only port 23456 is exposed on the master by default. Make sure that you do not include port 23456 in this custom port list. Important This parameter is mutually exclusive with | A semicolon-separated set of strings, where each string is a single port number or a port range connected by a hyphen, such as |
| PyTorch | Allows you to request a number of network ports to be exposed on each worker. You can use this parameter together with If left unconfigured, only port 23456 is exposed on the master by default. DLC randomly assigns ports to workers based on the number of ports defined in the parameter. The assigned port numbers are passed to the worker through the Important
| Integer (maximum: 65536) |
| Ray | When the framework is Ray, you can manually configure RayRuntimeEnv to define the runtime environment. Important Environment variables and third-party library configurations are overridden by this configuration. | Configure environment variables and third-party libraries ( |
| Ray | External GCS Redis address. | String |
| Ray | External GCS Redis username. | String |
| Ray | External GCS Redis password. | String |
| Ray | The number of retries for the submitter. | Positive integer (int) |
| Ray | Configures shared memory for a node. For example, to configure 1 GiB of shared memory for each node, use the following configuration: | Positive integer (int) |
button to select a bidding method: