@@ -117,6 +117,16 @@ def load_huggingface_chekckpoints(path, num_checkpoints):
117117 "time_projection.1.bias" ,
118118]
119119extra_first_part_dict = {
120+ "wan2_1_i2v" : [
121+ "img_emb.proj.0.weight" ,
122+ "img_emb.proj.0.bias" ,
123+ "img_emb.proj.1.weight" ,
124+ "img_emb.proj.1.bias" ,
125+ "img_emb.proj.3.weight" ,
126+ "img_emb.proj.3.bias" ,
127+ "img_emb.proj.4.weight" ,
128+ "img_emb.proj.4.bias" ,
129+ ],
120130 "wan2_2_i2v" : []
121131}
122132first_part_list = base_first_part_list + extra_first_part_dict .get (model_name , [])
@@ -158,6 +168,15 @@ def load_huggingface_chekckpoints(path, num_checkpoints):
158168 "decoder.layers.0.cross_attn.q_layernorm.weight" : "blocks.0.cross_attn.norm_q.weight" ,
159169 "decoder.layers.0.cross_attn.k_layernorm.weight" : "blocks.0.cross_attn.norm_k.weight" ,
160170}
171+ wan2_1_second_part_dict = {
172+ "decoder.layers.0.cross_attn.linear_k_img.weight" : "blocks.0.cross_attn.k_img.weight" ,
173+ "decoder.layers.0.cross_attn.linear_k_img.bias" : "blocks.0.cross_attn.k_img.bias" ,
174+ "decoder.layers.0.cross_attn.linear_v_img.weight" : "blocks.0.cross_attn.v_img.weight" ,
175+ "decoder.layers.0.cross_attn.linear_v_img.bias" : "blocks.0.cross_attn.v_img.bias" ,
176+ "decoder.layers.0.cross_attn.k_img_layernorm.weight" : "blocks.0.cross_attn.norm_k_img.weight" ,
177+ }
178+ if model_name == "wan2_1_i2v" :
179+ second_part_dict .update (wan2_1_second_part_dict )
161180# Parts that do not need transpose inside
162181inside_blk_replace_dict = {
163182 "blocks.0.ffn.0.weight" : "decoder.layers.0.ffn.0.weight" ,
@@ -171,6 +190,11 @@ def load_huggingface_chekckpoints(path, num_checkpoints):
171190 "blocks.0.cross_attn.norm_q.weight" : "decoder.layers.0.cross_attn.q_layernorm.weight" ,
172191 "blocks.0.cross_attn.norm_k.weight" : "decoder.layers.0.cross_attn.k_layernorm.weight" ,
173192}
193+ wan2_1_inside_blk_replace_dict = {
194+ "blocks.0.cross_attn.norm_k_img.weight" : "decoder.layers.0.cross_attn.k_img_layernorm.weight" ,
195+ }
196+ if model_name == "wan2_1_i2v" :
197+ inside_blk_replace_dict .update (wan2_1_inside_blk_replace_dict )
174198# Model last part
175199third_part_dict = {
176200 "head.modulation" ,
@@ -243,6 +267,21 @@ def load_huggingface_chekckpoints(path, num_checkpoints):
243267 concat_kv_bias
244268 )
245269
270+ if model_name == "wan2_1_i2v" :
271+ cross_k_img_w = state_dict ["blocks." + str (i ) + ".cross_attn.k_img.weight" ]
272+ cross_k_img_w = rearrange (cross_k_img_w , "(R N D) H -> (N R D) H" , R = 1 , N = 40 , D = 128 , H = 5120 )
273+ cross_k_img_b = state_dict ["blocks." + str (i ) + ".cross_attn.k_img.bias" ]
274+ cross_k_img_b = rearrange (cross_k_img_b , "(R N D H) -> (N R D H)" , R = 1 , N = 40 , D = 128 , H = 1 )
275+ new_state_dict ["decoder.layers." + str (i ) + ".cross_attn.linear_k_img.weight" ] = cross_k_img_w
276+ new_state_dict ["decoder.layers." + str (i ) + ".cross_attn.linear_k_img.bias" ] = cross_k_img_b
277+
278+ cross_v_img_w = state_dict ["blocks." + str (i ) + ".cross_attn.v_img.weight" ]
279+ cross_v_img_w = rearrange (cross_v_img_w , "(R N D) H -> (N R D) H" , R = 1 , N = 40 , D = 128 , H = 5120 )
280+ cross_v_img_b = state_dict ["blocks." + str (i ) + ".cross_attn.v_img.bias" ]
281+ cross_v_img_b = rearrange (cross_v_img_b , "(R N D H) -> (N R D H)" , R = 1 , N = 40 , D = 128 , H = 1 )
282+ new_state_dict ["decoder.layers." + str (i ) + ".cross_attn.linear_v_img.weight" ] = cross_v_img_w
283+ new_state_dict ["decoder.layers." + str (i ) + ".cross_attn.linear_v_img.bias" ] = cross_v_img_b
284+
246285 # cross_attention o transpose
247286 cross_o_weight = state_dict ["blocks." + str (i ) + ".cross_attn.o.weight" ]
248287 cross_o_weight = rearrange (
0 commit comments