Issue with MPS and dataloaders on Mac Intel

Hi,

I am trying to do lesson 4 of Fast AI course, but i get an issue when i add “dataloaders”. There seems to be an issue with the compatibility of my Mac 12.6.4 Intel Core i5 and MPS. What can I do about it?

Here is the error message I get:

‘’'Could not do one pass in your dataloader, there is something wrong in it. Please see the stack trace below:

RuntimeError Traceback (most recent call last)
Cell In[90], line 2
1 get_imdb = partial(get_text_files, folders=[‘train’, ‘test’, ‘unsup’])
----> 2 dls_lm = DataBlock(
3 blocks = TextBlock.from_folder(path, is_lm=True),
4 get_items = get_imdb, splitter=RandomSplitter(0.1)).dataloaders(path, path = path, bs=128, seq_len = 80)

File ~/mambaforge/lib/python3.10/site-packages/fastai/data/block.py:157, in DataBlock.dataloaders(self, source, path, verbose, **kwargs)
155 dsets = self.datasets(source, verbose=verbose)
156 kwargs = {**self.dls_kwargs, **kwargs, ‘verbose’: verbose}
→ 157 return dsets.dataloaders(path=path, after_item=self.item_tfms, after_batch=self.batch_tfms, **kwargs)

File ~/mambaforge/lib/python3.10/site-packages/fastai/data/core.py:337, in FilteredBase.dataloaders(self, bs, shuffle_train, shuffle, val_shuffle, n, path, dl_type, dl_kwargs, device, drop_last, val_bs, **kwargs)
335 dl = dl_type(self.subset(0), **merge(kwargs,def_kwargs, dl_kwargs[0]))
336 def_kwargs = {‘bs’:bs if val_bs is None else val_bs,‘shuffle’:val_shuffle,‘n’:None,‘drop_last’:False}
→ 337 dls = [dl] + [dl.new(self.subset(i), **merge(kwargs,def_kwargs,val_kwargs,dl_kwargs[i]))
338 for i in range(1, self.n_subsets)]
339 return self._dbunch_type(*dls, path=path, device=device)

File ~/mambaforge/lib/python3.10/site-packages/fastai/data/core.py:337, in (.0)
335 dl = dl_type(self.subset(0), **merge(kwargs,def_kwargs, dl_kwargs[0]))
336 def_kwargs = {‘bs’:bs if val_bs is None else val_bs,‘shuffle’:val_shuffle,‘n’:None,‘drop_last’:False}
→ 337 dls = [dl] + [dl.new(self.subset(i), **merge(kwargs,def_kwargs,val_kwargs,dl_kwargs[i]))
338 for i in range(1, self.n_subsets)]
339 return self._dbunch_type(*dls, path=path, device=device)

File ~/mambaforge/lib/python3.10/site-packages/fastai/text/data.py:108, in LMDataLoader.new(self, dataset, seq_len, **kwargs)
106 lens = self.lens.coll if dataset is None else None
107 seq_len = self.seq_len if seq_len is None else seq_len
→ 108 return super().new(dataset=dataset, lens=lens, seq_len=seq_len, **kwargs)

File ~/mambaforge/lib/python3.10/site-packages/fastai/data/core.py:97, in TfmdDL.new(self, dataset, cls, **kwargs)
95 if not hasattr(self, ‘_n_inp’) or not hasattr(self, ‘_types’):
96 try:
—> 97 self._one_pass()
98 res._n_inp,res._types = self._n_inp,self._types
99 except Exception as e:

File ~/mambaforge/lib/python3.10/site-packages/fastai/data/core.py:79, in TfmdDL._one_pass(self)
77 def _one_pass(self):
78 b = self.do_batch([self.do_item(None)])
—> 79 if self.device is not None: b = to_device(b, self.device)
80 its = self.after_batch(b)
81 self._n_inp = 1 if not isinstance(its, (list,tuple)) or len(its)==1 else len(its)-1

File ~/mambaforge/lib/python3.10/site-packages/fastai/torch_core.py:285, in to_device(b, device, non_blocking)
283 # if hasattr(o, “to_device”): return o.to_device(device)
284 return o
→ 285 return apply(_inner, b)

File ~/mambaforge/lib/python3.10/site-packages/fastai/torch_core.py:222, in apply(func, x, *args, **kwargs)
220 def apply(func, x, *args, **kwargs):
221 “Apply func recursively to x, passing on args”
→ 222 if is_listy(x): return type(x)([apply(func, o, *args, **kwargs) for o in x])
223 if isinstance(x,dict): return {k: apply(func, v, *args, **kwargs) for k,v in x.items()}
224 res = func(x, *args, **kwargs)

File ~/mambaforge/lib/python3.10/site-packages/fastai/torch_core.py:222, in (.0)
220 def apply(func, x, *args, **kwargs):
221 “Apply func recursively to x, passing on args”
→ 222 if is_listy(x): return type(x)([apply(func, o, *args, **kwargs) for o in x])
223 if isinstance(x,dict): return {k: apply(func, v, *args, **kwargs) for k,v in x.items()}
224 res = func(x, *args, **kwargs)

File ~/mambaforge/lib/python3.10/site-packages/fastai/torch_core.py:224, in apply(func, x, *args, **kwargs)
222 if is_listy(x): return type(x)([apply(func, o, *args, **kwargs) for o in x])
223 if isinstance(x,dict): return {k: apply(func, v, *args, **kwargs) for k,v in x.items()}
→ 224 res = func(x, *args, **kwargs)
225 return res if x is None else retain_type(res, x)

File ~/mambaforge/lib/python3.10/site-packages/fastai/torch_core.py:282, in to_device.._inner(o)
281 def _inner(o):
→ 282 if isinstance(o,Tensor): return o.to(device, non_blocking=non_blocking)
283 # if hasattr(o, “to_device”): return o.to_device(device)
284 return o

File ~/mambaforge/lib/python3.10/site-packages/fastai/torch_core.py:382, in TensorBase.torch_function(cls, func, types, args, kwargs)
380 if cls.debug and func.name not in (‘str’,‘repr’): print(func, types, args, kwargs)
381 if _torch_handled(args, cls._opt, func): types = (torch.Tensor,)
→ 382 res = super().torch_function(func, types, args, ifnone(kwargs, {}))
383 dict_objs = _find_args(args) if args else _find_args(list(kwargs.values()))
384 if issubclass(type(res),TensorBase) and dict_objs: res.set_meta(dict_objs[0],as_copy=True)

File ~/mambaforge/lib/python3.10/site-packages/torch/_tensor.py:1295, in Tensor.torch_function(cls, func, types, args, kwargs)
1292 return NotImplemented
1294 with _C.DisableTorchFunctionSubclass():
→ 1295 ret = func(*args, **kwargs)
1296 if func in get_default_nowrap_functions():
1297 return ret

RuntimeError: The MPS backend is supported on MacOS 12.3+.Current OS version can be queried using sw_vers’‘’

Hi!
Got same error on MBP 2015 with Intel i7 and MacOS 12.7.2
Any chance to fix it?

This is a torch issue, I recommend opening an issue on the PyTorch repo or in the torch forums for fixing, it’s not fastai related

1 Like