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

Show all

Help Center/ ModelArts/ SDK Reference/ Training Management (New Version)/ Training Jobs/ Debugging a Training Job/ Using the SDK to Debug a Multi-Node Distributed Training Job

Using the SDK to Debug a Multi-Node Distributed Training Job

Updated on 2024-01-18 GMT+08:00

Replace the OBS paths in the debugging code with your OBS paths.

PyTorch is used to write debugging code in this document. The process is the same for different AI frameworks. You only need to change the framework_type value in 7 and 11. For example, set framework_type to Ascend-Powered-Engine for MindSpore.

  1. Initialize session. This step is the same as that of debugging a single-node training job.
  2. Prepare training data. This step is the same as that of debugging a single-node training job. The only difference is that obs_path must be set here.
  1. Prepare the training script.

    from modelarts.train_params import TrainingFiles
    code_dir = os.path.join(base_local_path, "train/") 
    
    # The training script has been stored in OBS. The training script can be chosen from any source as long as it can be stored in a notebook instance.
    
    session.obs.download_file(os.path.join(base_bucket_path, "train/test-pytorch.py"), code_dir)
    training_file = TrainingFiles(code_dir=code_dir, boot_file="test-pytorch.py", obs_path=base_bucket_path + 'train/')

    Parameters:

    • code_dir: Code directory where a training script is stored. The directory must be a notebook directory for local debugging. This parameter is mandatory.
    • boot_file: Training boot file, which is stored in the code_dir directory. This parameter is mandatory.
    • obs_path: OBS directory. This parameter is mandatory for multi-node distributed debugging. The SDK zips the notebook directory code_dir and uploads the ZIP file to obs_path.

  1. Prepare the training output. This step is the same as 4 for debugging a single-node training job.
  2. Check the AI frameworks available for training. This step is the same as 5 for debugging a single-node training job.
  3. Save the current notebook instance as a new image. This step is the same as 9 for debugging a single-node training job.
  4. Initialize the Estimator.

    from modelarts.estimatorV2 import Estimator
    parameters = []
    parameters.append({"name": "data_url", "value": data_local})
    parameters.append({"name": "output_dir", "value": os.path.join(base_local_path, "output/")}) 
    parameters.append({"name": "epoc_num", "value": 2})
    # For Boolean, use parser.add_argument('--dist', action='store_true') in the boot script for parsing. If the parameter is set to True, the parameter is transferred in the format of the following lines of code.
    parameters.append({"name": "dist"})
    estimator = Estimator(session=session,
                          training_files=training_file,
                          outputs=[output],
                          parameters=parameters,
                          framework_type='PyTorch',  
                          train_instance_type='local', 
                          train_instance_count=2,
                          script_interpreter="/home/ma-user/anaconda3/envs/PyTorch-1.4/bin/python",
                          log_url=base_bucket_path + 'log/',
                          job_description='This is a image net train job')

    Parameters:

    • session: Initialized data in 1. This parameter is mandatory.
    • training_files: Initialized training files in 3. This parameter is mandatory.
    • outputs: A list of training outputs. Each element in the list is a training output initialized in 4. This parameter is optional.
    • parameters: A list of parameters. Each element in the list is a dictionary that contains the name and value fields, which are transferred to the training boot file in the form of -name=value. This parameter is optional. value can be a string, an integer, or a Boolean. For Boolean, use action='store_true' in the training script for parsing.
    • framework_type: Type of the AI framework used for a training job. For details, see the output item in 5. This parameter is mandatory.
    • train_instance_type: Type of training instance. If this parameter is set to local, the training job is performed in a notebook instance. This parameter is mandatory.
    • train_instance_count: Number of workers in a training job. Set this parameter to 2 for distributed debugging. When the training job starts, the SDK creates another notebook instance to form a 2-node distributed debugging environment with the current instance. This parameter is mandatory.
    • script_interpreter: Python environment used for a training job. If this parameter is not set, the current kernel is used by default. This parameter is optional.
    • log_url: OBS address. The SDK automatically uploads training logs to this address during local training. This parameter must be set only when training jobs run on Ascend.
    • job_description: describes a training job. This parameter is optional.

  1. Start training.

    estimator.fit(inputs=[input_data], job_name="cifar10-dis")

    Parameters:

    • inputs: A list of training inputs. Each element in the list is an input imported in 2. This parameter is optional.
    • job_name: Name of a training job. This parameter is optional.

    After a local distributed training job starts, the SDK automatically performs the following operations:

    1. Zips the training script and uploads the ZIP file to obs_path specified in 3.
    2. Zips the data and uploads the ZIP file to the specified obs_path if the training data is stored in .
    3. Creates another instance to form a two-worker environment for distributed training.
    4. Initializes the training job and downloads data to local_path.
    5. Executes the training job and saves the training outputs in local_path specified in 4.
    6. Uploads the training output to obs_path specified in 4 and the logs to log_url specified in 7.

  1. Perform debugging. This step is the same as 8 for debugging a single-node training job.
  2. Obtain the type of compute nodes available for training. This step is the same as 9 for debugging a single-node training job.
  3. Submit the remote training job.

    from modelarts.estimatorV2 import Estimator
    parameters = []
    parameters.append({"name": "data_url", "value": data_local})
    parameters.append({"name": "output_dir", "value": os.path.join(base_local_path, "output/")}) 
    parameters.append({"name": "epoc_num", "value": 2})
    # For Boolean, use parser.add_argument('--dist', action='store_true') in the boot script for parsing. If the parameter is set to True, the parameter is transferred in the format of the following lines of code.
    parameters.append({"name": "dist"})
    estimator = Estimator(session=session,
                          training_files=training_file,
                          outputs=[output],
                          parameters=parameters,
                          framework_type='PyTorch',  
                          train_instance_type='modelarts.p3.large.public.distributed', 
                          train_instance_count=2,
                          script_interpreter="/home/ma-user/anaconda3/envs/PyTorch-1.4/bin/python",
                          log_url=base_bucket_path + 'log/',
                          job_description='This is a image net train job')
    estimator.fit(inputs=[input_data], job_name="cifar10-dis-1")

    The difference between Estimator initialization and local training lies in the train_instance_type parameter. Configure this parameter based on the obtained result in 10. The value of train_instance_count depends on the value of max_num in 10.

    After the training job is submitted, the SDK automatically performs the following operations:

    1. Zips the training script and uploads the ZIP file to obs_path specified in 3.
    2. Zips the data and uploads the ZIP file to the specified obs_path if the training data is stored in .
    3. Submits the training job to the ModelArts training service. The image of the current instance is used to execute the training job.
    4. Uploads the training output to obs_path specified in 4 and the logs to the location specified by log_url.

      In this step, note the following:

      If you want to create a directory or file in your training script, create it in the following directories:

      (1) /home/ma-user/work

      (2) /cache

      (3) local_path specified in inputs or outputs. For example, if local_path is set to /home/ma-user/work/xx/yy/ during InputData initialization in 2, you can create directories or files in this directory.

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