tranquilk commited on
Commit
8c546f3
·
verified ·
1 Parent(s): 6e3a23d

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. convert_checkpoint.py +54 -0
  2. latest_checkpoint.pth +3 -0
convert_checkpoint.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import os
4
+
5
+ # --- 1. 配置你的路径 ---
6
+
7
+ # 你微调时使用的“基础模型”的Hugging Face Hub ID
8
+ # !!!这一步至关重要,必须是你开始训练时用的那个模型!!!
9
+ base_model_id = "Qwen/Qwen1.5-7B"
10
+
11
+ # 你保存的训练检查点 .pth 文件的路径
12
+ checkpoint_path = "/path/to/your/checkpoint.pth" # <--- 修改这里:你的.pth文件路径
13
+
14
+ # 你想将转换后的、可供评测的模型保存到哪里?
15
+ # 这会是一个新的目录,lm-evaluation-harness将从这里加载
16
+ output_dir = "../my_pretrain_for_eval" # <--- 修改这里:定义你的输出目录名
17
+
18
+ # --- 2. 加载基础模型和Tokenizer ---
19
+ # 这一步是获取模型的“骨架”(架构)和分词器
20
+
21
+ print(f"Loading base model architecture from: {base_model_id}")
22
+ # trust_remote_code=True 对于Qwen等模型是必需的
23
+ model = AutoModelForCausalLM.from_pretrained(base_model_id, trust_remote_code=True)
24
+ tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
25
+
26
+ # --- 3. 加载你的检查点并提取模型权重 ---
27
+
28
+ print(f"Loading training checkpoint from: {checkpoint_path}")
29
+ # 加载你保存的字典
30
+ checkpoint = torch.load(checkpoint_path, map_location='cpu') # 使用map_location='cpu'以避免GPU内存问题
31
+
32
+ # 从字典中提取模型的 state_dict
33
+ # 根据你保存的代码,权重在 'model' 这个键下
34
+ model_weights = checkpoint['model']
35
+
36
+ # --- 4. 将你的权重加载到模型“骨架”中 ---
37
+
38
+ print("Loading fine-tuned weights into the model...")
39
+ model.load_state_dict(model_weights)
40
+ print("Weights loaded successfully.")
41
+
42
+ # --- 5. 将模型和Tokenizer保存为标准的Hugging Face格式 ---
43
+
44
+ print(f"Saving model and tokenizer to: {output_dir}")
45
+ os.makedirs(output_dir, exist_ok=True)
46
+
47
+ # model.save_pretrained() 会自动创建 config.json, pytorch_model.bin 等文件
48
+ model.save_pretrained(output_dir)
49
+
50
+ # tokenizer.save_pretrained() 会自动创建 tokenizer.json 等文件
51
+ tokenizer.save_pretrained(output_dir)
52
+
53
+ print("Conversion complete!")
54
+ print(f"Your model is now ready for evaluation at: {output_dir}")
latest_checkpoint.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:875067c4a946633699e0f8875a243032d9abfdfe7b25463b52adb735d7501d37
3
+ size 310056955