Views
No views yet
1from peft import PeftModel
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3.5-2B", dtype="auto", device_map="auto")
5tok = AutoTokenizer.from_pretrained("Vicen-te/qwen3.5-2b-sql-lora")
6model = PeftModel.from_pretrained(base, "Vicen-te/qwen3.5-2b-sql-lora")
7
8messages = [
9 {"role": "system", "content": "You are a precise Text-to-SQL assistant. Output only the SQL query."},
10 {"role": "user", "content": "### Schema\nCREATE TABLE employees (id INT, name TEXT, salary REAL)\n\n### Question\nWhat is the average salary?\n\n### SQL"},
11]
12text = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)
13inputs = tok([text], return_tensors="pt").to(model.device)
14out = model.generate(**inputs, max_new_tokens=128, do_sample=False)
15print(tok.decode(out[0][inputs['input_ids'].shape[-1]:], skip_special_tokens=True))SFTTrainer