pere commited on
Commit
db6aa17
1 Parent(s): b64019e

Update export_models.sh

Browse files
Files changed (1) hide show
  1. export_models.sh +39 -0
export_models.sh ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ pip install "optimum[exporters]>=1.14.1" tensorflow
3
+
4
+ python << END
5
+ from transformers import WhisperForConditionalGeneration, TFWhisperForConditionalGeneration, WhisperTokenizerFast
6
+ import shutil
7
+
8
+ # Backup generation_config.json
9
+ shutil.copyfile('./generation_config.json', './generation_config_backup.json')
10
+
11
+ print("Saving model to PyTorch...", end=" ")
12
+ model = WhisperForConditionalGeneration.from_pretrained("./", from_flax=True)
13
+ model.save_pretrained("./", safe_serialization=True)
14
+ model.save_pretrained("./")
15
+ print("Done.")
16
+
17
+ print("Saving model to TensorFlow...", end=" ")
18
+ tf_model = TFWhisperForConditionalGeneration.from_pretrained("./", from_pt=True)
19
+ tf_model.save_pretrained("./")
20
+ print("Done.")
21
+
22
+ # Restore the backup of generation_config.json
23
+ shutil.move('./generation_config_backup.json', './generation_config.json')
24
+
25
+ print("Saving model to ONNX...", end=" ")
26
+ from optimum.onnxruntime import ORTModelForSpeechSeq2Seq
27
+ ort_model = ORTModelForSpeechSeq2Seq.from_pretrained("./", export=True)
28
+ ort_model.save_pretrained("./onnx")
29
+ print("Done")
30
+
31
+ END
32
+
33
+ echo "Saving model to GGML (whisper.cpp)"
34
+ wget -O convert-h5-to-ggml.py "https://raw.githubusercontent.com/ggerganov/whisper.cpp/94aa56f19eed8b2419bc5ede6b7fda85d5ca59be/models/convert-h5-to-ggml.py"
35
+ mkdir -p whisper/assets
36
+ wget -O whisper/assets/mel_filters.npz "https://github.com/openai/whisper/raw/c5d42560760a05584c1c79546a098287e5a771eb/whisper/assets/mel_filters.npz"
37
+ python ./convert-h5-to-ggml.py ./ ./ ./
38
+ rm ./convert-h5-to-ggml.py
39
+ rm -rf ./whisper