How do I install Pytorch 1.3.1 with CUDA enabled - python

I have a conda environment on my Ubuntu 16.04 system.
When I install Pytorch using:
conda install pytorch
and I try and run the script I need, I get the error message:
raise AssertionError("Torch not compiled with CUDA enabled")
From looking at forums, I see that this is because I have installed Pytorch without CUDA support.
I then tried:
conda install -c pytorch torchvision cudatoolkit=10.1 pytorch
but now I get the error:
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
File "/home/username/miniconda3/envs/super_resolution/lib/python3.6/site-packages/torch/__init__.py", line 81, in <module>
from torch._C import *
ImportError: /lib64/libc.so.6: version `GLIBC_2.14' not found
So it seems that these two installs are installing different versions of Pytorch(?). The first one that seemed to work was Pytorch 1.3.1.
My question: How do I install Pytorch with CUDA enabled, but ensure it is version 1.3.1 so that it works with my system?

Given that your system is running Ubuntu 16.04, it comes with glibc installed. You can check your version by typing ldd --version.
Keep in mind that PyTorch is compiled on CentOS which runs glibc version 2.17.
Then check the CUDA version installed on your system nvcc --version
Then install PyTorch as follows e.g. if your cuda version is 9.2:
conda install pytorch torchvision cudatoolkit=9.2 -c pytorch
If you get the glibc version error, try installing an earlier version of PyTorch.
If neither of the above options work, then try installing PyTorch from sources.
If you would like to set a specific PyTorch version to install, please set it as <version_nr> in the below command:
conda install pytorch=<version_nr> torchvision cudatoolkit=9.2 -c pytorch

For CUDA 10.1:
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
For CUDA 9.2:
conda install pytorch torchvision cudatoolkit=9.2 -c pytorch
For no CUDA:
conda install pytorch torchvision cpuonly -c pytorch

Not sure whether you have solved your problem or not, but I have this exact same problem before because I was trying to install pytorch on a cluster and I don't have root access. You need to download glibc into your directoryand set the environmental variable LD_LIBRARY_PATH to your local glibc https://stackoverflow.com/a/48650638/5662642.
To install glibc locally, I will point you to this thread that I read to solve my problem
https://stackoverflow.com/a/38317265/5662642 (instead of setting --prefix=/opt/glibc-2.14 when installing, you might want to set it to other directory that you have access to). Hope it works for you

Related

pytorch CUDA version vs. Nvidia CUDA version

Till Apr26th, 2022, CUDA has updated to version 11.6, which can be installed by Nvidia Instruction:
wget https://developer.download.nvidia.com/compute/cuda/11.6.2/local_installers/cuda_11.6.2_510.47.03_linux.run
sudo sh cuda_11.6.2_510.47.03_linux.run
I guess the version of cudatoolkit will also be 11.6
However, there is no version of pytorch that matches CUDA11.6.
On the website of pytorch, the newest CUDA version is 11.3, pytorch version will be 1.11.0(stable)
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
So if I used CUDA11.6 and pytorch1.11.0 with cudatoolkit=11.3, will it perform normally?
and if there is any difference between Nvidia Instruction and conda method below?
conda install cuda -c nvidia
Best regards!
It should be fine. Otherwise, I saw here that you can build it from the source (I have python=3.8.13) build instructions
pip install torch --pre --extra-index-url https://download.pytorch.org/whl/nightly/cu116

Install PyTorch without installing Python 3.9 on Win7

Got clean installation of Anaconda (Python 3.8.8), tried to install PyTorch by running conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch as suggested by the docs. The thing is, conda tries to install Python 3.9.7 in the process, which does not support Windows 7 (the famous "api-ms-win-core-path-l1-1-0.dll missing error"). Is there a way to make the installation of PyTorch without switching to the latest Python?
If you start with a clean package with a specific python version you could use the --freeze-installed flag to prevent the installer from making any changes to the installed packages, see documentation.

tensorflow-gpu installation problem on system with multiple cuda versions

I installed tensorflow-gpu using
sudo pip3 install tensorflow-gpu on python3.6
The system I am using has both cuda 10 and cuda 9.0 installed on it.
I have exported the cuda 9.0 paths, but import tensorflow still gives me
ImportError: libcublas.so.10.0: cannot open shared object file: No such file or directory
Is there any way I can force tensorflow to use cuda 9.0 because the default pre-compiled tensorflow using pip only works with cuda 9.0 according to the official documentation.
Additional info:
I do not want to use a virtualenv because I am installing tensorflow for the entire system so that all users can use it.
I have in the past installed tensorflow after compiling with bazel, but only I was able to use it. Other users could not, even after exporting the cuda paths to their profiles. So, I am trying to make the default pip installation work this time. I have uninstalled the previous tensorflow installation successfully.
try installing a different version of tensorflow like 1.11.0 i.e a version that supports cuda 9
To import tensorflow your environment should have numpy.So check numpy is installed or not using import numpy? If it is intalled then install tensorflow and tensorflow-gpu using following commands.
activate yourEnvName
conda install tensorflow
conda install tensorflow-gpu

Issues installing pytorch for OS X with conda

I used to have pytorch working for python 3 on OS X but now I can't get it to install automatically for some reason (I don't want to do from source).
I did:
conda install pytorch torchvision -c pytorch
as the website suggested... then I got a mkl error so I installed it but it still complains about it:
(FTIR_py3) brandomiranda~/home_simulation_research/FTIR/FTIR_proj $ conda install pytorch torchvision -c pytorch
Fetching package metadata ...........
Solving package specifications:
PackageNotFoundError: Package not found: '' Dependencies missing in current osx-64 channels:
- pytorch -> mkl >=2018
- torchvision -> pytorch >=0.3 -> mkl >=2018
You can search for packages on anaconda.org with
anaconda search -t conda mkl
You may need to install the anaconda-client command line client with
conda install anaconda-client
but I do have mkl:
(FTIR_py3) brandomiranda~/home_simulation_research/FTIR/FTIR_proj $ conda install mkl
Fetching package metadata .........
Solving package specifications: .
# All requested packages already installed.
# packages in environment at /Users/brandomiranda/miniconda3/envs/FTIR_py3:
#
mkl 2017.0.3 0
anyone know whats going on? it used to work a few days ago...
longer thread on pytorch forum:
https://discuss.pytorch.org/t/issues-installing-pytorch-for-os-x-with-conda/11496
As suggested in PyTorch forum, I think you should first install MKL. Your error trace also says that MKL is missing in your system. You can install MKL by doing:
$ conda install -c anaconda mkl
After this, install pytorch and torchvision by
$ conda install -c pytorch pytorch torchvision
Update conda first with conda update conda and try again.
It helped in my case.
Disclaimer: I didn't come up with this myself, but rather copied from github issue.

Installing tensorflow with Pip Python 3.5 anaconda in windows

I am trying to install Tensorslow on my Windows 7 64 bit computer.
I have installed Anaconda with Python 3.5.
After that I did
conda install theano
it is successfully done.
conda install mingw libpython
successfully done.
pip install tensorflow
Error
I am not able to install Tensorflow in the same way I installed these other packages. Am I missing something basic?
Ok, I've updated instructions:
*Launch your Anaconda CMD as Admin
#if tensorflow virtual env has been created, remove it first
conda remove --name tensorflow --all
conda create -n tensorflow --python=3.5 anaconda
activate tensorflow
conda install spyder
conda install ipython
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.0.1-cp35-cp35m-win_amd64.whl
spyder
Tensorflow on windows only works with Python 3.5 64-bit version, I don't know why doesn't work with Python > 3.5. Try this
conda create --name newEnv python=3.5
activate newEnv
(newEnv)C:> pip install tensorflow
This install Tensorflow in that particular environment. For testing run
(newEnv)C:> python
>>>import tensorflow as tf
>>>hello = tf.constant('Hello Tensorflow!')
>>>sess = tf.Session()
>>>sess.run(hello)
It should run without any error with output "Hello Tensorflow). Tested it on Windows 10 with python 3.5 64-bit and installed tensorflow 1.0.1 cpu version.
For Windows 10 (With NVidia 840M GPU)
If you have a different GPU check here to make sure your Compute number is > 3.0. My GPU has a 5.0
Mostly following instructions from official install instructions and steps from Stack Overflow Answer
I have found most answers do not combine the full installation from a clean install.
Configure the machine first
Download and install Anaconda from Download Anaconda-Windows Link
Installed Anaconda as User (I did not test installing as admin)
Download cuDNN v5.1 (Jan 20, 2017), for CUDA 8.0
Requires entering your email address and signing up.
Unzip this folder and add the */cuda/bin folder to your %PATH%
Install NVIDIA Cuda Version 8 for Windows 10
Also ensure this is in your path
Check for missing DLL: if where MSVCP140.DLL returns nothing you may need to either add it to the path or find it here
Open Anaconda CMD (with admin privilages)
Now install using conda and to test the installation
In Anaconda CMD (using Admin):
conda create -n tensorflow python=3.5 anaconda
activate tensorflow
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.0.1-cp35-cp35m-win_amd64.whl
In Python:
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
Also use the code in this answer to further confirm you are using the GPU

Categories