modelscope / DiffSynth-Studio

Enjoy the magic of Diffusion models!
Apache License 2.0
5.51k stars 502 forks source link

Error when loading HunyuanDiTCLIPTextEncoder: Missing key "embeddings.position_ids" in state_dict #46

Open hans1996 opened 1 week ago

hans1996 commented 1 week ago

Thank you for your help and support!

Issue Description

An error occurred while running ExVideo_svd_test.py. The error happens when loading the HunyuanDiTCLIPTextEncoder model, indicating a missing key "embeddings.position_ids" in the state dictionary.

Execute the following command:

python examples/ExVideo/ExVideo_svd_test.py

output

pytorch_model.bin has been already in models/HunyuanDiT/t2i/clip_text_encoder. pytorch_model.bin has been already in models/HunyuanDiT/t2i/mt5. pytorch_model_ema.pt has been already in models/HunyuanDiT/t2i/model. diffusion_pytorch_model.bin has been already in models/HunyuanDiT/t2i/sdxl-vae-fp16-fix. Traceback (most recent call last): File "/home/hans/DiffSynth-Studio/examples/ExVideo/ExVideo_svd_test.py", line 88, in image = generate_image() File "/home/hans/DiffSynth-Studio/examples/ExVideo/ExVideo_svd_test.py", line 34, in generate_image model_manager = ModelManager(torch_dtype=torch.float16, device="cuda", model_id_list=["HunyuanDiT"]) File "/home/hans/DiffSynth-Studio/diffsynth/models/init.py", line 98, in init self.load_models(downloaded_files + file_path_list) File "/home/hans/DiffSynth-Studio/diffsynth/models/init.py", line 476, in load_models self.load_model(file_path, lora_alphas=lora_alphas) File "/home/hans/DiffSynth-Studio/diffsynth/models/init.py", line 464, in load_model self.load_hunyuan_dit_clip_text_encoder(state_dict, file_path=file_path) File "/home/hans/DiffSynth-Studio/diffsynth/models/init.py", line 360, in load_hunyuan_dit_clip_text_encoder model.load_state_dict(model.state_dict_converter().from_civitai(state_dict)) File "/home/hans/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 2189, in load_state_dict raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( RuntimeError: Error(s) in loading state_dict for HunyuanDiTCLIPTextEncoder: Missing key(s) in state_dict: "embeddings.position_ids".

Artiprocher commented 1 week ago

I suspect that the model file encountered an error during the download process. You can delete the file models/HunyuanDiT/t2i/clip_text_encoder/pytorch_model.bin and download it again, or alternatively, you can manually download it using the link provided in the comments of ExVideo_svd_test.py.

PeterYoungQaQ commented 3 days ago

I updated the version of transformers to the latest version and that solved the problem