Fastai2 on Windows

Please use this topic to discuss issues related to fastai2 on Windows. This is a wiki post, so feel free to add any FAQs or resources directly to this top post.

1 Like

I use Linux more than Windows these days; my home system I recently upgraded to Ryzen. I usually use a GPU passthrough setup but I don’t have a spare GPU to use without an iGPU and I don’t have any spare drives to dual boot Ubuntu or similar from… So trying my best to get Windows working at the moment! If it turns out to be an impossibility, I’ll have to get a drive or something but I’d really like to make a good effort of getting it going. I’m just perplexed I have seemingly zero obvious reason as to why the GPU isn’t being utilised, it’s very odd indeed.

Tired of the frustrating limitations of free Paperspace/Colab and I have a 1080Ti sitting on my desk that I may as well be using!

1 Like

Full disclosure - I work for Microsoft - but I tend to use a data science VM on Azure running Ubuntu, but also don’t like my Win10 + 1080ti doing nothing - so I did aim to get v2 running for the course once it had settled down.

1 Like

Not sure what’s going on in your case, but fastai2 is training using my GPU on Windows 10. Using pytorch 1.4 installed with the default settings conda install pytorch torchvision cudatoolkit=10.1 -c pytorch. Worked on both the 441.x and 442.x drivers. Have to set num_workers=0 for the dataloader, of course.

4 Likes

Same here - GPU was showing cuda activity. On Win10 (insiders preview 19564), just did the install exactly as on Github (not editable) and ran 22_tutorial.imagenette.ipynb. Just needed the num_workers=0. I have cuda 10, 10.1 and 10.2 - drivers - looks like pytorch 1.4.0 targets 10.1. NVidia drivers 450.12. 1080 Ti.

1 Like

I am using fastai v1 atm I believe, good old dim me this is the v2 topic haha.

I will try v2 however - those steps are pretty much identical to what I did with v1.

Hi @Russbo, 10 days ago, my GPU couldn’t be used on my Windows laptop. I ran nvidia-smi and the output was the following:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 417.98       Driver Version: 417.98       CUDA Version: 10.0     |
|-------------------------------+----------------------+----------------------+

Then I updated my nvidia driver by downloading and installing the file from:
CUDA Toolkit 10.2 Download

Now, nvidia-smi shows the new driver version (441.22 ), and the new cuda version (10.2)

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 441.22       Driver Version: 441.22       CUDA Version: 10.2     |
|-------------------------------+----------------------+----------------------+

Since then, the GPU is used.

default_device()
device(type='cuda', index=0)

I am presently using this version of torch

# Name                    Version                   Build  Channel
pytorch                   1.3.1           py3.6_cuda101_cudnn7_0    pytorch
torchvision               0.5.0                    pypi_0    pypi

and this version of fastai2

# Name                    Version                   Build  Channel
fastai2                   0.0.11                    dev_0    <develop>

I hope this information will help.

I Can run it on windows nvidia driver is 442.19 and CUDA 10.2, but have to set num_workers=0 in the dataloader.

image

Out of curiosity i ran it on ubuntu and its 3.5-4x quicker.

image (1)

Is it because of num_workers?

Me too, so I gave up - far too old to learn Ubuntu and command line typing so I gave up! Bloody sad; My 2080Ti does render text very well.
Looking forward to developments for windows.
Cheers and good luck, Peter Kelly, Oz.

I’m facing the following error while running on Windows 7, CUDA Toolkit 10.2

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~\Anaconda3\lib\site-packages\fastai2\learner.py in one_batch(self, i, b)
    134             if len(self.yb) == 0: return
--> 135             self.loss = self.loss_func(self.pred, *self.yb); self('after_loss')
    136             if not self.training: return

~\Anaconda3\lib\site-packages\fastai2\learner.py in __call__(self, event_name)
    107 
--> 108     def __call__(self, event_name): L(event_name).map(self._call_one)
    109     def _call_one(self, event_name):

~\Anaconda3\lib\site-packages\fastcore\foundation.py in map(self, f, *args, **kwargs)
    361              else f.__getitem__)
--> 362         return self._new(map(g, self))
    363 

~\Anaconda3\lib\site-packages\fastcore\foundation.py in _new(self, items, *args, **kwargs)
    314     def _xtra(self): return None
--> 315     def _new(self, items, *args, **kwargs): return type(self)(items, *args, use_list=None, **kwargs)
    316     def __getitem__(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None)

~\Anaconda3\lib\site-packages\fastcore\foundation.py in __call__(cls, x, *args, **kwargs)
     40 
---> 41         res = super().__call__(*((x,) + args), **kwargs)
     42         res._newchk = 0

~\Anaconda3\lib\site-packages\fastcore\foundation.py in __init__(self, items, use_list, match, *rest)
    305         if (use_list is not None) or not _is_array(items):
--> 306             items = list(items) if use_list else _listify(items)
    307         if match is not None:

~\Anaconda3\lib\site-packages\fastcore\foundation.py in _listify(o)
    241     if isinstance(o, str) or _is_array(o): return [o]
--> 242     if is_iter(o): return list(o)
    243     return [o]

~\Anaconda3\lib\site-packages\fastcore\foundation.py in __call__(self, *args, **kwargs)
    207         fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
--> 208         return self.fn(*fargs, **kwargs)
    209 

~\Anaconda3\lib\site-packages\fastai2\learner.py in _call_one(self, event_name)
    110         assert hasattr(event, event_name)
--> 111         [cb(event_name) for cb in sort_by_run(self.cbs)]
    112 

~\Anaconda3\lib\site-packages\fastai2\learner.py in <listcomp>(.0)
    110         assert hasattr(event, event_name)
--> 111         [cb(event_name) for cb in sort_by_run(self.cbs)]
    112 

~\Anaconda3\lib\site-packages\fastai2\callback\core.py in __call__(self, event_name)
     22                (self.run_valid and not getattr(self, 'training', False)))
---> 23         if self.run and _run: getattr(self, event_name, noop)()
     24         if event_name=='after_fit': self.run=True #Reset self.run to True at each end of fit

<ipython-input-13-aa0bc7c3e6b5> in after_loss(self)
     24     def after_loss(self):
---> 25         loss0 = self.loss_func0(self.learn.pred, *self.learn.yb[0], reduction='none')
     26         loss1 = self.loss_func0(self.learn.pred, *self.learn.yb[1], reduction='none')

~\Anaconda3\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs)
    531         else:
--> 532             result = self.forward(*input, **kwargs)
    533         for hook in self._forward_hooks.values():

<ipython-input-11-4dd00339d91c> in forward(self, xs, reduction, *ys)
      7         for i, w, x, y in zip(range(len(xs)), self.w, xs, ys):
----> 8             if i == 0: loss = w*self.func(x, y, reduction=reduction)
      9             else: loss += w*self.func(x, y, reduction=reduction)

~\Anaconda3\lib\site-packages\torch\nn\functional.py in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction)
   2020         reduction = _Reduction.legacy_get_string(size_average, reduce)
-> 2021     return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
   2022 

~\Anaconda3\lib\site-packages\torch\nn\functional.py in nll_loss(input, target, weight, size_average, ignore_index, reduce, reduction)
   1837     if dim == 2:
-> 1838         ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
   1839     elif dim == 4:

RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #2 'target' in call to _thnn_nll_loss_forward

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
<ipython-input-18-d81c6bd29d71> in <module>
----> 1 learn.lr_find()

~\Anaconda3\lib\site-packages\fastai2\callback\schedule.py in lr_find(self, start_lr, end_lr, num_it, stop_div, show_plot, suggestions)
    217     n_epoch = num_it//len(self.dls.train) + 1
    218     cb=LRFinder(start_lr=start_lr, end_lr=end_lr, num_it=num_it, stop_div=stop_div)
--> 219     with self.no_logging(): self.fit(n_epoch, cbs=cb)
    220     if show_plot: self.recorder.plot_lr_find()
    221     if suggestions:

~\Anaconda3\lib\site-packages\fastai2\learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
    174                     try:
    175                         self.epoch=epoch;          self('begin_epoch')
--> 176                         self._do_epoch_train()
    177                         self._do_epoch_validate()
    178                     except CancelEpochException:   self('after_cancel_epoch')

~\Anaconda3\lib\site-packages\fastai2\learner.py in _do_epoch_train(self)
    147         try:
    148             self.dl = self.dls.train;                        self('begin_train')
--> 149             self.all_batches()
    150         except CancelTrainException:                         self('after_cancel_train')
    151         finally:                                             self('after_train')

~\Anaconda3\lib\site-packages\fastai2\learner.py in all_batches(self)
    125     def all_batches(self):
    126         self.n_iter = len(self.dl)
--> 127         for o in enumerate(self.dl): self.one_batch(*o)
    128 
    129     def one_batch(self, i, b):

~\Anaconda3\lib\site-packages\fastai2\learner.py in one_batch(self, i, b)
    139             self.opt.zero_grad()
    140         except CancelBatchException:                         self('after_cancel_batch')
--> 141         finally:                                             self('after_batch')
    142 
    143     def _do_begin_fit(self, n_epoch):

~\Anaconda3\lib\site-packages\fastai2\learner.py in __call__(self, event_name)
    106     def ordered_cbs(self, cb_func): return [cb for cb in sort_by_run(self.cbs) if hasattr(cb, cb_func)]
    107 
--> 108     def __call__(self, event_name): L(event_name).map(self._call_one)
    109     def _call_one(self, event_name):
    110         assert hasattr(event, event_name)

~\Anaconda3\lib\site-packages\fastcore\foundation.py in map(self, f, *args, **kwargs)
    360              else f.format if isinstance(f,str)
    361              else f.__getitem__)
--> 362         return self._new(map(g, self))
    363 
    364     def filter(self, f, negate=False, **kwargs):

~\Anaconda3\lib\site-packages\fastcore\foundation.py in _new(self, items, *args, **kwargs)
    313     @property
    314     def _xtra(self): return None
--> 315     def _new(self, items, *args, **kwargs): return type(self)(items, *args, use_list=None, **kwargs)
    316     def __getitem__(self, idx): return self._get(idx) if is_indexer(idx) else L(self._get(idx), use_list=None)
    317     def copy(self): return self._new(self.items.copy())

~\Anaconda3\lib\site-packages\fastcore\foundation.py in __call__(cls, x, *args, **kwargs)
     39             return x
     40 
---> 41         res = super().__call__(*((x,) + args), **kwargs)
     42         res._newchk = 0
     43         return res

~\Anaconda3\lib\site-packages\fastcore\foundation.py in __init__(self, items, use_list, match, *rest)
    304         if items is None: items = []
    305         if (use_list is not None) or not _is_array(items):
--> 306             items = list(items) if use_list else _listify(items)
    307         if match is not None:
    308             if is_coll(match): match = len(match)

~\Anaconda3\lib\site-packages\fastcore\foundation.py in _listify(o)
    240     if isinstance(o, list): return o
    241     if isinstance(o, str) or _is_array(o): return [o]
--> 242     if is_iter(o): return list(o)
    243     return [o]
    244 

~\Anaconda3\lib\site-packages\fastcore\foundation.py in __call__(self, *args, **kwargs)
    206             if isinstance(v,_Arg): kwargs[k] = args.pop(v.i)
    207         fargs = [args[x.i] if isinstance(x, _Arg) else x for x in self.pargs] + args[self.maxi+1:]
--> 208         return self.fn(*fargs, **kwargs)
    209 
    210 # Cell

~\Anaconda3\lib\site-packages\fastai2\learner.py in _call_one(self, event_name)
    109     def _call_one(self, event_name):
    110         assert hasattr(event, event_name)
--> 111         [cb(event_name) for cb in sort_by_run(self.cbs)]
    112 
    113     def _bn_bias_state(self, with_bias): return bn_bias_params(self.model, with_bias).map(self.opt.state)

~\Anaconda3\lib\site-packages\fastai2\learner.py in <listcomp>(.0)
    109     def _call_one(self, event_name):
    110         assert hasattr(event, event_name)
--> 111         [cb(event_name) for cb in sort_by_run(self.cbs)]
    112 
    113     def _bn_bias_state(self, with_bias): return bn_bias_params(self.model, with_bias).map(self.opt.state)

~\Anaconda3\lib\site-packages\fastai2\callback\core.py in __call__(self, event_name)
     21         _run = (event_name not in _inner_loop or (self.run_train and getattr(self, 'training', True)) or
     22                (self.run_valid and not getattr(self, 'training', False)))
---> 23         if self.run and _run: getattr(self, event_name, noop)()
     24         if event_name=='after_fit': self.run=True #Reset self.run to True at each end of fit
     25 

~\Anaconda3\lib\site-packages\fastai2\learner.py in after_batch(self)
    387         if len(self.yb) == 0: return
    388         mets = self._train_mets if self.training else self._valid_mets
--> 389         for met in mets: met.accumulate(self.learn)
    390         if not self.training: return
    391         self.lrs.append(self.opt.hypers[-1]['lr'])

~\Anaconda3\lib\site-packages\fastai2\learner.py in accumulate(self, learn)
    350     def accumulate(self, learn):
    351         self.count += 1
--> 352         self.val = torch.lerp(to_detach(learn.loss.mean(), gather=False), self.val, self.beta)
    353     @property
    354     def value(self): return self.val/(1-self.beta**self.count)

AttributeError: 'NoneType' object has no attribute 'mean'

This is my code:

# Create databunch
db = DataBlock(blocks=(ImageBlock(cls=PILImageBW), *(3*[CategoryBlock])),
                    getters=[ColReader('image_id', pref=TRAIN, suff='.png'),   # input
                             ColReader('species'),  
                             ColReader('genus'),   
                             ColReader('geo')],  
                    splitter=IndexSplitter(df.loc[df.fold==fold].index))

tfms = aug_transforms(do_flip=False, size=sz)
tfms += [Normalize.from_stats(*imagenet_stats)]
dls = db.dataloaders(df, bs=bs, batch_tfms=tfms, num_workers=0)
dls.n_inp = 1 # number of inputs

learn = Learner(dls, model, loss_func=Loss_combine(), cbs=[MixUp(), CSVLogger()],
                metrics=[RecallPartial(a=i) for i in range(len(dls.c))] + [RecallCombine()],
                splitter=lambda m: [list(m.body.parameters()), list(m.tails.parameters())])

learn.lr_find() --> **this is where it fails**

torch.cuda.is_available() – True
torch.backends.cudnn.enabled – True

Any pointers?

Thanks!

%debug

Although my Windows isn’t running very fast - for the course it will do anything you need it to - particularly with a 2080Ti. I’ll also be documenting how to get an Azure VM running Ubuntu up and running. Once you are in Jupyter Notebooks then really not much difference in the user experience. Same for the other vendors too. I’m old enough that I started on UNIX - so not as much of a learning curve - but plenty of people willing to help here Peter - you don’t have to give up :).

Hi Brian, I really appreciate your encouragement, interest and effort to contact me; THANK YOU VERY MUCH;

it may sound trite and hackneyed but I am sincerely humbled and actually feel a slight pang at the generosity that you, and some others, display and extend so selflessly.

Contrary to my perceived profile, I’m generally not a quitter. I did actually get all of pjh’s (professor Jeremy Howard’s) course stuff working; that is from all 3 previous courses. It is when I yeilded to my intrinsic stupidity and tried to install Cuda and all the other ‘dangerous to children’ stuff that I was ground into alternative deprecating and self-abusing avoidance behavior. My tiny mind cannot tolerate hours of mindless downloading (Australian steam powered internet) and monkey-see-monkey-do behavior with the mandatory requisites of exacting attention to wide version control, compatability, path maintenance and other dogmatical installation and set-up requirements. I feel tired already!

I also suffer substantial pride, a daunting ego and tireless impatience.

Apart from the above, I am really keen and ready to go.

Determined to properly ‘do’ pjh’s next online course in a few weeks, my preparations are underway, so I may call upon you, as invited - so be warned and have your excuses ready; I will understand.

As part of my preliminaries I’m considering buying (and reading) Jason Brownlee’s ebook “Deep Learning for Computer Vision” for US$37 from " http://machinelearningmastery.com/", and I would appreciate your opinion if you have seen it. Pjh’s courses are just so well researched and prepared, and they are presented so well with fantastic detail and invaluable anecdotal nuggets for all entry levels that such a diversion at this stage may be counterproductive.

My real interest is in ‘Feature Recognition and Extraction’ and that which I can best describe as its complementary dual ‘Feature Definition and Description’. This may appear a bit esoteric but in essence it refers to the idea of DESCRIBING a feature to look for, and this ‘description’ would not be restricted to verbal - I’m sorry if this sounds sloppy, it is - the idea is to allow the user to describe the objects in question or being sought so as to guide the process of Feature Extraction; the features could comprise base classes, derivatives (children) and ‘transfer features’ from other libraries. This Feature Extraction idea seems best setup with a Graphical User Interface and libraries. The GUI description can consist of dialog boxes, check boxes, radio buttons and can be augmented by pictures or any other media and feature libraries. Yep, I’m proposing an Object Oriented approach to feature definition. I don’t know if this has been tried or is even a good idea and seek your comments if you are interested. The result could bb to enable a search for faces with blue eyes and big ears etc. similar to a police identikit that we see on tv. Does this interest you? What do you think? Please be frank.

End of rant!

Brian, back to reality, again I sincerely thank you for your mail and kind offer.

Sorry for the rant, but I thought you might be interested.

Cheers Brian, p.

On Mar 3, 2020, at 13:34, Brian Smith via Deep Learning Course Forums < do-not-reply@fast.ai> wrote:

brismith Brian Smith
March 3

Although my Windows isn’t running very fast - for the course it will do anything you need it to - particularly with a 2080Ti. I’ll also be documenting how to get an Azure VM running Ubuntu up and running. Once you are in Jupyter Notebooks then really not much difference in the user experience. Same for the other vendors too. I’m old enough that I started on UNIX - so not as much of a learning curve - but plenty of people willing to help here Peter - you don’t have to give up :).

 PeterKelly:

far too old to learn Ubuntu and command line typing so I gave up!

Visit Topic to respond.

In Reply To

PeterKelly Peter Kelly (OZ)
February 24

Me too, so I gave up - far too old to learn Ubuntu and command line typing so I gave up! Bloody sad; My 2080Ti does render text very well. Looking forward to developments for windows. Cheers and good luck, Peter Kelly, Oz.

Visit Topic to respond.

To unsubscribe from these emails, click here.

1 Like

Anyone had success in installing and using fastai2 on Windows WSL Ubuntu ?

i didn’t read that book. i know machinelearning mastery have very good resources, so i think the book will be very good. one thing to note is that the book is using Keras, which is TensorFlow and Jeremy uses Pytorch for his course. It may be confusing to learn two frameworks at the same time…

1 Like

I installed fastai2 in WSL (ubuntu), and I use Ananconda 3. I created 2 virtual environments (a regular one, and editable one). I use the editable one on a regular basis.

If you have any problem installing it, you can post your questions here and I will try to walk you through the steps in order to be able to install it on your local machine.

1 Like

thank you Farid, that would be fantastic. i am just starting to use WSL Ubuntu on Windows… i have lots of issues, some silly questions expected xD

i installed miniconda 3 and did editable fastai2 intall and tried to run jupyter notebook but got error message below. however the notebook runs when i copy and pase the localhost url, so that’s OK for now :slight_smile:

also tried to install cuda drivers as per this instruction but it run out of free space on this Ubuntu WSL. not sure how to increase the disk size on the WSL Ubuntu. like for example i can’t see my other drives that i can access via Windows.
Edit: i was simply running out of space on my disk xD, but as explained below WSL at the moment doesn’t support GPU so will not work anyway.
Windows C drive is mounted at /mnt/c/ on WSL :wink:

thanks a lot!

@miwojc, I would uninstall the miniconda 3 version, and would install the full version of Anaconda.

Here is a video tutorial on how to install Anaconda on ubuntu.

and Here are the instructions that I wrote down while installing mine:

How to install Anaconda 3 on Windows Subsystem Linux
====================================================

$ curl -O https://repo.anaconda.com/archive/Anaconda3-2019.10-Linux-x86_64.sh

$ sha256sum Anaconda3-2019.10-Linux-x86_64.sh

it will print this :
46d762284d252e51cd58a8ca6c8adc9da2eadc82c342927b2f66ed011d1d8b53 Anaconda3-2019.10-Linux-x86_64.sh

$ bash Anaconda3-2019.10-Linux-x86_64.sh
$ source ~/.bashrc

$ conda list

If you want to install the latest version of Anaconda (for ubuntu), check this link

1 Like

thank you.
for some reason (anaconda loads a lot of stuff i don’t need) i prefer to use miniconda, which is same but with less packages loaded by default. i use miniconda on native ubuntu installs and it works great with fastai. however if this would fix my issue i am fine to install anaconda!

apart from installing Anaconda and fastai2 did you have to install cuda drivers separately?

Unfortunately, I never used miniconda.

You don’t have to install cuda because it isn’t supported by WSL for now. When, I need to use the GPU, I use the Anaconda version that I installed on Windows: I have the 2 versions installed on the same machine. I also use VSCode, and that way I can open my 2 repos side by side. I always test my project on the 2 platforms.

1 Like