Using the SDK to Debug a Multi-Node Distributed Training Job
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.
- Initialize session. This step is the same as that of debugging a single-node training job.
- 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.
- 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.
- Prepare the training output. This step is the same as 4 for debugging a single-node training job.
- Check the AI frameworks available for training. This step is the same as 5 for debugging a single-node training job.
- Save the current notebook instance as a new image. This step is the same as 9 for debugging a single-node training job.
- 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.
- 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:
- Zips the training script and uploads the ZIP file to obs_path specified in 3.
- Zips the data and uploads the ZIP file to the specified obs_path if the training data is stored in .
- Creates another instance to form a two-worker environment for distributed training.
- Initializes the training job and downloads data to local_path.
- Executes the training job and saves the training outputs in local_path specified in 4.
- Uploads the training output to obs_path specified in 4 and the logs to log_url specified in 7.
- Perform debugging. This step is the same as 8 for debugging a single-node training job.
- Obtain the type of compute nodes available for training. This step is the same as 9 for debugging a single-node training job.
- 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:
- Zips the training script and uploads the ZIP file to obs_path specified in 3.
- Zips the data and uploads the ZIP file to the specified obs_path if the training data is stored in .
- Submits the training job to the ModelArts training service. The image of the current instance is used to execute the training job.
- 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.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.