fastai / fastai2

Temporary home for fastai v2 while it's being developed
https://dev.fast.ai
Apache License 2.0
645 stars 235 forks source link

Learning rate finder breaks with pytorch DataLoader #514

Closed scart97 closed 4 years ago

scart97 commented 4 years ago

Please confirm you have the latest versions of fastai, fastcore, fastscript, and nbdev prior to reporting a bug: YES

Updated versions of all libs, fastai2 is installed as an editable install from current master (commit 0ceb34a)

Describe the bug While running a learning rate test with a Learner that has a pytorch DataLoader and uses CudaCallback, one error happens before the test ends, at the point where the old checkpoint is being loaded.

To Reproduce Steps to reproduce the behavior:

  1. Try to run a learning rate find test learn.lr_find() on the notebook nbs/examples/migrating_pytorch.ipynb

gist link demonstrating error: https://gist.github.com/scart97/a3cc3ba4aeddc5b640f283fd0522d8dd

Expected behavior Learning rate find test finish without errors.

Error with full stack trace

Full stack trace in the linked notebook. Important part here:

~/audio/fastai2/fastai2/learner.py in load(self, file, with_opt, device, **kwargs)
    287     @delegates(load_model)
    288     def load(self, file, with_opt=None, device=None, **kwargs):
--> 289         if device is None: device = self.dls.device
    290         if self.opt is None: self.create_opt()
    291         file = join_path_file(file, self.path/self.model_dir, ext='.pth')

~/miniconda3/envs/fastai2_migrate/lib/python3.7/site-packages/fastcore/foundation.py in __getattr__(self, k)
    232         if self._component_attr_filter(k):
    233             attr = getattr(self,self._default,None)
--> 234             if attr is not None: return getattr(attr,k)
    235         raise AttributeError(k)
    236     def __dir__(self): return custom_dir(self,self._dir())

AttributeError: 'DataLoader' object has no attribute 'device'

Additional context Add any other context about the problem here.