Updated on 2024-03-21 GMT+08:00

Debugging a Training Job

Before creating a real-time training job, create a local training job for debugging.

Sample Code

In ModelArts notebook, you do not need to enter authentication parameters for session authentication. For details about session authentication of other development environments, see Session Authentication.

  • Step 1: Create a local training job. If train_instance_type is set to local, a local training job is created, which can be used to debug code and parameters.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    from modelarts.session import Session
    from modelarts.estimator import Estimator
    from modelarts.environment import Environment
    from modelarts.environment.conda_env import CondaDependencies
    
    session = Session()
    env = Environment("tensorflow_mlp_mnist")
    cd = CondaDependencies.create(pip_packages=["tensorflow==1.13.1", "requests"], conda_packages=["python=3.6.2"])
    env.conda = cd
    src_local_path = "/home/ma-user/work/tensorflow_mlp_mnist_local_mode/train/"
    train_file = "tensorflow_mlp_mnist.py"
    estimator = Estimator(modelarts_session=session,
                          code_dir=src_local_path,            # Path of the local training script
                          boot_file=train_file,               # Path of the local training boot script
                          train_instance_type='local',        # Local training
                          train_instance_count=1,             # Number of training nodes
                          environment=env)                    # Environment for running the training script
    job_instance = estimator.fit(wait=False, job_name='my_training_job')
    
  • Step 2: After the local training job is complete, create a real-time training job. If train_instance_type is set to a training environment flavor, a real-time training job is created.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    from modelarts.session import Session
    from modelarts.estimator import Estimator
    from modelarts.environment import Environment
    from modelarts.environment.conda_env import CondaDependencies
    
    session = Session()
    env = Environment("tensorflow_mlp_mnist")
    cd = CondaDependencies.create(pip_packages=["tensorflow==1.13.1", "requests"], conda_packages=["python=3.6.2"])
    env.conda = cd
    src_local_path = "/home/ma-user/work/tensorflow_mlp_mnist_local_mode/train/"
    train_file = "tensorflow_mlp_mnist.py"
    estimator = Estimator(modelarts_session=session,
                          code_dir=src_local_path,                          # Path of the training script
                           boot_file=train_file,                             # Path of the training boot script
                          train_instance_type='modelarts.vm.cpu.2u',        # Real-time training
                          train_instance_count=1,                           # Number of training nodes
                          environment=env)                                  # Environment for running the training script
    job_instance = estimator.fit(wait=False, job_name='my_training_job')
    

Parameters

Table 1 Environment parameters

Parameter

Mandatory

Type

Description

name

Yes

String

Environment name

conda

No

CondaDependencies

Conda environment. For details, see Table 2.

Table 2 CondaDependencies parameters

Parameter

Mandatory

Type

Description

channels

No

List

Source for downloading the Python package

pip_packages

No

List

Python package required by the Conda virtual environment, such as TensorFlow and Pillow

conda_packages

No

List

Conda package required by the Conda virtual environment, for example, a specified Python version

Table 3 Estimator request parameters

Parameter

Mandatory

Type

Description

modelarts_session

Yes

Object

Session object. For details about the initialization method, see Session Authentication.

train_instance_count

Yes

Int

Number of compute nodes in a training job.

code_dir

No

String

Code directory of a training job, for example, /bucket/src/. Leave this parameter blank if model_name is set.

boot_file

No

String

Boot file of a training job, which needs to be stored in the code directory, for example, /bucket/src/boot.py. Leave this parameter blank if model_name is set.

model_name

No

String

Name of the built-in algorithm used by a training job. If you have configured model_name, you do not need to configure app_url, boot_file_url, framework_type, and framework_version. You can obtain this value by calling the API described in Querying a Built-in Algorithm.

output_path

Yes

String

Output path of a training job.

hyperparameters

No

JSON array

Running parameters of label-value pairs of the string type for a training job. This parameter is a container environment variable if a job uses a custom image.

log_url

No

String

OBS URL of training job logs. By default, this parameter is left blank. An example value is /usr/log/.

train_instance_type

Yes

String

Resource flavor selected for a training job. If you choose to train on the training platform, obtain the value by calling the API described in Querying the List of Resource Flavors.

framework_type

No

String

Engine selected for a training job. Obtain the value by calling the API described in Querying the List of Engine Types. Leave this parameter blank if model_name is set.

framework_version

No

String

Engine version selected for a training job. Obtain the value by calling the API described in Querying the List of Engine Types. Leave this parameter blank if model_name is set.

job_description

No

String

Description of a training job.

user_image_url

No

String

SWR URL of the custom image used by a training job. An example value is 100.125.5.235:20202/jobmng/custom-cpu-base:1.0.

user_command

No

String

Boot command used to start the container of the custom image used by a training job. The format is bash /home/work/run_train.sh python /home/work/user-job-dir/app/train.py {python_file_parameter}.

pool_id

No

String

ID of the resource pool for a training job. To obtain the ID, do as follows: Log in to the ModelArts console, choose Dedicated Resource Pools in the navigation pane, and view the resource pool ID in the dedicated resource pool list.

Table 4 fit request parameters

Parameter

Mandatory

Type

Description

inputs

Yes

String

Data storage location of a training job.

inputs cannot be used with dataset_id and dataset_version_id, or with data_source at the same time. However, one of these parameters must be set.

Only this parameter is supported in local training.

dataset_id

No

String

Dataset ID of a training job.

This parameter must be used with dataset_version_id, but cannot be used with inputs.

dataset_version_id

No

String

Dataset version ID of a training job.

This parameter must be used with dataset_id, but cannot be used with inputs.

wait

No

Boolean

Whether to wait for the completion of a training job. It defaults to False.

job_name

No

String

Name of a training job. Enter 1 to 64 characters. Only the following characters are allowed: a-z, A-Z, 0-9, hyphens (-), and underscores (_). If this parameter is left blank, a job name is generated randomly.