DEV Community

Discussion on: Setting up Stable Diffusion for MacOS

Collapse
 
tangsirongit profile image
laimj • Edited

Thanks for the detailed instructions!

after set up the enviroment.

the last step:
python scripts/orig_scripts/txt2img.py --prompt "An Armenia girl with curly hair goes to Senior school with her mum in Shanghai, and she carries a dark red shoulder bag" --plms --ckpt sd-v1-4.ckpt --skip_grid --n_samples 1

the error:

Loading model from sd-v1-4.ckpt
Global Step: 470000
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
making attention of type 'vanilla' with 512 in_channels
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
making attention of type 'vanilla' with 512 in_channels
Traceback (most recent call last):
  File "/Users/tangsir/Downloads/tools/stable-diffusion/scripts/orig_scripts/txt2img.py", line 327, in <module>
    main()
  File "/Users/tangsir/Downloads/tools/stable-diffusion/scripts/orig_scripts/txt2img.py", line 203, in main
    model = load_model_from_config(config, f"{opt.ckpt}")
  File "/Users/tangsir/Downloads/tools/stable-diffusion/scripts/orig_scripts/txt2img.py", line 42, in load_model_from_config
    model = instantiate_from_config(config.model)
  File "/Users/tangsir/Downloads/tools/stable-diffusion/ldm/util.py", line 89, in instantiate_from_config
    return get_obj_from_str(config['target'])(
  File "/Users/tangsir/Downloads/tools/stable-diffusion/ldm/models/diffusion/ddpm.py", line 657, in __init__
    self.instantiate_cond_stage(cond_stage_config)
  File "/Users/tangsir/Downloads/tools/stable-diffusion/ldm/models/diffusion/ddpm.py", line 768, in instantiate_cond_stage
    model = instantiate_from_config(config)
  File "/Users/tangsir/Downloads/tools/stable-diffusion/ldm/util.py", line 89, in instantiate_from_config
    return get_obj_from_str(config['target'])(
  File "/Users/tangsir/Downloads/tools/stable-diffusion/ldm/modules/encoders/modules.py", line 253, in __init__
    self.tokenizer = CLIPTokenizer.from_pretrained(
  File "/Users/tangsir/opt/anaconda3/envs/ldm/lib/python3.10/site-packages/transformers/tokenization_utils_base.py", line 1768, in from_pretrained
    raise EnvironmentError(
OSError: Can't load tokenizer for 'openai/clip-vit-large-patch14'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'openai/clip-vit-large-patch14' is the correct path to a directory containing all relevant files for a CLIPTokenizer tokenizer.
Enter fullscreen mode Exit fullscreen mode
Collapse
 
tangsirongit profile image
laimj

fixed by removing local_files_only=True:

diff --git a/ldm/modules/encoders/modules.py b/ldm/modules/encoders/modules.py
index 07e1da8..f7f5abb 100644
--- a/ldm/modules/encoders/modules.py
+++ b/ldm/modules/encoders/modules.py
@@ -118,7 +118,7 @@ class BERTTokenizer(AbstractEncoder):
         #   BertTokenizerFast.from_pretrained("bert-base-uncased")
         try:
             self.tokenizer = BertTokenizerFast.from_pretrained(
-                'bert-base-uncased', local_files_only=True
+                'bert-base-uncased'
             )
         except OSError:
             raise SystemExit(
@@ -251,10 +251,10 @@ class FrozenCLIPEmbedder(AbstractEncoder):
     ):
         super().__init__()
         self.tokenizer = CLIPTokenizer.from_pretrained(
-            version, local_files_only=True
+            version
         )
         self.transformer = CLIPTextModel.from_pretrained(
-            version, local_files_only=True
+            version
         )
         self.device = device
         self.max_length = max_length
Enter fullscreen mode Exit fullscreen mode
Collapse
 
sjoerdw_bijleveld_38e54 profile image
Sjoerd W. Bijleveld

I had the same problem and your method solved it, but the next error crept up:

Traceback (most recent call last):
Traceback (most recent call last):
File "/Users/SWB/stable-diffusion/scripts/orig_scripts/txt2img.py", line 327, in <module>
main()
File "/Users/SWB/stable-diffusion/scripts/orig_scripts/txt2img.py", line 277, in main
samples_ddim, _ = sampler.sample(S=opt.ddim_steps,
File "/Users/SWB/miniconda3/envs/ldm/lib/python3.10/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/Users/SWB/stable-diffusion/ldm/models/diffusion/plms.py", line 156, in sample
self.make_schedule(ddim_num_steps=S, ddim_eta=eta, verbose=verbose)
File "/Users/SWB/stable-diffusion/ldm/models/diffusion/plms.py", line 108, in make_schedule
(1 - self.alphas_cumprod_prev)
TypeError: unsupported operand type(s) for -: 'int' and 'builtin_function_or_method'
(ldm) SWB@SWB-iMac stable-diffusion %

For me it is hard to find the reason for this error. Please help!