Migration Process

What Is Model Migration

Model migration refers to migrating a deep learning model originally running on a GPU or other hardware platform to an NPU, while ensuring the model runs with high performance within a reasonable accuracy error range.

Why Perform Model Migration

When a model is migrated from other hardware platforms to an NPU, a series of adaptation operations from the bottom layer to the upper layer are involved due to differences in hardware architecture and libraries. Taking GPU as an example, the reasons why model migration to an NPU requires adaptation can be divided into three aspects:

  • Differences in hardware characteristics and performance features

    Due to the different hardware characteristics and performance features of NPUs and GPUs, models may require further performance debugging and optimization on NPUs to fully leverage their potential.

  • Differences in computing architecture

    GPUs use the Compute Unified Device Architecture (CUDA) parallel computing architecture, while NPUs use the Compute Architecture for Neural Networks (CANN) heterogeneous computing architecture.

  • Differences in deep learning frameworks

    To support NPU hardware, the PyTorch framework needs to be adapted through TorchNPU, including adapting tensor operations, automatic differentiation, and other functionalities for efficient execution on NPUs. In addition, PyTorch is continuously providing native support for NPUs to deliver a better model experience for users and minimize migration modifications.

How to Perform Model Migration

For model migration guidance, see Table 1.

Table 1 Model migration guidance

Category Migration Guide
Conventional models Adapted models See the list of version-evolving models and perform training and inference according to the corresponding model's README.
Unadapted models See this document for migration and training.

Migration-Phase Tasks

The chapters of this manual are designed based on the migration phases and their corresponding tasks, as shown in the table below.

Table 2 Migration-phase tasks

Migration Phase Task Task Description
Pre-migration preparation Model selection
  1. Investigate business requirements and select a model from mainstream repositories.
  2. Ensure the selected model can run on a third-party platform (such as GPU).
  3. Clarify the hardware model, precision, and performance baseline of the model before migration. Obtain the performance baseline of the source model from authoritative websites or data platforms, or measure the performance baseline on a third-party platform.
Pre-migration analysis
  1. Use the PyTorch Analyse tool to collect the list of models/operators in the target network, identify third-party libraries and operator support status in the target network, and analyze the feasibility of model migration.
    • If there are unsupported operators found on the platform during the migration support analysis, operator replacement, development, or adaptation is required.
    • If model suites or third-party libraries need to be called, NPU support must be checked.
  2. Confirm whether there are any currently known unsupported scenarios.
Model migration and training Model migration Follow the provided migration methods to replace GPU-to-NPU interfaces and adapt the NPU distributed framework.
Mixed-precision adaptation Use a mix of single-precision (float32) and half-precision (float16) data types during training to improve training efficiency.
Model training
  1. Configure training-related environment variables to ensure that model training can run properly on NPU. For details, see Environment Variable Configuration.
  2. Select the appropriate operation based on the actual scenario to complete model script configuration and start training. For details, see Executing Training.
  3. Follow the provided debugging methods for common issues encountered during training to identify the location and cause of problems. For details, see Model Debugging.
Model saving Save the model for subsequent weight loading, resumable training resumption, or online inference.
Accuracy debugging
  1. Analyze model accuracy issues during training and promptly address training instability problems.
  2. Analyze and evaluate model accuracy differences before and after migration in terms of loss/ppl and downstream evaluation task scores, and assess the accuracy deviation.
  3. Ensure that the model accuracy difference before and after migration is within an acceptable range and that there is no abnormal data overflow/underflow. If accuracy-related issues occur, use accuracy issue analysis tools for analysis.