Skip to content

Commit

Permalink
Update src/transformers/models/moonshine/convert_usefulsensors_to_hf.py
Browse files Browse the repository at this point in the history
Co-authored-by: Joshua Lochner <[email protected]>
  • Loading branch information
eustlb and xenova authored Dec 16, 2024
1 parent f548504 commit 3d52b1e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/transformers/models/moonshine/convert_usefulsensors_to_hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,29 @@ def convert_usefulsensors_moonshine_to_hf(model_name, pytorch_dump_folder_path):
converted_decoder_weights = _convert_weights(loaded_decoder_weights, encoder=False)
converted_decoder_weights['embed_tokens.weight'] = converted_decoder_weights['embed_tokens.weight'].T

final_weights = {}
for k, v in encoder_state_dict.items():
final_weights[f"model.encoder.{k}"] = v

for k, v in converted_decoder_weights.items():
final_weights[f"model.decoder.{k}"] = v

if model_name == 'tiny':
config = MoonshineConfig()
elif model_name == 'base':
config = MoonshineConfig(
hidden_size=416,
num_hidden_layers=8,
num_attention_heads=8,
)
else:
raise ValueError(f"Unknown model name {model_name}")

final_weights['proj_out.weight'] = converted_decoder_weights['embed_tokens.weight']

model = MoonshineForConditionalGeneration(config)
model.load_state_dict(final_weights)
model.save_pretrained(pytorch_dump_folder_path)



Expand Down

0 comments on commit 3d52b1e

Please sign in to comment.