import torchfrom unsloth.models.decision import FastDecisionModel, ClefDataCollator # Load the full merged 16-bit model directly from Hugging Face or local pathmodel_id = "kaushik-harsh-99/Qwen3-0.6B-Game-Decision-Model"model, tokenizer = FastDecisionModel.from_pretrained( model_name=model_id, max_seq_length=1024, load_in_4bit=False, # Set to True for 4-bit quantization (<2 GB VRAM)) # Example game state (e.g. Blackjack)sample_state = { "game": "blackjack", "state": "Game: Blackjack (blackjack).\nRules: Beat the dealer without exceeding 21.\nCurrent state: Dealer shows 7. Player hand total: 16 (Hard 16).", "questions": { "action": { "type": "choice", "instructions": "Select the optimal blackjack move.", "criteria": { "Hit": "Take another card", "Stand": "End turn and keep current total", "Double Down": "Double bet and take one card", "Surrender": "Forfeit half bet" } } }, "gold": { "action": "Hit" # Placeholder for inference schema }} # Format and tokenizeitems, _ = FastDecisionModel.build_dataset([sample_state], tokenizer, model)pad_token_id = getattr(tokenizer, "tokenizer", tokenizer).pad_token_idcollator = ClefDataCollator(pad_token_id, tokenizer=getattr(tokenizer, "tokenizer", tokenizer))batch = collator(items)batch.pop("target", None) # Run inferencemodel.eval()with torch.no_grad(): device = next(model.parameters()).device inputs = {k: v.to(device) if torch.is_tensor(v) else v for k, v in batch.items()} logits, _ = model(**inputs) # Extract predicted actionlogits = logits.float()choices = list(sample_state["questions"]["action"]["criteria"].keys())predicted_index = int(logits[0, :len(choices)].argmax().item())best_action = choices[predicted_index] print(f"Optimal Action: {best_action}")