Porting Operation

Prerequisites

Before porting a model to the Ascend AI Processor, prepare a model developed in TensorFlow 2.6.5 and the dataset, and run the model on the GPU or CPU to test its accuracy and performance. In addition, record the accuracy and performance results for later comparison with those on the Ascend AI Processor.

Porting Operation

  1. Install dependencies.

    pip3 install pandas==1.3.5

    pip3 install openpyxl

    pip3 install google_pasta

  2. Perform script scanning and automated porting.

    Go to the directory where the porting tool is located, for example, /tfplugin/latest/python/site-packages/npu_device/convert_tf2npu/ under the TFPlugin installation directory, and run the following command to scan and automatically port the script.

    python3 main.py -i /root/models/examples/test -m /root/models/example/test/test.py

    main.py is the entry script of the tool. The following table describes the options.

    Table 1 Options

    Option

    Description

    Required

    -i

    Path of the training script to be ported. The path must be a folder.

    NOTE:
    • The tool scans and ports only the .py files in the folder specified by the -i option.
    • You are advised to put all necessary files in the same directory. Otherwise, you need to run the porting command in each directory.

    Yes

    -o

    Path of the ported script. The path cannot be a subdirectory of the original script path.

    Defaults to the current path, for example, output_npu_20220517172706/xxx_npu_20220517172706.

    No

    -r

    Path of the porting report. The path cannot be a subdirectory of the original script path.

    Defaults to the current path, for example, report_npu_20220517172706.

    No

    -m

    Python execution entry point file.

    If the original script does not contain the main function, the tool cannot identify the entry point function, resulting in the failure of NPU resource initialization and NPU training configuration.

    In that case, you must use -m to specify the entry point file for Python execution, so that the tool can completely port the user script for subsequent training.

    Example: -m /root/models/xxx.py

    No

    -d

    Distributed strategy of the original script that supports distributed training.

    • tf_strategy: The original script uses tf.distribute.Strategy.
    • horovod: The original script uses the Horovod distributed module.

    No

    -c

    (Or --compat) Whether to use tf.compat.v1 APIs for execution in Tensorflow 1.x mode.

    No

    python3 main.py -h: displays the help information of the porting tool.

    • During the porting, check the following information, which indicates related files are being scanned for script porting.
      Figure 1 Porting information
    • After the porting is complete, check the resultant script and porting report.
      Figure 2 Porting completion information