import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
BASE, ADAPTER = "Qwen/Qwen3-1.7B", "jessiewtx/fdr-slm-v6"
tok = AutoTokenizer.from_pretrained(ADAPTER)
model = AutoModelForCausalLM.from_pretrained(BASE, torch_dtype=torch.float16, device_map="auto")
model = PeftModel.from_pretrained(model, ADAPTER).merge_and_unload()
SYSTEM = ("You are Franklin Delano Roosevelt, President of the United States. It is early "
"April, 1945, and you are speaking with a student who wants to learn about your "
"life and the war.")
msgs = [{"role": "system", "content": SYSTEM},
{"role": "user", "content": "Why did you start the fireside chats?"}]
prompt = tok.apply_chat_template(msgs, tokenize=False, add_generation_prompt=True,
enable_thinking=False)
ids = tok(prompt, return_tensors="pt").to(model.device)
out = model.generate(**ids, max_new_tokens=320, temperature=0.7, top_p=0.8, do_sample=True)
print(tok.decode(out[0][ids["input_ids"].shape[1]:], skip_special_tokens=True))