from peft import PeftModelfrom transformers import AutoModelForCausalLM, AutoTokenizer base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3.5-2B", dtype="auto", device_map="auto")tok = AutoTokenizer.from_pretrained("Vicen-te/qwen3.5-2b-sql-lora")model = PeftModel.from_pretrained(base, "Vicen-te/qwen3.5-2b-sql-lora") messages = [ {"role": "system", "content": "You are a precise Text-to-SQL assistant. Output only the SQL query."}, {"role": "user", "content": "### Schema\nCREATE TABLE employees (id INT, name TEXT, salary REAL)\n\n### Question\nWhat is the average salary?\n\n### SQL"},]text = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)inputs = tok([text], return_tensors="pt").to(model.device)# Qwen3.5-2B ships no generation_config.json, so stop on the chat turn end explicitly.out = model.generate(**inputs, max_new_tokens=128, do_sample=False, eos_token_id=tok.eos_token_id)print(tok.decode(out[0][inputs['input_ids'].shape[-1]:], skip_special_tokens=True))