"ascend_npu": "<h1 id=\"installing-on-ascend-npu\">Installing on Ascend NPU</h1>\n<p><strong>Ascend for PyTorch (TorchNPU)</strong> is a deep learning adaptation framework built on Ascend. It enables Ascend NPUs to support the PyTorch framework, delivering the powerful computing capabilities of Ascend AI processors to PyTorch developers and users.</p>\n<h2 id=\"prerequisites\">Prerequisites</h2>\n<h3 id=\"hardware-requirements\">Hardware Requirements</h3>\n<ul>\n<li>Ascend for PyTorch supports most Ascend platforms. Please check the hardware compatibility before installing.</li>\n</ul>\n<h3 id=\"software-requirements\">Software Requirements</h3>\n<ul>\n<li>Python >= 3.10</li>\n<li>CANN (Compute Architecture for Neural Networks) toolkit installed >= 8.0</li>\n<li>Ascend driver and firmware installed</li>\n</ul>\n<p>Before installing PyTorch with Ascend NPU support, you must install the CANN toolkit. Download it from the <a href=\"https://www.hiascend.com/en\">Ascend Community</a> and follow the <a href=\"https://www.hiascend.com/en/cann/download\">CANN Installation Guide</a>.</p>\n<h2 id=\"installation\">Installation</h2>\n<h3 id=\"pip\">pip</h3>\n<div class=\"highlight\"><pre><span></span><code>pip3<span class=\"w\"> </span>install<span class=\"w\"> </span><span class=\"nv\">torch</span><span class=\"o\">==</span><span class=\"m\">2</span>.10.0<span class=\"w\"> </span>--index-url<span class=\"w\"> </span>https://download.pytorch.org/whl/cpu<span class=\"w\"> </span><span class=\"o\">&&</span><span class=\"w\"> </span>pip3<span class=\"w\"> </span>install<span class=\"w\"> </span>torch-npu<span class=\"o\">==</span><span class=\"m\">2</span>.10.0\n</code></pre></div>\n\n<p>Use the pip package manager to install PyTorch with Ascend NPU support. Please refer to the <a href=\"https://www.hiascend.com/en/developer/software/ai-frameworks/pytorch/download\">installation page</a> and select your preferred options in the selector above to get the installation command.</p>\n<h2 id=\"verification\">Verification</h2>\n<p>To ensure that PyTorch was installed correctly with Ascend NPU support, run the following code:</p>\n<div class=\"highlight\"><pre><span></span><code><span class=\"kn\">import</span><span class=\"w\"> </span><span class=\"nn\">torch</span>\n<span class=\"kn\">import</span><span class=\"w\"> </span><span class=\"nn\">torch_npu</span>\n\n<span class=\"n\">x</span> <span class=\"o\">=</span> <span class=\"n\">torch</span><span class=\"o\">.</span><span class=\"n\">randn</span><span class=\"p\">(</span><span class=\"mi\">2</span><span class=\"p\">,</span> <span class=\"mi\">2</span><span class=\"p\">,</span> <span class=\"n\">device</span><span class=\"o\">=</span><span class=\"s2\">"npu"</span><span class=\"p\">)</span>\n<span class=\"n\">y</span> <span class=\"o\">=</span> <span class=\"n\">torch</span><span class=\"o\">.</span><span class=\"n\">randn</span><span class=\"p\">(</span><span class=\"mi\">2</span><span class=\"p\">,</span> <span class=\"mi\">2</span><span class=\"p\">,</span> <span class=\"n\">device</span><span class=\"o\">=</span><span class=\"s2\">"npu"</span><span class=\"p\">)</span>\n<span class=\"n\">z</span> <span class=\"o\">=</span> <span class=\"n\">x</span><span class=\"o\">.</span><span class=\"n\">mm</span><span class=\"p\">(</span><span class=\"n\">y</span><span class=\"p\">)</span>\n\n<span class=\"nb\">print</span><span class=\"p\">(</span><span class=\"n\">z</span><span class=\"p\">)</span>\n</code></pre></div>\n\n<p>The following, or a similar output, indicates successful installation:</p>\n<div class=\"highlight\"><pre><span></span><code>tensor<span class=\"o\">([[</span>-0.0515,<span class=\"w\"> </span><span class=\"m\">0</span>.3664<span class=\"o\">]</span>,\n<span class=\"w\"> </span><span class=\"o\">[</span>-0.1258,<span class=\"w\"> </span>-0.5425<span class=\"o\">]]</span>,<span class=\"w\"> </span><span class=\"nv\">device</span><span class=\"o\">=</span><span class=\"s1\">'npu:0'</span><span class=\"o\">)</span>\n</code></pre></div>\n\n<h2 id=\"documentation\">Documentation</h2>\n<p>For more information, please visit:</p>\n<ul>\n<li>Ascend for PyTorch Official Documentation (<a href=\"https://www.hiascend.com/document/detail/en/Pytorch/latest/index/index.html\">English</a>, <a href=\"https://www.hiascend.com/document/detail/zh/Pytorch/2600/index/index.html\">Chinese</a>)</li>\n<li>Ascend Community Portal (<a href=\"https://www.hiascend.com/en\">English</a>, <a href=\"https://www.hiascend.com/\">Chinese</a>)</li>\n<li>CANN Main Page (<a href=\"https://www.hiascend.com/eng/cann\">English</a>, <a href=\"https://www.hiascend.com/cann\">Chinese</a>)</li>\n<li>PyTorch Adaptation for Ascend Portal (<a href=\"https://www.hiascend.com/en/developer/software/ai-frameworks/pytorch\">English</a>, <a href=\"https://www.hiascend.com/cn/developer/software/ai-frameworks/pytorch\">Chinese</a>)</li>\n<li>Ascend Hardware Compatibility (English <em>coming soon</em>, <a href=\"https://www.hiascend.com/hardware/compatibility\">Chinese</a>)</li>\n<li><a href=\"https://github.com/Ascend/pytorch\">GitHub Repository</a></li>\n<li><a href=\"https://pypi.org/project/torch-npu/\">PyPI</a></li>\n</ul>"
0 commit comments