Skip to content
Snippets Groups Projects
Commit 48b62996 authored by Hashim Sharif's avatar Hashim Sharif
Browse files

Adding weight manipulation scripts (FP16 + Transpose)

parent 46bdcda8
No related branches found
No related tags found
No related merge requests found
import numpy as np
import os
import sys
if __name__ == "__main__":
weights_dir = sys.argv[1]
list_dir = os.listdir(weights_dir)
print (list_dir)
for file_name in list_dir:
if "_b" not in file_name and "dense" in file_name and "fp16" in file_name:
print ("name = ", file_name)
f_path = weights_dir + "/" + file_name
x = np.fromfile(f_path, dtype='float16')
x_reshaped = np.reshape(x, (10, 4096))
x_transposed = np.transpose(x_reshaped, (1, 0))
print (x_reshaped)
print ("x_trans = ", x_transposed)
x_flat = x_transposed.flatten()
x_fp16 = x_flat.astype(np.float16)
outfile = open("transpose.bin", "w+")
x_fp16.tofile(outfile)
outfile.close()
# Double transpose to check corectness
x_double_transposed = np.transpose(x_transposed, (1, 0))
print ("double_tranposed = ", x_double_transposed)
x2_flat = x_double_transposed.flatten()
x2_fp16 = x2_flat.astype(np.float16)
outfile = open("double_transpose.bin", "w+")
x2_fp16.tofile(outfile)
outfile.close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment