fastai icon indicating copy to clipboard operation
fastai copied to clipboard

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

Open baida21 opened this issue 2 years ago • 3 comments
trafficstars

HI, I have a mac prp 2017 2.3 GHz Dual-Core Intel Core i5 and no "MPS" backend. Graphics : Intel Iris Plus Graphics 640 1536 MB

Fastai version : 2.7.12

I've tried to make a learn with "CPU" but got a error message like a title. "RuntimeError: The MPS backend is supported RuntimeError: The MPS backend is supported on MacOS 12.3+.Current OS version can be queried using sw_vers"

The code is simple. ` from fastai.vision.all import *

trn_path = Path('./train_images') dls = ImageDataLoaders.from_folder(trn_path, seed=316, valid_pct=0.2, bs=128, item_tfms=[Resize((224, 224))], batch_tfms=aug_transforms(min_scale=0.75), ) `

so tried to change a device to "CPU"

` from fastai.vision.all import * defaults.device = default_device(use=-1)

print(default_device(use=-1)) ... ` But no changes. It shows "mps"

Spending some time to verify the source code, added up following codes and the problem is resolved.

` from fastai.torch_core import defaults

defaults.use_cuda = False `

  • Code snippets in fastai/torch_core.py

` defaults.use_cuda = None

def default_device(use=-1): "Return or set default device; use_cuda: -1 - CUDA/mps if available; True - error if not available; False - CPU" if use == -1: use = defaults.use_cuda else: defaults.use_cuda=use if use is None: if torch.cuda.is_available() or _has_mps(): use = True if use: if torch.cuda.is_available(): return torch.device(torch.cuda.current_device()) if _has_mps(): return torch.device('mps') return torch.device('cpu')

` The reason I thought is that the function of _has_mps() return "True".

I am not sure it is a bug or intended result, but showing "mps" on Mac Pro which does not support MPS, appears to be a bug.

Please take a look.

baida21 avatar Sep 01 '23 00:09 baida21

 ImageDataLoaders.from_folder (path, train='train', valid='valid',
                               valid_pct=None, seed=None, vocab=None,
                               item_tfms=None, batch_tfms=None,
                               img_cls=<class
                               'fastai.vision.core.PILImage'>, bs:int=64,
                               val_bs:int=None, shuffle:bool=True,
                               device=None)

in the from_folder function, you can set device= torch.device('cpu')

hpmax00 avatar Sep 01 '23 09:09 hpmax00

I'm using Datablock what should I do

XxMicrowavexX avatar Sep 25 '23 01:09 XxMicrowavexX

I'm using Datablock what should I do

@XxMicrowavexX it works in my case

dls = DataBlock( blocks=(ImageBlock, CategoryBlock), get_items=get_image_files, splitter=RandomSplitter(valid_pct=0.2, seed=42), get_y=parent_label, item_tfms=[Resize(192, method='squish')] ).dataloaders(path, bs=32, device='cpu')

hatttruong avatar Oct 09 '23 06:10 hatttruong