StableCascade icon indicating copy to clipboard operation
StableCascade copied to clipboard

ValueError: Trying to set a tensor of shape torch.Size([77, 1280]) in "weight" (which has shape torch.Size([77, 512])), this look incorrect.

Open ScottishFold007 opened this issue 1 year ago • 4 comments

I have try "pip install git+https://github.com/kashif/diffusers.git@wuerstchen-v3",but still occur the things:

A matching Triton is not available, some optimizations will not be enabled. Error caught was: No module named 'triton' WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.autotrackable has been moved to tensorflow.python.trackable.autotrackable. The old module will be deleted in version 2.11. WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.base has been moved to tensorflow.python.trackable.base. The old module will be deleted in version 2.11. WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.base_delegate has been moved to tensorflow.python.trackable.base_delegate. The old module will be deleted in version 2.11. WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.data_structures has been moved to tensorflow.python.trackable.data_structures. The old module will be deleted in version 2.11. WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.graph_view has been moved to tensorflow.python.checkpoint.graph_view. The old module will be deleted in version 2.11. WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.util has been moved to tensorflow.python.checkpoint.checkpoint. The old module will be deleted in version 2.11. WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.checkpoint_management has been moved to tensorflow.python.checkpoint.checkpoint_management. The old module will be deleted in version 2.9. WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.resource has been moved to tensorflow.python.trackable.resource. The old module will be deleted in version 2.11. WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.asset has been moved to tensorflow.python.trackable.asset. The old module will be deleted in version 2.11. WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.python_state has been moved to tensorflow.python.trackable.python_state. The old module will be deleted in version 2.11. WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.saving.checkpoint_options has been moved to tensorflow.python.checkpoint.checkpoint_options. The old module will be deleted in version 2.11. Loading pipeline components...: 0% 0/3 [00:00<?, ?it/s]

ValueError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_4928\1705133580.py in 5 num_images_per_prompt = 2 6 model_path= r"D:\all_models_archives\stable-cascade" ----> 7 prior = StableCascadePriorPipeline.from_pretrained(model_path, torch_dtype=torch.bfloat16, use_safetensors =True).to(device) 8 decoder = StableCascadeDecoderPipeline.from_pretrained(model_path, torch_dtype=torch.float16, use_safetensors =True).to(device) 9

~\anaconda3\lib\site-packages\huggingface_hub\utils_validators.py in _inner_fn(*args, **kwargs) 116 kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.name, has_token=has_token, kwargs=kwargs) 117 --> 118 return fn(*args, **kwargs) 119 120 return _inner_fn # type: ignore

~\anaconda3\lib\site-packages\diffusers\pipelines\pipeline_utils.py in from_pretrained(cls, pretrained_model_name_or_path, **kwargs) 1261 else: 1262 # load sub model -> 1263 loaded_sub_model = load_sub_model( 1264 library_name=library_name, 1265 class_name=class_name,

~\anaconda3\lib\site-packages\diffusers\pipelines\pipeline_utils.py in load_sub_model(library_name, class_name, importable_classes, pipelines, is_pipeline_module, pipeline_class, torch_dtype, provider, sess_options, device_map, max_memory, offload_folder, offload_state_dict, model_variants, name, from_flax, variant, low_cpu_mem_usage, cached_folder, revision) 529 # check if the module is in a subdirectory 530 if os.path.isdir(os.path.join(cached_folder, name)): --> 531 loaded_sub_model = load_method(os.path.join(cached_folder, name), **loading_kwargs) 532 else: 533 # else load from the root directory

~\AppData\Roaming\Python\Python39\site-packages\transformers\modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, config, cache_dir, ignore_mismatched_sizes, force_download, local_files_only, token, revision, use_safetensors, *model_args, **kwargs) 3478 offload_index, 3479 error_msgs, -> 3480 ) = cls._load_pretrained_model( 3481 model, 3482 state_dict,

~\AppData\Roaming\Python\Python39\site-packages\transformers\modeling_utils.py in _load_pretrained_model(cls, model, state_dict, loaded_keys, resolved_archive_file, pretrained_model_name_or_path, ignore_mismatched_sizes, sharded_metadata, _fast_init, low_cpu_mem_usage, device_map, offload_folder, offload_state_dict, dtype, is_quantized, keep_in_fp32_modules) 3868 if low_cpu_mem_usage: 3869 if not is_fsdp_enabled() or is_fsdp_enabled_and_dist_rank_0(): -> 3870 new_error_msgs, offload_index, state_dict_index = _load_state_dict_into_meta_model( 3871 model_to_load, 3872 state_dict,

~\AppData\Roaming\Python\Python39\site-packages\transformers\modeling_utils.py in _load_state_dict_into_meta_model(model, state_dict, loaded_state_dict_keys, start_prefix, expected_keys, device_map, offload_folder, offload_index, state_dict_folder, state_dict_index, dtype, is_quantized, is_safetensors, keep_in_fp32_modules) 741 elif not is_quantized: 742 # For backward compatibility with older versions of accelerate --> 743 set_module_tensor_to_device(model, param_name, param_device, **set_module_kwargs) 744 else: 745 if param.dtype == torch.int8 and param_name.replace("weight", "SCB") in state_dict.keys():

~\anaconda3\lib\site-packages\accelerate\utils\modeling.py in set_module_tensor_to_device(module, tensor_name, device, value, dtype, fp16_statistics, tied_params_map) 343 if value is not None: 344 if old_value.shape != value.shape: --> 345 raise ValueError( 346 f'Trying to set a tensor of shape {value.shape} in "{tensor_name}" (which has shape {old_value.shape}), this look incorrect.' 347 )

ValueError: Trying to set a tensor of shape torch.Size([77, 1280]) in "weight" (which has shape torch.Size([77, 512])), this look incorrect.

ScottishFold007 avatar Feb 17 '24 15:02 ScottishFold007

I have the same problem, I'm running on Ubuntu though. In the error it says:

If you want to instead overwrite randomly initialized weights, please make sure to pass both `low_cpu_mem_usage=False` and `ignore_mismatched_sizes=True`. For more information, see also: https://github.com/huggingface/diffusers/issues/1619#issuecomment-1345604389 as an example.

However, looking at the issues associated with the link it seems like this is something that needs to be updated in the app itself.

davejhahn avatar Feb 18 '24 00:02 davejhahn

I believe you are correct, I am also running in Ubuntu and get the size mismatch.

embedding.1.weight expected shape tensor(..., device='meta', size=(320, 64, 1, 1)), but got torch.Size([320, 16, 1, 1]). If you want to instead overwrite randomly initialized weights, please make sure to pass both low_cpu_mem_usage=Falseandignore_mismatched_sizes=True. For more information, see also: https://github.com/huggingface/diffusers/issues/1619#issuecomment-1345604389 as an example.

prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", torch_dtype=torch.bfloat16).to(device) decoder = StableCascadeDecoderPipeline.from_pretrained("stabilityai/stable-cascade", torch_dtype=torch.float16, ignore_mismatched_sizes=True).to(device)

I have made these adjustments and to no avail.

KylanDixonMF avatar Feb 20 '24 03:02 KylanDixonMF

I'm running this on M2 and getting this error:

WARNING[XFORMERS]: xFormers can't load C++/CUDA extensions. xFormers was built for:
    PyTorch 2.1.0a0+git4add06e with CUDA None (you have 2.1.1)
    Python  3.11.5 (you have 3.11.5)
  Please reinstall xformers (see https://github.com/facebookresearch/xformers#installing-xformers)
  Memory-efficient attention, SwiGLU, sparse and more won't be available.
  Set XFORMERS_MORE_DETAILS=1 for more details
RUNNING ON: mps
Loading pipeline components...:  67%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████▎                                                         | 4/6 [00:01<00:00,  3.07it/s]The config attributes {'c_in': 16} were passed to StableCascadeUnet, but are not expected and will be ignored. Please verify your config.json configuration file.
/opt/homebrew/lib/python3.11/site-packages/diffusers/models/lora.py:384: FutureWarning: `LoRACompatibleLinear` is deprecated and will be removed in version 1.0.0. Use of `LoRACompatibleLinear` is deprecated. Please switch to PEFT backend by installing PEFT: `pip install peft`.
  deprecate("LoRACompatibleLinear", "1.0.0", deprecation_message)
Loading pipeline components...: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 6/6 [00:40<00:00,  6.82s/it]
Fetching 13 files: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 13/13 [00:00<00:00, 20.46it/s]
Loading pipeline components...:  40%|█████████████████████████████████████████████████████████████████████▏                                                                                                       | 2/5 [00:00<00:00, 16.00it/s]The config attributes {'c_in': 4} were passed to StableCascadeUnet, but are not expected and will be ignored. Please verify your config.json configuration file.
Loading pipeline components...:  40%|█████████████████████████████████████████████████████████████████████▏                                                                                                       | 2/5 [00:05<00:08,  2.72s/it]
Traceback (most recent call last):
  File "/Users/it6/cascade/gradio_app/app.py", line 14, in <module>
    decoder = StableCascadeDecoderPipeline.from_pretrained("stabilityai/stable-cascade", torch_dtype=torch.half)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/diffusers/pipelines/pipeline_utils.py", line 1263, in from_pretrained
    loaded_sub_model = load_sub_model(
                       ^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/diffusers/pipelines/pipeline_utils.py", line 531, in load_sub_model
    loaded_sub_model = load_method(os.path.join(cached_folder, name), **loading_kwargs)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/huggingface_hub/utils/_validators.py", line 118, in _inner_fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/diffusers/models/modeling_utils.py", line 669, in from_pretrained
    unexpected_keys = load_model_dict_into_meta(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/diffusers/models/modeling_utils.py", line 154, in load_model_dict_into_meta
    raise ValueError(
ValueError: Cannot load /Users/it6/.cache/huggingface/hub/models--stabilityai--stable-cascade/snapshots/e3aee2fd11a00865f5c085d3e741f2e51aef12d3/decoder because embedding.1.weight expected shape tensor(..., device='meta', size=(320, 64, 1, 1)), but got torch.Size([320, 16, 1, 1]). If you want to instead overwrite randomly initialized weights, please make sure to pass both `low_cpu_mem_usage=False` and `ignore_mismatched_sizes=True`. For more information, see also: https://github.com/huggingface/diffusers/issues/1619#issuecomment-1345604389 as an example.

jcplus avatar Feb 21 '24 10:02 jcplus

It appears that no matter how you run it, there is an issue with the mismatched types that setting: ignore_mismatched_sizes=True doesn't have any effect at this point. At least from what I have seen so far.

KylanDixonMF avatar Feb 21 '24 22:02 KylanDixonMF