import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
MODEL = "Ace-2504/slm-500m-sft"
model = AutoModelForCausalLM.from_pretrained(MODEL, torch_dtype=torch.bfloat16).eval()
tok = AutoTokenizer.from_pretrained(MODEL)
SYS = ('You are a precise legal and financial assistant. Answer clearly using the '
'provided context; do not invent facts.')
user = 'Context:\n<passage>\n\nQuestion: <your question>'
prompt = f'<|system|>\n{SYS}<|eos|>\n<|user|>\n{user}<|eos|>\n<|assistant|>\n'
enc = tok(prompt, return_tensors='pt', add_special_tokens=False).to(model.device)
eos = tok.convert_tokens_to_ids('<|eos|>')
out = model.generate(**enc, max_new_tokens=160, eos_token_id=eos,
pad_token_id=eos)
print(tok.decode(out[0, enc['input_ids'].shape[1]:], skip_special_tokens=True))