Skip to content

AttributeError: module 'torchvision.models' has no attribute 'mnasnet' #5087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
anamariaUIC opened this issue Dec 10, 2021 · 15 comments
Closed

Comments

@anamariaUIC
Copy link

🐛 Describe the bug

I installed pytorch via:
conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=9.2 -c pytorch

associated python version is: Python 3.7.4 (default, Aug 13 2019, 20:35:49)
[GCC 7.3.0] :: Anaconda, Inc. on linux

I am running this script: https://github.com/ryujaehun/pytorch-gpu-benchmark/blob/main/benchmark_models.py

and I am getting this Error:
Traceback (most recent call last):
File "python_test_GPU.py", line 22, in
models.mnasnet: models.mnasnet.all[1:],
AttributeError: module 'torchvision.models' has no attribute 'mnasnet'

Versions

Collecting environment information...
PyTorch version: 1.0.1.post2
Is debug build: False
CUDA used to build PyTorch: 9.0.176
ROCM used to build PyTorch: N/A

OS: CentOS Linux 7 (Core) (x86_64)
GCC version: (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)
Clang version: Could not collect
CMake version: version 2.8.12.2
Libc version: glibc-2.10

Python version: 3.7.4 (default, Aug 13 2019, 20:35:49) [GCC 7.3.0] (64-bit runtime)
Python platform: Linux-3.10.0-862.el7.x86_64-x86_64-with-centos-7.5.1804-Core
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.20.2
[pip3] numpydoc==0.9.1
[pip3] torch==1.0.1.post2
[pip3] torchaudio==0.7.0a0+ac17b64
[pip3] torchvision==0.2.2.post3
[conda] blas 1.0 mkl
[conda] cudatoolkit 10.2.89 hfd86e86_1
[conda] mkl 2019.4 243
[conda] mkl-service 2.3.0 py37he904b0f_0
[conda] mkl_fft 1.0.14 py37ha843d7b_0
[conda] mkl_random 1.1.0 py37hd6b4f25_0
[conda] numpy 1.17.2 py37haad9e8e_0
[conda] numpy-base 1.17.2 py37hde5b4d6_0
[conda] numpydoc 0.9.1 py_0
[conda] pytorch 1.7.0 py3.7_cuda10.2.89_cudnn7.6.5_0 pytorch
[conda] torchaudio 0.7.0 py37 pytorch
[conda] torchvision 0.8.0 py37_cu102 pytorch

@oke-aditya
Copy link
Contributor

oke-aditya commented Dec 11, 2021

I think your pytorch and torchvision versions don't match. Also see #2912

Pytorch = 1.7.0  should have torchvision =  0.8.1 

Edit:
Also you have conflicting conda and pip installation.
The best suggested way is to install using only conda as per the getting started guide

@oke-aditya
Copy link
Contributor

You should try

conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=9.2 -c pytorch

@anamariaUIC
Copy link
Author

@oke-aditya Thanks how do I uninstall the previous version that I installed? Or I don't need to do anything just run that command that you provided?

@oke-aditya
Copy link
Contributor

You can either create a fresh environment using conda and install again. (easy way)

Or uninstall packages using pip and conda then install

@anamariaUIC
Copy link
Author

@oke-aditya can you please send me command how do I uninstall it using pip in order to remove all files?
Do I only do:
pip uninstall torch

Please send me all commands for the complete uninstallation

@oke-aditya
Copy link
Contributor

oke-aditya commented Dec 11, 2021

I would suggest to remove all the packages.

pip uninstall numpy numpydoc torch torchaudio torchvision

(Press y to say yes and remove stuff)

Then cleanup the conda environment. (Coz your device is CUDA 9.2 and you have CUDA 10. 2 installed so pytorch won't run)

This will activate the base environment

conda activate base

Beware!! The below command will completely remove the environment.

conda env remove -n YOUR_PREVIOUS_ENV_NAME

Now you can create a fresh environment

conda create --name NEW_ENVIRONMENT_NAME

conda activate NEW_ENVIRONMENT_NAME

And proceed with installation as mentioned on the site.

Hope I helped you. :) It's bit hard to communicate installation issues :(

@anamariaUIC
Copy link
Author

@oke-aditya Thank you so much for your help. I tried installing with the command you gave me:
conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=9.2 -c pytorch

but when I run this

I get this:
Traceback (most recent call last):
File "python_test_GPU.py", line 22, in
models.mnasnet: models.mnasnet.all[1:],
AttributeError: module 'torchvision.models' has no attribute 'mnasnet'
end

vi system_info.txt
benchmark start : 2021/12/11 14:34:46
system_configs

uname_result(system='Linux', node='gpu-2-0.saber', release='3.10.0-862.el7.x86_64', version='#1 SMP Fri Apr 20 16:44:24 UTC 2018', machine='x86_64', processor='x86_64')
scpufreq(current=2100.0, min=0.0, max=0.0)
cpu_count: 16
memory_available: 90282246144
gpu_configs

Number of GPUs on current device : 1
CUDA Version : 9.0.176
Cudnn Version : 7402
Device Name : Tesla V100-PCIE-16GB
benchmark end : 2021/12/11 14:58:58

Can you please advice how to install pytorch so that the above scrip can run, this module part:
MODEL_LIST = {
models.mnasnet: models.mnasnet.all[1:],
models.resnet: models.resnet.all[1:],
models.densenet: models.densenet.all[1:],
models.squeezenet: models.squeezenet.all[1:],
models.vgg: models.vgg.all[1:],
models.mobilenet: models.mobilenet.mv2_all[1:],
models.mobilenet: models.mobilenet.mv3_all[1:],
models.shufflenetv2: models.shufflenetv2.all[1:],
}

For this version of pytorch installation these modules don't work:
models.mnasnet
models.mobilenet
models.mobilenet

What is the version and how to install Pytorch so that it does work with my:
Cuda 9.2
Drivers: NVIDIA-SMI 396.44, Driver Version: 396.44

Please advise,
Thanks!

@pmeier
Copy link
Collaborator

pmeier commented Dec 13, 2021

@anamariaUIC It should be one of

  • mnasnet0_5
  • mnasnet0_75
  • mnasnet1_0
  • mnasnet1_3

See this list for all available classification models.

@anamariaUIC
Copy link
Author

@pmeier @oke-aditya thank you for getting back to me. @pmeier How should I use the information from your comment to either install or run pytorch, given I want to run this script

@NicolasHug
Copy link
Member

@anamariaUIC please follow the latest pytorch version following the official instructions https://pytorch.org/get-started/locally/

FYI this works fine (from the script you linked) with the latest version:

MODEL_LIST = {
    models.mnasnet: models.mnasnet.__all__[1:],
    models.resnet: models.resnet.__all__[1:],
    models.densenet: models.densenet.__all__[1:],
    models.squeezenet: models.squeezenet.__all__[1:],
    models.vgg: models.vgg.__all__[1:],
    models.mobilenet: models.mobilenet.mv2_all[1:],
    models.mobilenet: models.mobilenet.mv3_all[1:],
    models.shufflenetv2: models.shufflenetv2.__all__[1:],
}

Since this is a usage question more than a bug or an issue related to torchvision, I'll close the issue.

@pmeier
Copy link
Collaborator

pmeier commented Dec 13, 2021

That is a question you should ask the author of the script. You can import the MNASNet models like this:

from torchvision import models

models.mnasnet0_5(...)

@anamariaUIC
Copy link
Author

anamariaUIC commented Dec 13, 2021

@NicolasHug does the latest version of pytorch works with CUDA 9.2? Because if it doesn't I can't use it. I am doing this on a cluster where drivers are version 396 (please see details from my previous comments) and only Cuda 9.2 can be used...

@NicolasHug
Copy link
Member

@anamariaUIC please see https://pytorch.org/get-started/previous-versions/ for cuda / pytroch compatibility and our readme for torch / torchvision compatibility.

There's a chance that not all models will be available in torchvision if you need to rely on such an old CUDA version, unfortunately

@pmeier
Copy link
Collaborator

pmeier commented Dec 13, 2021

does the latest version of pytorch works with CUDA 9.2?

Nope. The last release that supports CUDA 9.2 is torch==1.7.1 / torchvision==0.8.2.

@anamariaUIC
Copy link
Author

ok, So I did install the latest version of pytorch that works with CUDA 9.2 via:

conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=9.2 -c pytorch

And for example models.mnasnet doesn't work with it as invoked in this script:
models.mnasnet: models.mnasnet.all[1:]

Is this only the issue of invoking it instead with:
models.mnasnet: models.mnasnet0_5.all[1:],

or mnasnet: models doesn't work at all with pytorch==1.7.1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants