When I am trying to predict using CPU, I’m seeing errors related to CUDA drivers.
Code:
device = 'cpu'
dls_clas = torch.load(f"{path}/ulm_clas.pkl", map_location=device)
opt_func = partial(Adam, wd=0.1)
loss_f = CrossEntropyLossFlat()
learn = text_classifier_learner(dls_clas, AWD_LSTM, path=path, drop_mult=1.0, opt_func=opt_func, loss_func=loss_f)
learn.dls.device = device
test_df = pd.read_csv(args.test_file)
test_df['text'] = test_df['Subject'] + ". " + test_df['Description']
test_dl = learn.dls.test_dl(test_items=test_df['text'], verbose=True)
learn.load('ulm_base', device=device)
_,preds_base_raw_1,_,_ = learn.get_preds(dl=test_dl, with_input=True, with_decoded=True, reorder=True)
Errors:
AssertionError:
Found no NVIDIA driver on your system. Please check that you
have an NVIDIA GPU and installed a driver from
http://www.nvidia.com/Download/index.aspx
AssertionError Traceback (most recent call last)
in engine
----> 1 _,preds_base_raw_1,_,_ = learn.get_preds(dl=test_dl, with_input=True, with_decoded=True, reorder=True)
/home/cdsw/.local/lib/python3.6/site-packages/fastai/learner.py in get_preds(self, ds_idx, dl, with_input, with_decoded, with_loss, act, inner, reorder, cbs, n_workers, **kwargs)
233 if with_loss: ctx_mgrs.append(self.loss_not_reduced())
234 with ContextManagers(ctx_mgrs):
--> 235 self._do_epoch_validate(dl=dl)
236 if act is None: act = getattr(self.loss_func, 'activation', noop)
237 res = cb.all_tensors()
/home/cdsw/.local/lib/python3.6/site-packages/fastai/learner.py in _do_epoch_validate(self, ds_idx, dl)
186 if dl is None: dl = self.dls[ds_idx]
187 self.dl = dl
--> 188 with torch.no_grad(): self._with_events(self.all_batches, 'validate', CancelValidException)
189
190 def _do_epoch(self):
/home/cdsw/.local/lib/python3.6/site-packages/fastai/learner.py in _with_events(self, f, event_type, ex, final)
153
154 def _with_events(self, f, event_type, ex, final=noop):
--> 155 try: self(f'before_{event_type}') ;f()
156 except ex: self(f'after_cancel_{event_type}')
157 finally: self(f'after_{event_type}') ;final()
/home/cdsw/.local/lib/python3.6/site-packages/fastai/learner.py in all_batches(self)
159 def all_batches(self):
160 self.n_iter = len(self.dl)
--> 161 for o in enumerate(self.dl): self.one_batch(*o)
162
163 def _do_one_batch(self):
/home/cdsw/.local/lib/python3.6/site-packages/fastai/data/load.py in __iter__(self)
102 self.before_iter()
103 for b in _loaders[self.fake_l.num_workers==0](self.fake_l):
--> 104 if self.device is not None: b = to_device(b, self.device)
105 yield self.after_batch(b)
106 self.after_iter()
/home/cdsw/.local/lib/python3.6/site-packages/fastai/torch_core.py in to_device(b, device)
215 elif device is None: device=default_device()
216 def _inner(o): return o.to(device, non_blocking=True) if isinstance(o,Tensor) else o.to_device(device) if hasattr(o, "to_device") else o
--> 217 return apply(_inner, b)
218
219 # Cell
/home/cdsw/.local/lib/python3.6/site-packages/fastai/torch_core.py in apply(func, x, *args, **kwargs)
163 def apply(func, x, *args, **kwargs):
164 "Apply `func` recursively to `x`, passing on args"
--> 165 if is_listy(x): return type(x)([apply(func, o, *args, **kwargs) for o in x])
166 if isinstance(x,dict): return {k: apply(func, v, *args, **kwargs) for k,v in x.items()}
167 res = func(x, *args, **kwargs)
/home/cdsw/.local/lib/python3.6/site-packages/fastai/torch_core.py in <listcomp>(.0)
163 def apply(func, x, *args, **kwargs):
164 "Apply `func` recursively to `x`, passing on args"
--> 165 if is_listy(x): return type(x)([apply(func, o, *args, **kwargs) for o in x])
166 if isinstance(x,dict): return {k: apply(func, v, *args, **kwargs) for k,v in x.items()}
167 res = func(x, *args, **kwargs)
/home/cdsw/.local/lib/python3.6/site-packages/fastai/torch_core.py in apply(func, x, *args, **kwargs)
165 if is_listy(x): return type(x)([apply(func, o, *args, **kwargs) for o in x])
166 if isinstance(x,dict): return {k: apply(func, v, *args, **kwargs) for k,v in x.items()}
--> 167 res = func(x, *args, **kwargs)
168 return res if x is None else retain_type(res, x)
169
/home/cdsw/.local/lib/python3.6/site-packages/fastai/torch_core.py in _inner(o)
214 if defaults.use_cuda==False: device='cpu'
215 elif device is None: device=default_device()
--> 216 def _inner(o): return o.to(device, non_blocking=True) if isinstance(o,Tensor) else o.to_device(device) if hasattr(o, "to_device") else o
217 return apply(_inner, b)
218
/home/cdsw/.local/lib/python3.6/site-packages/fastai/torch_core.py in _f(self, *args, **kwargs)
298 def _f(self, *args, **kwargs):
299 cls = self.__class__
--> 300 res = getattr(super(TensorBase, self), fn)(*args, **kwargs)
301 return retain_type(res, self, copy_meta=True)
302 return _f
/home/cdsw/.local/lib/python3.6/site-packages/torch/cuda/__init__.py in _lazy_init()
184 raise RuntimeError(
185 "Cannot re-initialize CUDA in forked subprocess. " + msg)
--> 186 _check_driver()
187 if _cudart is None:
188 raise AssertionError(
/home/cdsw/.local/lib/python3.6/site-packages/torch/cuda/__init__.py in _check_driver()
66 Found no NVIDIA driver on your system. Please check that you
67 have an NVIDIA GPU and installed a driver from
---> 68 http://www.nvidia.com/Download/index.aspx""")
69 else:
70 # TODO: directly link to the alternative bin that needs install
AssertionError:
Found no NVIDIA driver on your system. Please check that you
have an NVIDIA GPU and installed a driver from
http://www.nvidia.com/Download/index.aspx
Is there any other place that I need to set the device?