pytorch / pytorch/vision

MNIST import fails: cannot import name 'OpOverloadPacket' from 'torch._ops'

Open
#5,748 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs reproduction topic: binaries
Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

🐛 Describe the bug

Trying to import the MNIST dataset on Linux as follows:

import torchvision.datasets as datasets
mnist_trainset = datasets.MNIST(root='./data', train=True, download=True, transform=None)

fails with an ImportError:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/tmp/ipykernel_13067/1857463301.py in <module>
----> 1 import torchvision.datasets as datasets
      2 
      3 mnist_trainset = datasets.MNIST(root='./data', train=True, download=True, transform=None)

~/miniforge3/envs/bios8366/lib/python3.9/site-packages/torchvision/__init__.py in <module>
      5 from torchvision import datasets
      6 from torchvision import io
----> 7 from torchvision import models
      8 from torchvision import ops
      9 from torchvision import transforms

~/miniforge3/envs/bios8366/lib/python3.9/site-packages/torchvision/models/__init__.py in <module>
      1 from .alexnet import *
----> 2 from .convnext import *
      3 from .resnet import *
      4 from .vgg import *
      5 from .squeezenet import *

~/miniforge3/envs/bios8366/lib/python3.9/site-packages/torchvision/models/convnext.py in <module>
      8 from .._internally_replaced_utils import load_state_dict_from_url
      9 from ..ops.misc import ConvNormActivation
---> 10 from ..ops.stochastic_depth import StochasticDepth
     11 from ..utils import _log_api_usage_once
     12 

~/miniforge3/envs/bios8366/lib/python3.9/site-packages/torchvision/ops/__init__.py in <module>
     16 from .giou_loss import generalized_box_iou_loss
     17 from .misc import FrozenBatchNorm2d, SqueezeExcitation
---> 18 from .poolers import MultiScaleRoIAlign
     19 from .ps_roi_align import ps_roi_align, PSRoIAlign
     20 from .ps_roi_pool import ps_roi_pool, PSRoIPool

~/miniforge3/envs/bios8366/lib/python3.9/site-packages/torchvision/ops/poolers.py in <module>
      3 
      4 import torch
----> 5 import torch.fx
      6 import torchvision
      7 from torch import nn, Tensor

~/miniforge3/envs/bios8366/lib/python3.9/site-packages/torch/fx/__init__.py in <module>
     81 '''
     82 
---> 83 from .graph_module import GraphModule
     84 from ._symbolic_trace import symbolic_trace, Tracer, wrap, PH, ProxyableClassMeta
     85 from .graph import Graph

~/miniforge3/envs/bios8366/lib/python3.9/site-packages/torch/fx/graph_module.py in <module>
      6 import linecache
      7 from typing import Type, Dict, List, Any, Union, Optional, Set
----> 8 from .graph import Graph, _is_from_torch, _custom_builtins, PythonCode
      9 from ._compatibility import compatibility
     10 from torch.package import Importer, sys_importer

~/miniforge3/envs/bios8366/lib/python3.9/site-packages/torch/fx/graph.py in <module>
----> 1 from .node import Node, Argument, Target, map_arg, _type_repr, _get_qualified_name
      2 import torch.utils._pytree as pytree
      3 from . import _pytree as fx_pytree
      4 from ._compatibility import compatibility
      5 import contextlib

~/miniforge3/envs/bios8366/lib/python3.9/site-packages/torch/fx/node.py in <module>
      7 import types
      8 import warnings
----> 9 from torch.fx.operator_schemas import normalize_function, normalize_module, ArgsKwargsPair
     10 
     11 if TYPE_CHECKING:

~/miniforge3/envs/bios8366/lib/python3.9/site-packages/torch/fx/operator_schemas.py in <module>
      8 from torch._jit_internal import boolean_dispatched
      9 from ._compatibility import compatibility
---> 10 from torch._ops import OpOverloadPacket
     11 
     12 if TYPE_CHECKING:

ImportError: cannot import name 'OpOverloadPacket' from 'torch._ops' (/home/fonnesbeck/miniforge3/envs/bios8366/lib/python3.9/site-packages/torch/_ops.py)
Versions

PyTorch version: 1.11.0+cu102
Is debug build: False
CUDA used to build PyTorch: 10.2
ROCM used to build PyTorch: N/A

OS: Debian GNU/Linux 11 (bullseye) (x86_64)
GCC version: (Debian 10.2.1-6) 10.2.1 20210110
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.31

Python version: 3.9.9 | packaged by conda-forge | (main, Dec 20 2021, 02:41:03) [GCC 9.4.0] (64-bit runtime)
Python platform: Linux-5.10.102.1-microsoft-standard-WSL2-x86_64-with-glibc2.31
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
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] numpy==1.21.5
[pip3] numpyro==0.9.1
[pip3] torch==1.11.0
[pip3] torchvision==0.12.0
[conda] Could not collect

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the versions listed in the issue, starting at torchvision/init.py and following the imports through ops/poolers.py to torch.fx/operator_schemas.py. Compare the referenced torch._ops import with the installed PyTorch API and inspect the related compatibility points. Done means importing torchvision.datasets and constructing the MNIST dataset succeeds without ImportError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
computer-vision, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.