ChibuUkachi commited on
Commit
dac04dc
·
verified ·
1 Parent(s): 3beb36a

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. convert_ministral_hf_to_mistral.py +4 -4
convert_ministral_hf_to_mistral.py CHANGED
@@ -130,21 +130,21 @@ def convert_state_dict(hf_state_dict, config):
130
  if "language_model" in hf_key:
131
  if hf_key.endswith("q_proj.weight"):
132
  tensor = permute_for_mistral_rope(tensor, text_num_attention_heads, text_query_dim, text_hidden_size)
133
- elif hf_key.endswith("q_proj.weight_scale") and tensor.size(0) == text_num_attention_heads:
134
  tensor = permute_for_mistral_rope(tensor, text_num_attention_heads, text_query_dim, 1)
135
  elif hf_key.endswith("k_proj.weight"):
136
  tensor = permute_for_mistral_rope(tensor, text_num_key_value_heads, text_key_value_dim, text_hidden_size)
137
- elif hf_key.endswith("k_proj.weight_scale") and tensor.size(0) == text_num_key_value_heads:
138
  tensor = permute_for_mistral_rope(tensor, text_num_key_value_heads, text_key_value_dim, 1)
139
 
140
  if "vision_tower" in hf_key:
141
  if hf_key.endswith("q_proj.weight"):
142
  tensor = permute_for_mistral_rope(tensor, vision_num_attention_heads, vision_query_dim, vision_hidden_size)
143
- elif hf_key.endswith("q_proj.weight_scale") and tensor.size(0) == vision_num_attention_heads:
144
  tensor = permute_for_mistral_rope(tensor, vision_num_attention_heads, vision_query_dim, 1)
145
  elif hf_key.endswith("k_proj.weight"):
146
  tensor = permute_for_mistral_rope(tensor, vision_num_key_value_heads, vision_key_value_dim, vision_hidden_size)
147
- elif hf_key.endswith("k_proj.weight_scale") and tensor.size(0) == vision_num_key_value_heads:
148
  tensor = permute_for_mistral_rope(tensor, vision_num_key_value_heads, vision_key_value_dim, 1)
149
 
150
  mistral_dict[mistral_key] = tensor
 
130
  if "language_model" in hf_key:
131
  if hf_key.endswith("q_proj.weight"):
132
  tensor = permute_for_mistral_rope(tensor, text_num_attention_heads, text_query_dim, text_hidden_size)
133
+ elif hf_key.endswith("q_proj.weight_scale") and tensor.size(0) > 1:
134
  tensor = permute_for_mistral_rope(tensor, text_num_attention_heads, text_query_dim, 1)
135
  elif hf_key.endswith("k_proj.weight"):
136
  tensor = permute_for_mistral_rope(tensor, text_num_key_value_heads, text_key_value_dim, text_hidden_size)
137
+ elif hf_key.endswith("k_proj.weight_scale") and tensor.size(0) > 1:
138
  tensor = permute_for_mistral_rope(tensor, text_num_key_value_heads, text_key_value_dim, 1)
139
 
140
  if "vision_tower" in hf_key:
141
  if hf_key.endswith("q_proj.weight"):
142
  tensor = permute_for_mistral_rope(tensor, vision_num_attention_heads, vision_query_dim, vision_hidden_size)
143
+ elif hf_key.endswith("q_proj.weight_scale") and tensor.size(0) > 1:
144
  tensor = permute_for_mistral_rope(tensor, vision_num_attention_heads, vision_query_dim, 1)
145
  elif hf_key.endswith("k_proj.weight"):
146
  tensor = permute_for_mistral_rope(tensor, vision_num_key_value_heads, vision_key_value_dim, vision_hidden_size)
147
+ elif hf_key.endswith("k_proj.weight_scale") and tensor.size(0) > 1:
148
  tensor = permute_for_mistral_rope(tensor, vision_num_key_value_heads, vision_key_value_dim, 1)
149
 
150
  mistral_dict[mistral_key] = tensor