[ "MindSpore Made Easy" ]

[ "MindSpore Made Easy" ]

MindSpore Made Easy API Structure and Usage

June 20, 2022

Introduction

An API document is a tool usage guide. To learn a tool, you need to be familiar with its APIs, and the API document determines how fast you learn. This blog will describe MindSpore APIs.

API Definition

An application programming interface (API) is to provide applications and developers with the ability to access a set of routines without accessing the source code or understanding the details of the internal working mechanism. An API is an interface and therefore an abstraction. The software that provides the functions defined by an API is called the API implementation.

The explanation above is professional but general. In actual applications, a toolkit can be regarded as a service hall. Each API is a window, and different windows handle different services. A user only needs to go to the corresponding window as required and provides the name and ID card number to get feedback. This helps us understand the relationship between APIs, toolkits, and users.

If you want to use MindSpore, start with its APIs.

MindSpore API Structure

On the documentation page of the MindSpore official website, the API module is located below the Design and Specifications modules, which are the cores of MindSpore. The Design module contains the overall structure design and unique key features and the Specifications module describes the benchmark performance of MindSpore and its support for networks, operators, and syntax. You are advised to read them carefully.

Among the six modules on the documentation page, content of the API module accounts for the largest proportion. The API module contains actual applications, and it is difficult for you to remember all of them. However, you can quickly find required APIs by familiarizing yourself with the API structure.

The API structure sequence corresponds to the model training sequence. The following classifies the APIs based on the training sequence.

Parameter Initialization:

· The mindspore and mindspore.common.initializer modules provide initialization setting APIs used before model training, covering hardware parameters such as the data types, random seeds, and operating environments, as well as neuron parameters.

· The mindspore.communication module contains collective communication APIs that are used in Ascend and GPU hardware environments for distributed training. CPU environments are not supported currently.

Data Processing:

· The mindspore.dataset module provides APIs for loading and processing various public datasets, such as MNIST, CIFAR-10, COCO, ImageNet, and CLUE. It can also load datasets in standard formats in the industry, such as MindRecord, TFRecord, and Manifest. You can also use this module to define and load your own datasets.

· The mindspore.dataset.audio, mindspore.dataset.text, and mindspore.dataset.vision are audio, text, and image data processing modules, containing data augmentation and preprocessing methods.

· The mindspore.dataset.config module is used to set or obtain configuration parameters for data processing.

· mindspore.dataset.transforms is the data augmentation module, which can be used for various types of data.

· The mindspore.mindrecord module converts different datasets into the MindRecord format, an efficient data format developed by MindSpore. You can also use corresponding submodules to convert datasets in other formats to the MindRecord format.

Network Building:

· The mindspore.nn and mindspore.nn.probability modules provide predefined building blocks or compute units for building neural networks and some advanced components for constructing probability networks.

· The mindspore.numpy module is the accessed NumPy computing package. It can use NumPy-like syntax to build models and can be used for array generation, array operations, logical operations, and mathematical operations.

· The mindspore.ops and mindspore.ops.functional modules contain lowest-level operator APIs opened to users. One primitive operator corresponds to one primitive and encapsulates the implementation of multiple operators at the bottom layer, such as Ascend, GPU, AI CPU, and CPU.

Debugging and Tuning:

· The mindspore.rewrite, mindspore.scipy, and mindspore.boost modules implement node viewing, data computing and solving, and network acceleration.

API Query

It is difficult to remember how every API is used. We need some methods for quick API query. The following describes two methods.

· Detailed query on the official website: https://mindspore.cn/docs/en/master/index.html

· Window query: Enter python -m pydoc -p 4567.

The corresponding web page is automatically displayed, on which you can query all installed packages or view the detailed APIs of each package. The following figure shows the queried MindSpore page.

Conclusion

This blog analyzes the structure of MindSpore APIs to facilitate MindSpore API query and use. You are welcome to provide comments and suggestions to help build MindSpore.