Pre-migration Preparation
Model Selection
When selecting models for migration, it is recommended that you choose authoritative PyTorch model implementation repositories, including but not limited to PyTorch (imagenet/vision, etc.), Meta Research (Detectron/detectron2, etc.), and open-mmlab (MMDetection/mmpose, etc.).
Evaluate the feasibility of migrating the selected model:
- Ensure that the selected model can run successfully on a third-party platform (such as a GPU).
- Obtain the accuracy and performance baselines of the selected model from authoritative websites or data platforms, or measure the accuracy and performance baselines on a third-party platform.
Pre-Migration Analysis
Whether a model can be successfully migrated to the Ascend AI Processor primarily depends on whether the operators it uses are supported by the Ascend platform. To ensure migration feasibility, the following methods can be used for analysis before migration:
-
If the original model code calls a model suite or third-party library, check their support for the NPU.
- If the third-party library natively supports NPU, check the current NPU's support for the library's features.
- If it is a third-party library adapted for Ascend, additionally install the Ascend-adapted version of that library and check its adaptation status. If you wish to achieve higher performance after adapting the above third-party libraries and model suites to Ascend devices, perform your own tuning.
-
Confirm whether the following known unsupported scenarios exist.
Table 1 List of unsupported scenarios
Scenario/Component Support Status Migration Guide Alternative Solution Data-parallel model Not supported Incompatible with the torch.nn.parallel.DataParallelinterfaceManually modify the interface to torch.nn.parallel.DistributedDataParallelto perform multi-device training.
The original script must run successfully in a GPU environment based on Python 3.8 or later.FusedAdam optimizer in the APEX library Partially supported Automatic migration or migration using the PyTorch GPU2Ascend tool is not supported. Manual migration is required. For specific methods, refer to Apex Patch. bitsandbytes Partially supported Installation on Ascend is supported. For details, see Supported Backends. Only migration for the NF4 quantization/dequantization function is supported for QLoRA fine-tuning; other functions are not yet supported. xFormers Not supported xFormers not natively supported For migration of the FlashAttentionScore operator in xFormers, refer to FlashAttentionScore. bmtrain framework Not supported Not supported in model migration scenarios No alternative solution available HybridAdam optimizer in the colossalai library Not supported Not supported in model migration scenarios No alternative solution available grouped_gemm third-party library Not supported Installation is not supported on the NPU. No alternative solution available composer third-party library Not supported Installation is supported on the NPU but not adapted. No alternative solution available -
Use the PyTorch Analyse tool to analyze the support status of third-party library suites, APIs, dynamic shapes, and affinity APIs in the GPU-based PyTorch training script on the Ascend AI Processor. See Table 2 for details. For detailed guidance on using the tool, see Analysis and Migration Tool User Guide.
Table 2 Introduction to analysis modes
Analysis Mode Analysis Script Analysis Result Tuning Suggestion Third-party library suite analysis You are required to provide the source code of the third-party library suite for analysis. Unsupported third-party library APIs and CUDA information in the source code can be quickly obtained.
Note:
A third-party library API is defined as a function in the third-party library's source code. Any function whose body contains unsupported torch operators or CUDA custom operators is considered an unsupported API. Furthermore, any other function that calls such unsupported APIs is also classified as an unsupported API.- API support status analysis You are required to provide the PyTorch training script for analysis. Unsupported torch API and CUDA API information in the training script can be quickly obtained. Output expert suggestions for API precision and performance tuning in the training script. Dynamic shape analysis Dynamic shape information contained in the training script can be quickly obtained. - Affinity API analysis The information about replaceable affinity APIs in the training script can be quickly obtained. - If there are operators not supported by the platform during the migration feasibility analysis, refer to the following methods for operator adaptation:
- Modify the model script to replace with equivalently supported operators.
- Refer to the Ascend C Operator Development Guide or the TBE & AI CPU Operator Development Guide for operator development, and the "Custom Operator Adaptation" section in the PyTorch Framework Feature Guide for operator adaptation.
- Contact Huawei engineers to submit operator development and adaptation requests.