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

any use for arm64 MacOS Monterey on a M1 MAX Macbook? #294

Open
Smiril opened this issue Jul 8, 2022 · 14 comments
Open

any use for arm64 MacOS Monterey on a M1 MAX Macbook? #294

Smiril opened this issue Jul 8, 2022 · 14 comments

Comments

@Smiril
Copy link

Smiril commented Jul 8, 2022

gettin some error on:python3 train.py --name simswap224_test --batchSize 8 --gpu_ids 0 --dataset /var/deep/DSC_0015.JPG Traceback (most recent call last): File "train.py", line 17, in <module> import numpy as np ModuleNotFoundError: No module named 'numpy'

@Smiril
Copy link
Author

Smiril commented Jul 8, 2022

fixed on my system above and following errors with: python3 -m pip install modul

but ehhh I got none Cuda gpu

script tells me:

Traceback (most recent call last): File "/Users/Smiril/deep/SimSwap/train.py", line 139, in <module> model.initialize(opt) File "/Users/Smiril/deep/SimSwap/models/projected_model.py", line 44, in initialize self.netG.cuda() File "/opt/homebrew/lib/python3.9/site-packages/torch/nn/modules/module.py", line 689, in cuda return self._apply(lambda t: t.cuda(device)) File "/opt/homebrew/lib/python3.9/site-packages/torch/nn/modules/module.py", line 579, in _apply module._apply(fn) File "/opt/homebrew/lib/python3.9/site-packages/torch/nn/modules/module.py", line 579, in _apply module._apply(fn) File "/opt/homebrew/lib/python3.9/site-packages/torch/nn/modules/module.py", line 602, in _apply param_applied = fn(param) File "/opt/homebrew/lib/python3.9/site-packages/torch/nn/modules/module.py", line 689, in <lambda> return self._apply(lambda t: t.cuda(device)) File "/opt/homebrew/lib/python3.9/site-packages/torch/cuda/__init__.py", line 211, in _lazy_init raise AssertionError("Torch not compiled with CUDA enabled") AssertionError: Torch not compiled with CUDA enabled

anyone can help?

@ExponentialML
Copy link

Try following the instructions here.

I'm not sure about onnxruntime and torch compatibility on a Mac, but you're going to have to do a bit of research for anything built for CUDA, and find the M1 builds in place of it.

@Smiril
Copy link
Author

Smiril commented Jul 9, 2022

thank you it helps a lot ..
the test on the instruction

work with 👍
conda create -n torch-gpu python=3.9 conda activate torch-gpu conda install pytorch torchvision torchaudio -c pytorch-nightly conda install -c conda-forge jupyter jupyterlab python3 -m pip install torch

`import torch
import math
print(torch.backends.mps.is_available())
print(torch.backends.mps.is_built())
dtype = torch.float
device = torch.device("mps")

x = torch.linspace(-math.pi, math.pi, 2000, device=device, dtype=dtype)
y = torch.sin(x)

a = torch.randn((), device=device, dtype=dtype)
b = torch.randn((), device=device, dtype=dtype)
c = torch.randn((), device=device, dtype=dtype)
d = torch.randn((), device=device, dtype=dtype)

learning_rate = 1e-6
for t in range(2000):
y_pred = a + b * x + c * x ** 2 + d * x ** 3

loss = (y_pred - y).pow(2).sum().item()
if t % 100 == 99:
    print(t, loss)

grad_y_pred = 2.0 * (y_pred - y)
grad_a = grad_y_pred.sum()
grad_b = (grad_y_pred * x).sum()
grad_c = (grad_y_pred * x ** 2).sum()
grad_d = (grad_y_pred * x ** 3).sum()

a -= learning_rate * grad_a
b -= learning_rate * grad_b
c -= learning_rate * grad_c
d -= learning_rate * grad_d

print(f'Result: y = {a.item()} + {b.item()} x + {c.item()} x^2 + {d.item()} x^3')`

give following output ...

True True 99 569.908935546875 199 399.8172302246094 299 281.5032958984375 399 199.13519287109375 499 141.7447052001953 599 101.72549438476562 699 73.79811096191406 799 54.29474639892578 899 40.664642333984375 999 31.1326904296875 1099 24.46240234375 1199 19.79174041748047 1299 16.51934051513672 1399 14.225279808044434 1499 12.616241455078125 1599 11.487083435058594 1699 10.694307327270508 1799 10.137439727783203 1899 9.746109962463379 1999 9.471000671386719 Result: y = 0.026000667363405228 + 0.8636452555656433 x + -0.004485549405217171 x^2 + -0.09431249648332596 x^3

@ExponentialML
Copy link

Great! If you haven't already, reinstall Simswap using these instructions, but replace the conda install pytorch... lines with your Mac instructions, and let us know if it works.

@Smiril
Copy link
Author

Smiril commented Jul 9, 2022

replaced and work ... I'll made a pull request of two scripts bash and python3

@Smiril
Copy link
Author

Smiril commented Jul 9, 2022

the cuda error is every time popup

------------ Options ------------- Arc_path: arcface_model/arcface_checkpoint.tar Gdeep: False batchSize: 8000000000000 beta1: 0.0 checkpoints_dir: ./checkpoints continue_train: False dataset: crop_224/6.jpg gpu_ids: 0 isTrain: True lambda_feat: 10.0 lambda_id: 30.0 lambda_rec: 10.0 load_pretrain: ./checkpoints/simswap224_test log_frep: 200 lr: 0.0004 model_freq: 10000 name: simswap224_test niter: 10000 niter_decay: 10000 phase: train sample_freq: 1000 total_step: 1000000 use_tensorboard: False which_epoch: 10000 -------------- End ---------------- GPU used : 0 Traceback (most recent call last): File "/Users/pandora/Documents/deep/SimSwap/train.py", line 139, in <module> model.initialize(opt) File "/Users/pandora/Documents/deep/SimSwap/models/projected_model.py", line 44, in initialize self.netG.cuda() File "/opt/homebrew/lib/python3.9/site-packages/torch/nn/modules/module.py", line 689, in cuda return self._apply(lambda t: t.cuda(device)) File "/opt/homebrew/lib/python3.9/site-packages/torch/nn/modules/module.py", line 579, in _apply module._apply(fn) File "/opt/homebrew/lib/python3.9/site-packages/torch/nn/modules/module.py", line 579, in _apply module._apply(fn) File "/opt/homebrew/lib/python3.9/site-packages/torch/nn/modules/module.py", line 602, in _apply param_applied = fn(param) File "/opt/homebrew/lib/python3.9/site-packages/torch/nn/modules/module.py", line 689, in <lambda> return self._apply(lambda t: t.cuda(device)) File "/opt/homebrew/lib/python3.9/site-packages/torch/cuda/__init__.py", line 211, in _lazy_init raise AssertionError("Torch not compiled with CUDA enabled") AssertionError: Torch not compiled with CUDA enabled

@Smiril
Copy link
Author

Smiril commented Jul 10, 2022

hello I use TensorFlow GPU script from my git fork m1_tf_setup.sh
what calculate with m1_tf_test.py

well work fine !!!!

thank you :)


Layer (type) Output Shape Param #

flatten (Flatten) (None, 784) 0

dense (Dense) (None, 128) 100480

dropout (Dropout) (None, 128) 0

dense_1 (Dense) (None, 10) 1290

dropout_1 (Dropout) (None, 10) 0

dense_2 (Dense) (None, 2) 22

=================================================================
Total params: 101,792
Trainable params: 101,792
Non-trainable params: 0

@Smiril
Copy link
Author

Smiril commented Jul 10, 2022

take a closer look on this:

2022-07-10 16:41:42.188712: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support.
2022-07-10 16:41:42.188823: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: )
2022-07-10 16:41:42.315135: W tensorflow/core/platform/profile_utils/cpu_utils.cc:128] Failed to get CPU frequency: 0 Hz
Epoch 1/10
2022-07-10 16:41:42.480309: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:113] Plugin optimizer for device_type GPU is enabled.
1875/1875 [==============================] - 11s 5ms/step - loss: 0.1113 - accuracy: 0.1557
Epoch 2/10
1875/1875 [==============================] - 10s 5ms/step - loss: 0.0886 - accuracy: 0.1642
Epoch 3/10
1875/1875 [==============================] - 10s 6ms/step - loss: 0.0828 - accuracy: 0.1690
Epoch 4/10
1875/1875 [==============================] - 10s 5ms/step - loss: 0.0776 - accuracy: 0.1713
Epoch 5/10
1875/1875 [==============================] - 10s 5ms/step - loss: 0.0757 - accuracy: 0.1713
Epoch 6/10
1875/1875 [==============================] - 10s 5ms/step - loss: 0.0751 - accuracy: 0.1716
Epoch 7/10
1875/1875 [==============================] - 10s 6ms/step - loss: 0.0749 - accuracy: 0.1715
Epoch 8/10
1875/1875 [==============================] - 10s 5ms/step - loss: 0.0742 - accuracy: 0.1724
Epoch 9/10
1875/1875 [==============================] - 10s 5ms/step - loss: 0.0743 - accuracy: 0.1724
Epoch 10/10
1875/1875 [==============================] - 10s 5ms/step - loss: 0.0744 - accuracy: 0.1717
Model: "sequential"


Layer (type) Output Shape Param #

flatten (Flatten) (None, 784) 0

dense (Dense) (None, 128) 100480

dropout (Dropout) (None, 128) 0

dense_1 (Dense) (None, 10) 1290

dropout_1 (Dropout) (None, 10) 0

dense_2 (Dense) (None, 2) 22

dropout_2 (Dropout) (None, 2) 0

=================================================================
Total params: 101,792
Trainable params: 101,792
Non-trainable params: 0


@Smiril
Copy link
Author

Smiril commented Jul 11, 2022

unfortunly ... no luck ... but a error log

python3 test_one_image.py --name people --Arc_path arcface_model/arcface_checkpoint.tar --pic_a_path crop_224/3.jpg --pic_b_path crop_224/1.jpg --output_path ./ Traceback (most recent call last): File "/Users/Smiril/Documents/deep/SimSwap/test_one_image.py", line 30, in <module> opt = TestOptions().parse() File "/Users/Smiril/Documents/deep/SimSwap/options/base_options.py", line 84, in parse torch.cuda.set_device(self.opt.gpu_ids[0]) File "/Users/Smiril/opt/miniconda3/envs/torch-m1/lib/python3.10/site-packages/torch/cuda/__init__.py", line 314, in set_device torch._C._cuda_setDevice(device) AttributeError: module 'torch._C' has no attribute '_cuda_setDevice'

should stand "mps" NOT "cuda" --->>> device = torch.device("mps")

possible to find with : print(torch.backends.mps.is_available())

@tikitong
Copy link

tikitong commented Sep 19, 2022

Hi @Smiril, thanks for raising the issue and for the feedback. I am under M1 arm64 and I have the following error that is raised for the command line: pip install insightface==0.2.1 onnxruntime moviepy likely due to onnx as @ExponentialML said too.

UPDATE

I finally solved my problem and gave a solution for working with amr64 by #180


(simswap) user@Users-MacBook-Air ~ % pip install insightface==0.2.1 onnxruntime moviepy
Collecting insightface==0.2.1
  Using cached insightface-0.2.1-py2.py3-none-any.whl (24 kB)
Collecting onnxruntime
  Using cached onnxruntime-1.12.1-cp39-cp39-macosx_11_0_arm64.whl (5.3 MB)
Collecting moviepy
  Using cached moviepy-1.0.3.tar.gz (388 kB)
  Preparing metadata (setup.py) ... done
Collecting matplotlib
  Using cached matplotlib-3.6.0-cp39-cp39-macosx_11_0_arm64.whl (7.2 MB)
Collecting scipy
  Using cached scipy-1.9.1-cp39-cp39-macosx_12_0_arm64.whl (29.9 MB)
Collecting easydict
  Using cached easydict-1.9.tar.gz (6.4 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: requests in ./miniconda3/envs/simswap/lib/python3.9/site-packages (from insightface==0.2.1) (2.28.1)
Collecting scikit-learn
  Using cached scikit_learn-1.1.2-cp39-cp39-macosx_12_0_arm64.whl (7.7 MB)
Collecting scikit-image
  Using cached scikit_image-0.19.3-cp39-cp39-macosx_12_0_arm64.whl (12.5 MB)
Requirement already satisfied: Pillow in ./miniconda3/envs/simswap/lib/python3.9/site-packages (from insightface==0.2.1) (9.2.0)
Requirement already satisfied: numpy in ./miniconda3/envs/simswap/lib/python3.9/site-packages (from insightface==0.2.1) (1.23.3)
Collecting onnx
  Using cached onnx-1.12.0.tar.gz (10.1 MB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [7 lines of output]
      fatal: not a git repository (or any of the parent directories): .git
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/f9/xk3yn2n574x8_hbd83875qd40000gn/T/pip-install-t22tviae/onnx_1a1072999dce4bc6b7542af1a92f22c0/setup.py", line 81, in <module>
          assert CMAKE, "Could not find cmake executable!"
      AssertionError: Could not find cmake executable!
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Did you find a way to run the command? Also is SimSwap executable with a CPU? Thanks a lot!

@Smiril
Copy link
Author

Smiril commented Sep 24, 2022

updated pull request

adding following:
# set gpu ids
if not torch.backends.mps.is_available():
if not torch.backends.mps.is_built():
if len(self.opt.gpu_ids) > 0:
torch.cuda.set_device(self.opt.gpu_ids[0])
else:
torch.device("mps")
else:
torch.device("mps")
else:
torch.device("mps")

updated pull request

running:

pip3 install opencv-python
pip3 install torch torchvision torchaudio onnx insightface==0.2.1 onnxruntime moviepy imageio imageio-ffmpeg

@Smiril
Copy link
Author

Smiril commented Sep 25, 2022

by adding :pull request

is the following error on: python3 test_video_swapsingle.py --crop_size 224 --use_mask --name people --Arc_path arcface_model/arcface_checkpoint.tar --pic_a_path demo_file/Iron_man.jpg --video_path demo_file/multi_people_1080p.mp4 --output_path output/multi_test_swapsingle.mp4 --temp_path temp_results

Traceback (most recent call last):
File "/Users/Smiril/Documents/deep/SimSwap/test_video_swapsingle.py", line 18, in
from options.test_options import TestOptions
File "/Users/Smiril/Documents/deep/SimSwap/options/test_options.py", line 11
class TestOptions(BaseOptions):
IndentationError: unexpected indent

@Smiril
Copy link
Author

Smiril commented Sep 25, 2022

Hi @Smiril, thanks for raising the issue and for the feedback. I am under M1 arm64 and I have the following error that is raised for the command line: pip install insightface==0.2.1 onnxruntime moviepy likely due to onnx as @ExponentialML said too.

UPDATE

I finally solved my problem and gave a solution for working with amr64 by #180

(simswap) user@Users-MacBook-Air ~ % pip install insightface==0.2.1 onnxruntime moviepy
Collecting insightface==0.2.1
  Using cached insightface-0.2.1-py2.py3-none-any.whl (24 kB)
Collecting onnxruntime
  Using cached onnxruntime-1.12.1-cp39-cp39-macosx_11_0_arm64.whl (5.3 MB)
Collecting moviepy
  Using cached moviepy-1.0.3.tar.gz (388 kB)
  Preparing metadata (setup.py) ... done
Collecting matplotlib
  Using cached matplotlib-3.6.0-cp39-cp39-macosx_11_0_arm64.whl (7.2 MB)
Collecting scipy
  Using cached scipy-1.9.1-cp39-cp39-macosx_12_0_arm64.whl (29.9 MB)
Collecting easydict
  Using cached easydict-1.9.tar.gz (6.4 kB)
  Preparing metadata (setup.py) ... done
Requirement already satisfied: requests in ./miniconda3/envs/simswap/lib/python3.9/site-packages (from insightface==0.2.1) (2.28.1)
Collecting scikit-learn
  Using cached scikit_learn-1.1.2-cp39-cp39-macosx_12_0_arm64.whl (7.7 MB)
Collecting scikit-image
  Using cached scikit_image-0.19.3-cp39-cp39-macosx_12_0_arm64.whl (12.5 MB)
Requirement already satisfied: Pillow in ./miniconda3/envs/simswap/lib/python3.9/site-packages (from insightface==0.2.1) (9.2.0)
Requirement already satisfied: numpy in ./miniconda3/envs/simswap/lib/python3.9/site-packages (from insightface==0.2.1) (1.23.3)
Collecting onnx
  Using cached onnx-1.12.0.tar.gz (10.1 MB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [7 lines of output]
      fatal: not a git repository (or any of the parent directories): .git
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/f9/xk3yn2n574x8_hbd83875qd40000gn/T/pip-install-t22tviae/onnx_1a1072999dce4bc6b7542af1a92f22c0/setup.py", line 81, in <module>
          assert CMAKE, "Could not find cmake executable!"
      AssertionError: Could not find cmake executable!
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

Did you find a way to run the command? Also is SimSwap executable with a CPU? Thanks a lot!

want to run on "mps" the M1 GPU

@tikitong
Copy link

tikitong commented Oct 1, 2022

@Smiril to run with mps/cpu with M1 chip, use the following command to install PyTorch: conda install pytorch torchvision -c pytorch-nightly , see here. After doing it, running with the cpu seems to have same (or better) performance than mps (pytorch/pytorch#77799) for the moment.

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