diff --git a/_static/ascend_actions.js b/_static/ascend_actions.js index dfb8acd..7083a7c 100644 --- a/_static/ascend_actions.js +++ b/_static/ascend_actions.js @@ -189,14 +189,14 @@ $(document).ready(function () { var cann_name = parts[parts.length - 1]; // download and install driver - $('#install_drvier').html('wget "' + driver_url + '"
sudo sh ' + driver_name + ' --full --install-for-all'); + $('#codecell5').html('wget "' + driver_url + '"
sudo sh ' + driver_name + ' --full --install-for-all'); // download and install firmware - $('#install_firmware').html('wget "' + firmware_url + '"
sudo sh ' + firmware_name + ' --full'); + $('#codecell6').html('wget "' + firmware_url + '"
sudo sh ' + firmware_name + ' --full'); if (options['install_type'] === 'direct') { // download and install cann - $('#install_cann').html('wget "' + cann_url + '"
sh ' + cann_name + ' --install'); + $('#codecell8').html('wget "' + cann_url + '"
sh ' + cann_name + ' --install'); // download and install kernel if exist. if (kernel_url == null) { @@ -207,7 +207,7 @@ $(document).ready(function () { var kernel_name = parts[parts.length - 1]; $('#install_kernel_section').show(); // download and install kernel - $('#install_kernel').html('wget "' + kernel_url + '"
sh ' + kernel_name + ' --install'); + $('#codecell9').html('wget "' + kernel_url + '"
sh ' + kernel_name + ' --install'); } $('#use_docker_section').hide(); @@ -231,7 +231,7 @@ docker run \\ -it ${docker_images[i]} bash `; - $('#use_docker').html(dockerCommand.trim()); + $('#codecell11').html(dockerCommand.trim()); break; } } diff --git a/_static/package_info.js b/_static/package_info.js index 2f3bfa6..3eb753c 100644 --- a/_static/package_info.js +++ b/_static/package_info.js @@ -195,16 +195,19 @@ const pytorch_versions = { '2.2.0': { torch_npu: '2.2.0', npu_branch: 'v2.2.0-6.0.rc1', - cann: 'CANN 8.0.RC1' + cann: 'CANN 8.0.RC1', + docker: 'cosdt/torch:2.2.0' }, '2.1.0': { torch_npu: '2.1.0.post3', npu_branch: 'v2.1.0-6.0.rc1', - cann: 'CANN 8.0.RC1' + cann: 'CANN 8.0.RC1', + docker: 'cosdt/torch:2.1.0' }, '2.0.1': { torch_npu: '2.0.1.post1', npu_branch: 'v2.1.0-5.0.0', - cann: 'CANN 7.0.0' + cann: 'CANN 7.0.0', + docker: 'cosdt/torch:2.0.1' } } \ No newline at end of file diff --git a/_static/pytorch_actions.js b/_static/pytorch_actions.js index 6702004..de98780 100644 --- a/_static/pytorch_actions.js +++ b/_static/pytorch_actions.js @@ -12,10 +12,10 @@ $(document).ready(function () { var id = $(this).attr("id").split("-"); var category = id[0]; var value = id[1]; - if(category == 'pytorch') - options[category] = value; - else + if(category == 'cann' || category == 'pytorch_npu') options[category] = $(this).text(); + else + options[category] = value; }); }); return options; @@ -24,7 +24,7 @@ $(document).ready(function () { $.update_table = function () { var options = $.get_options(); var pytorch_version = options['pytorch']; - match_versions = pytorch_versions[pytorch_version]; + var match_versions = pytorch_versions[pytorch_version]; $("#pytorch_npu-version").text(match_versions['torch_npu']); $("#cann-version").text(match_versions['cann']); } @@ -44,27 +44,48 @@ $(document).ready(function () { $.gen_content = function () { var options = $.get_options(); - if (options['install_type'] == "pip") { + if (options['install_type'] == "docker") { + var pytorch_version = options['pytorch']; + var match_versions = pytorch_versions[pytorch_version]; + var dockerCommand = ` +docker run \\ + --name cann_container \\ + --device /dev/davinci1 \\ + --device /dev/davinci_manager \\ + --device /dev/devmm_svm \\ + --device /dev/hisi_hdc \\ + -v /usr/local/dcmi:/usr/local/dcmi \\ + -v /usr/local/bin/npu-smi:/usr/local/bin/npu-smi \\ + -v /usr/local/Ascend/driver/lib64/:/usr/local/Ascend/driver/lib64/ \\ + -v /etc/ascend_install.info:/etc/ascend_install.info \\ + -v /usr/local/Ascend/driver/version.info:/usr/local/Ascend/driver/version.info \\ + -it ${match_versions['docker']} bash + `; + + $('#codecell0').html(dockerCommand); + $('#install-pytorch-source-section').hide(); + $('#install-pytorch-pip-section').hide(); + $('#install-pytorch-docker-section').show(); + } else if (options['install_type'] == "pip") { + $('#codecell1').html("# install torch
"); if(options['arch'] == "aarch64") - $('#install-pytorch-pip').html("pip3 install torch==" + options['pytorch']); + $('#codecell1').append("pip3 install torch==" + options['pytorch']); else - $('#install-pytorch-pip').html("pip3 install torch=="+options['pytorch']+"+cpu --index-url https://download.pytorch.org/whl/cpu"); + $('#codecell1').append("pip3 install torch=="+options['pytorch']+"+cpu --index-url https://download.pytorch.org/whl/cpu"); - $("#install-pytorch_npu-pip").html("pip3 install torch-npu==" + options['pytorch_npu']); + $("#codecell1").append("

# install torch-npu
pip3 install torch-npu==" + options['pytorch_npu']); $('#install-pytorch-source-section').hide(); - $('#install-pytorch_npu-source-section').hide(); + $('#install-pytorch-docker-section').hide(); $('#install-pytorch-pip-section').show(); - $('#install-pytorch_npu-pip-section').show(); } else { - $("#install-pytorch-source-build").html("# install requirements
conda install cmake ninja

# get source
git clone -b "+options['pytorch']+" --recursive https://github.com/pytorch/pytorch
cd pytorch
git submodule update --init --recursive

# install PyTorch
pip install -r requirements.txt
export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-\"$(dirname $(which conda))/../\"}
python setup.py develop"); + $("#codecell2").html("# install requirements
conda install cmake ninja

# get torch source
git clone -b "+options['pytorch']+" --recursive https://github.com/pytorch/pytorch
cd pytorch
git submodule update --init --recursive

# install torch
pip install -r requirements.txt
export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-\"$(dirname $(which conda))/../\"}
python setup.py develop"); - $('#install-pytorch_npu-source-build').html("# get source
git clone https://github.com/ascend/pytorch.git -b "+options['pytorch_npu']+" --depth 1 pytorch_npu
cd pytorch_npu

#install pytorch_npu
bash ci/build.sh --python=$(python --version 2>&1 | awk '{print $2}' | cut -d '.' -f 1,2)"); + $('#codecell2').append("

# get torch-npu source
git clone https://github.com/ascend/pytorch.git -b "+options['pytorch_npu']+" --depth 1 pytorch_npu
cd pytorch_npu

#install torch-npu
bash ci/build.sh --python=$(python --version 2>&1 | awk '{print $2}' | cut -d '.' -f 1,2)"); $('#install-pytorch-pip-section').hide(); - $('#install-pytorch_npu-pip-section').hide(); + $('#install-pytorch-docker-section').hide(); $('#install-pytorch-source-section').show(); - $('#install-pytorch_npu-source-section').show(); } } diff --git a/conf.py b/conf.py index c96a9f4..07ec80f 100644 --- a/conf.py +++ b/conf.py @@ -33,7 +33,8 @@ extensions = [ 'sphinx.ext.autodoc', 'recommonmark', - 'sphinxext.remoteliteralinclude' + 'sphinxext.remoteliteralinclude', + 'sphinx_copybutton' ] # Add any paths that contain templates here, relative to this directory. diff --git a/requirements.txt b/requirements.txt index 79debd6..ce4a18e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ Sphinx sphinx-autobuild sphinx-rtd-theme recommonmark -sphinxext-remoteliteralinclude \ No newline at end of file +sphinxext-remoteliteralinclude +sphinx-copybutton \ No newline at end of file diff --git a/sources/ascend/quick_install.rst b/sources/ascend/quick_install.rst index b8d4160..4fdb1b7 100644 --- a/sources/ascend/quick_install.rst +++ b/sources/ascend/quick_install.rst @@ -3,17 +3,19 @@ 跟随指导,在您的机器上快速安装昇腾环境。 -1. 系统要求 +系统要求 ---------------- 1.1 前置检查 ^^^^^^^^^^^^^ 确认昇腾AI处理器已经安装妥当 -:: + +.. code-block:: bash lspci | grep 'Processing accelerators' 确认操作系统架构及版本 -:: + +.. code-block:: bash uname -m && cat /etc/*release @@ -28,7 +30,7 @@ Python 3.8, 3.9, 3.10 ======== ======================================== -2. 环境安装 +环境安装 ------------------ 根据您的需求,选择合适的软件包版本: @@ -102,14 +104,14 @@ Python 3.8, 3.9, 3.10

下载并安装

-

+                            

                         

2.2 安装固件

-

+                            

                         
@@ -124,14 +126,14 @@ Python 3.8, 3.9, 3.10

下载并安装

-

+                                

                             

安装算子包(可选)

-

+                                    

                                 
@@ -149,7 +151,7 @@ Python 3.8, 3.9, 3.10
-

+                                

                             
@@ -158,13 +160,14 @@ Python 3.8, 3.9, 3.10 -3. 验证安装(可选) +验证安装(可选) --------------------- **验证驱动** 确认您的驱动是否安装成功,可以通过以下命令验证:``npu-smi info`` ,若出现以下回显信息,说明驱动安装成功。 -:: + +.. code-block:: bash +-------------------------------------------------------------------------------------------+ | npu-smi 23.0.2 Version: 23.0.2 | @@ -200,31 +203,36 @@ Python 3.8, 3.9, 3.10 **验证固件** 安装固件后,若系统出现如下关键回显信息,表示固件安装成功。 -:: + +.. code-block:: bash Firmware package installed successfully! **验证CANN-toolkit** 安装CANN-toolkit后,若系统出现以下关键回显信息,表示CANN-toolkit安装成功。 -:: + +.. code-block:: bash [INFO] Ascend-cann-toolkit install success -4. 卸载 +卸载 ---------- **卸载驱动** -:: + +.. code-block:: bash sudo /usr/local/Ascend/firmware/script/uninstall.sh **卸载固件** -:: + +.. code-block:: bash sudo /usr/local/Ascend/driver/script/uninstall.sh **卸载CANN-toolkit** -:: + +.. code-block:: bash /ascend-toolkit//{arch}-linux/script/uninstall.sh \ No newline at end of file diff --git a/sources/pytorch/examples.rst b/sources/pytorch/examples.rst index d8df575..07456b1 100644 --- a/sources/pytorch/examples.rst +++ b/sources/pytorch/examples.rst @@ -7,12 +7,13 @@ 在运行下述示例之前,需要您已经安装了PyTorch-NPU环境,有关环境安装,请参考 :doc:`./install` -1. 数据并行 +数据并行 ----------------------- PyTorch的数据并行主要分为以下几种:DP、DDP以及FSDP(HSDP变种),接下来将简单描述在Ascend NPU场景下如何实现上述数据并行。 -DDP: +DDP +^^^^^^ .. code-block:: python :linenos: @@ -82,7 +83,8 @@ DDP: if __name__ == "__main__": main() -FSDP: +FSDP +^^^^^^ .. code-block:: python :linenos: diff --git a/sources/pytorch/install.rst b/sources/pytorch/install.rst index abeb581..b777ab1 100644 --- a/sources/pytorch/install.rst +++ b/sources/pytorch/install.rst @@ -4,9 +4,9 @@ 跟随指导,安装在NPU上运行的PyTorch版本。 -1. 选择需要安装的PyTorch版本 +选择需要安装的 PyTorch 版本 ------------------------------ -根据您的需求,选择合适的PyTorch和CANN版本: +准备安装 PyTorch: .. raw:: html @@ -42,68 +42,52 @@
安装方式
-
pip
-
源码构建
+
Docker
+
pip
+
源码构建
+.. warning:: -请先根据上述表格建议的CANN-toolkit版本 :doc:`安装昇腾环境<../ascend/quick_install>`。 + 非Docker的安装方式,需要根据上述表格的建议 :doc:`安装<../ascend/quick_install>` CANN-toolkit版本。 -2. 安装PyTorch +安装 PyTorch ---------------- .. raw:: html +
+
+

+        
+
-

使用pip安装

-
-

-                
+
+

+        
-

2.1 环境依赖

-

1. Python 3.8及以上
2. 支持C++17的编译器,例如clang 或者 gcc (9.4.0及以上)

-
-
-

2.2 构建

-
-

-                
-
-
- -3. 安装PyTorch-NPU --------------------- - -.. raw:: html - -
-

使用pip安装

-
-

-                
-
-
-
-

3.1 环境依赖

+

环境依赖

1. Python 3.8 ~ 3.10
2. 支持C++17的编译器,例如clang 或者 gcc (9.4.0及以上)

-

3.2 构建

+

构建

-

+                    

                 
-4. 验证安装结果 + +验证安装结果 ------------------ -:: +.. code-block:: python + :linenos: import torch import torch_npu diff --git a/sources/pytorch/quick_start.rst b/sources/pytorch/quick_start.rst index baa10b4..1fab091 100644 --- a/sources/pytorch/quick_start.rst +++ b/sources/pytorch/quick_start.rst @@ -1,14 +1,17 @@ 快速开始 =========================== -以下说明假设您已经安装了PyTorch-NPU环境,有关环境安装,请参考 :doc:`./install` +.. note:: + + 在运行下述示例之前,需要您已经安装了PyTorch-NPU环境,有关环境安装,请参考 :doc:`./install` 一般来说,要在代码中使用NPU进行训练推理,需要做以下更改: #. 导入torch_npu扩展包 ``import torch_npu`` #. 将模型,以及模型输入上传到NPU上 -:: +.. code-block:: python + :linenos: device= torch.device("npu") model = model.to(device) @@ -16,7 +19,7 @@ 下面的实例演示了如何使用NPU进行训练和推理任务: -1. 单卡训练 +单卡训练 ----------------------- 以下代码使用了cifar10数据集在NPU上训练模型(截取自 `PyTorch tutorials `_),请关注高亮的内容。 @@ -208,7 +211,7 @@ accuracy = 100 * float(correct_count) / total_pred[classname] print(f'Accuracy for class: {classname:5s} is {accuracy:.1f} %') -2. 使用DeepSpeed多卡并行训练 +使用DeepSpeed多卡并行训练 ------------------------------- 以下代码使用了cifar10数据集,使用DeepSpeed训练模型在多张NPU卡上进行模型训练(来自 `DeepSpeed Examples `_),自DeepSpeed v0.12.6之后,代码无需任何修改,即可自动检测NPU并进行训练。 @@ -217,7 +220,7 @@ :linenos: -3. 使用Transforms进行模型微调 +使用Transforms进行模型微调 --------------------------------- 以下代码使用了Transforms对LLM进行微调(来自 `transforms examples `_),自transforms xxx版本以及accelerator 0.21.0版本以后,代码无需任何修改,即可自动检测NPU并进行。 @@ -239,7 +242,7 @@ --do_eval \ --output_dir /tmp/test-clm -4. 使用Diffusers进行模型微调 +使用Diffusers进行模型微调 --------------------------------- 以下代码使用了Diffusers对文生图模型进行微调(来自 `diffusers examples `_),自diffusers v0.27.0版本以后,代码无需任何修改,即可自动检测NPU并进行。