"ImportError: cannot import name 'BatchSampler'"

(Laurent) #12

Ran into the same error. I think it’s got to do with the move to the rewritten fastai library.
What fixed it for me was just reverting to an earlier, working commit by issuing:
git checkout 2e1ccb58121dc648751e2109fc0fbf6925aa8887

That puts the repo back to an earlier stage which gets everything working for me again. Note that this isn’t a resilient fix: if you intend to work on the fastai library code, this definitely wouldn’t be the way to go. Then again, if that’s the case, you probably know enough to fix the underlying root cause.

(Sarada Lee) #13

I reset the symbolic link to point to …/fastai/old/fastai/ (old library). Then, it works again. I also have the latest library for the upcoming course.

Howto: installation on Windows
Problem with running fast.ai chapter 8
(Pagadi Shyam) #14

I am using Google colab for setting up Fastai, how can i resolve this issue in colab…

(Gianfrancesco Angelini) #15

You can pip install from github repository, choosing your preferred branch or commit.




So for example, in Laurenth case it should be

!pip install git+https://github.com/fastai/fastai@2e1ccb58121dc648751e2109fc0fbf6925aa8887

Personally I used the following, and solved that error, but a new one raised

!pip install git+https://github.com/fastai/fastai@ulmfit_cleanup

It returned:

AttributeError: module 'torch.nn' has no attribute 'functional'

but that’s another story…


Thank you,

It seems to be the best option for now as they changed a lot to the fastai repo to use pytorch 0.4.1 features, but the setup process still using 0.3.1. Installing 0.4.1 is an option but in the future who knows what might break.

(ritika) #17

@jakelong Can you please help me in installing fastai library. I have followed all the steps mentioned in the forum

But when I import fastai module I am getting the error.



It seems like you already had your fastai conda env set up. In the step 8 of the howto you can see the instruction as:
cd courses\dl1
del fastai
mklink /d fastai ..\..\fastai
cd ..\..

If you already did the above things, open an anaconda prompt, cd into fastai folder, activate fastai env and run these
cd courses\dl1
rmdir fastai
mklink /d fastai ..\..\old\fastai
cd ..\..

Don’t try to import fastai from python started in the command line, run jupyter notebook and open lession1.ipynb in courses/dl1 and run the first 6 blocks of code. It should run without problem and torch.cuda.is_available() and torch.backends.cudnn.enabled should both return True.

Hope this help

(Gianfrancesco Angelini) #19

Hoping to be helpful here I shared a Google Colab notebook ready to go, in order to make fast.ai course ready to go to anyone.
It has comments about common issues I solved too.
You are free to comment or fork it and let me/us know if/how you’ll improve it.

(ritika) #20

Hi Jake,

Thank you for the quick response. I tried to followed the instructions shared by you.
I got the error.Please suggest how to solve this error.


(ritika) #21

Thanks ! This will save a lot of time.Waiting notes for other lessons too.


In my case I enabled Developer mode in windows by opening start menu and search for developers settings, however I’m using windows 10 pro and not sure if you have the same. Also I saw that you ran del fastai, which doesn’t remove the symlink but rather delete files in fastai folder, instead of rmdir fastai. You should check to see if you had deleted any files in that folder and revert changes made to it, then run only the second bunch of code in my previous post, not the first one.

(rares t) #23

Hello, i pointed it to the old fastai but now in the jupyter notebook it tells me it can not find imports.

(rares t) #24

do you have an imports folder in /old/fastai? thanks

(ritika) #25

Hi Jake,

I tried to replicate the same steps.Still I am facing the issues. I am not able to import fastai library.Please suggest how to proceed.


(Sarada Lee) #26

No. If you can’t import. It is possibly related to the folder structure. Make sure the symbolic link is point to your working directory.


can you post the error so we can have a look please

(Kevin Bird) #28

Thanks, that was my issue. I had tried making a new folder for all Kaggle competitions and I had it as fastai/kaggle/fastai(symlink) I had to add another layer to the structure so now I have fastai/kaggle/competitions/fastai(symlink)

(ritika) #29

Hi Jake,

Please find the screenshot attached.


(Sarada Lee) #30

Hi @ritika26 Try this ln -s source_file myfile (details https://kb.iu.edu/d/abbe)

Personally, I prefer using absolute paths to make sure the folder structure is right.


it seems like you are using windows 10, then try open start menu and search for ‘developers settings’ and switch to developer mode, that should allow you to perform mklink command