<aside> 💡 A guide to highlight the general procedure to convert a PyTorch model to .om
</aside>
Export model from PyTorch (script & .pth) to ONNX
Convert simplified onnx model to om with ATC/MindStudio
Evaluate om
.pth → .om
ProcedureExport PyTorch model to ONNX — ****only forward pass should matter in this case
Model Conversion: PyTorch → ONNX
It is not guaranteed conversion will run smoothly without fail when converting from .pth
→ .onnx
— So what to do if export to onnx fails?
Core dump: Segmentation Fault
A general rule-of-thumb — visualizing the computation graph of the network and understanding how the data (shape, type) changes also help tremendously when debugging this type of error.
Converting simplified ONNX to OM — convert the ONNX model to OM such that we can use it on Ascend hardware
There are 2 ways to convert from ONNX to OM:
**ATC**
command line tool (reference)**ATC**
backend) — you can either install MindStudio directly [link] or use the following docker image.For MindStudio Docker Image: (ensure you have docker
installed on your machine)
First, download the MindStudio Docker Image [link] (mindstudio_504a005.zip, ~9G), and unzip it to obtain the mindstudio_504a005.tar file.
unzip mindstudio_504a005.zip
Load the tar file with Docker and verify
docker load < mindstudio_504a005.tar
docker images | grep mindstudio
Start a container with the image
docker run -it --rm --privileged=true -p 23:22 \\
--env="DISPLAY=$DISPLAY" \\
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \\
-v /home/${USER}/Public:/home/HwHiAiUser/Public \\
mindstudio:5.0.4.a005
# password: Mind@123
For a more detailed explanation. refer to the “Setup Cross Compiling Environment, Option 1: Docker” section in the Atlas 200 DK Setup Guide
cd Mindstudio/bin && ./Mindstudio.sh
to open the GUI.onnx → .om
model conversion failsEvaluate OM — ****Evaluate the converted .om
model to ensure the converted model is runnable on Ascend AI processor
The general step to test a converted model:
<aside> 💡 We recommend 2 ways to visualize the model (computation graph) — Netron and MindStudio’s Model Visualizer
</aside>
Netron — https://netron.app/
Supports many types of format (even .om)
MindStudio - Model Visualizer (for visualizing .om)
Inside the MindStudio GUI — click on ‘Ascend’ → ‘Model Visualizer’ and select the .om file you want to visualize.
Sample code for running the pipeline.