This is my error when I use the fit()
method of the Learner with:
-
dls = DataLoaders(train_dl, valid_dl)
# train_dl and valid_dl are Pytorch Dataloader
-
cbs = [CudaCallback]
# and others
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-29-b60c6a88c37b> in <module>
----> 1 learn.fit(1, 1e-2) # learn.fit_one_cycle(1, 1e-2)
~/.local/lib/python3.9/site-packages/fastai/learner.py in fit(self, n_epoch, lr, wd, cbs, reset_opt)
210 self.opt.set_hypers(lr=self.lr if lr is None else lr)
211 self.n_epoch = n_epoch
--> 212 self._with_events(self._do_fit, 'fit', CancelFitException, self._end_cleanup)
213
214 def _end_cleanup(self): self.dl,self.xb,self.yb,self.pred,self.loss = None,(None,),(None,),None,None
~/.local/lib/python3.9/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
158
159 def _with_events(self, f, event_type, ex, final=noop):
--> 160 try: self(f'before_{event_type}'); f()
161 except ex: self(f'after_cancel_{event_type}')
162 self(f'after_{event_type}'); final()
~/.local/lib/python3.9/site-packages/fastai/learner.py in _do_fit(self)
201 for epoch in range(self.n_epoch):
202 self.epoch=epoch
--> 203 self._with_events(self._do_epoch, 'epoch', CancelEpochException)
204
205 def fit(self, n_epoch, lr=None, wd=None, cbs=None, reset_opt=False):
~/.local/lib/python3.9/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
158
159 def _with_events(self, f, event_type, ex, final=noop):
--> 160 try: self(f'before_{event_type}'); f()
161 except ex: self(f'after_cancel_{event_type}')
162 self(f'after_{event_type}'); final()
~/.local/lib/python3.9/site-packages/fastai/learner.py in _do_epoch(self)
195
196 def _do_epoch(self):
--> 197 self._do_epoch_train()
198 self._do_epoch_validate()
199
~/.local/lib/python3.9/site-packages/fastai/learner.py in _do_epoch_train(self)
187 def _do_epoch_train(self):
188 self.dl = self.dls.train
--> 189 self._with_events(self.all_batches, 'train', CancelTrainException)
190
191 def _do_epoch_validate(self, ds_idx=1, dl=None):
~/.local/lib/python3.9/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
158
159 def _with_events(self, f, event_type, ex, final=noop):
--> 160 try: self(f'before_{event_type}'); f()
161 except ex: self(f'after_cancel_{event_type}')
162 self(f'after_{event_type}'); final()
~/.local/lib/python3.9/site-packages/fastai/learner.py in all_batches(self)
164 def all_batches(self):
165 self.n_iter = len(self.dl)
--> 166 for o in enumerate(self.dl): self.one_batch(*o)
167
168 def _do_one_batch(self):
~/.local/lib/python3.9/site-packages/fastai/learner.py in one_batch(self, i, b)
181 def one_batch(self, i, b):
182 self.iter = i
--> 183 b_on_device = tuple( e.to(device=self.dls.device) for e in b if hasattr(e, "to")) if self.dls.device is not None else b
184 self._split(b_on_device)
185 self._with_events(self._do_one_batch, 'batch', CancelBatchException)
~/.local/lib/python3.9/site-packages/fastcore/basics.py in __getattr__(self, k)
386 if self._component_attr_filter(k):
387 attr = getattr(self,self._default,None)
--> 388 if attr is not None: return getattr(attr,k)
389 raise AttributeError(k)
390 def __dir__(self): return custom_dir(self,self._dir())
AttributeError: 'DataLoader' object has no attribute 'device'
And this is my error at creating the Learner with on of these options for the dls
:
dls = DataLoaders(train_dl, valid_dl, device="cuda")
dls = DataLoaders(train_dl, valid_dl).cuda()
dls = DataLoaders(train_dl, valid_dl).to("cuda")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-33-5e8af8ac536d> in <module>
----> 1 learn = Learner(dls = DataLoaders(train_dl, valid_dl, device="cuda"),
2 model = MyModel(),
3 loss_func = CrossEntropyLossFlat())
~/.local/lib/python3.9/site-packages/fastai/data/core.py in __init__(self, path, device, *loaders)
142 def __init__(self, *loaders, path='.', device=None):
143 self.loaders,self.path = list(loaders),Path(path)
--> 144 if device is not None or hasattr(loaders[0],'to'): self.device = device
145
146 def __getitem__(self, i): return self.loaders[i]
~/.local/lib/python3.9/site-packages/fastai/data/core.py in device(self, d)
158 @device.setter
159 def device(self, d):
--> 160 for dl in self.loaders: dl.to(d)
161 self._device = d
162
AttributeError: 'DataLoader' object has no attribute 'to'