import torchfrom transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfigfrom peft import PeftModel base = AutoModelForCausalLM.from_pretrained( "Qwen/Qwen3-14B", quantization_config=BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.bfloat16), device_map="auto")model = PeftModel.from_pretrained(base, "Foodoo1/Qwen3-14B-RLCD-Decision-LoRA")tok = AutoTokenizer.from_pretrained("Qwen/Qwen3-14B") catalog = ''' "fraud_risk": Fraud risk tier of this transaction. Choose one of: LOW, ELEVATED, SUSPICIOUS, CRITICAL. "block_account": Whether the account should be blocked immediately'''context = "New device login from abroad, wiring $49,500 offshore, 0 prior transfers." # One prompt per field; decision = argmax over candidate first tokens at the last positionprompt = (f"<|im_start|>system\nClassify JSON attributes:\n{catalog}<|im_end|>\n" f"<|im_start|>user\n{context}<|im_end|>\n" f'<|im_start|>assistant\n{{\n "fraud_risk": "')ids = tok(prompt, return_tensors="pt").to(model.device)logits = model(**ids).logits[0, -1]cands = {c: tok.encode(c, add_special_tokens=False)[0] for c in ["LOW", "ELEVATED", "SUSPICIOUS", "CRITICAL"]}print(max(cands, key=lambda c: logits[cands[c]].item())) # CRITICAL