import torchfrom transformers import AutoModelForCausalLM, AutoTokenizerfrom peft import PeftModel base_model = "Qwen/Qwen2.5-0.5B-Instruct"adapter_id = "j-llm/navspec-lora-0.5b-v0.1" tokenizer = AutoTokenizer.from_pretrained(base_model)model = AutoModelForCausalLM.from_pretrained( base_model, torch_dtype=torch.float16, device_map="auto")model = PeftModel.from_pretrained(model, adapter_id) # プロンプト例(ChatML形式)messages = [ { "role": "system", "content": "You are navspec-armament-judge. Given the ship context and proposed main battery, return only JSON matching navspec.armament_verdict.v1." }, { "role": "user", "content": "{\"hull\":{\"displacement_t\":2000},\"candidate\":{...}}" }] prompt = tokenizer.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)inputs = tokenizer(prompt, return_tensors="pt").to(model.device) with torch.no_grad(): outputs = model.generate(**inputs, max_new_tokens=100, do_sample=False)print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))