v3: multi-turn eval batch size
Browse filesFiles changed (3)
- merge_local.pyAdded+25
- test_runtime.pyAdded+46
- train_eval.py+1-1
12345678910111213141516171819202122232425"""Merge the LoRA into the base model locally (CPU) so it can be converted to GGUF."""import shutilfrom pathlib import Path
import torchfrom peft import PeftModelfrom transformers import AutoModelForCausalLM, AutoTokenizer
BASE = "openbmb/MiniCPM5-1B"ADAPTER = "DevGwardo/minicpm5-1b-toolcall"OUT = Path("merged")
tok = AutoTokenizer.from_pretrained(ADAPTER)model = AutoModelForCausalLM.from_pretrained( BASE, dtype=torch.float32, low_cpu_mem_usage=True, use_kernels=False)model = PeftModel.from_pretrained(model, ADAPTER)model = model.merge_and_unload()model = model.half()model.save_pretrained(OUT, safe_serialization=True, max_shard_size="2GB")tok.save_pretrained(OUT)tpl = Path("output/chat_template.jinja")if tpl.exists(): shutil.copy(tpl, OUT / "chat_template.jinja")print("merged ->", OUT)12345678910111213141516171819202122232425262728293031323334353637383940414243444546"""End-to-end check: call the merged GGUF through llama-server's OpenAI endpoint."""import jsonimport sys
import requests
URL = sys.argv[1] if len(sys.argv) > 1 else "http://127.0.0.1:8080/v1/chat/completions"tools = [ { "type": "function", "function": { "name": "get_weather", "description": "Get the current weather for a city", "parameters": { "type": "object", "properties": { "location": {"type": "string"}, "units": {"type": "string", "enum": ["celsius", "fahrenheit"]}, }, "required": ["location"], }, }, }]cases = [ ("What's the weather in Paris in celsius?", True), ("What is the capital of France?", False),]for q, expect in cases: r = requests.post( URL, json={ "messages": [{"role": "user", "content": q}], "tools": tools, "tool_choice": "auto", "temperature": 0, "max_tokens": 192, }, timeout=300, ) r.raise_for_status() msg = r.json()["choices"][0]["message"] calls = msg.get("tool_calls") or [] print(f"\nQ: {q}") print("expect call:", expect, "| got:", len(calls)) print(json.dumps(calls or msg.get("content", "")[:300], ensure_ascii=False, indent=2))209 unmodified lines210211212213214215216209 unmodified linesdef generate(prompts):texts = []for batch in make_batches(prompts, 16):enc = tok(batch, return_tensors="pt", padding=True, add_special_tokens=False).to(model.device)out = model.generate(**enc, max_new_tokens=192, do_sample=False, eos_token_id=im_end, pad_token_id=tok.pad_token_id209 unmodified lines210211212213214215216209 unmodified linesdef generate(prompts):texts = []for batch in make_batches(prompts, 8):enc = tok(batch, return_tensors="pt", padding=True, add_special_tokens=False).to(model.device)out = model.generate(**enc, max_new_tokens=192, do_sample=False, eos_token_id=im_end, pad_token_id=tok.pad_token_id
merge_local.pyAdded+25
test_runtime.pyAdded+46
train_eval.py+1-1