chatglm_export.py 568 Bytes
Newer Older
zhouxiang's avatar
zhouxiang committed
1
2
3
4
5
import sys
from transformers import AutoTokenizer, AutoModel
from fastllm_pytools import torch2flm

if __name__ == "__main__":
6
7
8
    model_path = "/home/ZhipuAI/chatglm3-6b"
    tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
    model = AutoModel.from_pretrained(model_path, trust_remote_code=True)
zhouxiang's avatar
zhouxiang committed
9
10
11
    model = model.eval()

    dtype = sys.argv[2] if len(sys.argv) >= 3 else "float16"
12
    exportPath = sys.argv[1] if len(sys.argv) >= 2 else "chatglm-6b-" + dtype + ".flm"
zhouxiang's avatar
zhouxiang committed
13
    torch2flm.tofile(exportPath, model, tokenizer, dtype = dtype)