Browse Source

[fix] decide native-vs-transformers loading by directory name, not substring

"model" in args.load_from matched any path containing "model" (for
example a Hugging Face cache path or /data/models/...), so the scripts
loaded ./out/*.pth instead of the transformers checkpoint the user
passed. Compare the last path component with "model" instead.

Signed-off-by: YoungjuKim <fjvbn2003@gmail.com>
YoungjuKim 1 month ago
parent
commit
cd36b4a013
3 changed files with 4 additions and 3 deletions
  1. 2 1
      eval_llm.py
  2. 1 1
      scripts/eval_toolcall.py
  3. 1 1
      scripts/serve_openai_api.py

+ 2 - 1
eval_llm.py

@@ -1,3 +1,4 @@
+import os
 import time
 import argparse
 import random
@@ -11,7 +12,7 @@ warnings.filterwarnings('ignore')
 
 def init_model(args):
     tokenizer = AutoTokenizer.from_pretrained(args.load_from)
-    if 'model' in args.load_from:
+    if os.path.basename(os.path.normpath(args.load_from)) == 'model':
         model = MiniMindForCausalLM(MiniMindConfig(
             hidden_size=args.hidden_size,
             num_hidden_layers=args.num_hidden_layers,

+ 1 - 1
scripts/eval_toolcall.py

@@ -56,7 +56,7 @@ TEST_CASES = [
 
 def init_model(args):
     tokenizer = AutoTokenizer.from_pretrained(args.load_from)
-    if 'model' in args.load_from:
+    if os.path.basename(os.path.normpath(args.load_from)) == 'model':
         model = MiniMindForCausalLM(MiniMindConfig(hidden_size=args.hidden_size, num_hidden_layers=args.num_hidden_layers, use_moe=bool(args.use_moe)))
         moe_suffix = '_moe' if args.use_moe else ''
         ckp = f'./{args.save_dir}/{args.weight}_{args.hidden_size}{moe_suffix}.pth'

+ 1 - 1
scripts/serve_openai_api.py

@@ -27,7 +27,7 @@ app = FastAPI()
 
 def init_model(args):
     tokenizer = AutoTokenizer.from_pretrained(args.load_from)
-    if 'model' in args.load_from:
+    if os.path.basename(os.path.normpath(args.load_from)) == 'model':
         moe_suffix = '_moe' if args.use_moe else ''
         ckp = f'../{args.save_dir}/{args.weight}_{args.hidden_size}{moe_suffix}.pth'
         model = MiniMindForCausalLM(MiniMindConfig(