cantrell / stable-diffusion-api-server

A local API server on top of Stable Diffusion.
Apache License 2.0
358 stars 61 forks source link

TypeError: __init__() got an unexpected keyword argument 'device_map' #4

Open houdinii opened 1 year ago

houdinii commented 1 year ago

I installed the plugin and server this afternoon, and it's immediately failing after downloading the requirements from Hugginface. I'm personally at a loss on how to fix it. Do you have any ideas?

(sd-api-server) D:\stable-diffusion\ps_plugin\stable-diffusion-api-server>python server.py
Downloading: 100%|█████████████████████████████████████████████████████████████████████| 543/543 [00:00<00:00, 118kB/s]
D:\anaconda3\envs\sd-api-server\lib\site-packages\huggingface_hub\file_download.py:123: UserWarning: `huggingface_hub` cache-system uses symlinks by default to efficiently store duplicated files but your machine does not support them in C:\Users\brian\.cache\huggingface\diffusers. Caching files will still work but in a degraded version that might require more space on your disk. This warning can be disabled by setting the `HF_HUB_DISABLE_SYMLINKS_WARNING` environment variable. For more details, see https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations.
To support symlinks on Windows, you either need to activate Developer Mode or to run Python as an administrator. In order to see activate developer mode, see this article: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development
  warnings.warn(message)
Downloading: 100%|████████████████████████████████████████████████████████████████████| 342/342 [00:00<00:00, 21.9kB/s]
Downloading: 100%|████████████████████████████████████████████████████████████████████████| 4.56k/4.56k [00:00<?, ?B/s]
Downloading: 100%|████████████████████████████████████████████████████████████████| 1.22G/1.22G [00:22<00:00, 53.8MB/s]
Downloading: 100%|█████████████████████████████████████████████████████████████████████| 209/209 [00:00<00:00, 163kB/s]
Downloading: 100%|█████████████████████████████████████████████████████████████████████| 230/230 [00:00<00:00, 230kB/s]
Downloading: 100%|█████████████████████████████████████████████████████████████████████| 592/592 [00:00<00:00, 587kB/s]
Downloading: 100%|██████████████████████████████████████████████████████████████████| 492M/492M [00:09<00:00, 52.9MB/s]
Downloading: 100%|██████████████████████████████████████████████████████████████████| 525k/525k [00:00<00:00, 1.32MB/s]
Downloading: 100%|█████████████████████████████████████████████████████████████████████| 472/472 [00:00<00:00, 237kB/s]
Downloading: 100%|█████████████████████████████████████████████████████████████████████| 806/806 [00:00<00:00, 587kB/s]
Downloading: 100%|████████████████████████████████████████████████████████████████| 1.06M/1.06M [00:00<00:00, 2.79MB/s]
Downloading: 100%|█████████████████████████████████████████████████████████████████████| 743/743 [00:00<00:00, 743kB/s]
Downloading: 100%|████████████████████████████████████████████████████████████████| 3.44G/3.44G [01:04<00:00, 53.3MB/s]
Downloading: 100%|█████████████████████████████████████████████████████████████████████| 522/522 [00:00<00:00, 523kB/s]
Downloading: 100%|██████████████████████████████████████████████████████████████████| 335M/335M [00:06<00:00, 54.4MB/s]
Fetching 16 files: 100%|███████████████████████████████████████████████████████████████| 16/16 [01:58<00:00,  7.41s/it]
Traceback (most recent call last):
  File "server.py", line 108, in <module>
    manager.add_engine( 'txt2img', EngineStableDiffusion( diffusers.StableDiffusionPipeline,        sibling=None ) )
  File "server.py", line 62, in __init__
    self.engine = pipe.from_pretrained( 'CompVis/stable-diffusion-v1-4', use_auth_token=token.strip() )
  File "D:\anaconda3\envs\sd-api-server\lib\site-packages\diffusers\pipeline_utils.py", line 517, in from_pretrained
    loaded_sub_model = load_method(os.path.join(cached_folder, name), **loading_kwargs)
  File "D:\anaconda3\envs\sd-api-server\lib\site-packages\transformers\modeling_utils.py", line 2024, in from_pretrained
    model = cls(config, *model_args, **model_kwargs)
TypeError: __init__() got an unexpected keyword argument 'device_map'
seeingthings commented 1 year ago

Having the same issue when using the MPS fallback method; to get the server working w the PyTorch nightlies method try installing optimum via pip: python -m pip install git+https://GitHub.com/huggingface/optimum.git

alexisargyris commented 1 year ago

Got exactly the same as @houdinii (on Windows). Any suggestion would be very welcome!

robertsehlke commented 1 year ago

Updating the transformers package solved the issue for me:

https://github.com/cantrell/stable-diffusion-api-server/issues/2#issuecomment-1279479888

alexisargyris commented 1 year ago

@robertsehlke 's suggestion works! This means that (in windows) we need to edit line 14 of the environment.yaml file from "4.19.2" to "4.23.1"

Gitterman69 commented 1 year ago
Downloading: 100%|██████████████████████████████| 472/472 [00:00<00:00, 108kB/s]
Downloading: 100%|██████████████████████████████| 806/806 [00:00<00:00, 111kB/s]
Downloading: 100%|█████████████████████████| 1.06M/1.06M [00:00<00:00, 1.38MB/s]
Downloading: 100%|██████████████████████████████| 743/743 [00:00<00:00, 184kB/s]
Downloading: 100%|█████████████████████████| 3.44G/3.44G [01:30<00:00, 37.9MB/s]
Downloading: 100%|██████████████████████████████| 522/522 [00:00<00:00, 142kB/s]
Downloading: 100%|███████████████████████████| 335M/335M [00:16<00:00, 20.0MB/s]
Fetching 16 files: 100%|████████████████████████| 16/16 [03:01<00:00, 11.35s/it]
ftfy or spacy is not installed using BERT BasicTokenizer instead of ftfy.
Traceback (most recent call last):
  File "/Users/bamboozle/Downloads/stable-diffusion-api-server-main/server.py", line 108, in <module>
    manager.add_engine( 'txt2img', EngineStableDiffusion( diffusers.StableDiffusionPipeline,        sibling=None ) )
  File "/Users/bamboozle/Downloads/stable-diffusion-api-server-main/server.py", line 62, in __init__
    self.engine = pipe.from_pretrained( 'CompVis/stable-diffusion-v1-4', use_auth_token=token.strip() )
  File "/Users/bamboozle/opt/miniconda3/envs/sd-api-server/lib/python3.9/site-packages/diffusers/pipeline_utils.py", line 517, in from_pretrained
    loaded_sub_model = load_method(os.path.join(cached_folder, name), **loading_kwargs)
  File "/Users/bamboozle/opt/miniconda3/envs/sd-api-server/lib/python3.9/site-packages/transformers/modeling_utils.py", line 2024, in from_pretrained
    model = cls(config, *model_args, **model_kwargs)
TypeError: __init__() got an unexpected keyword argument 'device_map'
(sd-api-server) ➜  stable-diffusion-api-server-main 
showcaseearth commented 1 year ago

Installing https://github.com/huggingface/optimum directly via pip resolved the unexpected keyword argument 'device_map' for me as well (which also updated to transformers-4.23.1), but two issues remain:

I doubt those two things are related, but as of now not having success.

Gitterman69 commented 1 year ago

Having the same issue when using the MPS fallback method; to get the server working w the PyTorch nightlies method try installing optimum via pip: python -m pip install git+https://GitHub.com/huggingface/optimum.git

this made it work for me too! but its soooooo slow to generate an image....