import torchfrom peft import PeftModelfrom transformers import AutoModelForCausalLM, AutoTokenizer BASE_ID = "Qwen/Qwen3-1.7B"BASE_REV = "70d244cc86ccca08cf5af4e1e306ecf908b1ad5e"ADAPTER_ID = "abubakar56/formulalm-qwen3-1.7b-lora-v3" tok = AutoTokenizer.from_pretrained(BASE_ID, revision=BASE_REV)base = AutoModelForCausalLM.from_pretrained( BASE_ID, revision=BASE_REV, dtype=torch.float16, device_map="auto")model = PeftModel.from_pretrained(base, ADAPTER_ID).eval() messages = [ { "role": "system", "content": ( "You are FormulaLM. Given a spreadsheet schema and a user request, reply with only " "the Excel formula starting with '='. No explanation, no markdown." ), }, { "role": "user", "content": ( "Sheet: sales_retail_store (rows 2..115)\n" "Columns:\nA: Receipt Code (text)\nB: Sale Date (date)\n" "C: Store Branch (category)\nD: Item Name (text)\n" "E: Quantity (integer)\nF: Net Amount (decimal)\n\n" "Request: Total Net Amount for the Mirehaven branch" ), },]prompt = tok.apply_chat_template( messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)inputs = tok(prompt, return_tensors="pt").to(model.device)out = model.generate(**inputs, max_new_tokens=96, do_sample=False)print(tok.decode(out[0, inputs["input_ids"].shape[1] :], skip_special_tokens=True).strip())