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 Support #22

Open
cocktailpeanut opened this issue Jan 22, 2024 · 3 comments
Open

MPS Support #22

cocktailpeanut opened this issue Jan 22, 2024 · 3 comments

Comments

@cocktailpeanut
Copy link

Thank you for open sourcing the code.

I was trying to get this to work on Mac MPS machines, and got it to work but not sure if I am doing it correctly since I didn't dig deep into the code. I'll just share the parts I updated from the original gradio demo on huggingface:

  1. check the device for mps: https://huggingface.co/spaces/cocktailpeanut/InstantID/blob/main/app.py#L27-L34
  2. used torch_dtype of float32 for MPS (otherwise it keeps giving me black images) and use enable attention slicing: https://huggingface.co/spaces/cocktailpeanut/InstantID/blob/main/app.py#L53-L76

It works, but it uses a lot of memory, so I was wondering if there's a better way. Also even though it's working, I might be completely missing some parts or making a mistake. Would appreciate feedback. It's very fast on CUDA but on MPS takes much longer, so hopefully there's a way to improve the speed as well. Thank you!

@AltayYuzeir
Copy link

I am on a Mac studio M2 Ultra 128 GB, Sonoma 14.1.2
I created a conda venv and installed pytorch suit from https://developer.apple.com/metal/pytorch/
Then I ran the command to install your requirements.txt file
But when I run the app.py file I get a fatal error which I could not resole.

Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. Intel MKL WARNING: Support of Intel(R) Streaming SIMD Extensions 4.2 (Intel(R) SSE4.2) enabled only processors has been deprecated. Intel oneAPI Math Kernel Library 2025.0 will require Intel(R) Advanced Vector Extensions (Intel(R) AVX) instructions. /Users/aggokce2/miniconda3/envs/instantid/lib/python3.10/site-packages/transformers/utils/generic.py:441: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead. _torch_pytree._register_pytree_node( /Users/aggokce2/miniconda3/envs/instantid/lib/python3.10/site-packages/transformers/utils/generic.py:309: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead. _torch_pytree._register_pytree_node( /Users/aggokce2/miniconda3/envs/instantid/lib/python3.10/site-packages/diffusers/utils/outputs.py:63: UserWarning: torch.utils._pytree._register_pytree_node is deprecated. Please use torch.utils._pytree.register_pytree_node instead. torch.utils._pytree._register_pytree_node( Traceback (most recent call last): File "/Users/aggokce2/Desktop/Altay/InstantID/app.py", line 16, in <module> import insightface File "/Users/aggokce2/miniconda3/envs/instantid/lib/python3.10/site-packages/insightface/__init__.py", line 18, in <module> from . import app File "/Users/aggokce2/miniconda3/envs/instantid/lib/python3.10/site-packages/insightface/app/__init__.py", line 2, in <module> from .mask_renderer import * File "/Users/aggokce2/miniconda3/envs/instantid/lib/python3.10/site-packages/insightface/app/mask_renderer.py", line 8, in <module> from ..thirdparty import face3d File "/Users/aggokce2/miniconda3/envs/instantid/lib/python3.10/site-packages/insightface/thirdparty/face3d/__init__.py", line 3, in <module> from . import mesh File "/Users/aggokce2/miniconda3/envs/instantid/lib/python3.10/site-packages/insightface/thirdparty/face3d/mesh/__init__.py", line 9, in <module> from .cython import mesh_core_cython ImportError: dlopen(/Users/aggokce2/miniconda3/envs/instantid/lib/python3.10/site-packages/insightface/thirdparty/face3d/mesh/cython/mesh_core_cython.cpython-310-darwin.so, 0x0002): tried: '/Users/aggokce2/miniconda3/envs/instantid/lib/python3.10/site-packages/insightface/thirdparty/face3d/mesh/cython/mesh_core_cython.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/aggokce2/miniconda3/envs/instantid/lib/python3.10/site-packages/insightface/thirdparty/face3d/mesh/cython/mesh_core_cython.cpython-310-darwin.so' (no such file), '/Users/aggokce2/miniconda3/envs/instantid/lib/python3.10/site-packages/insightface/thirdparty/face3d/mesh/cython/mesh_core_cython.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

I tried to install and compile insightface from source, but did not work.

@wangqixun
Copy link
Member

wangqixun commented Jan 25, 2024

try

  1. git clone https://github.com/deepinsight/insightface.git
  2. cd insightface/python-package
  3. pip install -v .

@AltayYuzeir
Copy link

Thank you a lot for the quick response.
Unfortunately I receive the same error as above, perhaps I need to set some flags specific to MacOS when compiling.

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

No branches or pull requests

3 participants