basujindal / stable-diffusion

Optimized Stable Diffusion modified to run on lower GPU VRAM
Other
3.14k stars 469 forks source link

Issue with a poorly formatted JSON file when trying to run sample prompts on windows #147

Open ErikBleifield opened 2 years ago

ErikBleifield commented 2 years ago

Hi,

Seeking to run the sample prompts on Windows and getting this error: (ldm) C:\StableDiffusion\stable-diffusion-main>python optimizedSD/optimized_txt2img.py --prompt "Cyberpunk style image of a Telsa car reflection in rain" --H 512 --W 512 --seed 27 --n_iter 2 --n_samples 5 --ddim_steps 50 Global seed set to 27 Loading model from models/ldm/stable-diffusion-v1/model.ckpt Global Step: 470000 UNet: Running in eps-prediction mode CondStage: Running in eps-prediction mode Traceback (most recent call last): File "C:\Users\erikb\miniconda3\envs\ldm\lib\site-packages\transformers\configuration_utils.py", line 650, in _get_config_dict config_dict = cls._dict_from_json_file(resolved_config_file) File "C:\Users\erikb\miniconda3\envs\ldm\lib\site-packages\transformers\configuration_utils.py", line 734, in _dict_from_json_file return json.loads(text) File "C:\Users\erikb\miniconda3\envs\ldm\lib\json__init__.py", line 357, in loads return _default_decoder.decode(s) File "C:\Users\erikb\miniconda3\envs\ldm\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Users\erikb\miniconda3\envs\ldm\lib\json\decoder.py", line 353, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 88 column 3 (char 2317)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "optimizedSD/optimized_txt2img.py", line 211, in modelCS = instantiate_from_config(config.modelCondStage) File "c:\stablediffusion\stable-diffusion-main\ldm\util.py", line 85, in instantiate_from_config return get_obj_from_str(config["target"])(config.get("params", dict())) File "c:\stablediffusion\stable-diffusion-main\optimizedSD\ddpm.py", line 262, in init self.instantiate_cond_stage(cond_stage_config) File "c:\stablediffusion\stable-diffusion-main\optimizedSD\ddpm.py", line 282, in instantiate_cond_stage model = instantiate_from_config(config) File "c:\stablediffusion\stable-diffusion-main\ldm\util.py", line 85, in instantiate_from_config return get_obj_from_str(config["target"])(config.get("params", dict())) File "c:\stablediffusion\stable-diffusion-main\ldm\modules\encoders\modules.py", line 142, in init self.transformer = CLIPTextModel.from_pretrained(version) File "C:\Users\erikb\miniconda3\envs\ldm\lib\site-packages\transformers\modeling_utils.py", line 1764, in from_pretrained config, model_kwargs = cls.config_class.from_pretrained( File "C:\Users\erikb\miniconda3\envs\ldm\lib\site-packages\transformers\models\clip\configuration_clip.py", line 126, in from_pretrained config_dict, kwargs = cls.get_config_dict(pretrained_model_name_or_path, kwargs) File "C:\Users\erikb\miniconda3\envs\ldm\lib\site-packages\transformers\configuration_utils.py", line 553, in get_config_dict config_dict, kwargs = cls._get_config_dict(pretrained_model_name_or_path, kwargs) File "C:\Users\erikb\miniconda3\envs\ldm\lib\site-packages\transformers\configuration_utils.py", line 652, in _get_config_dict raise EnvironmentError( OSError: It looks like the config file at 'C:\Users\erikb/.cache\huggingface\transformers\9c24e6cd9f499d02c4f21a033736dabd365962dc80fe3aeb57a8f85ea45a20a3.26fead7ea4f0f843f6eb4055dfd25693f1a71f3c6871b184042d4b126244e142' is not a valid JSON file.

This does appear to be creating a poorly formed JSON file with some "dangling commas" at the end of structures... if you run it through lint you will see it right away.

{ "_name_or_path": "clip-vit-large-patch14/", "architectures": [ "CLIPModel" ], "initializer_factor": 1.0, "logit_scale_init_value": 2.6592, "model_type": "clip", "projection_dim": 768, "text_config": { "_name_or_path": "", "add_cross_attention": false, "architectures": null, "attention_dropout": 0.0, "bad_words_ids": null, "bos_token_id": 0, "chunk_size_feed_forward": 0, "cross_attention_hidden_size": null, "decoder_start_token_id": null, "diversity_penalty": 0.0, "do_sample": false, "dropout": 0.0, "early_stopping": false, "encoder_no_repeat_ngram_size": 0, "eos_token_id": 2, "finetuning_task": null, "forced_bos_token_id": null, "forced_eos_token_id": null, "hidden_act": "quick_gelu", "hidden_size": 768, "id2label": { "0": "LABEL_0", "1": "LABEL_1" }, "initializer_factor": 1.0, "initializer_range": 0.02, "intermediate_size": 3072, "is_decoder": false, "is_encoder_decoder": false, "label2id": { "LABEL_0": 0, "LABEL_1": 1 }, "layer_norm_eps": 1e-05, "length_penalty": 1.0, "max_length": 20, "max_position_embeddings": 77, "min_length": 0, "model_type": "clip_text_model", "no_repeat_ngram_size": 0, "num_attention_heads": 12, "num_beam_groups": 1, "num_beams": 1, "num_hidden_layers": 12, "num_return_sequences": 1, "output_attentions": false, "output_hidden_states": false, "output_scores": false, "pad_token_id": 1, "prefix": null, "problem_type": null, "projection_dim" : 768, "pruned_heads": {}, "remove_invalid_values": false, "repetition_penalty": 1.0, "return_dict": true, "return_dict_in_generate": false, "sep_token_id": null, "task_specific_params": null, "temperature": 1.0, "tie_encoder_decoder": false, "tie_word_embeddings": true, "tokenizer_class": null, "top_k": 50, "top_p": 1.0, "torch_dtype": null, "torchscript": false, "transformers_version": "4.16.0.dev0", "use_bfloat16": false, "vocab_size": 49408 }, "text_config_dict": { "hidden_size": 768, "intermediate_size": 3072, "num_attention_heads": 12, "num_hidden_layers": 12, "projection_dim": 768, }, "torch_dtype": "float32", "transformers_version": null, "vision_config": { "_name_or_path": "", "add_cross_attention": false, "architectures": null, "attention_dropout": 0.0, "bad_words_ids": null, "bos_token_id": null, "chunk_size_feed_forward": 0, "cross_attention_hidden_size": null, "decoder_start_token_id": null, "diversity_penalty": 0.0, "do_sample": false, "dropout": 0.0, "early_stopping": false, "encoder_no_repeat_ngram_size": 0, "eos_token_id": null, "finetuning_task": null, "forced_bos_token_id": null, "forced_eos_token_id": null, "hidden_act": "quick_gelu", "hidden_size": 1024, "id2label": { "0": "LABEL_0", "1": "LABEL_1" }, "image_size": 224, "initializer_factor": 1.0, "initializer_range": 0.02, "intermediate_size": 4096, "is_decoder": false, "is_encoder_decoder": false, "label2id": { "LABEL_0": 0, "LABEL_1": 1 }, "layer_norm_eps": 1e-05, "length_penalty": 1.0, "max_length": 20, "min_length": 0, "model_type": "clip_vision_model", "no_repeat_ngram_size": 0, "num_attention_heads": 16, "num_beam_groups": 1, "num_beams": 1, "num_hidden_layers": 24, "num_return_sequences": 1, "output_attentions": false, "output_hidden_states": false, "output_scores": false, "pad_token_id": null, "patch_size": 14, "prefix": null, "problem_type": null, "projection_dim" : 768, "pruned_heads": {}, "remove_invalid_values": false, "repetition_penalty": 1.0, "return_dict": true, "return_dict_in_generate": false, "sep_token_id": null, "task_specific_params": null, "temperature": 1.0, "tie_encoder_decoder": false, "tie_word_embeddings": true, "tokenizer_class": null, "top_k": 50, "top_p": 1.0, "torch_dtype": null, "torchscript": false, "transformers_version": "4.16.0.dev0", "use_bfloat16": false }, "vision_config_dict": { "hidden_size": 1024, "intermediate_size": 4096, "num_attention_heads": 16, "num_hidden_layers": 24, "patch_size": 14, "projection_dim": 768, } }

Perhaps there is some additional configuration to run on Windows that I am missing. Any advice or fix would be appreciated.

jlafleur93 commented 2 years ago

Haven't tested this solution yet, but have you checked out this? https://github.com/huggingface/transformers/issues/18965#issuecomment-1242366207

Lime-Cakes commented 2 years ago

Wait a bit. I think the fix will be passed through soon. If you don't want to wait, disable internet access and use local file (assuming you got the model cached)

GucciFlipFlops1917 commented 2 years ago

I got this recently and was baffled. I thought I was alone but considered if it was just a new issue. Anyway, here's how I personally fixed it in my local installation:

Go to C:/Users/[user]/.cache/huggingface/transformers/

Open "9c24e6cd9f499d02c4f21a033736dabd365962dc80fe3aeb57a8f85ea45a20a3.26fead7ea4f0f843f6eb4055dfd25693f1a71f3c6871b184042d4b126244e142.json"

Download the config file indicated in the url and place it in the directory.

Edit "9c24e...json" to call the file address in your local directory, and it should work (or at least it does for me).

I think it's sort of like what @jlafleur93 is indicating in his linked solution, except it's still using the file indicated in the url. For some reason, this works after being downloaded but not when called as a url.

Edit: nvm, it's reported as fixed so that may be the reason why it worked.

eelstork commented 2 years ago

This is from a file that's being downloaded, not an error in this repo.

ErikBleifield commented 2 years ago

I can report that it now runs without an error - and I changed nothing. So something downstream must have gotten fixed. Thank you everyone who commented. I appreciate the quick assistance!