question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: ImportError: cannot import name 'FakeQuantizeBase' from 'torch.quantization'

See original GitHub issue

After your recent release, I got this error from my code. I can only use my code by downgrading fvcore version to previous one.

Error Traceback:

2021-10-15T09:46:49.0347680Z ==================================== ERRORS ====================================
2021-10-15T09:46:49.0350615Z ________________________ ERROR collecting test session _________________________
2021-10-15T09:46:49.0352801Z /usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py:495: in _importconftest
2021-10-15T09:46:49.0358791Z     return self._conftestpath2mod[key]
2021-10-15T09:46:49.0360317Z E   KeyError: PosixPath('/app/cv_ner_detectron/tests/conftest.py')
2021-10-15T09:46:49.0360877Z 
2021-10-15T09:46:49.0362075Z During handling of the above exception, another exception occurred:
2021-10-15T09:46:49.0363832Z /usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py:501: in _importconftest
2021-10-15T09:46:49.0364711Z     mod = conftestpath.pyimport()
2021-10-15T09:46:49.0365834Z /usr/local/lib/python3.8/dist-packages/py/_path/local.py:704: in pyimport
2021-10-15T09:46:49.0368988Z     __import__(modname)
2021-10-15T09:46:49.0370340Z /usr/local/lib/python3.8/dist-packages/_pytest/assertion/rewrite.py:152: in exec_module
2021-10-15T09:46:49.0372267Z     exec(co, module.__dict__)
2021-10-15T09:46:49.0373441Z cv_ner_detectron/tests/conftest.py:11: in <module>
2021-10-15T09:46:49.0377209Z     from cv_ner_detectron.detectron.datamodels import CvNerExample
2021-10-15T09:46:49.0378686Z cv_ner_detectron/detectron/datamodels.py:7: in <module>
2021-10-15T09:46:49.0380548Z     from detectron2.structures import BoxMode
2021-10-15T09:46:49.0382497Z /usr/local/lib/python3.8/dist-packages/detectron2/structures/__init__.py:6: in <module>
2021-10-15T09:46:49.0385934Z     from .keypoints import Keypoints, heatmaps_to_keypoints
2021-10-15T09:46:49.0387443Z /usr/local/lib/python3.8/dist-packages/detectron2/structures/keypoints.py:6: in <module>
2021-10-15T09:46:49.0389906Z     from detectron2.layers import interpolate
2021-10-15T09:46:49.0391270Z /usr/local/lib/python3.8/dist-packages/detectron2/layers/__init__.py:10: in <module>
2021-10-15T09:46:49.0397234Z     from .blocks import CNNBlockBase, DepthwiseSeparableConv2d
2021-10-15T09:46:49.0402621Z /usr/local/lib/python3.8/dist-packages/detectron2/layers/blocks.py:4: in <module>
2021-10-15T09:46:49.0406940Z     import fvcore.nn.weight_init as weight_init
2021-10-15T09:46:49.0408469Z /usr/local/lib/python3.8/dist-packages/fvcore/nn/__init__.py:2: in <module>
2021-10-15T09:46:49.0409904Z     from .activation_count import ActivationCountAnalysis, activation_count
2021-10-15T09:46:49.0411437Z /usr/local/lib/python3.8/dist-packages/fvcore/nn/activation_count.py:10: in <module>
2021-10-15T09:46:49.0414217Z     from .jit_analysis import JitModelAnalysis
2021-10-15T09:46:49.0415640Z /usr/local/lib/python3.8/dist-packages/fvcore/nn/jit_analysis.py:15: in <module>
2021-10-15T09:46:49.0417905Z     from fvcore.common.checkpoint import _named_modules_with_dup
2021-10-15T09:46:49.0419295Z /usr/local/lib/python3.8/dist-packages/fvcore/common/checkpoint.py:23: in <module>
2021-10-15T09:46:49.0422403Z     from torch.quantization import ObserverBase, FakeQuantizeBase
2021-10-15T09:46:49.0424633Z E   ImportError: cannot import name 'FakeQuantizeBase' from 'torch.quantization' (/usr/local/lib/python3.8/dist-packages/torch/quantization/__init__.py)
2021-10-15T09:46:49.0425328Z 

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jmspereiracommented, Oct 15, 2021

+1

I guess that the problem is related to the last commit where torch.quantization is imported if the torch version is smaller than 1.11. However, that does not maintain the past behavior since the references to torch.quantization were replaced assuming that the import works (and before it was verified that the torch version is larger than 1.8).

1reaction
Siba-07commented, Oct 16, 2021

+1 ! python -m pip install detectron2 -f
https://dl.fbaipublicfiles.com/detectron2/wheels/cu110/torch1.7/index.html

This is the pytorch version I am installing and still getting the error

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting:- ImportError: cannot import name 'FakeQuantizeBase ...
Hey, I am using torch version 1.7.1 CPU and detectron2 along with torch 1.7 but when I used it through my own package,...
Read more >
Cannot import name 'QuantStub' from 'torch.ao.quantization'
Hi I am new to pytorch. I encounter an issue when I run the below. Can someone assist ? from torchvision import datasets,...
Read more >
quantization/fake_quantize.py · neilisaac/torch - Gemfury
import torch from torch.nn import Module from .observer import ... class FakeQuantizeBase(ABC, Module): r""" Base fake quantize module Any fake quantize ...
Read more >
Cannot import name 'QuantStub' from 'torch.ao.quantization'
I was able to creaet a fastai 2.5.x / Python 3.9 conda env using: conda env create -n fastbook -c defaults python=3.9 conda...
Read more >
python/microsoft/unilm/dit/object_detection/ditod ...
... quantization, \ ObserverBase, FakeQuantizeBase from torch import distributed ... C2 or L != H * W: logger.warning("Error in loading absolute_pos_embed, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found