Tool Overview

Features

The Ascend platform provides a porting tool targeted at TensorFlow 2.6.5. The tool analyzes the support for native TensorFlow Python APIs on the Ascend AI Processor, and automatically ports native TensorFlow training scripts to those supported by the Ascend AI Processor. The ported script can be trained on the Ascend AI Processor. For APIs unportable by the tool, modify your training script according to the tool report.

How to Obtain

After CANN is installed, you can find that the porting tool is located in /tfplugin/latest/python/site-packages/npu_device/convert_tf2npu/ under the TFPlugin installation directory.

Restrictions

Before using the tool, you are advised to learn the restrictions on the original training script.
  1. The original script can run on the GPU or CPU for accuracy convergence.
  2. The original script must use only the official TensorFlow 2.6 APIs. The Horovod APIs can be used when the script calls the Tensorflow 1.x APIs in the form of tf.compat.v1.
    The tool does not support porting if the script uses other third-party APIs. For example:
    1. Native Keras APIs are not supported. TensorFlow Keras APIs are supported.
    2. CuPy APIs are not supported. The original script using CuPy APIs may fail to run on the Ascend AI Processor even if it can run properly on the GPU.
  3. It is recommended that the TensorFlow module in the original script be referenced as follows. Otherwise, the porting report may not be accurate. (This does not affect the script porting.)
    1
    2
    import tensorflow as tf
    import horovod.tensorflow as hvd
    
  4. Data types float64, complex64, complex128, and DT_VARIANT are not supported.
  5. Restrictions on distributed-training script porting:
    1. Before using the tool, you must manually add dataset sharding logic. For details, see 3.
    2. Currently, the tool automatically ports only distributed-training scripts that use the TensorFlow Keras optimizer (including SGD, RMSprop, Adam, Ftrl, Adagrad, Adadelta, Adamax, and Nadam). Other distributed-training scripts need to be ported manually. For details, see Distributed Training Script Adaptation (Single Device).
    3. For LossScaleOptimizer in the original script, the tool supports only the porting from tf.keras.mixed_precision.LossScaleOptimizer to npu.train.optimizer.NpuLossScaleOptimizer. If your script uses a different LossScaleOptimizer, change it to tf.keras.mixed_precision.LossScaleOptimizer, test the functionality and accuracy, and then manually replace it with npu.train.optimizer.NpuLossScaleOptimizer.
  6. The tool cannot automatically enable iteration offload to the NPU at this moment. If iteration offload is used in your original script, manually enable it in the ported script. For details, see Setting the Number of Iterations Offloaded to NPU.