diff --git a/_static/images/pytorch_wechat.jpg b/_static/images/pytorch_wechat.jpg index 1e7bc34..55f1e9c 100644 Binary files a/_static/images/pytorch_wechat.jpg and b/_static/images/pytorch_wechat.jpg differ diff --git a/_static/pytorch_actions.js b/_static/pytorch_actions.js index 1bab89c..0f2167c 100644 --- a/_static/pytorch_actions.js +++ b/_static/pytorch_actions.js @@ -80,9 +80,9 @@ docker run \\ $('#install-pytorch-docker-section').hide(); $('#install-pytorch-pip-section').show(); } else { - $("#codecell4").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"); + $("#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("\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"); + $('#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(); diff --git a/sources/pytorch/examples.rst b/sources/pytorch/examples.rst index 07456b1..8a09e47 100644 --- a/sources/pytorch/examples.rst +++ b/sources/pytorch/examples.rst @@ -7,13 +7,13 @@ 在运行下述示例之前,需要您已经安装了PyTorch-NPU环境,有关环境安装,请参考 :doc:`./install` -数据并行 +1. 数据并行 ----------------------- PyTorch的数据并行主要分为以下几种:DP、DDP以及FSDP(HSDP变种),接下来将简单描述在Ascend NPU场景下如何实现上述数据并行。 -DDP -^^^^^^ +1.1 DDP +^^^^^^^^^^ .. code-block:: python :linenos: @@ -83,8 +83,8 @@ DDP if __name__ == "__main__": main() -FSDP -^^^^^^ +1.2 FSDP +^^^^^^^^^^ .. code-block:: python :linenos: diff --git a/sources/pytorch/install.rst b/sources/pytorch/install.rst index 9965fbb..cbb8211 100644 --- a/sources/pytorch/install.rst +++ b/sources/pytorch/install.rst @@ -4,7 +4,7 @@ 跟随指导,安装在NPU上运行的PyTorch版本。 -选择需要安装的 PyTorch 版本 +1. 选择需要安装的 PyTorch 版本 ------------------------------ 准备安装 PyTorch: @@ -50,8 +50,12 @@ -安装 PyTorch +2. 安装 PyTorch ---------------- + +.. warning:: + + 如果使用了非CANN安装时的Python环境(如Conda),请确保CANN-toolkit依赖的Python包在该环境中已经 `安装 <../ascend/quick_install.html>`_ 。 .. raw:: html
@@ -78,21 +82,12 @@

备注

请确保已经根据上述表格建议安装了对应的CANN-toolkit版本以及相应的固件和驱动,并应用了CANN-toolkit环境变量。

-

环境依赖

-
    +

    2.1 环境依赖

    +
-
-

备注

-

如果使用Conda,请确保CANN-toolkit依赖的Python包在Conda环境中已经安装

-
-
-

警告

-

不建议您使用Conda提供的gcc,可能需要解决一些编译依赖问题,如果一定要使用,可参考以下命令:

-
-
conda install -c conda-forge libstdcxx-ng libgcc-ng gcc=9.4 gxx=9.4
+
  • Conda
  • +
    @@ -100,7 +95,7 @@

    请确认CXX11_ABI是关闭的,如果无法确定,建议显式关闭:

    export _GLIBCXX_USE_CXX11_ABI=0
    -

    构建

    +

    2.2 构建

    
                     
    @@ -108,7 +103,7 @@ -验证安装结果 +3. 验证安装结果 ------------------ .. code-block:: python diff --git a/sources/pytorch/quick_start.rst b/sources/pytorch/quick_start.rst index 1fab091..136bd2c 100644 --- a/sources/pytorch/quick_start.rst +++ b/sources/pytorch/quick_start.rst @@ -19,7 +19,7 @@ 下面的实例演示了如何使用NPU进行训练和推理任务: -单卡训练 +1. 单卡训练 ----------------------- 以下代码使用了cifar10数据集在NPU上训练模型(截取自 `PyTorch tutorials `_),请关注高亮的内容。 @@ -211,7 +211,7 @@ accuracy = 100 * float(correct_count) / total_pred[classname] print(f'Accuracy for class: {classname:5s} is {accuracy:.1f} %') -使用DeepSpeed多卡并行训练 +2. 使用DeepSpeed多卡并行训练 ------------------------------- 以下代码使用了cifar10数据集,使用DeepSpeed训练模型在多张NPU卡上进行模型训练(来自 `DeepSpeed Examples `_),自DeepSpeed v0.12.6之后,代码无需任何修改,即可自动检测NPU并进行训练。 @@ -220,7 +220,7 @@ :linenos: -使用Transforms进行模型微调 +3. 使用Transforms进行模型微调 --------------------------------- 以下代码使用了Transforms对LLM进行微调(来自 `transforms examples `_),自transforms xxx版本以及accelerator 0.21.0版本以后,代码无需任何修改,即可自动检测NPU并进行。 @@ -242,7 +242,7 @@ --do_eval \ --output_dir /tmp/test-clm -使用Diffusers进行模型微调 +4. 使用Diffusers进行模型微调 --------------------------------- 以下代码使用了Diffusers对文生图模型进行微调(来自 `diffusers examples `_),自diffusers v0.27.0版本以后,代码无需任何修改,即可自动检测NPU并进行。