Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update cann and pytorch #41

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions _static/ascend_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ $(document).ready(function () {
// reset table.
var cann_version_select = $('#cann-version');
cann_version_select.empty();
cann_version_select.append(new Option("选择CANN的版本", "na"));
$.reset_selection(cann_version_select);
$('#driver-version').text("Driver");
$('#firmware-version').text("Firmware");
Expand Down Expand Up @@ -114,7 +113,7 @@ $(document).ready(function () {
$("#col-values").on("click", ".values-element", function () {
id = $(this).attr("id");
fields = id.split("-");
if (id == "cann-version")
if (fields[1] == "version")
return;

$.reset_selection($(this));
Expand Down Expand Up @@ -189,14 +188,14 @@ $(document).ready(function () {
var cann_name = parts[parts.length - 1];

// download and install driver
$('#codecell5').html('wget "' + driver_url + '"<br>sudo sh ' + driver_name + ' --full --install-for-all');
$('#codecell6').html('wget "' + driver_url + '"\nsudo sh ' + driver_name + ' --full --install-for-all');

// download and install firmware
$('#codecell6').html('wget "' + firmware_url + '"<br>sudo sh ' + firmware_name + ' --full');
$('#codecell8').html('wget "' + firmware_url + '"\nsudo sh ' + firmware_name + ' --full');

if (options['install_type'] === 'direct') {
// download and install cann
$('#codecell8').html('wget "' + cann_url + '"<br>sh ' + cann_name + ' --install');
$('#codecell11').html('wget "' + cann_url + '"\nsh ' + cann_name + ' --install');

// download and install kernel if exist.
if (kernel_url == null) {
Expand All @@ -207,7 +206,7 @@ $(document).ready(function () {
var kernel_name = parts[parts.length - 1];
$('#install_kernel_section').show();
// download and install kernel
$('#codecell9').html('wget "' + kernel_url + '"<br>sh ' + kernel_name + ' --install');
$('#codecell13').html('wget "' + kernel_url + '"\nsh ' + kernel_name + ' --install');
}

$('#use_docker_section').hide();
Expand All @@ -232,7 +231,7 @@ docker run \\
-it ${docker_images[i]} bash
`;

$('#codecell11').html(dockerCommand.trim());
$('#codecell16').html(dockerCommand.trim());
break;
}
}
Expand All @@ -244,4 +243,5 @@ docker run \\
$.update_os_verions();
$.change_options_visible();
$.update_cann_versions();

});
Binary file modified _static/images/pytorch_wechat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions _static/pytorch_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ docker run \\
$('#install-pytorch-pip-section').hide();
$('#install-pytorch-docker-section').show();
} else if (options['install_type'] == "pip") {
$('#codecell1').html("# install torch<br>");
$('#codecell1').html("# install torch\n");
if(options['arch'] == "aarch64")
$('#codecell1').append("pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple torch==" + options['pytorch']);
else
$('#codecell1').append("pip3 install torch=="+options['pytorch']+"+cpu --index-url https://download.pytorch.org/whl/cpu");

$("#codecell1").append("<br><br># install torch-npu<br>pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple torch-npu==" + options['pytorch_npu']);
$("#codecell1").append("\n\n# install torch-npu\npip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple torch-npu==" + options['pytorch_npu']);

$('#install-pytorch-source-section').hide();
$('#install-pytorch-docker-section').hide();
$('#install-pytorch-pip-section').show();
} else {
$("#codecell4").html("# install requirements<br>conda install cmake ninja git<br><br># get torch source<br>git clone -b v"+options['pytorch']+" --recursive https://github.com/pytorch/pytorch<br>cd pytorch<br>git submodule sync<br>git submodule update --init --recursive<br><br># install torch<br>pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt<br>export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-\"$(dirname $(which conda))/../\"}<br>USE_CUDA=0 python setup.py develop");
$("#codecell3").html("# install requirements\nconda install cmake ninja git\n\n# get torch source\ngit clone -b v"+options['pytorch']+" --recursive https://github.com/pytorch/pytorch\ncd pytorch\ngit submodule sync\ngit submodule update --init --recursive\n\n# install torch\npip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt\nexport CMAKE_PREFIX_PATH=${CONDA_PREFIX:-\"$(dirname $(which conda))/../\"}\nUSE_CUDA=0 python setup.py develop");

$('#codecell4').append("<br><br># get torch-npu source<br>git clone https://github.com/ascend/pytorch.git -b "+match_versions['npu_branch']+" --depth 1 pytorch_npu<br>cd pytorch_npu<br><br># install torch-npu<br>pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt<br>bash ci/build.sh --python=$(python --version 2>&1 | awk '{print $2}' | cut -d '.' -f 1,2)<br>pip install dist/torch_npu*.whl");
$('#codecell3').append("\n\n# get torch-npu source\ngit clone https://github.com/ascend/pytorch.git -b "+match_versions['npu_branch']+" --depth 1 pytorch_npu\ncd pytorch_npu\n\n# install torch-npu\npip install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt\nbash ci/build.sh --python=$(python --version 2>&1 | awk '{print $2}' | cut -d '.' -f 1,2)\npip install dist/torch_npu*.whl");

$('#install-pytorch-pip-section').hide();
$('#install-pytorch-docker-section').hide();
Expand Down
123 changes: 61 additions & 62 deletions sources/ascend/quick_install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

跟随指导,在您的机器上快速安装昇腾环境。

系统要求
1. 系统要求
----------------
前置检查
1.1 前置检查
^^^^^^^^^^^^^
确认昇腾AI处理器已经安装妥当

Expand All @@ -19,8 +19,14 @@

uname -m && cat /etc/*release

确认Python版本

软件要求
.. code-block:: bash

python --version


1.2 软件要求
^^^^^^^^^^^^^
======== ========================================
软件 版本
Expand All @@ -30,13 +36,13 @@ Python 3.8, 3.9, 3.10
======== ========================================


环境安装
2. 环境安装
------------------
根据您的需求,选择合适的软件包版本:

.. note::
.. warning::

建议使用非root用户安装
以下文档需要使用非root用户进行安装安装

.. raw:: html

Expand Down Expand Up @@ -87,8 +93,8 @@ Python 3.8, 3.9, 3.10
</div>
<div id="install-instructions" style="display:none;">
<section>
<h3>安装驱动</h3>
<p><b>安装依赖</b></p>
<h3>2.1 安装驱动</h3>
<p><b>2.1.1 安装依赖</b></p>
<div class="highlight-default notranslate" id="install-dependencies-ubuntu">
<div class="highlight">
<pre>sudo apt-get install -y gcc g++ make cmake zlib1g zlib1g-dev openssl libsqlite3-dev libssl-dev libffi-dev unzip pciutils net-tools libblas-dev gfortran libblas3 python3-dev</pre>
Expand All @@ -99,20 +105,39 @@ Python 3.8, 3.9, 3.10
<pre>sudo yum install -y gcc gcc-c++ make cmake unzip zlib-devel libffi-devel openssl-devel pciutils net-tools sqlite-devel lapack-devel gcc-gfortran python3-devel</pre>
</div>
</div>
<p><b>创建驱动运行用户</b></p>
<p><b>2.1.2 创建驱动运行用户</b></p>
<div class="admonition note">
<p class="admonition-title">备注</p>
<p>请使用命令 <code class="docutils literal notranslate">id HwHiAiUser</code> 查看用户是否存在,若存在请跳过此步骤</p>
</div>
<div class="highlight-default notranslate">
<div class="highlight">
<pre>sudo groupadd -g HwHiAiUser<br>sudo useradd -g HwHiAiUser -d /home/HwHiAiUser -m HwHiAiUser -s /bin/bash<br>sudo usermod -aG HwHiAiUser $USER</pre>
</div>
</div>
<p><b>下载并安装</b></p>
<p><b>2.1.3 下载并安装</b></p>
<div class="highlight-default notranslate">
<div class="highlight">
<pre></pre>
</div>
</div>
<p>确认您的驱动是否安装成功,可以通过以下命令验证:<code class="docutils literal notranslate"><span class="pre">npu-smi</span> <span class="pre">info</span></code>,若出现以下回显信息,说明驱动安装成功。</p>
<div class="highlight-default notranslate">
<div class="highlight">
<pre>+-------------------------------------------------------------------------------------------+
| npu-smi 23.0.2 Version: 23.0.2 |
+----------------------+---------------+----------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+======================+===============+====================================================+
| 0 xxx | OK | 0.0 40 0 / 0 |
| 0 | 0000:C1:00.0 | 0 882 / 15169 0 / 32768 |
+======================+===============+====================================================+
</pre>
</div>
</div>
<section>
<h3>安装固件</h3>
<h3>2.2 安装固件</h3>
<div class="highlight-default notranslate">
<div class="highlight">
<pre></pre>
Expand All @@ -122,38 +147,56 @@ Python 3.8, 3.9, 3.10
<p class="admonition-title">备注</p>
<p>根据提示决定是否需要重启系统</p>
</div>
<p>安装固件后,若系统出现如下关键回显信息,表示固件安装成功。</p>
<div class="highlight-default notranslate">
<div class="highlight">
<pre>Firmware package installed successfully!</pre>
</div>
</div>
</section>
<section id="install_cann_section">
<h3>安装CANN</h3>
<p><b>安装python依赖</b></p>
<h3>2.3 安装CANN</h3>
<p><b>2.3.1 安装python依赖</b></p>
<div class="highlight-default notranslate">
<div class="highlight">
<pre>pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple attrs numpy decorator sympy cffi pyyaml pathlib2 psutil protobuf scipy requests absl-py wheel typing_extensions</pre>
</div>
</div>
<p><b>下载并安装</b></p>
<p><b>2.3.2 下载并安装</b></p>
<div class="highlight-default notranslate">
<div class="highlight">
<pre></pre>
</div>
</div>
<p>安装CANN-toolkit后,若系统出现以下关键回显信息,表示CANN-toolkit安装成功。</p>
<div class="highlight-default notranslate">
<div class="highlight">
<pre>Ascend-cann-toolkit install success.</pre>
</div>
</div>
<div id="install_kernel_section">
<p><b>安装算子包(可选)</b></p>
<p><b>2.3.3 安装算子包</b></p>
<div class="highlight-default notranslate">
<div class="highlight">
<pre></pre>
</div>
</div>
</div>
<p><b>设置环境变量</b></p>
<p>安装算子包后,若系统出现以下关键回显信息,表示算子包安装成功。</p>
<div class="highlight-default notranslate">
<div class="highlight">
<pre>Ascend-cann-kernels install success.</pre>
</div>
</div>
<p><b>2.3.4 设置环境变量</b></p>
<div class="highlight-default notranslate">
<div class="highlight">
<pre>echo "source ~/Ascend/ascend-toolkit/set_env.sh" >> ~/.bashrc<br>source ~/.bashrc</pre>
</div>
</div>
</section>
<section id="use_docker_section">
<h3>运行Docker容器</h3>
<h3>2.3 运行Docker容器</h3>
<div>
下列命令将创建一个名为'cann-container'的Docker容器,并将设备和驱动挂载到容器中。<br><br>
</div>
Expand All @@ -168,51 +211,7 @@ Python 3.8, 3.9, 3.10
</div>


验证安装(可选)
---------------------
**验证驱动**

确认您的驱动是否安装成功,可以通过以下命令验证:``npu-smi info``
,若出现以下回显信息,说明驱动安装成功。

.. code-block:: bash

+-------------------------------------------------------------------------------------------+
| npu-smi 23.0.2 Version: 23.0.2 |
+----------------------+---------------+----------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|
| Chip | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+======================+===============+====================================================+
| 0 xxx | OK | 0.0 40 0 / 0 |
| 0 | 0000:C1:00.0 | 0 882 / 15169 0 / 32768 |
+======================+===============+====================================================+

... ...

**验证固件**

安装固件后,若系统出现如下关键回显信息,表示固件安装成功。

.. code-block:: bash

Firmware package installed successfully!

**验证CANN-toolkit**

安装CANN-toolkit后,若系统出现以下关键回显信息,表示CANN-toolkit安装成功。

.. code-block:: bash

Ascend-cann-toolkit install success.

安装算子包后,若系统出现以下关键回显信息,表示算子包安装成功。

.. code-block:: bash

Ascend-cann-kernels install success.


卸载
3. 卸载
----------
**卸载驱动**

Expand Down
10 changes: 5 additions & 5 deletions sources/pytorch/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

在运行下述示例之前,需要您已经安装了PyTorch-NPU环境,有关环境安装,请参考 :doc:`./install`

数据并行
1. 数据并行
-----------------------

PyTorch的数据并行主要分为以下几种:DP、DDP以及FSDP(HSDP变种),接下来将简单描述在Ascend NPU场景下如何实现上述数据并行。

DDP
^^^^^^
1.1 DDP
^^^^^^^^^^

.. code-block:: python
:linenos:
Expand Down Expand Up @@ -83,8 +83,8 @@ DDP
if __name__ == "__main__":
main()

FSDP
^^^^^^
1.2 FSDP
^^^^^^^^^^

.. code-block:: python
:linenos:
Expand Down
29 changes: 12 additions & 17 deletions sources/pytorch/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
跟随指导,安装在NPU上运行的PyTorch版本。


选择需要安装的 PyTorch 版本
1. 选择需要安装的 PyTorch 版本
------------------------------
准备安装 PyTorch:

Expand Down Expand Up @@ -50,8 +50,12 @@
</div>


安装 PyTorch
2. 安装 PyTorch
----------------

.. warning::

如果使用了非CANN安装时的Python环境(如Conda),请确保CANN-toolkit依赖的Python包在该环境中已经 `安装 <../ascend/quick_install.html>`_ 。
.. raw:: html

<section id="install-pytorch-docker-section">
Expand All @@ -78,37 +82,28 @@
<p class="admonition-title">备注</p>
<p>请确保已经根据上述表格建议<a class="reference internal" href="../ascend/quick_install.html"><span class="doc">安装</span></a>了对应的CANN-toolkit版本以及相应的固件和驱动,并应用了CANN-toolkit环境变量。</p>
</div>
<h3>环境依赖</h3>
<ol>
<h3>2.1 环境依赖</h3>
<ul>
<li>Python 3.8 ~ 3.10</li>
<li>支持C++17的编译器,例如clang 或者 gcc (9.4.0及以上)</li>
<li><a class="reference internal" href="https://docs.anaconda.com/free/miniconda/#quick-command-line-install"><span class="doc">Conda (可选)</span></a></li>
</ol>
<div class="admonition note">
<p class="admonition-title">备注</p>
<p>如果使用Conda,请确保CANN-toolkit依赖的Python包在Conda环境中已经<a class="reference internal" href="../ascend/quick_install.html"><span class="doc">安装</span></a></p>
</div>
<div class="admonition warning">
<p class="admonition-title">警告</p>
<p>不建议您使用Conda提供的gcc,可能需要解决一些编译依赖问题,如果一定要使用,可参考以下命令:</p>
</div>
<div class="highlight"><pre>conda install -c conda-forge libstdcxx-ng libgcc-ng gcc=9.4 gxx=9.4</pre></div>
<li><a class="reference internal" href="https://docs.anaconda.com/free/miniconda/#quick-command-line-install"><span class="doc">Conda</span></a></li>
</ul>
</section>
<section>
<div class="admonition note">
<p class="admonition-title">备注</p>
<p>请确认CXX11_ABI是关闭的,如果无法确定,建议显式关闭:</p>
</div>
<div class="highlight"><pre>export _GLIBCXX_USE_CXX11_ABI=0</pre></div>
<h3>构建</h3>
<h3>2.2 构建</h3>
<div class="highlight">
<pre></pre>
</div>
</section>
</div>


验证安装结果
3. 验证安装结果
------------------

.. code-block:: python
Expand Down
Loading