What is Ascend MindSpore
Ascend MindSpore is a new open-source full-scenario deep learning framework launched by Huawei for device-edge-cloud scenarios. Ascend MindSpore has powerful distributed training capabilities and built-in multiple parallel strategies, simplifying large model development. Ascend MindSpore is deeply adapted to Ascend processors, fully leveraging hardware performance, shortening training time, and improving inference efficiency. Ascend MindSpore supports the integration of AI and high-performance computing (HPC), meeting the needs of AI for Science scenarios. Ascend MindSpore has a rich ecosystem, providing open-source projects, cases, and SOTA models, making it easy for developers to get started and apply.
Main features of Ascend MindSpore
- Full-scenario AI framework: Ascend MindSpore supports rapid deployment on cloud, edge, and device sides, and is suitable for various hardware platforms, such as Ascend processors, GPUs, CPUs, etc.
- Distributed training: Built-in multiple parallel capabilities, providing a simple and easy-to-use distributed strategy configuration interface for large models, supporting efficient large model training.
- AI4S integrated computing framework: Supports full-process programmable AI + HPC, meeting the heterogeneous parallel acceleration needs of AI for Science scenarios.
- Unlocking hardware potential: Unified dynamic and static programming, best matched with Ascend processors, helping developers shorten training time and improve inference performance.
- Installation and usage: Provides detailed installation guides and commands, supporting multiple hardware platforms.
- Cloud platform support: Provides cloud platform support, helping users quickly create and deploy models, and manage the full lifecycle of AI workflows.
- Ecosystem resources: Provides open-source projects, case collections, SOTA models and their derivative tools, and supports multiple domain suites (such as NLP, CV, Audio, etc.).
How to use Ascend MindSpore
- Environment preparation:
- Hardware environment: Ascend MindSpore supports multiple hardware platforms, including Ascend processors, GPUs (such as NVIDIA series), CPUs (such as Intel x86, Arm architecture), etc.
- Software environment:
-
Operating system: Linux is recommended (such as Ubuntu 18.04 or CentOS 7.6 and above); Windows and macOS are also supported.
-
Python environment: Python 3.7 and above is recommended.
-
- Install MindSpore:
- Installation method: Choose the appropriate installation command according to the hardware platform used. The following are some common installation methods:
- Install CPU version:
- Installation method: Choose the appropriate installation command according to the hardware platform used. The following are some common installation methods:
pip install mindspore
-
-
- Install GPU version (taking CUDA 11.1 as an example):
-
pip install mindspore-gpu==1.10.0
-
-
- Install Ascend version:
-
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.6.0/MindSpore/unified/aarch64/mindspore-2.6.0-cp39-cp39-linux_aarch64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
-
- Verify installation: After installation is complete, run the following command to verify whether MindSpore is installed successfully:
import mindspore
print(mindspore.__version__)
- Quick start:
- Data processing: The framework provides an efficient data processing pipeline, supporting multiple dataset loading and preprocessing operations.
import mindspore.dataset as ds
from mindspore.dataset.transforms import Compose, ToTensor, Normalize
# 加载MNIST数据集
dataset = ds.MnistDataset("path/to/mnist_dataset")
transforms = Compose([ToTensor(), Normalize((0.1307,), (0.3081,))])
dataset = dataset.map(operations=transforms, input_columns=["image"])
dataset = dataset.batch(batch_size=64)
-
- Build model: The framework provides rich APIs, supporting dynamic graph and static graph programming.
import mindspore.nn as nn
import mindspore.ops as ops
class LeNet5(nn.Cell):
def __init__(self):
super(LeNet5, self).__init__()
self.conv1 = nn.Conv2d(1, 6, 5, pad_mode='valid')
self.conv2 = nn.Conv2d(6, 16, 5, pad_mode='valid')
self.fc1 = nn.Dense(16 * 5 * 5, 120)
self.fc2 = nn.Dense(120, 84)
self.fc3 = nn.Dense(84, 10)
self.relu = nn.ReLU()
self.max_pool2d = nn.MaxPool2d(kernel_size=2)
self.flatten = ops.Flatten()
def construct(self, x):
x = self.max_pool2d(self.relu(self.conv1(x)))
x = self.max_pool2d(self.relu(self.conv2(x)))
x = self.flatten(x)
x = self.relu(self.fc1(x))
x = self.relu(self.fc2(x))
x = self.fc3(x)
return x
model = LeNet5()
-
- Train model: The framework provides
Modelclass, simplifying the training and evaluation process.
- Train model: The framework provides
from mindspore.train import Model
from mindspore.nn import SoftmaxCrossEntropyWithLogits, Momentum
from mindspore.train.callback import ModelCheckpoint, CheckpointConfig
# 定义损失函数和优化器
loss_fn = SoftmaxCrossEntropyWithLogits(sparse=True, reduction='mean')
optimizer = Momentum(model.trainable_params(), learning_rate=0.01, momentum=0.9)
# 创建Model实例
model = Model(model, loss_fn=loss_fn, optimizer=optimizer, metrics={'accuracy'})
# 设置保存检查点的配置
config_ck = CheckpointConfig(save_checkpoint_steps=1875, keep_checkpoint_max=10)
ckpoint_cb = ModelCheckpoint(prefix="lenet", config=config_ck)
# 开始训练
model.train(10, dataset, callbacks=[ckpoint_cb])
-
- Evaluate model: After training is complete, use the test set to evaluate model performance.
# 加载测试数据集
test_dataset = ds.MnistDataset("path/to/mnist_test_dataset")
test_dataset = test_dataset.map(operations=transforms, input_columns=["image"])
test_dataset = test_dataset.batch(batch_size=64)
# 评估模型
acc = model.eval(test_dataset)
print(f"Accuracy: {acc['accuracy']}")
Application scenarios of Ascend MindSpore
- Intelligent transportation and autonomous driving: In autonomous vehicles and intelligent transportation systems, it is used for real-time object detection, path planning, and traffic flow management, improving traffic efficiency and safety.
- Industrial automation and smart manufacturing: Deployed on industrial production lines, it is used for real-time quality inspection and equipment failure prediction, optimizing production processes and improving production efficiency.
- Healthcare and medical imaging: It is used in medical image analysis and smart health monitoring devices to assist doctors in diagnosing diseases and improve the level of medical services.
- Scientific research and engineering simulation: Combined with the AI4S suite, it accelerates scientific computing tasks such as electromagnetic simulation, fluid simulation, and molecular dynamics simulation, supporting scientific research and innovation.
- Enterprise data analysis and decision support: It is used for enterprise customer behavior analysis, market trend forecasting, and risk assessment, helping enterprises make more precise decisions.