AttributeError: type object 'Tensor' has no attribute 'as_subclass'

I am trying to import fastai2 for inference and a few days ago I had no issues. Now however I can’t get past this error.

 File "app/server.py", line 4, in <module>
    from fastai2.vision.all import *
  File "/usr/local/lib/python3.7/site-packages/fastai2/vision/all.py", line 1, in <module>
    from ..basics import *
  File "/usr/local/lib/python3.7/site-packages/fastai2/basics.py", line 1, in <module>
    from .data.all import *
  File "/usr/local/lib/python3.7/site-packages/fastai2/data/all.py", line 1, in <module>
    from ..torch_basics import *
  File "/usr/local/lib/python3.7/site-packages/fastai2/torch_basics.py", line 4, in <module>
    from .torch_core import *
  File "/usr/local/lib/python3.7/site-packages/fastai2/torch_core.py", line 246, in <module>
    setattr(torch, 'as_subclass', torch.Tensor.as_subclass)
AttributeError: type object 'Tensor' has no attribute 'as_subclass'

Hey nole, did you ever figure this out? I’m having the same issue with fastai (now that 2 is in the main channel).
Cheers!
Mark

1 Like

Hey Nole,
I updated my requirements:
#torch==1.5.1 #old
torch>=1.6 #new, works

Seemed to be a torch issue! Hope this helps!

1 Like

I am facing the same issue and my torch version is 1.6, do I need to uninstall v1 of Fastai. I currently have both installed.

I’m not sure as i only have been able to get any version of fastai to work through a remote linux box,colab, or docker. currently i don’t know if my repo works since the update and can’t work on it until next week. sorry this doesn’t help but i felt bad not responding.

As an update to this I have set my installation reqs to

torch==1.6.0+cpu 
torchvision==0.7.0+cpu 
-f https://download.pytorch.org/whl/torch_stable.html
fastai

And now get this error

Traceback (most recent call last):
  File "app/server.py", line 4, in <module>
    from fastai2.vision.all import *
  File "/usr/local/lib/python3.7/site-packages/fastai2/vision/all.py", line 1, in <module>
    from ..basics import *
  File "/usr/local/lib/python3.7/site-packages/fastai2/basics.py", line 1, in <module>
    from .data.all import *
  File "/usr/local/lib/python3.7/site-packages/fastai2/data/all.py", line 5, in <module>
    from .transforms import *
  File "/usr/local/lib/python3.7/site-packages/fastai2/data/transforms.py", line 230, in <module>
    class Categorize(DisplayedTransform):
  File "/usr/local/lib/python3.7/site-packages/fastai2/data/transforms.py", line 232, in Categorize
    loss_func,order,store_attrs=CrossEntropyLossFlat(),1,'vocab,add_na'
  File "/usr/local/lib/python3.7/site-packages/fastcore/utils.py", line 472, in _f
    return inst if to_return else f(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/fastai2/layers.py", line 306, in __init__
    def __init__(self, *args, axis=-1, **kwargs): super().__init__(nn.CrossEntropyLoss, *args, axis=axis, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/fastcore/utils.py", line 472, in _f
    return inst if to_return else f(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/fastai2/layers.py", line 281, in __init__
    store_attr(self, "axis,flatten,floatify,is_2d")
  File "/usr/local/lib/python3.7/site-packages/fastcore/utils.py", line 97, in store_attr
    if not hasattr(self, '__stored_args__'): self.__stored_args__ = {}
AttributeError: 'str' object has no attribute '__stored_args__'
PS C:\Users\Dingu\Documents\FastAPI-Fastai2>

After ,

!pip install fastai2

I was getting the same error in kaggle kernal. Somehow when i tried installing in Google Colab it seems to work fine. Perhaps preinstalled issue.

Were we able to solve above issue, as I am also facing same issue