mindspore-lab / mindone

one for all, Optimal generator with No Exception
Apache License 2.0
328 stars 62 forks source link

使用转换权重脚本转换sd1.5原生的模型生成图片失败 #540

Closed jxzhang789 closed 1 week ago

jxzhang789 commented 2 weeks ago

Thanks for sending an issue! Here are some tips for you:

If this is your first time, please read our contributor guidelines: https://github.com/mindspore-ai/mindspore/blob/master/CONTRIBUTING.md

Hardware Environment | 硬件环境

Software Environment | 软件环境

Describe the current behavior | 目前输出

e.g. the current output is xxx/ the error is xxx/ 目前的输出是xx 、 目前的报错是关于xx Traceback (most recent call last): File "/home/ma-user/work/mindone/examples/stable_diffusion_v2/text_to_image.py", line 592, in main(args) File "/home/ma-user/work/mindone/examples/stable_diffusion_v2/text_to_image.py", line 199, in main model = load_model_from_config( File "/home/ma-user/work/mindone/examples/stable_diffusion_v2/text_to_image.py", line 118, in load_model_from_config _load_model(model, ckpt) File "/home/ma-user/work/mindone/examples/stable_diffusion_v2/text_to_image.py", line 69, in _load_model param_not_load, ckpt_not_load = model_utils.load_param_into_net_with_filter( File "/home/ma-user/work/mindone/examples/stable_diffusion_v2/utils/model_utils.py", line 71, in load_param_into_net_with_filter _update_param(param, new_param, strict_load) File "/home/ma-user/anaconda3/envs/MindSpore/lib/python3.9/site-packages/mindspore/train/serialization.py", line 142, in _update_param param.set_data(new_param.data, param.sliced) File "/home/ma-user/anaconda3/envs/MindSpore/lib/python3.9/site-packages/mindspore/_check_jit_forbidden_api.py", line 35, in jit_forbidden return fn(*args, **kwargs) File "/home/ma-user/anaconda3/envs/MindSpore/lib/python3.9/site-packages/mindspore/common/parameter.py", line 853, in set_data Parameter._set_data_check_input_valid(self.shape, data.shape, current_tensor_is_init, incoming_tensor_is_init, File "/home/ma-user/anaconda3/envs/MindSpore/lib/python3.9/site-packages/mindspore/common/parameter.py", line 805, in _set_data_check_input_valid raise ValueError(f"Can not change the shape of Parameter which has been initialized." ValueError: Can not change the shape of Parameter which has been initialized. Current shape is (320, 320), and incoming is (320, 320, 1, 1)

Describe the expected behavior | 期望输出

please describe expected outputs or functions you want to have: 请告诉我们您期望得到的结果或功能 能正常输出图片

Steps to reproduce the issue | 复现报错的步骤

1.使用权重转换脚本转换模型 python tools/model_conversion/convert_weights.py --source /home/ma-user/work/myckpt/v1-5-pruned-emaonly.safetensors --target /home/ma-user/work/myckpt/v1-5-conver.ckpt --model sdv1 --source_version pt 2.脚本转换成功之后,使用文生图脚本进行图片生成 python text_to_image.py \ --prompt "1boy" \ --n_iter 1 \ --n_samples 2 \ --ckpt_path /home/ma-user/work/myckpt/v1-5-conver.ckpt

Related log / screenshot | 完整日志

/home/ma-user/anaconda3/envs/MindSpore/lib/python3.9/site-packages/numpy/core/getlimits.py:549: UserWarning: The value of the smallest subnormal for <class 'numpy.float64'> type is zero. setattr(self, word, getattr(machar, word).flat[0]) /home/ma-user/anaconda3/envs/MindSpore/lib/python3.9/site-packages/numpy/core/getlimits.py:549: UserWarning: The value of the smallest subnormal for <class 'numpy.float32'> type is zero. setattr(self, word, getattr(machar, word).flat[0]) flash attention is available. [2024-06-11 09:53:01] INFO: Loading model from /home/ma-user/work/myckpt/v1-5-conver.ckpt Traceback (most recent call last): File "/home/ma-user/work/mindone/examples/stable_diffusion_v2/text_to_image.py", line 592, in main(args) File "/home/ma-user/work/mindone/examples/stable_diffusion_v2/text_to_image.py", line 199, in main model = load_model_from_config( File "/home/ma-user/work/mindone/examples/stable_diffusion_v2/text_to_image.py", line 118, in load_model_from_config _load_model(model, ckpt) File "/home/ma-user/work/mindone/examples/stable_diffusion_v2/text_to_image.py", line 69, in _load_model param_not_load, ckpt_not_load = model_utils.load_param_into_net_with_filter( File "/home/ma-user/work/mindone/examples/stable_diffusion_v2/utils/model_utils.py", line 71, in load_param_into_net_with_filter _update_param(param, new_param, strict_load) File "/home/ma-user/anaconda3/envs/MindSpore/lib/python3.9/site-packages/mindspore/train/serialization.py", line 142, in _update_param param.set_data(new_param.data, param.sliced) File "/home/ma-user/anaconda3/envs/MindSpore/lib/python3.9/site-packages/mindspore/_check_jit_forbidden_api.py", line 35, in jit_forbidden return fn(*args, **kwargs) File "/home/ma-user/anaconda3/envs/MindSpore/lib/python3.9/site-packages/mindspore/common/parameter.py", line 853, in set_data Parameter._set_data_check_input_valid(self.shape, data.shape, current_tensor_is_init, incoming_tensor_is_init, File "/home/ma-user/anaconda3/envs/MindSpore/lib/python3.9/site-packages/mindspore/common/parameter.py", line 805, in _set_data_check_input_valid raise ValueError(f"Can not change the shape of Parameter which has been initialized." ValueError: Can not change the shape of Parameter which has been initialized. Current shape is (320, 320), and incoming is (320, 320, 1, 1).

Special notes for this issue | 其他信息

Songyuanwei commented 2 weeks ago

please set -v "1.5" for python text_to_image.py to load sd1.5 checkpoint