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 |
|
| Pre-migration analysis |
|
|
| 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 |
|
|
| Model saving | Save the model for subsequent weight loading, resumable training resumption, or online inference. | |
| Accuracy debugging |
|