Help Center/ ModelArts/ Troubleshooting/ Training Jobs/ In-Cloud Migration Adaptation Issues/ Failed to Parse Parameters and Log Error Occurs
Updated on 2024-06-11 GMT+08:00

Failed to Parse Parameters and Log Error Occurs

Symptom

The ModelArts training job failed to parse parameters, and the following error occurs:

error: unrecognized arguments: --data_url=xxx://xxx/xxx
absl.flags._exceptions.UnrecognizedFlagError:Unknown command line flag 'task_index'

Possible Cause

In the training environment, the system may transfer other parameter names that are not defined in the Python script. As a result, the parameters failed to be parsed, and an error occurs in the log.

Solution

Replace args = parser.parse_args() with the args, unparsed = parser.parse_known_args() parsing method. The following is a code example.

import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--data_url', type=str, default=None, help='obs path of dataset')
args, unparsed = parser.parse_known_args()