from peft import PeftModelfrom transformers import AutoModelForCausalLM, AutoTokenizerimport torch base = "Qwen/Qwen2.5-Coder-1.5B-Instruct"tokenizer = AutoTokenizer.from_pretrained(base)# float32 or bfloat16. Avoid float16: Qwen2.5 degrades badly in float16.model = AutoModelForCausalLM.from_pretrained(base, dtype=torch.float32)model = PeftModel.from_pretrained(model, "krishna382nitjsr/index-drift-rl-qwen1.5b-grpo-v0.1") system = ("You are a PostgreSQL performance engineer. You recommend B-tree indexes that make " "slow queries fast without hurting production: always use CREATE INDEX CONCURRENTLY, " "prefer the smallest index that does the job, and recommend nothing when no index would help.")user = """Schema (only primary keys are indexed):CREATE TABLE orders (id bigint NOT NULL, tenant_id integer NOT NULL, customer_id bigint NOT NULL, status text NOT NULL, total numeric(12,2) NOT NULL, created_at timestamp with time zone NOT NULL, PRIMARY KEY (id)); -- ~1,000,000 rows Slow query:SELECT id, customer_id, total, created_at FROM orders WHERE tenant_id = 7 AND status = 'pending' ORDER BY created_at LIMIT 100 Current plan (EXPLAIN):Limit -> Sort -> Seq Scan on orders Filter: ((tenant_id = 7) AND (status = 'pending'::text)) Recommend the single best index for this query. Reply with exactly one SQL statement of the form `CREATE INDEX CONCURRENTLY <name> ON <table> (...);` or the words `NO INDEX` if no index would help. Do not explain.""" messages = [{"role": "system", "content": system}, {"role": "user", "content": user}]inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_dict=True, return_tensors="pt")out = model.generate(**inputs, max_new_tokens=96, do_sample=False)print(tokenizer.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))