Update download_model.py
Browse files- 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 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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")
|