Broken torchtext conda package?

username: ra_schoonhoven
cooked: <p>I need to use the torchtext package to run a certain model, and I have been having a strange bug that trying to run ‘import torch’ at any point causes the process to hang indefintely. I pinned pytorch to 1.X because otherwise it can only choose torchtext=0.6.0 for pytorch=2.X, and I need a newer version. I also posted a workaround at the bottom of the post for those who need it.</p>
<p>I stripped it down to the following conda environment and if I execute this:</p>
<pre><code class="lang-auto">conda create -n test pytorch=1 python=3.11 torchtext=0.14 -c nvidia -c pytorch -c defaults -c conda-forge
conda activate test
python -c "import torch"
</code></pre>
<p>it hangs indefinitely. If I run<br>
<code>python -v -c "import torch"</code></p>
<p>to see what is going on, I see that the final lines where it hangs are the following import:</p>
<pre><code class="lang-auto">import 'torch._utils_internal' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x7c0442d3a050&gt;
# /home/schoonho/anaconda3/envs/test/lib/python3.11/site-packages/torch/__pycache__/torch_version.cpython-311.pyc matches /home/schoonho/anaconda3/envs/test/lib/python3.11/site-packages/torch/torch_version.py
# code object from '/home/schoonho/anaconda3/envs/test/lib/python3.11/site-packages/torch/__pycache__/torch_version.cpython-311.pyc'
# /home/schoonho/anaconda3/envs/test/lib/python3.11/site-packages/torch/__pycache__/version.cpython-311.pyc matches /home/schoonho/anaconda3/envs/test/lib/python3.11/site-packages/torch/version.py
# code object from '/home/schoonho/anaconda3/envs/test/lib/python3.11/site-packages/torch/__pycache__/version.cpython-311.pyc'
import 'torch.version' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x7c0442dab250&gt;
import 'torch.torch_version' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x7c0442d3a390&gt;
# /home/schoonho/anaconda3/envs/test/lib/python3.11/site-packages/torch/__pycache__/_six.cpython-311.pyc matches /home/schoonho/anaconda3/envs/test/lib/python3.11/site-packages/torch/_six.py
# code object from '/home/schoonho/anaconda3/envs/test/lib/python3.11/site-packages/torch/__pycache__/_six.cpython-311.pyc'
import 'torch._six' # &lt;_frozen_importlib_external.SourceFileLoader object at 0x7c0442dab590&gt;
</code></pre>
<p><strong>Fix:</strong><br>
Weirdly, if I change the Python version to 3.10 in the conda environment it does work:</p>
<pre><code class="lang-auto">conda create -n test pytorch=1 python=3.10 torchtext=0.14 -c nvidia -c pytorch -c defaults -c conda-forge
</code></pre>
<p>To conclude, I can just continue using python 3.10 and all will be fine, but it is strange that this happens I think.</p>
<p>Not sure if I am doing something wrong but it seems that if conda finds this a valid environment then maybe something is wrong in the conda packaging.</p>
<p><strong>Information on broken environment</strong><br>
Ubuntu 22.04.4 LTS<br>
Nvidia driver 555.42.06<br>
pytorch 1.13.1   (cuda112py311)<br>
torchtext 0.14.1<br>
cudatoolkit 11.7.0</p>
<p>I can post the full environment if desirable.</p>

username: ra_schoonhoven
cooked: <p>So I have a suspicion of what is going on. For the python 3.10 env it installs:</p>
<pre><code class="lang-auto">pytorch      1.13.1      py3.10_cuda11.7_cudnn8.5.0_0    pytorch
</code></pre>
<p>and for the python 3.11 env it installs:</p>
<pre><code class="lang-auto">pytorch      1.13.1      cuda112py311h13fee9e_200    conda-forge
</code></pre>
<p>So probably its a broken conda-forge pytorch package that is not playing nicely with torchtext.</p>

username: ptrblck
cooked: <p>Yes, this could be the reason as we do not maintain or build the <code>conda-forge</code> PyTorch binaries. The “hang” sounds a bit as if PyTorch wasn’t compiled for your GPU architecture and CUDA JIT might try to compile it live.</p>

username: ra_schoonhoven
cooked: <p>I did not understand what could be causing the hang but this seems like a good candidate. Thanks for the response!</p>