File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 2121 else :
2222 torch .set_default_tensor_type (torch .cuda .FloatTensor )
2323elif torch .backends .mps .is_available ():
24+ fallback_device = torch .get_default_device ()
2425 torch .set_default_device ("mps" )
25- torch ._dynamo .disable () # A temporary trick to evade the Pytorch MPS bug (https://github.com/pytorch/pytorch/issues/149184)
26+
27+ # As of March 2025, the MacOS X-based GitHub Actions building enviroment sees
28+ # the MPS GPU, but can't access it. Thus as try-except workaround is applied.
29+ try :
30+ # A temporary trick to evade the Pytorch optimizer bug on MPS
31+ # See https://github.com/pytorch/pytorch/issues/149184
32+ torch ._dynamo .disable ()
33+
34+ except Exception as e :
35+ import warnings
36+ warnings .warn (
37+ f'An MPS GPU has been detected, but cannot be used.'
38+ f'Falling back to CPU.\n The exception message is:\n { e } '
39+ )
40+ torch .set_default_device (fallback_device )
2641
2742
2843lib = torch
You can’t perform that action at this time.
0 commit comments