Skip to content

TypeError: Class advice impossible in Python3 #116

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
lynnna-xu opened this issue Jan 7, 2019 · 15 comments
Closed

TypeError: Class advice impossible in Python3 #116

lynnna-xu opened this issue Jan 7, 2019 · 15 comments

Comments

@lynnna-xu
Copy link

TypeError Traceback (most recent call last)
in ()
----> 1 from pytorch_pretrained_bert import BertTokenizer

/opt/conda/envs/py3/lib/python3.6/site-packages/pytorch_pretrained_bert/init.py in ()
1 version = "0.4.0"
2 from .tokenization import BertTokenizer, BasicTokenizer, WordpieceTokenizer
----> 3 from .modeling import (BertConfig, BertModel, BertForPreTraining,
4 BertForMaskedLM, BertForNextSentencePrediction,
5 BertForSequenceClassification, BertForMultipleChoice,

/opt/conda/envs/py3/lib/python3.6/site-packages/pytorch_pretrained_bert/modeling.py in ()
152
153 try:
--> 154 from apex.normalization.fused_layer_norm import FusedLayerNorm as BertLayerNorm
155 except ImportError:
156 print("Better speed can be achieved with apex installed from https://www.github.com/nvidia/apex.")

/opt/conda/envs/py3/lib/python3.6/site-packages/apex/init.py in ()
16 from apex.exceptions import (ApexAuthSecret,
17 ApexSessionSecret)
---> 18 from apex.interfaces import (ApexImplementation,
19 IApex)
20 from apex.lib.libapex import (groupfinder,

/opt/conda/envs/py3/lib/python3.6/site-packages/apex/interfaces.py in ()
8 pass
9
---> 10 class ApexImplementation(object):
11 """ Class so that we can tell if Apex is installed from other
12 applications

/opt/conda/envs/py3/lib/python3.6/site-packages/apex/interfaces.py in ApexImplementation()
12 applications
13 """
---> 14 implements(IApex)

/opt/conda/envs/py3/lib/python3.6/site-packages/zope/interface/declarations.py in implements(*interfaces)
481 # the coverage for this block there. :(
482 if PYTHON3:
--> 483 raise TypeError(_ADVICE_ERROR % 'implementer')
484 _implements("implements", interfaces, classImplements)
485

TypeError: Class advice impossible in Python3. Use the @Implementer class decorator instead.

Hi, I came across this error after running import pytorch_pretrained_bert. My configurations are as follows:
torch version 1.0.0
python version 3.6
cuda 9.2

@lynnna-xu
Copy link
Author

I uninstalled the old version of apex and reinstalled a new version. It worked. Thanks.

git clone https://www.github.com/nvidia/apex
cd apex
python setup.py install

@demeiyan
Copy link

I uninstalled the old version of apex and reinstalled a new version. It worked. Thanks.

git clone https://www.github.com/nvidia/apex
cd apex
python setup.py install

I install follow your steps but it don't work.

@ptrblck
Copy link
Collaborator

ptrblck commented Jul 16, 2019

@demeiyan
Could you make sure to uninstall all previous apex versions and try to reinstall it again?

@duyvuleo
Copy link

duyvuleo commented Sep 4, 2019

It works in my case. Thanks @lynnna-xu .

@jakubLangr
Copy link

jakubLangr commented Sep 23, 2019

Hi I do not think this issue should be closed at all.

I have just replicated this issue on:

  • Mac OS X (10.14.6)
  • Ubuntu 16.04 running nvidia's official image using nvidia-docker (specifically nvidia/cuda:9.0-cudnn7-devel-ubuntu16.04)
  • AWS Deep Learning AMI 22.0

The proposed solution also did not help on any of the above. I therefore have to conclude that current Apex build is simply broken.

EDIT: Error messages as per @ptrblck 's request

Mac OS X

python webcam.py --min-image-size 300 MODEL.DEVICE cpu
Traceback (most recent call last):
  File "webcam.py", line 6, in <module>
    from predictor import COCODemo
  File "/Users/jakublangr/code/experiments/maskrcnn-benchmark/demo/predictor.py", line 6, in <module>
    from maskrcnn_benchmark.modeling.detector import build_detection_model
  File "/Users/jakublangr/code/experiments/maskrcnn-benchmark/maskrcnn-benchmark/maskrcnn_benchmark/modeling/detector/__init__.py", line 2, in <module>
    from .detectors import build_detection_model
  File "/Users/jakublangr/code/experiments/maskrcnn-benchmark/maskrcnn-benchmark/maskrcnn_benchmark/modeling/detector/detectors.py", line 2, in <module>
    from .generalized_rcnn import GeneralizedRCNN
  File "/Users/jakublangr/code/experiments/maskrcnn-benchmark/maskrcnn-benchmark/maskrcnn_benchmark/modeling/detector/generalized_rcnn.py", line 11, in <module>
    from ..backbone import build_backbone
  File "/Users/jakublangr/code/experiments/maskrcnn-benchmark/maskrcnn-benchmark/maskrcnn_benchmark/modeling/backbone/__init__.py", line 2, in <module>
    from .backbone import build_backbone
  File "/Users/jakublangr/code/experiments/maskrcnn-benchmark/maskrcnn-benchmark/maskrcnn_benchmark/modeling/backbone/backbone.py", line 7, in <module>
    from maskrcnn_benchmark.modeling.make_layers import conv_with_kaiming_uniform
  File "/Users/jakublangr/code/experiments/maskrcnn-benchmark/maskrcnn-benchmark/maskrcnn_benchmark/modeling/make_layers.py", line 10, in <module>
    from maskrcnn_benchmark.layers import Conv2d
  File "/Users/jakublangr/code/experiments/maskrcnn-benchmark/maskrcnn-benchmark/maskrcnn_benchmark/layers/__init__.py", line 10, in <module>
    from .nms import nms
  File "/Users/jakublangr/code/experiments/maskrcnn-benchmark/maskrcnn-benchmark/maskrcnn_benchmark/layers/nms.py", line 5, in <module>
    from apex import amp
  File "/Users/jakublangr/miniconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/apex/__init__.py", line 18, in <module>
    from apex.interfaces import (ApexImplementation,
  File "/Users/jakublangr/miniconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/apex/interfaces.py", line 10, in <module>
    class ApexImplementation(object):
  File "/Users/jakublangr/miniconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/apex/interfaces.py", line 14, in ApexImplementation
    implements(IApex)
  File "/Users/jakublangr/miniconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/zope/interface/declarations.py", line 483, in implements
    raise TypeError(_ADVICE_ERROR % 'implementer')
TypeError: Class advice impossible in Python3.  Use the @implementer class decorator instead.

Nvidia-docker

TypeErrorTraceback (most recent call last)
<ipython-input-3-63734ee6f49e> in <module>
      1 from maskrcnn_benchmark.config import cfg
----> 2 from predictor import COCODemo

/notebooks/maskrcnn-benchmark/demo/predictor.py in <module>
      4 from torchvision import transforms as T
      5 from torchvision.transforms import functional as F
----> 6 from maskrcnn_benchmark.modeling.detector import build_detection_model
      7 from maskrcnn_benchmark.utils.checkpoint import DetectronCheckpointer
      8 from maskrcnn_benchmark.structures.image_list import to_image_list

/notebooks/maskrcnn-benchmark/maskrcnn_benchmark/modeling/detector/__init__.py in <module>
      1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
----> 2 from .detectors import build_detection_model

/notebooks/maskrcnn-benchmark/maskrcnn_benchmark/modeling/detector/detectors.py in <module>
      1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
----> 2 from .generalized_rcnn import GeneralizedRCNN
      3 
      4 
      5 _DETECTION_META_ARCHITECTURES = {"GeneralizedRCNN": GeneralizedRCNN}

/notebooks/maskrcnn-benchmark/maskrcnn_benchmark/modeling/detector/generalized_rcnn.py in <module>
      9 from maskrcnn_benchmark.structures.image_list import to_image_list
     10 
---> 11 from ..backbone import build_backbone
     12 from ..rpn.rpn import build_rpn
     13 from ..roi_heads.roi_heads import build_roi_heads

/notebooks/maskrcnn-benchmark/maskrcnn_benchmark/modeling/backbone/__init__.py in <module>
      1 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
----> 2 from .backbone import build_backbone
      3 from . import fbnet

/notebooks/maskrcnn-benchmark/maskrcnn_benchmark/modeling/backbone/backbone.py in <module>
      5 
      6 from maskrcnn_benchmark.modeling import registry
----> 7 from maskrcnn_benchmark.modeling.make_layers import conv_with_kaiming_uniform
      8 from . import fpn as fpn_module
      9 from . import resnet

/notebooks/maskrcnn-benchmark/maskrcnn_benchmark/modeling/make_layers.py in <module>
      8 from torch.nn import functional as F
      9 from maskrcnn_benchmark.config import cfg
---> 10 from maskrcnn_benchmark.layers import Conv2d
     11 from maskrcnn_benchmark.modeling.poolers import Pooler
     12 

/notebooks/maskrcnn-benchmark/maskrcnn_benchmark/layers/__init__.py in <module>
      8 from .misc import BatchNorm2d
      9 from .misc import interpolate
---> 10 from .nms import nms
     11 from .roi_align import ROIAlign
     12 from .roi_align import roi_align

/notebooks/maskrcnn-benchmark/maskrcnn_benchmark/layers/nms.py in <module>
      3 from maskrcnn_benchmark import _C
      4 
----> 5 from apex import amp
      6 
      7 # Only valid with fp32 inputs - give AMP the hint

/miniconda/envs/py36/lib/python3.6/site-packages/apex/__init__.py in <module>
     16 from apex.exceptions import (ApexAuthSecret,
     17                              ApexSessionSecret)
---> 18 from apex.interfaces import (ApexImplementation,
     19                              IApex)
     20 from apex.lib.libapex import (groupfinder,

/miniconda/envs/py36/lib/python3.6/site-packages/apex/interfaces.py in <module>
      8     pass
      9 
---> 10 class ApexImplementation(object):
     11     """ Class so that we can tell if Apex is installed from other 
     12     applications

/miniconda/envs/py36/lib/python3.6/site-packages/apex/interfaces.py in ApexImplementation()
     12     applications
     13     """
---> 14     implements(IApex)

/miniconda/envs/py36/lib/python3.6/site-packages/zope/interface/declarations.py in implements(*interfaces)
    481     # the coverage for this block there. :(
    482     if PYTHON3:
--> 483         raise TypeError(_ADVICE_ERROR % 'implementer')
    484     _implements("implements", interfaces, classImplements)
    485 

TypeError: Class advice impossible in Python3.  Use the @implementer class decorator instead.

EDIT 2:
I can no longer exactly replicate it on the AWS Deep Learning AMI 22.0, instead I fail on installation:

(maskrcnn_benchmark) ubuntu@ip-172-31-16-110:~/projects/maskrcnn-benchmark/apex$ python setup.py install --cuda_ext --cpp_ext
Traceback (most recent call last):
  File "setup.py", line 1, in <module>
    import torch
  File "/home/ubuntu/anaconda3/envs/maskrcnn_benchmark/lib/python3.7/site-packages/torch/__init__.py", line 79, in <module>
    from torch._C import *
ImportError: /home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/lib/libtorch.so.1: undefined symbol: nvrtcGetProgramLogSize

This is after installing as per the official PyTorch command conda install pytorch torchvision cudatoolkit=10.0 -c pytorch

@ptrblck
Copy link
Collaborator

ptrblck commented Sep 23, 2019

@jakubLangr
Could you post your error message?

@jakubLangr
Copy link

@ptrblck done as per above.

@ptrblck
Copy link
Collaborator

ptrblck commented Sep 23, 2019

@jakubLangr Thanks for the error logs.
Have you installed apex from pip, as both containers seem to point to this library, which implements some authentication functions.
Could you uninstall all apex versions and try to rebuild?

@jakubLangr
Copy link

Hi @ptrblck apologies I kept running into different errors when installing apex from the nVidia repo. It should have raised some flags in my head when an installation of something this low level goes so smoothly, something is wrong. Also I appreciate you don't control pypi but this naming is a tad bit confusing :)

Will do some more investigating today.

@ls-simon-he
Copy link

I got this issue with python3, but fixed by following @lynnna-xu with

pip3 uninstall apex

git clone https://www.github.com/nvidia/apex
cd apex
python3 setup.py install

@zzj0402
Copy link

zzj0402 commented Jun 18, 2020

pip3 uninstall apex && git clone https://www.github.com/nvidia/apex && cd apex && python3 setup.py install && rm -rf ../apex

Just to make it one line ^^

@spacewaterbear
Copy link

It's appearing that the lib changed its name to pytorch extension => https://pypi.org/project/pytorch-extension/

@YutongWang1216
Copy link

It's appearing that the lib changed its name to pytorch extension => https://pypi.org/project/pytorch-extension/

That solves the problem perfectly! Thanks a lot 😊

@edwardzjl
Copy link

It's appearing that the lib changed its name to pytorch extension => https://pypi.org/project/pytorch-extension/

I don't think it's an official release.

@Hangsiin
Copy link

It's appearing that the lib changed its name to pytorch extension => https://pypi.org/project/pytorch-extension/

thanks. I struggled with this issue for 2 days... it worked perfectly.

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