fix eval_llm: add --tokenizer_path/--native flags, auto-detect num_hidden_layers from checkpoint; update README with correct inference commands
Browse files- README.md +22 -10
- scripts/eval_llm.py +11 -7
README.md
CHANGED
|
@@ -67,15 +67,11 @@ src/
|
|
| 67 |
│ └── checkpoint.py # checkpoint 读写辅助
|
| 68 |
├── serve/ # 实时语音会话(SileroVAD / RealtimeSession)
|
| 69 |
configs/
|
| 70 |
-
├──
|
| 71 |
-
├── lm_full_sft_moe.yaml # 纯文本 MoE SFT 训练配置
|
| 72 |
-
├── lm_pretrain.yaml # 纯文本预训练配置
|
| 73 |
-
├── lm_pretrain_moe.yaml # 纯文本 MoE 预训练配置
|
| 74 |
-
├── vlm.yaml # 视觉多模态训练配置
|
| 75 |
-
├── lm/ # 纯文本 LM 配置
|
| 76 |
├── vlm/ # 视觉多模态 VLM 配置
|
| 77 |
-
|
| 78 |
-
|
|
|
|
| 79 |
scripts/ # 推理 / 服务 / 转换脚本
|
| 80 |
├── eval_llm.py # 命令行推理与对话
|
| 81 |
├── eval_vlm.py # 视觉多模态推理
|
|
@@ -111,7 +107,7 @@ python -m trainers.lm.pretrain --config configs/lm/lm_pretrain.yaml
|
|
| 111 |
# 全量 SFT(以预训练权重初始化,指令微调)
|
| 112 |
python -m trainers.lm.full_sft --config configs/lm/lm_full_sft.yaml
|
| 113 |
|
| 114 |
-
# 训练 tokenizer
|
| 115 |
python -m trainers.lm.train_tokenizer --data_path dataset/sft_t2t_mini.jsonl \
|
| 116 |
--vocab_size 6400 \
|
| 117 |
--checkpoint_dir ./checkpoint \
|
|
@@ -177,7 +173,23 @@ torchrun --nproc_per_node=4 -m trainers.lm.full_sft --config configs/lm/lm_full_
|
|
| 177 |
### 推理 / 对话
|
| 178 |
|
| 179 |
```bash
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
```
|
| 182 |
|
| 183 |
## 配置说明
|
|
|
|
| 67 |
│ └── checkpoint.py # checkpoint 读写辅助
|
| 68 |
├── serve/ # 实时语音会话(SileroVAD / RealtimeSession)
|
| 69 |
configs/
|
| 70 |
+
├── lm/ # 纯文本 LM 配置(pretrain / full_sft / MoE / mini)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
├── vlm/ # 视觉多模态 VLM 配置
|
| 72 |
+
└── vam/ # 全模态 VAM 配置
|
| 73 |
+
checkpoint/
|
| 74 |
+
└── tokenizer/ # tokenizer.json / tokenizer_config.json(由 train_tokenizer.py 生成)
|
| 75 |
scripts/ # 推理 / 服务 / 转换脚本
|
| 76 |
├── eval_llm.py # 命令行推理与对话
|
| 77 |
├── eval_vlm.py # 视觉多模态推理
|
|
|
|
| 107 |
# 全量 SFT(以预训练权重初始化,指令微调)
|
| 108 |
python -m trainers.lm.full_sft --config configs/lm/lm_full_sft.yaml
|
| 109 |
|
| 110 |
+
# 训练 tokenizer
|
| 111 |
python -m trainers.lm.train_tokenizer --data_path dataset/sft_t2t_mini.jsonl \
|
| 112 |
--vocab_size 6400 \
|
| 113 |
--checkpoint_dir ./checkpoint \
|
|
|
|
| 173 |
### 推理 / 对话
|
| 174 |
|
| 175 |
```bash
|
| 176 |
+
# 加载 SFT 模型对话(mini 版)
|
| 177 |
+
python scripts/eval_llm.py --save_dir checkpoint/lm_full_sft_mini \
|
| 178 |
+
--weight full_sft --hidden_size 128 --native
|
| 179 |
+
|
| 180 |
+
# 加载 pretrain 模型(仅续写,无对话格式)
|
| 181 |
+
python scripts/eval_llm.py --save_dir checkpoint/lm_pretrain_mini \
|
| 182 |
+
--weight pretrain --hidden_size 128 --native
|
| 183 |
+
|
| 184 |
+
# 全量版(hidden_size=512)
|
| 185 |
+
python scripts/eval_llm.py --save_dir checkpoint/lm/full_sft \
|
| 186 |
+
--weight full_sft --hidden_size 512 --native
|
| 187 |
+
|
| 188 |
+
# 多模态视觉 VLM
|
| 189 |
+
python scripts/eval_vlm.py --save_dir checkpoint/vlm --weight full_sft
|
| 190 |
+
|
| 191 |
+
# 全模态 VAM(文本 + 视觉 + 语音)
|
| 192 |
+
python scripts/eval_vam.py --save_dir checkpoint/vam --weight full_sft
|
| 193 |
```
|
| 194 |
|
| 195 |
## 配置说明
|
scripts/eval_llm.py
CHANGED
|
@@ -10,17 +10,19 @@ from utils.training import setup_seed, get_model_params
|
|
| 10 |
warnings.filterwarnings('ignore')
|
| 11 |
|
| 12 |
def init_model(args):
|
| 13 |
-
tokenizer = AutoTokenizer.from_pretrained(args.
|
| 14 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
model = LMForCausalLM(LMConfig(
|
| 16 |
hidden_size=args.hidden_size,
|
| 17 |
-
num_hidden_layers=
|
| 18 |
use_moe=bool(args.use_moe),
|
| 19 |
inference_rope_scaling=args.inference_rope_scaling
|
| 20 |
))
|
| 21 |
-
|
| 22 |
-
ckp = f'./{args.save_dir}/{args.weight}_{args.hidden_size}{moe_suffix}.pth'
|
| 23 |
-
model.load_state_dict(torch.load(ckp, map_location=args.device), strict=True)
|
| 24 |
if args.lora_weight != 'None':
|
| 25 |
apply_lora(model)
|
| 26 |
load_lora(model, f'./{args.save_dir}/{args.lora_weight}_{args.hidden_size}.pth')
|
|
@@ -31,7 +33,9 @@ def init_model(args):
|
|
| 31 |
|
| 32 |
def main():
|
| 33 |
parser = argparse.ArgumentParser(description="MiniMind模型推理与对话")
|
| 34 |
-
parser.add_argument('--load_from', default='
|
|
|
|
|
|
|
| 35 |
parser.add_argument('--save_dir', default='out', type=str, help="模型权重目录")
|
| 36 |
parser.add_argument('--weight', default='full_sft', type=str, help="权重名称前缀(pretrain, full_sft, rlhf, reason, ppo_actor, grpo, spo)")
|
| 37 |
parser.add_argument('--lora_weight', default='None', type=str, help="LoRA权重名称(None表示不使用,可选:lora_identity, lora_medical)")
|
|
|
|
| 10 |
warnings.filterwarnings('ignore')
|
| 11 |
|
| 12 |
def init_model(args):
|
| 13 |
+
tokenizer = AutoTokenizer.from_pretrained(args.tokenizer_path)
|
| 14 |
+
if args.native:
|
| 15 |
+
moe_suffix = '_moe' if args.use_moe else ''
|
| 16 |
+
ckp = f'./{args.save_dir}/{args.weight}_{args.hidden_size}{moe_suffix}.pth'
|
| 17 |
+
state = torch.load(ckp, map_location=args.device)
|
| 18 |
+
n_layers = max(int(k.split('.')[2]) for k in state if k.startswith('model.layers.')) + 1
|
| 19 |
model = LMForCausalLM(LMConfig(
|
| 20 |
hidden_size=args.hidden_size,
|
| 21 |
+
num_hidden_layers=n_layers,
|
| 22 |
use_moe=bool(args.use_moe),
|
| 23 |
inference_rope_scaling=args.inference_rope_scaling
|
| 24 |
))
|
| 25 |
+
model.load_state_dict(state, strict=True)
|
|
|
|
|
|
|
| 26 |
if args.lora_weight != 'None':
|
| 27 |
apply_lora(model)
|
| 28 |
load_lora(model, f'./{args.save_dir}/{args.lora_weight}_{args.hidden_size}.pth')
|
|
|
|
| 33 |
|
| 34 |
def main():
|
| 35 |
parser = argparse.ArgumentParser(description="MiniMind模型推理与对话")
|
| 36 |
+
parser.add_argument('--load_from', default='', type=str, help="模型加载路径(transformers格式,native模式不感知此参数)")
|
| 37 |
+
parser.add_argument('--tokenizer_path', default='checkpoint/tokenizer', type=str, help="tokenizer 路径")
|
| 38 |
+
parser.add_argument('--native', action='store_true', help="加载原生 torch checkpoint(由 save_dir/weight/hidden_size 定位)")
|
| 39 |
parser.add_argument('--save_dir', default='out', type=str, help="模型权重目录")
|
| 40 |
parser.add_argument('--weight', default='full_sft', type=str, help="权重名称前缀(pretrain, full_sft, rlhf, reason, ppo_actor, grpo, spo)")
|
| 41 |
parser.add_argument('--lora_weight', default='None', type=str, help="LoRA权重名称(None表示不使用,可选:lora_identity, lora_medical)")
|