MindSpore Documentation

repository·master·Indexed 26 days ago

https://github.com/mindspore-ai/mindspore

An 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.

Tokens
92.2K
Snippets
135
Records
367
Agent score
89%

What's inside MindSpore

  1. Overview of MindSpore

    master
    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.
  2. Overview of mindspore.numpy

    master

    The mindspore.numpy package 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, and math operation.

    Note on Performance: While mindspore.numpy provides a consistent programming experience by assembling low-level operators, the performance of some interfaces may be weaker than the native MindSpore function or ops interfaces. Users should choose between them based on their specific performance requirements.

  3. Overview of MindSpore Lite

    master

    MindSpore 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.
  4. Use mindspore.multiprocessing for multi-process execution

    master

    The mindspore.multiprocessing module provides multi-processing capabilities by inheriting from Python's native multiprocessing module. It overloads specific interfaces to ensure the MindSpore framework functions correctly during a fork, such as cleaning up threads, locks, and resetting the backend to CPU in the child process to prevent resource conflicts.

    Key Constraints:

    • Tensor Sharing: Only Tensors with the CPU backend can be shared between processes.
    • Platform Support: The fork start method is only supported on POSIX systems (e.g., Linux and macOS), not on Windows.
  5. Automatic Parallel in MindSpore

    master
    MindSpore'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.
  6. Automatic Differentiation in MindSpore

    master
    MindSpore 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.
  7. Understand MindSpore branch maintenance lifecycle

    master

    MindSpore 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.
  8. MindSpore Lite AI Deployment Workflow

    master

    The deployment process for MindSpore Lite follows four main stages:

    1. 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.
    2. 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 .C code.
    3. Model Deployment: Implement model management, deployment, and operational monitoring.
    4. Model Inference: Load the model and execute computations to obtain predictions by running input data through the model.
  9. Run Distributed Communication Samples with mpirun

    master

    To run MindSpore distributed communication operations (like AllReduce, AllGather, etc.), you must use mpirun with OpenMPI and NCCL installed.

    1. Save your code as communication.py.
    2. 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.py

    Logs for each rank will be saved in the log/1/rank.0 directory structure (e.g., log/1/rank.0 for rank 0).