Cannot import name 'random_split'

Xiaoyu_Song: <p>I got this</p>
<pre><code class="lang-auto">&gt;&gt;&gt; from torch.utils.data import Dataset, DataLoader, random_split
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
ImportError: cannot import name 'random_split'
</code></pre>
<p>error<br>
It means my installation of torch exists some issue?</p>
<pre><code class="lang-auto">torchvision               0.2.1                    py35_0
python                    3.5.6                hc3d631a_0
cudatoolkit               9.0                  h13b8566_0
pytorch                   0.4.0
</code></pre>

Xiaoyu_Song: <p>I used conda and tried to install the updated version:</p>
<pre><code class="lang-auto">conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=9.0 -c pytorch
</code></pre>
<p>The problem solved.</p>

ptrblck: <p>Good to hear a newer version solved this import error.<br>
However, PyTorch <code>1.1.0</code> is also quite old by now so I would recommend to install the latest stable version including the latest <code>torchvision</code>. Is there a reason you are installing this old lib stack?</p>

Xiaoyu_Song: <p>Thank you <a class="mention" href="/u/ptrblck">@ptrblck</a>. Sometimes I recieve an error indicating the cuda version is incompetitive with torchvision. So what do you suggest the installation versions? I encountered the “version” issues many times.</p>

ptrblck: <p>What does “sometimes” mean in this context? Is <code>torchvision</code> working in some scripts and raises an error regarding the CUDA version in other scripts?</p>
<p>You should be able to install PyTorch and torchvision using the binary install instructions from <a href="https://pytorch.org/get-started/locally/">here</a> and specifying one CUDA version, which would be compatible with your NVIDIA drivers.</p>

Xiaoyu_Song: <pre><code class="lang-auto"> Is torchvision working in some scripts and raises an error regarding the CUDA version in other scripts?
</code></pre>
<p>Yes, I encountered this kind of compatibility issue and</p>
<pre><code class="lang-auto">nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Sep__1_21:08:03_CDT_2017
Cuda compilation tools, release 9.0, V9.0.176

</code></pre>
<p>This means I should install cudatoolkit == 9.0 right?</p>
<p>And in order to use other updated version of cudatoolkit. I need to upgrade my Driver, right?</p>
<p>Thank you again <a class="mention" href="/u/ptrblck">@ptrblck</a></p>

ptrblck: <p>If you install the binaries, your local CUDA installation won’t be used and the shipped <code>cudatoolkit</code> will be used instead.<br>
You would only have to make sure your driver is up to date or has at least the minimal version as seen in <a href="https://docs.nvidia.com/deploy/cuda-compatibility/index.html#binary-compatibility__table-toolkit-driver">this table</a>.</p>
<p>You can check the driver version via <code>nvidia-smi</code>.</p>
<p>Your local CUDA 9.0 version (or rather the <code>nvcc</code> compiler) would be used, if you are building PyTorch from source or a custom extension.</p>

Xiaoyu_Song: <pre><code class="lang-auto">nvidia-smi
Mon Jul 27 12:49:25 2020
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 418.67       Driver Version: 418.67       CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla V100-DGXS...  On   | 00000000:07:00.0  On |                    0 |
| N/A   32C    P0    38W / 300W |    351MiB / 32478MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  Tesla V100-DGXS...  On   | 00000000:08:00.0 Off |                    0 |
| N/A   32C    P0    37W / 300W |      1MiB / 32478MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   2  Tesla V100-DGXS...  On   | 00000000:0E:00.0 Off |                    0 |
| N/A   33C    P0    38W / 300W |      1MiB / 32478MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   3  Tesla V100-DGXS...  On   | 00000000:0F:00.0 Off |                    0 |
| N/A   32C    P0    39W / 300W |      1MiB / 32478MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0       382      G   /usr/bin/gnome-shell                         107MiB |
|    0      1830      G   /usr/lib/xorg/Xorg                            18MiB |
|    0      1857      G   /usr/bin/gnome-shell                          86MiB |
|    0     40890      G   /usr/lib/xorg/Xorg                           136MiB |
+-----------------------------------------------------------------------------+

</code></pre>
<p>The CUDA version showed here is 10.1</p>
<p>And I encontered this error:</p>
<pre><code class="lang-auto">The NVIDIA driver on your system is too old (found version 10010).
Please update your GPU driver by downloading and installing a new
version from the URL: http://www.nvidia.com/Download/index.aspx
Alternatively, go to: https://pytorch.org to install
a PyTorch version that has been compiled with your version
of the CUDA driver.
</code></pre>
<p>what should i do?</p>

ptrblck: <p>If you are trying to install the CUDA10.2 binaries, your would have to update your NVIDIA driver to <code>&gt;=440.33</code> as given in the table.<br>
Your current driver would support CUDA10.1 and older.</p>

Xiaoyu_Song: <p>I created 2 conda env</p>
<pre><code class="lang-auto">cudatoolkit               10.0.130 
pytorch                      1.2.0
torchvision                 0.5.0
</code></pre>
<p>will give me the</p>
<pre><code class="lang-auto">The NVIDIA driver on your system is too old (found version 10010).
Please update your GPU driver by downloading and installing a new
version from the URL: http://www.nvidia.com/Download/index.aspx
Alternatively, go to: https://pytorch.org to install
a PyTorch version that has been compiled with your version
of the CUDA driver.
</code></pre>
<p>error.</p>
<p>While</p>
<pre><code class="lang-auto">torchvision               0.2.1                    py35_0
python                    3.5.6                hc3d631a_0
cudatoolkit               9.0                  h13b8566_0
pytorch                   0.4.0
</code></pre>
<p>has no error.</p>
<p>So this means the cudatoolkit 9.0 works fine on my driver? which config causes the compile error?</p>

ptrblck: <p>Unsure, where this error is coming from.<br>
Could you update the driver to <code>440.33</code> or newer, create a new conda env, and install the latest PyTorch version?</p>

Xiaoyu_Song: <pre><code class="lang-auto">File "finetune_xy.py", line 166, in &lt;module&gt;
    torch.cuda.set_device(gpu_ids[0])
  File "/home/song/.local/lib/python3.7/site-packages/torch/cuda/__init__.py", line 245, in set_device
    torch._C._cuda_setDevice(device)
  File "/home/song/.local/lib/python3.7/site-packages/torch/cuda/__init__.py", line 149, in _lazy_init
    _check_driver()
  File "/home/song/.local/lib/python3.7/site-packages/torch/cuda/__init__.py", line 63, in _check_driver
    of the CUDA driver.""".format(str(torch._C._cuda_getDriverVersion())))

</code></pre>
<p>Currently the 9.0 cuda toolkit works fine. I will update the driver when I have time <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>