PyTorch RISC-V support

username: AlexChiang
cooked: <p>Hi, it’s Alex from SiFive.</p>
<p>We’ve successfully built PyTorch v2.4.0 for RISC-V on Ubuntu QEMU and have run some AI models. We have some demo snapshots for Stable Diffusion.</p>
<p>Stable Diffusion on RISC-V QEMU:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/0/60b166f2f42f0a67a61141da9fd678fae9f58f6e.png" data-download-href="https://discuss.pytorch.org/uploads/default/60b166f2f42f0a67a61141da9fd678fae9f58f6e" title="output_image_cpu_15"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/6/0/60b166f2f42f0a67a61141da9fd678fae9f58f6e_2_500x500.png" alt="output_image_cpu_15" data-base62-sha1="dNnV0zPjHewMe3e2D0A3fJ6sT5Y" width="500" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/6/0/60b166f2f42f0a67a61141da9fd678fae9f58f6e_2_500x500.png, https://discuss.pytorch.org/uploads/default/original/3X/6/0/60b166f2f42f0a67a61141da9fd678fae9f58f6e.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/6/0/60b166f2f42f0a67a61141da9fd678fae9f58f6e.png 2x" data-dominant-color="7F7D74"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">output_image_cpu_15</span><span class="informations">512×512 406 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>We’re planning to contribute PyTorch support for RISC-V by submitting patches that include test scripts for CI, Docker images, build scripts, and documentation to guide users in building RISC-V PyTorch.</p>
<p>Any feedback or suggestions for PyTorch RISC-V support?</p>

username: SDK
cooked: <p>Hi Alex,</p>
<p>I am interesting in testing this out on keystone riscv. Can you share your build process?</p>

username: AlexChiang
cooked: <p>Hi SDK,</p>
<p>The related patches are ongoing. I will update this thread with any updates.</p>

username: AlexChiang
cooked: <p>Hi SDK,<br>
Unfortunately, the PR#140816 was closed, and we are looking for an alternative way.</p><aside class="onebox githubpullrequest" data-onebox-src="https://github.com/pytorch/pytorch/pull/140816">
  <header class="source">

      <a href="https://github.com/pytorch/pytorch/pull/140816" target="_blank" rel="noopener nofollow ugc">github.com/pytorch/pytorch</a>
  </header>

  <article class="onebox-body">
    <div class="github-row" data-github-private-repo="false">



    <div class="github-icon-container" title="Pull Request">
      <svg width="60" height="60" class="github-icon" viewBox="0 0 12 16" aria-hidden="true"><path fill-rule="evenodd" d="M11 11.28V5c-.03-.78-.34-1.47-.94-2.06C9.46 2.35 8.78 2.03 8 2H7V0L4 3l3 3V4h1c.27.02.48.11.69.31.21.2.3.42.31.69v6.28A1.993 1.993 0 0 0 10 15a1.993 1.993 0 0 0 1-3.72zm-1 2.92c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zM4 3c0-1.11-.89-2-2-2a1.993 1.993 0 0 0-1 3.72v6.56A1.993 1.993 0 0 0 2 15a1.993 1.993 0 0 0 1-3.72V4.72c.59-.34 1-.98 1-1.72zm-.8 10c0 .66-.55 1.2-1.2 1.2-.65 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>
    </div>

  <div class="github-info-container">



      <h4>
        <a href="https://github.com/pytorch/pytorch/pull/140816" target="_blank" rel="noopener nofollow ugc">Add RISC-V CI support</a>
      </h4>

    <div class="branches">
      <code>pytorch:main</code> ← <code>jysh1214:riscv_ci_support</code>
    </div>

      <div class="github-info">
        <div class="date">
          opened <span class="discourse-local-date" data-format="ll" data-date="2024-11-15" data-time="15:51:56" data-timezone="UTC">03:51PM - 15 Nov 24 UTC</span>
        </div>

        <div class="user">
          <a href="https://github.com/jysh1214" target="_blank" rel="noopener nofollow ugc">
            <img alt="jysh1214" src="https://avatars.githubusercontent.com/u/13050616?v=4" class="onebox-avatar-inline" width="20" height="20">
            jysh1214
          </a>
        </div>

        <div class="lines" title="1 commits changed 5 files with 149 additions and 0 deletions">
          <a href="https://github.com/pytorch/pytorch/pull/140816/files" target="_blank" rel="noopener nofollow ugc">
            <span class="added">+149</span>
            <span class="removed">-0</span>
          </a>
        </div>
      </div>
  </div>
</div>

  <div class="github-row">
    <p class="github-body-container">cc @seemethere @malfet @pytorch/pytorch-dev-infra</p>
  </div>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>


username: tuler
cooked: <p>hey <a class="mention" href="/u/alexchiang">@AlexChiang</a> I checked the PR and there are only additions to CI, no patch to source code itself. Does that mean that PyTorch can be built to riscv64 without any patches? Or do you have uncommitted patches?</p>
<p>Thanks</p>

username: fede2cr
cooked: <p>Hi <a class="mention" href="/u/tuler">@tuler</a>, you absolutely can build PyTorch without any patches, natively on riscv and even run the benchmark test. I follow steps 4 and 5 of this GitHub repo that also releases prebuilt whl packages (I build my own) <a href="https://github.com/KumaTea/pytorch-riscv64" class="inline-onebox" rel="noopener nofollow ugc">GitHub - KumaTea/pytorch-riscv64: PyTorch wheels for linux riscv64</a>. I have tested this on 2.5.1, the 2.6-rc series and on main as well.</p>
<p>Here you can see the output of the benchmark, having to modify the value of timeout in env.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/8/b/8b6894285f7bb4a64bafda9dcdb08926f2e8576d.png" data-download-href="https://discuss.pytorch.org/uploads/default/8b6894285f7bb4a64bafda9dcdb08926f2e8576d" title="Screenshot 2025-01-14 at 3.09.00 PM"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/8/b/8b6894285f7bb4a64bafda9dcdb08926f2e8576d_2_690x356.png" alt="Screenshot 2025-01-14 at 3.09.00 PM" data-base62-sha1="jTgquAm3g6ofOvHkGc483JAAn7v" width="690" height="356" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/8/b/8b6894285f7bb4a64bafda9dcdb08926f2e8576d_2_690x356.png, https://discuss.pytorch.org/uploads/default/original/3X/8/b/8b6894285f7bb4a64bafda9dcdb08926f2e8576d.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/8/b/8b6894285f7bb4a64bafda9dcdb08926f2e8576d.png 2x" data-dominant-color="272727"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">Screenshot 2025-01-14 at 3.09.00 PM</span><span class="informations">1010×522 81.4 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>(I tried to add another screenshot of how btop looks on my milkv pioneer with 64 cores, but I can only do one image per post. Anyway, it was only eye candy.)</p>
<p>Any other tests that I can run agains PyTorch on riscv that could help out?</p>

username: AlexChiang
cooked: <p>Hi <a class="mention" href="/u/tuler">@tuler</a>,<br>
Sorry for the late reply.</p>
<p>As <a class="mention" href="/u/fede2cr">@fede2cr</a> mentioned, we can build PyTorch without any patches on RISC-V.</p>
<p>You can report the issue, if you encounter any problem when building it.</p>

username: vyrsh1
cooked: <p>will PyTorch use the Vector extension when we build it ourselves?<br>
isnt there in line assembly in a lot of places?<br>
out of topic question, does the same work for numpy?</p>