2.3K Star 7.9K Fork 4.1K

GVPMindSpore / mindspore

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

MindSpore标志

PyPI - Python Version PyPI Downloads DockerHub LICENSE Slack PRs Welcome

View English

MindSpore介绍

MindSpore是一种适用于端边云场景的新型开源深度学习训练/推理框架。 MindSpore提供了友好的设计和高效的执行,旨在提升数据科学家和算法工程师的开发体验,并为Ascend AI处理器提供原生支持,以及软硬件协同优化。

同时,MindSpore作为全球AI开源社区,致力于进一步开发和丰富AI软硬件应用生态。

MindSpore Architecture

欲了解更多详情,请查看我们的总体架构

自动微分

当前主流深度学习框架中有两种自动微分技术:

  • 操作符重载法: 通过操作符重载对编程语言中的基本操作语义进行重定义,封装其微分规则。 在程序运行时记录算子过载正向执行时网络的运行轨迹,对动态生成的数据流图应用链式法则,实现自动微分。
  • 代码变换法: 该技术是从功能编程框架演进而来,以即时编译(Just-in-time Compilation,JIT)的形式对中间表达式(程序在编译过程中的表达式)进行自动差分转换,支持复杂的控制流场景、高阶函数和闭包。

PyTorch采用的是操作符重载法。相较于代码变换法,操作符重载法是在运行时生成微分计算图的, 无需考虑函数调用与控制流等情况, 开发更为简单。 但该方法不能在编译时刻做微分图的优化, 控制流也需要根据运行时的信息来展开, 很难实现性能的极限优化。

MindSpore则采用的是代码变换法。一方面,它支持自动控制流的自动微分,因此像PyTorch这样的模型构建非常方便。另一方面,MindSpore可以对神经网络进行静态编译优化,以获得更好的性能。

Automatic Differentiation

MindSpore自动微分的实现可以理解为程序本身的符号微分。MindSpore IR是一个函数中间表达式,它与基础代数中的复合函数具有直观的对应关系。复合函数的公式由任意可推导的基础函数组成。MindSpore IR中的每个原语操作都可以对应基础代数中的基本功能,从而可以建立更复杂的流控制。

自动并行

MindSpore自动并行的目的是构建数据并行、模型并行和混合并行相结合的训练方法。该方法能够自动选择开销最小的模型切分策略,实现自动分布并行训练。

Automatic Parallel

目前MindSpore采用的是算子切分的细粒度并行策略,即图中的每个算子被切分为一个集群,完成并行操作。在此期间的切分策略可能非常复杂,但是作为一名Python开发者,您无需关注底层实现,只要顶层API计算是有效的即可。

安装

pip方式安装

MindSpore提供跨多个后端的构建选项:

硬件平台 操作系统 状态
Ascend 910 Ubuntu-x86 ✔️
Ubuntu-aarch64 ✔️
EulerOS-aarch64 ✔️
CentOS-x86 ✔️
CentOS-aarch64 ✔️
GPU CUDA 10.1 Ubuntu-x86 ✔️
CPU Ubuntu-x86 ✔️
Ubuntu-aarch64 ✔️
Windows-x86 ✔️

使用pip命令安装,以CPUUbuntu-x86build版本为例:

  1. 请从MindSpore下载页面下载并安装whl包。

    pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/1.2.0-rc1/MindSpore/cpu/ubuntu_x86/mindspore-1.2.0rc1-cp37-cp37m-linux_x86_64.whl
  2. 执行以下命令,验证安装结果。

    import numpy as np
    import mindspore.context as context
    import mindspore.nn as nn
    from mindspore import Tensor
    from mindspore.ops import operations as P
    
    context.set_context(mode=context.GRAPH_MODE, device_target="CPU")
    
    class Mul(nn.Cell):
        def __init__(self):
            super(Mul, self).__init__()
            self.mul = P.Mul()
    
        def construct(self, x, y):
            return self.mul(x, y)
    
    x = Tensor(np.array([1.0, 2.0, 3.0]).astype(np.float32))
    y = Tensor(np.array([4.0, 5.0, 6.0]).astype(np.float32))
    
    mul = Mul()
    print(mul(x, y))
    [ 4. 10. 18.]

使用pip方式,在不同的环境安装MindSpore,可参考以下文档。

源码编译方式安装

使用源码编译方式,在不同的环境安装MindSpore,可参考以下文档。

Docker镜像

MindSpore的Docker镜像托管在Docker Hub上。 目前容器化构建选项支持情况如下:

硬件平台 Docker镜像仓库 标签 说明
CPU mindspore/mindspore-cpu x.y.z 已经预安装MindSpore x.y.z CPU版本的生产环境。
devel 提供开发环境从源头构建MindSpore(CPU后端)。安装详情请参考https://www.mindspore.cn/install
runtime 提供运行时环境安装MindSpore二进制包(CPU后端)。
GPU mindspore/mindspore-gpu x.y.z 已经预安装MindSpore x.y.z GPU版本的生产环境。
devel 提供开发环境从源头构建MindSpore(GPU CUDA10.1后端)。安装详情请参考https://www.mindspore.cn/install
runtime 提供运行时环境安装MindSpore二进制包(GPU CUDA10.1后端)。

注意: 不建议从源头构建GPU devel Docker镜像后直接安装whl包。我们强烈建议您在GPU runtime Docker镜像中传输并安装whl包。

  • CPU

    对于CPU后端,可以直接使用以下命令获取并运行最新的稳定镜像:

    docker pull mindspore/mindspore-cpu:1.1.0
    docker run -it mindspore/mindspore-cpu:1.1.0 /bin/bash
  • GPU

    对于GPU后端,请确保nvidia-container-toolkit已经提前安装,以下是Ubuntu用户安装指南:

    DISTRIBUTION=$(. /etc/os-release; echo $ID$VERSION_ID)
    curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | apt-key add -
    curl -s -L https://nvidia.github.io/nvidia-docker/$DISTRIBUTION/nvidia-docker.list | tee /etc/apt/sources.list.d/nvidia-docker.list
    
    sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit nvidia-docker2
    sudo systemctl restart docker

    编辑文件 daemon.json:

    $ vim /etc/docker/daemon.json
    {
        "runtimes": {
            "nvidia": {
                "path": "nvidia-container-runtime",
                "runtimeArgs": []
            }
        }
    }

    再次重启docker:

    sudo systemctl daemon-reload
    sudo systemctl restart docker

    使用以下命令获取并运行最新的稳定镜像:

    docker pull mindspore/mindspore-gpu:1.1.0
    docker run -it -v /dev/shm:/dev/shm --runtime=nvidia --privileged=true mindspore/mindspore-gpu:1.1.0 /bin/bash

    要测试Docker是否正常工作,请运行下面的Python代码并检查输出:

    import numpy as np
    import mindspore.context as context
    from mindspore import Tensor
    from mindspore.ops import functional as F
    
    context.set_context(mode=context.PYNATIVE_MODE, device_target="GPU")
    
    x = Tensor(np.ones([1,3,3,4]).astype(np.float32))
    y = Tensor(np.ones([1,3,3,4]).astype(np.float32))
    print(F.tensor_add(x, y))
    [[[ 2.  2.  2.  2.],
    [ 2.  2.  2.  2.],
    [ 2.  2.  2.  2.]],
    
    [[ 2.  2.  2.  2.],
    [ 2.  2.  2.  2.],
    [ 2.  2.  2.  2.]],
    
    [[ 2.  2.  2.  2.],
    [ 2.  2.  2.  2.],
    [ 2.  2.  2.  2.]]]

如果您想了解更多关于MindSpore Docker镜像的构建过程,请查看docker repo了解详细信息。

快速入门

参考快速入门实现图片分类。

文档

有关安装指南、教程和API的更多详细信息,请参阅用户文档

社区

治理

查看MindSpore如何进行开放治理

交流

贡献

欢迎参与贡献。更多详情,请参阅我们的贡献者Wiki

分支维护策略

MindSpore的版本分支有以下几种维护阶段:

状态 持续时间 说明
Planning 1 - 3 months 特性规划。
Development 3 months 特性开发。
Maintained 6 - 12 months 允许所有问题修复的合入,并发布版本。
Unmaintained 0 - 3 months 允许所有问题修复的合入,无专人维护,不再发布版本。
End Of Life (EOL) N/A 不再接受修改合入该分支。

现有分支维护状态

分支名 当前状态 上线时间 后续状态 EOL 日期
r2.1 Maintained 2023-07-29 Unmaintained
2024-07-29 estimated
r2.0 Maintained 2023-06-15 Unmaintained
2024-06-15 estimated
r1.10 Maintained 2023-02-02 Unmaintained
2024-02-02 estimated
r1.9 Maintained 2022-10-26 Unmaintained
2023-10-26 estimated
r1.8 End Of Life 2022-07-29 2023-07-29
r1.7 End Of Life 2022-04-29 2023-04-29
r1.6 End Of Life 2022-01-29 2023-01-29
r1.5 End Of Life 2021-10-15 2022-10-15
r1.4 End Of Life 2021-08-15 2022-08-15
r1.3 End Of Life 2021-07-15 2022-07-15
r1.2 End Of Life 2021-04-15 2022-04-29
r1.1 End Of Life 2020-12-31 2021-09-30
r1.0 End Of Life 2020-09-24 2021-07-30
r0.7 End Of Life 2020-08-31 2021-02-28
r0.6 End Of Life 2020-07-31 2020-12-30
r0.5 End Of Life 2020-06-30 2021-06-30
r0.3 End Of Life 2020-05-31 2020-09-30
r0.2 End Of Life 2020-04-30 2020-08-31
r0.1 End Of Life 2020-03-28 2020-06-30

版本说明

版本说明请参阅RELEASE

许可证

Apache License 2.0

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

MindSpore is a new open source deep learning training/inference framework that could be used for mobile, edge and cloud scenarios. 展开 收起
Python 等 6 种语言
Apache-2.0
取消

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/mindspore/mindspore.git
git@gitee.com:mindspore/mindspore.git
mindspore
mindspore
mindspore
master

搜索帮助

14c37bed 8189591 565d56ea 8189591