Building torch from source is failing

venkataramesh: <p>Hi,</p>
<p>I’m looking to pursue contributing to PyTorch and as part of this i’m looking to set up the environment.</p>
<p>As a first step, i’m looking to build from source locally.</p>
<p>I have tried multiple ways of doing this job.</p>
<ol>
<li>On a fresh ec2 instance with ubuntu 22.04 image</li>
<li>On my personal work station with rtx 4090</li>
<li>On my personal laptop with RTX 5000 using wsl and docker.<br>
Each time im seeing some issues.</li>
</ol>
<p>One standard issue i’m seeing is that the build is failing with this error</p>
<p>[2309/2331] Linking CXX executable bin/torch_shm_manager<br>
FAILED: bin/torch_shm_manager<br>
: &amp;&amp; /usr/bin/g++ -D_GLIBCXX_USE_CXX11_ABI=1 -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DUSE_KINETO -DLIBKINETO_NOROCTRACER -DLIBKINETO_NOXPUPTI=ON -DUSE_X86_SIMD_SORT -DXSS_USE_OPENMP -DUSE_PYTORCH_QNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-strict-overflow -Wno-strict-aliasing -Wno-stringop-overflow -Wsuggest-override -Wno-psabi -Wno-error=old-style-cast -Wno-missing-braces -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow -DHAVE_AVX512_CPU_DEFINITION -DHAVE_AVX2_CPU_DEFINITION -g -fno-omit-frame-pointer -O0 -L/opt/conda/lib/ -rdynamic     -Wl,–no-as-needed caffe2/torch/lib/libshm/CMakeFiles/torch_shm_manager.dir/manager.cpp.o -o bin/torch_shm_manager  -Wl,-rpath,/workspaces/pytorch/build/lib:  lib/libshm.so  -lrt  lib/libc10.so  -Wl,-rpath-link,/workspaces/pytorch/build/lib &amp;&amp; /opt/conda/bin/cmake -E __run_co_compile --lwyu=“ldd;-u;-r” --source=bin/torch_shm_manager &amp;&amp; :<br>
/usr/bin/ld: warning: libopenblas.so.0, needed by /workspaces/pytorch/build/lib/libtorch_cpu.so, not found (try using -rpath or -rpath-link)</p>
<p>I tried following the dev container way as well as the local conda environment.</p>
<p>I also matched the CUDA version inside the dev container to the driver i had.</p>
<p>Any help is appreciated.</p>
<p>Here is the google drive link for the full log</p>
<aside class="onebox googledrive" data-onebox-src="https://drive.google.com/file/d/1-mwpFjrcub8xx8UIC3u5RFJblZeAN_qK/view?usp=drive_link">
  <header class="source">

      <a href="https://drive.google.com/file/d/1-mwpFjrcub8xx8UIC3u5RFJblZeAN_qK/view?usp=drive_link" target="_blank" rel="noopener nofollow ugc">drive.google.com</a>
  </header>

  <article class="onebox-body">
      <a href="https://drive.google.com/file/d/1-mwpFjrcub8xx8UIC3u5RFJblZeAN_qK/view?usp=drive_link" target="_blank" rel="noopener nofollow ugc"><span class="googledocs-onebox-logo g-drive-logo"></span></a>



<h3><a href="https://drive.google.com/file/d/1-mwpFjrcub8xx8UIC3u5RFJblZeAN_qK/view?usp=drive_link" target="_blank" rel="noopener nofollow ugc">pytorch_setup_develop_log.txt</a></h3>

<p>Google Drive file.</p>

  </article>

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

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

<p>Thanks in Advance,<br>
Venkat</p>

ptrblck: <aside class="quote no-group" data-username="venkataramesh" data-post="1" data-topic="212524">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/v/a3d4f5/48.png" class="avatar"> venkataramesh:</div>
<blockquote>
<p>I also matched the CUDA version inside the dev container to the driver i had.</p>
</blockquote>
</aside>
<p>CUDA is unrelated to your error which points to a missing <code>OpenBLAS</code> library:</p>
<aside class="quote no-group" data-username="venkataramesh" data-post="1" data-topic="212524">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/v/a3d4f5/48.png" class="avatar"> venkataramesh:</div>
<blockquote>
<p>/usr/bin/ld: warning: libopenblas.so.0, needed by /workspaces/pytorch/build/lib/libtorch_cpu.so, not found (try using -rpath or -rpath-link)</p>
</blockquote>
</aside>
<p>Did you try installing any BLAS library, e.g. <code>OpenBLAS</code>, <code>MKL</code> etc.?</p>

venkataramesh: <p>Couple of things i checked.</p>
<ol>
<li>From this blog <a href="https://leimao.github.io/blog/PyTorch-Official-VSCode-DevContainer/" rel="noopener nofollow ugc">post</a>, it should run out of the box and the only thing i needed to do is to match the CUDA version.</li>
<li>From .devcontainer/cuda/environment.yml, i see that it has the libopenblas as dependency. So i assumed it should be have been installed.</li>
</ol>
<p>From the main README.md, there is a section called Install dependencies. When i was trying the conda environment, i tried them. But right now i’m giving a try to install all those dependencies inside the dev container.</p>
<p>Only thing missing is the mkl part from the log. I will keep you posted.</p>
<p>Thanks for your reply and time.</p>

venkataramesh: <p>Even after the dependency installation, it is still failing. Must be something other than blas, mkl libraries.</p>
<p>I also read somewhere that these kind of errors could be caused by large parallelism. So i tried chaning the MAX_JOBS anywhere from 2-16 and still see these errors.</p>
<p>Thanks<br>
Venkat</p>

venkataramesh: <p>Also, it is not specific to CUDA container, it also failed the same way for cpu container as well.</p>
<p>Since the failure is pointing to torch_shm_manager, i also tried increasing the shared mem for the container but to no avail!</p>

venkataramesh: <p><a class="mention" href="/u/leimao">@leimao</a> do you have any thoughts on this?</p>

leimao: <ol>
<li>I have not been using PyTorch recently, so I don’t know whether the latest PyTorch can be installed successfully on my machine. (But it definitely can be built at least for some configurations. Otherwise the PyTorch team would not be able to release the build.)</li>
<li>Your problem does not seem to be a parallelized building problem to me, because, as indicated clearly, it’s missing some dependencies.</li>
<li>If the problem is originated from the PyTorch official DevContainer, you should file a bug on PyTorch GitHub.</li>
<li>You might also want to try building my <a href="https://github.com/leimao/pytorch" rel="noopener nofollow ugc">PyTorch clone</a> 9 months ago. You can either use the DevContainer or my <a href="https://leimao.github.io/blog/Build-Develop-PyTorch/" rel="noopener nofollow ugc">custom container</a>. I remember I used that clone for building PyTorch from scratch for my two blog posts. If you could build that clone but could not build the latest PyTorch from the official main, definitely there is something wrong in their building config and it was not captured by the build test.</li>
</ol>

venkataramesh: <p>Hello Lei,</p>
<p>I tried your custom container and it builds fine there.</p>
<p>I can go two routes.</p>
<ol>
<li>Get started with your container to play around.</li>
<li>file a bug in pytorch and simultaneously figure out whats wrong with the devcontainer in the master repo.</li>
</ol>
<p>Thanks for pitching in.</p>