ImportError: cannot import name 'as_tensor'?

I am running fast.ai notebooks on clouderizer.com with google colab for the Gpu. I am getting this error when I execute this line:

from fastai.imports import *

Help!

Edit: Problem Solved. Solution here

4 Likes

Hello,

I have the same issue running Fast.ai notebook directly on google colab interface.

Hello
Me too getting the same error !!!

Hi,
The problem is: when you installed fastai dependencies you install Fastai 1.0 which is not made for courses. You need to use Fastai framework 0.7.0

Just replace the configuration code (for Google Colab) with this one, which worked for me:

!pip uninstall fastai
!pip install Pillow==4.1.1
!pip install "fastai==0.7.0"
!pip install torchtext==0.2.3
!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python
import cv2
from os import path
from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag
platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())
!apt update && apt install -y libsm6 libxext6

accelerator = 'cu80' if path.exists('/opt/bin/nvidia-smi') else 'cpu'
!pip install -q http://download.pytorch.org/whl/{accelerator}/torch-0.3.0.post4-{platform}-linux_x86_64.whl torchvision
import torch
!pip install image

%matplotlib inline
from fastai.imports import *
6 Likes

It depends if you’re trying to use the newer fast ai or the older one. It looks like you’re trying to run a notebook that relies on the older version. environment.yml doesn’t specify a version, and so it downloads the latest fastai. You can do something along the lines of pip install 'fastai<=0.7'. Or put that in the environment.yml and do a conda env update.

You’ll also need to get the right version of torchtext. See Google Colab-AttributeError: module ‘torch’ has no attribute ‘float32’

Just to confirm, when you say Fastai 1.0 is not made for courses, you mean the current ML,DL1 &2 courses rely on fastai v0.7 right?
The live DL1 (v3) starting on October 22 will rely on v1.0. Correct?

Yes the upcoming course will be based on fastai v1. The current vidoes are based on 0.7.0.

1 Like

I have the same issue. I am running fastai on an AWS EC2 instance (as an AMI) and I am getting this error when doing “from fastai.imports import *” on a Jupyter notebook (run on the same instance). I tried the solution linked by Alankar (pip install torchtext==0.2.3) but it hasn’t fixed it. Any ideas? Thanks in advance.

1 Like

Thanks, this method worked for me.

Thank you so much. Your way works for me.

Still can’t step over this error. I already have torchtext 0.2.3 installed via pip (running all on local Ubuntu machine) in conda env, but got this:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
in
----> 1 from fastai.imports import *

~/anaconda3/envs/fastai_one/lib/python3.6/site-packages/fastai/init.py in
----> 1 from .basic_train import *
2 from .callback import *
3 from .callbacks import *
4 from .core import *
5 from .basic_data import *

~/anaconda3/envs/fastai_one/lib/python3.6/site-packages/fastai/basic_train.py in
1 "Provides basic training and validation with Learner"
----> 2 from .torch_core import *
3 from .basic_data import *
4 from .callback import *
5

~/anaconda3/envs/fastai_one/lib/python3.6/site-packages/fastai/torch_core.py in
1 “Utility functions to help deal with tensors”
----> 2 from .imports.torch import *
3 from .core import *
4
5 AffineMatrix = Tensor

~/anaconda3/envs/fastai_one/lib/python3.6/site-packages/fastai/imports/init.py in
1 from .core import *
----> 2 from .torch import *

~/anaconda3/envs/fastai_one/lib/python3.6/site-packages/fastai/imports/torch.py in
1 import torch, torch.nn.functional as F
2 from torch import ByteTensor, DoubleTensor, FloatTensor, HalfTensor, LongTensor, ShortTensor, Tensor
----> 3 from torch import nn, optim, as_tensor
4 from torch.utils.data import BatchSampler, DataLoader, Dataset, Sampler, TensorDataset

ImportError: cannot import name ‘as_tensor’

1 Like

Has anyone had this error (or solved it) using Crestle?

Thanks, this worked for me.

im using jupyter notebook on windows. Can you specify the command usning conda or pip