mwauranjorogekelvin commited on
Commit
4018801
·
verified ·
1 Parent(s): 2241a78

Update download_model.py

Browse files
Files changed (1) hide show
  1. download_model.py +20 -5
download_model.py CHANGED
@@ -1,4 +1,5 @@
1
  from huggingface_hub import hf_hub_download
 
2
  import shutil
3
  import os
4
 
@@ -25,8 +26,22 @@ for cfg in configs:
25
  except Exception as e:
26
  print(f"❌ Failed: {e}")
27
 
28
- if model_path:
29
- shutil.copy(model_path, "./model/model.onnx")
30
- print("✅ ONNX model saved to ./model/model.onnx")
31
- else:
32
- raise RuntimeError("Could not find model.onnx in any repo type")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  from huggingface_hub import hf_hub_download
2
+ from onnxruntime.quantization import quantize_dynamic, QuantType
3
  import shutil
4
  import os
5
 
 
26
  except Exception as e:
27
  print(f"❌ Failed: {e}")
28
 
29
+ if not model_path:
30
+ raise RuntimeError("Could not find model.onnx in any repo type")
31
+
32
+ # Save original first
33
+ print("Saving original model...")
34
+ shutil.copy(model_path, "./model/model_original.onnx")
35
+
36
+ # Quantize to INT8
37
+ print("Quantizing to INT8...")
38
+ quantize_dynamic(
39
+ model_input="./model/model_original.onnx",
40
+ model_output="./model/model.onnx",
41
+ weight_type=QuantType.QUInt8,
42
+ optimize_model=True
43
+ )
44
+
45
+ # Remove original to save space
46
+ os.remove("./model/model_original.onnx")
47
+ print("✅ Quantized ONNX model saved to ./model/model.onnx")