From bd9f17a775c36aa51397e4aa6f131647c5f88df3 Mon Sep 17 00:00:00 2001
From: Hashim Sharif <hsharif3@miranda.cs.illinois.edu>
Date: Wed, 30 Jun 2021 23:11:13 -0500
Subject: [PATCH] Adding FP16 weight quantization script - NVDLA needs FP16
 weights

---
 .../alexnet_cifar10/scripts/fp16_quantize.py  | 30 +++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 hpvm/test/dnn_benchmarks/hpvm-c/benchmarks/alexnet_cifar10/scripts/fp16_quantize.py

diff --git a/hpvm/test/dnn_benchmarks/hpvm-c/benchmarks/alexnet_cifar10/scripts/fp16_quantize.py b/hpvm/test/dnn_benchmarks/hpvm-c/benchmarks/alexnet_cifar10/scripts/fp16_quantize.py
new file mode 100644
index 0000000000..ded4932c04
--- /dev/null
+++ b/hpvm/test/dnn_benchmarks/hpvm-c/benchmarks/alexnet_cifar10/scripts/fp16_quantize.py
@@ -0,0 +1,30 @@
+
+import numpy as np
+import os
+
+
+if __name__ == "__main__":
+
+    list_dir = os.listdir("./")
+    print (list_dir)
+
+    for file_name in list_dir:
+        if "fp16" not in file_name and ".bin" in file_name:
+            print ("name = ", file_name)
+            weights_arr = np.fromfile(file_name, dtype ='float32')
+            print (weights_arr[:5], weights_arr.shape)
+            fp16_weights = weights_arr.astype(np.float16)
+            print (fp16_weights[:5], fp16_weights.shape)
+        
+            fp16_file = open(file_name.split(".")[0] + "_fp16.bin", "w+")
+            fp16_weights.tofile(fp16_file)
+            fp16_file.close()
+
+
+    for file_name in list_dir:
+        if "fp16" in file_name:
+            print ("fp16_name = ", file_name)
+            weights_arr = np.fromfile(file_name, dtype ='float16')
+            print (weights_arr[:5], weights_arr.shape)
+            
+
-- 
GitLab