InvokeAI icon indicating copy to clipboard operation
InvokeAI copied to clipboard

[bug]: Error GPU Mac M1 when training Stable Diffusion using Textual Inversion

Open TruongQuocTruong opened this issue 2 years ago • 10 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

OS

macOS

GPU

mps

VRAM

16

What happened?

I have a problem when I re-implement it. I run it on Mac pro M1, and I have error: "RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (CPU) " when I training with command:

python main.py --base ./configs/stable-diffusion/v1-finetune.yaml
-t
--actual_resume ./models/ldm/stable-diffusion-v1/model.ckpt
-n my_key
--gpus 0,
--data_root ./training_data/key/

So, Can you help me fix this error, please? Thank you very much! My laptop is Macbook Pro 14" M1pro

Screenshots

Screen Shot 2022-11-03 at 00 04 17 Screen Shot 2022-11-03 at 00 07 47

Additional context

No response

Contact Details

[email protected]

TruongQuocTruong avatar Nov 02 '22 17:11 TruongQuocTruong

fix for this: https://github.com/Birch-san/stable-diffusion/commit/46f793b5ecd5bdd70ee8c9da9c6f379aa566afc5 also, if you are using a nightly build of pytorch, you might face some bugs

remixer-dec avatar Nov 02 '22 21:11 remixer-dec

fix for this: Birch-san/stable-diffusion@46f793b also, if you are using a nightly build of pytorch, you might face some bugs

Thank you very much! I'll try this

TruongQuocTruong avatar Nov 03 '22 01:11 TruongQuocTruong

Thanks @remixer-dec for pointing to the solution. I’ll apply it to InvokeAI.

lstein avatar Nov 03 '22 21:11 lstein

Im still getting the same error, any idea what I should be doing differently?

pangshengwei avatar Nov 10 '22 08:11 pangshengwei

@pangshengwei Try this command:

python main.py --base ./configs/stable-diffusion/v1-finetune.yaml 
-t 
--actual_resume ./models/ldm/stable-diffusion-v1/model.ckpt 
-n my_key 
--accelarator "cpu"
--data_root ./training_data/key/

use --accelarator "cpu", or --accelarator "mps", not --gpus 0

FreeBlues avatar Nov 10 '22 17:11 FreeBlues

@FreeBlues for M1 chips there is a config called v1-m1-finetune.yaml

remixer-dec avatar Nov 10 '22 18:11 remixer-dec

@remixer-dec Thank you, I will have a try.

FreeBlues avatar Nov 14 '22 06:11 FreeBlues

I was getting this error on an M1 mac while attempting textual inversion...

MisconfigurationException: MPSAccelerator can not run on your system since the accelerator is not available. The following accelerator(s) is available and can be passed into accelerator argument of Trainer: ['cpu'].

I went down a rabbithole of attempting various version changes, nightlies, updates, etc - nothing worked.

I finally realized that despite actually being on an M1, and having built python and conda and so on with the arm64 appropriate invocations ... there is some code that determines while running, what platform it's running on.

When I would run things like uname and uname -m and arch and so on, I was getting answers in the x86_64 and i386 and such. I eventually realized that because I was running a zsh which was installed through intel homebrew (probably from migrating previous laptop onto this newer M1 device), that was cascading down.

I was able to install both the M1-specific version of homebrew, and then separately reinstall zsh with that homebrew ... and now I get arm64 from arch command and arm64 from uname -m as well.

...I'm not sure if this is the end of my issues or not, but it at least got me past the error I was seeing and the inversion script is running now. Hope this helps someone else!

mjankowski avatar Dec 09 '22 18:12 mjankowski

I was getting this error on an M1 mac while attempting textual inversion...

MisconfigurationException: MPSAccelerator can not run on your system since the accelerator is not available. The following accelerator(s) is available and can be passed into accelerator argument of Trainer: ['cpu'].

I went down a rabbithole of attempting various version changes, nightlies, updates, etc - nothing worked.

I finally realized that despite actually being on an M1, and having built python and conda and so on with the arm64 appropriate invocations ... there is some code that determines while running, what platform it's running on.

When I would run things like uname and uname -m and arch and so on, I was getting answers in the x86_64 and i386 and such. I eventually realized that because I was running a zsh which was installed through intel homebrew (probably from migrating previous laptop onto this newer M1 device), that was cascading down.

I was able to install both the M1-specific version of homebrew, and then separately reinstall zsh with that homebrew ... and now I get arm64 from arch command and arm64 from uname -m as well.

...I'm not sure if this is the end of my issues or not, but it at least got me past the error I was seeing and the inversion script is running now. Hope this helps someone else!

@mjankowski Do you have a link to installing the M1-specific version of homebrew?

Trying to train Textual Inversion on my M1 Mac and getting no where.

joshdance avatar Dec 09 '22 19:12 joshdance

You just reinstall it and it will install the M1 version when it pulls down from the repo. This blog post was useful - https://earthly.dev/blog/homebrew-on-m1/ as were random notes in the homebrew repo.

You might have to supply something like arch -arm64 /bin/bash -c "$(curl ..." during the install so that it selects properly, if its attempting to reinstall the intel versions.

Notably - homebrew switched to keeping things in /opt/homebrew for the m1 version ... so unrelated to anything to do with GPUs or inversion, you'll have to manage that.

mjankowski avatar Dec 09 '22 20:12 mjankowski