MindSpore Documentation
repository·master·Indexed 26 days ago
https://github.com/mindspore-ai/mindsporeAn open-source deep learning framework optimized for training and inference across mobile, edge, and cloud environments, with specialized support for Ascend AI hardware. The documentation covers core C++ utilities including task management (Task, TaskGroup, TaskManager), synchronization primitives (CondVar, WaitPost, SpinLock, RWLock), memory management (MemoryPool, Arena), and the NNACL library for ARM-based neural network inference.
What's inside MindSpore
- MindSpore is an open-source deep learning training and inference framework designed for mobile, edge, and cloud scenarios. It provides a developer-friendly experience with efficient execution, native support for Ascend AI processors, and software-hardware co-optimization.
Overview of NNACL (Neural Network Accelerated Computing Library)
masterNNACL is a high-performance library specifically designed for neural network inference computing kernels on ARM architectures. It provides optimized kernels to accelerate inference tasks on ARM-based devices.Overview of mindspore.numpy
masterThe
mindspore.numpypackage provides a set of Numpy-like interfaces, allowing developers to build models using syntax similar to native Numpy. It is composed of four functional modules:array generation,array operation,logic operation, andmath operation.Note on Performance: While
mindspore.numpyprovides a consistent programming experience by assembling low-level operators, the performance of some interfaces may be weaker than the native MindSporefunctionoropsinterfaces. Users should choose between them based on their specific performance requirements.Overview of MindSpore Lite
masterMindSpore Lite is a high-performance, lightweight open-source reasoning framework designed for deploying AI applications on mobile devices, IoT, and smart screens. It is optimized for effective AI technology deployment and is integrated into Huawei Mobile Services (HMS) for tasks like image classification, object detection, and OCR.
Key features include:
- Cooperative Work with MindSpore Training: Uses a unified IR to realize device-cloud AI application integration.
- Lightweight: Supports model compression and provides MindSpore Micro for extreme environments like smartwatches and headphones.
- High-performance: Includes the NNACL kernel computing library with optimized convolution algorithms (Slide window, im2col+gemm, winograde, etc.) and assembly code support for CPU, GPU, and NPU.
- Versatility: Supports iOS, Android, Lite OS, and third-party models such as TFLite, CAFFE, and ONNX.
Modify network forward computation with mindspore.rewrite
masterThe
mindspore.rewritemodule allows you to modify a network's forward computation process by applying custom rules. You can use it to insert, delete, or replace statements within the computation graph.For a detailed tutorial on how to implement these modifications, refer to the official Modifying Network With ReWrite guide.
Use mindspore.multiprocessing for multi-process execution
masterThe
mindspore.multiprocessingmodule provides multi-processing capabilities by inheriting from Python's nativemultiprocessingmodule. It overloads specific interfaces to ensure the MindSpore framework functions correctly during afork, such as cleaning up threads, locks, and resetting the backend toCPUin the child process to prevent resource conflicts.Key Constraints:
- Tensor Sharing: Only Tensors with the
CPUbackend can be shared between processes. - Platform Support: The
forkstart method is only supported on POSIX systems (e.g., Linux and macOS), not on Windows.
- Tensor Sharing: Only Tensors with the
Modify networks using the ReWrite module
masterThemindspore.rewritemodule allows you to modify a network's forward computation process by recording it into aSymbolTree. Each statement in the forward pass is expanded and stored as nodes in the tree. You can then insert, delete, or replace these nodes to create a modified network or a new network instance.Automatic Parallel in MindSpore
masterMindSpore's Automatic Parallel feature enables distributed parallel training by combining data parallelism, model parallelism, and hybrid parallelism. It automatically selects the most efficient model splitting strategy. While it uses a fine-grained parallel strategy of splitting operators, developers can use top-level APIs without needing to manage the underlying implementation details.Automatic Differentiation in MindSpore
masterMindSpore implements automatic differentiation using Source Transformation (ST). Unlike Operator Overloading (OO) used by frameworks like PyTorch, which generates gradient graphs at runtime, MindSpore's ST approach performs automatic differential transformation on intermediate expressions during just-in-time (JIT) compilation. This allows MindSpore to support complex control flows, higher-order functions, and closures while enabling static compilation optimizations for high performance.Understand MindSpore branch maintenance lifecycle
masterMindSpore follows a structured branch maintenance strategy. Understanding these stages helps in choosing a stable version for production or a feature-rich version for development:
- Planning: Feature planning phase (1 - 3 months).
- Development: Active feature development phase (3 months).
- Maintained: Active phase where bug fixes are merged and new versions are released (6 - 12 months).
- Unmaintained: Bug fixes are allowed, but there is no dedicated maintenance team and no new versions are released (0 - 3 months).
- End Of Life (EOL): No further modifications or fixes are accepted for this branch.
MindSpore Lite AI Deployment Workflow
masterThe deployment process for MindSpore Lite follows four main stages:
- Model Selection and Personalized Training: Choose a new model or perform incremental training on existing models using annotated data. Consider model size, precision, and computational load for edge design. Pre-trained models for image classification are available in the MindSpore Model Zoo.
- Model Conversion/Optimization: Convert MindSpore or third-party models (TensorFlow Lite, Caffe, ONNX) into the MindSpore Lite format using the MindSpore Lite Model Converter Tool. This tool supports operator fusion and quantization. For IoT devices, a tool is also available to convert models into
.Ccode. - Model Deployment: Implement model management, deployment, and operational monitoring.
- Model Inference: Load the model and execute computations to obtain predictions by running input data through the model.
Run Distributed Communication Samples with mpirun
masterTo run MindSpore distributed communication operations (like
AllReduce,AllGather, etc.), you must usempirunwith OpenMPI and NCCL installed.- Save your code as
communication.py. - Execute the following command to launch 4 processes (occupying cards 0, 1, 2, and 3):
mpirun -output-filename log -merge-stderr-to-stdout -np 4 python communication.pyLogs for each rank will be saved in the
log/1/rank.0directory structure (e.g.,log/1/rank.0for rank 0).- Save your code as