Delete host_weight/gen_csv.py
Browse files- host_weight/gen_csv.py +0 -30
host_weight/gen_csv.py
DELETED
|
@@ -1,30 +0,0 @@
|
|
| 1 |
-
from transformers import AutoModelForCausalLM
|
| 2 |
-
import argparse
|
| 3 |
-
import numpy as np
|
| 4 |
-
import os
|
| 5 |
-
|
| 6 |
-
def write_csv_chunked(path, array, chunk_rows=1024):
|
| 7 |
-
with open(path, "w") as f:
|
| 8 |
-
n_rows = array.shape[0]
|
| 9 |
-
for start in range(0, n_rows, chunk_rows):
|
| 10 |
-
end = min(start + chunk_rows, n_rows)
|
| 11 |
-
np.savetxt(f, array[start:end], delimiter=",")
|
| 12 |
-
|
| 13 |
-
if __name__ == "__main__":
|
| 14 |
-
parser = argparse.ArgumentParser(description="Generate CSV file with model information.")
|
| 15 |
-
parser.add_argument("--model_dir", type=str, default="../../quant/hf_weight", help="Directory to save the model files.")
|
| 16 |
-
parser.add_argument("--emb", type=str, default="emb", help="Path to save the embedding CSV file.")
|
| 17 |
-
parser.add_argument("--whead", type=str, default="Whead_fp", help="Path to save the Whead CSV file.")
|
| 18 |
-
args = parser.parse_args()
|
| 19 |
-
model = AutoModelForCausalLM.from_pretrained(args.model_dir)
|
| 20 |
-
|
| 21 |
-
emb = model.model.embed_tokens.weight.detach().cpu().numpy() # (V, H)
|
| 22 |
-
whead = model.lm_head.weight.detach().cpu().numpy()
|
| 23 |
-
|
| 24 |
-
emb_csv = args.emb + ".csv"
|
| 25 |
-
write_csv_chunked(emb_csv, emb)
|
| 26 |
-
print(f"Saved embeddings to {emb_csv}.")
|
| 27 |
-
whead_csv = args.whead + ".csv"
|
| 28 |
-
write_csv_chunked(whead_csv, whead)
|
| 29 |
-
print(f"Saved Whead to {whead_csv}.")
|
| 30 |
-
print("Conversion to binary completed.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|