PAI-DLC lets you create single-node or distributed training jobs. The service automatically provisions compute nodes through Kubernetes, so you don't need to purchase machines or configure runtime environments. It supports multiple deep learning frameworks, including TensorFlow and PyTorch, and offers flexible resource configuration.
Quick start
This topic demonstrates single-GPU and multi-node multi-GPU distributed training in DLC using the MNIST handwritten digit recognition example. For more information, see Get started with Deep Learning Containers (DLC).
Console parameters
Basic information
Configure the Job Name and Tag.
Environment
Parameter | Description |
Image Configuration | In addition to Alibaba Cloud Image, the following image types are supported:
|
Mount dataset | Datasets provide data files for model training. Two dataset types are supported:
Mount Path: the path where the dataset is mounted in the DLC container, for example, Important If a CPFS dataset is configured, DLC must be configured with a VPC that matches the CPFS VPC. Otherwise, the job may get stuck in the environment preparation state for an extended period. |
Mount storage | You can also mount a data source path directly to read data or store intermediate and output files.
For more information, see Use cloud storage. |
Startup Command | Specify the startup command for the job. Shell commands are supported. DLC automatically injects common environment variables for PyTorch and TensorFlow, such as
Important The mount path configured for code (such as /mnt/data) is the location of code files in the DLC container. Your startup command must use this path to reference code files. For example, if the code mount path is /mnt/data and the code file is train.py, the startup command should be: python /mnt/data/train.py |
Resources
Parameter | Description |
Resource Type | Default: General Computing. Lingjun Intelligence Resources Available regions: China (Ulanqab), Singapore, China (Shenzhen), China (Beijing), China (Shanghai), China (Hangzhou), China (Guangzhou), China (Hong Kong), Malaysia (Kuala Lumpur), Germany (Frankfurt), US (Atlanta). |
Source |
|
Framework | The following deep learning frameworks and training tools are supported: TensorFlow, PyTorch, ElasticBatch, XGBoost, OneFlow, MPIJob、Slurm, Ray, Custom, DataJuicer, and MPI. Note When Resource Quota is set to Lingjun intelligent computing resources, only TensorFlow, PyTorch, ElasticBatch, MPIJob、Slurm, and Ray jobs are supported. |
Job Resource | Based on the selected Framework, configure resources for Worker, PS, Chief, Evaluator, and GraphLearn node types. When using the Ray framework, you can click Add Role to define custom Worker roles for heterogeneous resource mixing.
|
Scheduling Policy | You can customize the resource scheduling strategy for job containers based on your workload characteristics:
|
DLC does not support modifying the instance specification of a submitted job. To switch to a different specification (for example, an instance that supports eRDMA high-performance networking such as ecs.ebmgn8v.48xlarge), use the Clone Job feature to create a new job with the target specification. The platform automatically enables high-performance networking and configures NCCL parameters.
VPC configuration
If no VPC is configured, the job uses the public network and the public gateway. The public gateway has limited bandwidth, which may cause job slowdowns or failures.
Configure a VPC and select the corresponding vSwitch and security group to improve bandwidth, stability, and security. Job clusters can also directly access services within the VPC.
ImportantWhen using a VPC, make sure the job resource group, dataset storage (OSS), and code repository are in the same region and have network connectivity.
When using CPFS datasets, a VPC must be configured and the selected VPC must match the CPFS network. Otherwise, the DLC job may get stuck in the environment preparation state for an extended period.
A VPC must be configured when submitting DLC jobs with Lingjun intelligent computing spot resources.
You can also configure Internet Access Gateway. Two options are available:
Public Gateway: bandwidth is limited. Network speed may not meet requirements during high-concurrency workloads or large file downloads.
Private Gateway: to overcome public gateway bandwidth limits, create a public-facing NAT gateway in the DLC VPC, bind an EIP, and configure SNAT entries. For more information, see Improve internet access with a private gateway.
Fault tolerance and diagnostics
Parameter | Description |
Automatic Fault Tolerance | Enable Automatic Fault Tolerance and configure the parameters to enable job detection and control. The system detects algorithm-level errors in real time and takes corrective actions to improve GPU utilization. For more information, see AIMaster: An elastic and automatic fault tolerance engine. Note When auto fault tolerance is enabled, an AIMaster instance runs alongside the job instance and consumes compute resources. AIMaster resource usage:
|
Sanity Check | Enable Sanity Check to perform a comprehensive health check on all training resources, automatically isolate faulty nodes, and trigger backend automated operations. This reduces the likelihood of early-stage training failures and improves training success rates. For more information, see SanityCheck: Compute health checks. Note Health checks are available only for PyTorch jobs submitted with Lingjun intelligent computing resource quotas with at least one GPU. |
Roles and permissions
Configure the RAM role for the instance. For more information, see Configure a RAM role for DLC.
Instance RAM role | Description |
Default Role of PAI | Uses the AliyunPAIDLCDefaultRole service role, which has fine-grained permissions for accessing only MaxCompute and OSS. Temporary credentials issued under the default PAI role:
|
Custom Role | Select or enter a custom RAM role. When accessing cloud services from within the instance using STS temporary credentials, the permissions match those of the custom role. |
Does Not Associate Role | Do not associate a RAM role with the DLC job. This is the default option. |
References
View job details, resource views, and operation logs. For more information, see Training details.
View billing details for job runs. For more information, see Billing details.
For common DLC job issues and solutions, see FAQ about DLC.
For DLC use cases, see DLC use cases.
Appendix
Create a job by using the SDK or CLI
Python SDK
Step 1: Install the Alibaba Cloud Credentials tool
To use Alibaba Cloud SDKs for resource management API calls, install the Credentials tool to configure your access credentials. Requirements:
Python version >= 3.7.
Alibaba Cloud SDK V2.0 is used.
pip install alibabacloud_credentialsStep 2: Obtain an AccessKey pair
This example uses the AccessKey pair to configure access credentials. To prevent credential leakage, we recommend that you configure the AccessKey pair as environment variables. The environment variable names are ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET.
For more information about how to obtain an AccessKey pair, see Create an AccessKey.
For more information about how to configure environment variables, see Configure environment variables.
For more information about 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
Use public resources to submit a job
The following sample code shows how to create and submit a job.
Use a prepaid resource quota to submit a job
Log on to the PAI console.
View the workspace ID. In the left-side navigation pane, click Workspaces. Find the target workspace and click the ⓘ icon next to its name. In the information card that appears, view and copy the Workspace ID.
View the resource quota ID. In the left-side navigation pane, choose AI Computing Resources > Quotas. Click the General Computing Resources tab and obtain the Quota ID from the Name/ID column in the resource quota list.
Use the following code to create and submit a job. For the list of available public images, 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 DLC APIs. region = 'cn-hangzhou' # The AccessKey of an Alibaba Cloud account has access to all APIs. We recommend that you use a RAM user for API access and routine O&M. # We strongly recommend that you do not store the AccessKey ID and AccessKey Secret in your project code. Otherwise, your AccessKey may be leaked, threatening the security of all resources under your account. # In this example, the Credentials SDK is used to read the AccessKey from environment variables by default for identity verification. 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 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 for the job. req = CreateJobRequest( resource_id='<Replace with your own resource quota ID>', workspace_id='<Replace with your own Workspace ID>', 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
Use spot resources to submit a job
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>' cred = CredClient() workspace_id = '12****' 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 region_id = '<region-id>' cred = CredClient() workspace_id = '12****' 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", "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'", })) job_id = create_job_resp.body.job_id print(f'jobId is {job_id}')
The following table describes the key parameters.
Parameter | Description |
SpotStrategy | The preemption policy. This parameter takes effect only when this parameter is set toSpotWithPriceLimit. |
SpotDiscountLimit | The bidding type isspotdiscount. Note
|
SpotPriceLimit | The bidding type isspotprice. |
UserVpc | Required when you use Lingjun preemptible resources to submit a job. Specify the VPC ID, vSwitch ID, and security group ID in the region where the job runs. |
When you create a DLC job by calling the API or using the SDK (createJob), you cannot directly upload local code files. You must first upload your code to one of the following locations:
Git repository: Create a code configuration through AI asset management and associate it with a Git repository URL.
OSS storage: Upload the code to OSS and then provide it to the job through dataset mounting.
Custom image: Package the code into a Docker image.
CLI
Step 1: Download the CLI tool and complete user authentication
Download the CLI tool for Linux 64-bit or Mac based on your operating system and complete user authentication. For more information, see Before you begin.
Step 2: Submit a job
Log on to the PAI console.
View your workspace ID on the Workspaces page. In the left-side navigation pane, click Workspaces. Find the target workspace and click the ⓘ icon next to its name. In the information panel that appears, view the Workspace ID.
View your resource quota ID. In the left-side navigation pane, choose AI Computing Resources > Quotas. Select the target resource type tab (such as General Computing Resources) and obtain the resource quota ID from the Name/ID column.
Prepare a parameter file
tfjob.paramsbased on the following file content. For more information about how to configure a 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=<Replace with your resource quota ID> workspace_id=<Replace with your WorkspaceID>Use the following code sample to pass the params_file parameter and submit a job. You can submit the DLC job to the specified workspace and resource quota.
./dlc submit tfjob --job_file ./tfjob.paramsUse the following code to view the DLC job that you submitted.
./dlc get job <jobID>
Advanced parameters
Parameter (key) | Supported framework | Description | Value |
| ALL | Configure a custom resource release policy. If left unspecified, all pod resources are released when the job completes. If configured, 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 IBGDA when loading the GPU driver. |
|
| ALL | Specifies whether to install the GDRCopy kernel module. Version 2.4.4 is installed. |
|
| ALL | Specifies whether to enable NUMA. |
|
| ALL | Specifies whether to verify that the total resources (node specifications) in the quota can meet the specifications of all roles in the job when a job is submitted. |
|
| PyTorch | Whether to allow network communication between workers.
After this parameter is enabled, the domain name of each worker is the worker name, such as |
|
| PyTorch | Allows you to specify the network ports to open on each worker. This parameter can be used together with If left unspecified, only port 23456 is open on the master by default. Make sure to avoid port 23456 in the custom port list. Important This parameter is mutually exclusive with | A semicolon-separated list of strings, where each string is a port number or a port range connected by a hyphen, such as |
| PyTorch | Allows you to request a number of network ports to open on each worker. This parameter can be used together with If left unspecified, only port 23456 is open on the master by default. DLC randomly assigns ports to workers based on the number of ports specified in this parameter. The assigned port numbers are passed to the workers through the Important
| Integer (maximum: 65536) |
| Ray | When the framework is Ray, you can manually configure RayRuntimeEnv to define the runtime environment. Important Environment variable and third-party library configurations will be overridden by this setting. | Configure environment variables and third-party libraries ( |
| Ray | The address of the external GCS Redis. | String |
| Ray | The username of the external GCS Redis. | String |
| Ray | The password of the external GCS Redis. | String |
| Ray | The number of submitter retries. | Positive integer |
| Ray | Configure shared memory for nodes. For example, to allocate 1 GiB of shared memory per node, use the following configuration: | Positive integer |
button to choose a bidding method: