Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mps device option is selected if you run this repository in MacOS #300

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

cperales
Copy link

I have been running this code in Ubuntu and Windows (through Flowframes), and I would like to run it in a Macbook 16 that I am using. Reading PyTorch documentation, MPS device enables high-performance training on GPU for MacOS devices with Metal programming framework. Basically, MPS is the analogous to CUDA but in MacOs.

The main problem is that Conv3D is not available yet for MPS, so that part of the code must be run with CPU. The environment variable PYTORCH_ENABLE_MPS_FALLBACK must also set to 1, so I included that part too.

@aak-lear
Copy link

@cperales did you use custom models for inference?

I tried to use your code on Mac with model from README and faced with RuntimeError:
Input type (MPSFloatType) and weight type (torch.FloatTensor) should be the same

It's traced on conv2d call.

I'm not sure that it is problem with model, but have no other ideas. Maybe you have?

@corlene-r
Copy link

corlene-r commented Apr 21, 2023

@cperales did you use custom models for inference?

I tried to use your code on Mac with model from README and faced with RuntimeError: Input type (MPSFloatType) and weight type (torch.FloatTensor) should be the same

It's traced on conv2d call.

I'm not sure that it is problem with model, but have no other ideas. Maybe you have?

I was able to fix this by editing both the IFNet_HDv3.py and RIFE_HDv3.py files, which are files that come with the pre-trained model linked in the README (I used this version). Right under the imports for these files (on lines 6 and 13 respectively), the files say:

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

When running on a mac, I take it that we're just trying to change everything to the MPS device, so I simply changed the lines to the following:

device = torch.device("mps" if torch.backends.mps.is_available() else "cpu")

After this, I got running the code to work.

@SAI-sentinal-ai
Copy link

SAI-sentinal-ai commented May 24, 2023

Hi, after all changes I still get "RuntimeError: MPS: Unsupported Border padding mode". Which python version and torch version are you guys using?

/edit: fixed it. In case anyone stumbles upon it here; paste this:
return torch.nn.functional.grid_sample(input=tenInput, grid=g, mode='bilinear', padding_mode='zeros', align_corners=True)
in "warplayer.py". (thanks ChatGPT!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants