Views
No views yet
<move>left</move>1import torch
2from unsloth import FastLanguageModel
3
4# Load the model
5model, tokenizer = FastLanguageModel.from_pretrained(
6 model_name="justinj92/Qwen2.5-3B-2048Player",
7 max_seq_length=8192,
8 dtype=torch.bfloat16,
9 load_in_4bit=True,
10)
11FastLanguageModel.for_inference(model)
12
13# Game setup
14messages = [
15 {
16 "role": "system",
17 "content": "You are an excellent 2048 player. Always choose the move most likely to lead to combine cells to eventually reach the number 2048. Optional moves are 'left', 'right', 'up', 'down'. Return your move as an XML object with a single property 'move', like so: <move>left</move>"
18 },
19 {
20 "role": "user",
21 "content": "2 | 4 | _ | _\n"
22 "_ | 2 | _ | _\n"
23 "_ | _ | _ | _\n"
24 "_ | _ | _ | _"
25 }
26]
27
28# Generate move
29inputs = tokenizer.apply_chat_template(
30 messages,
31 return_tensors="pt",
32 add_generation_prompt=True
33).to("cuda")
34
35outputs = model.generate(
36 input_ids=inputs,
37 max_new_tokens=100,
38 temperature=0.7,
39 top_p=0.9,
40)
41
42response = tokenizer.decode(outputs[0][inputs.shape[1]:], skip_special_tokens=True)
43print(response) # <move>left</move>2 | 4 | 8 | 16
32 | 64 | 128 | 256
512 | 1024 | _ | 2
4 | 8 | 16 | 32_ represents empty cells.1@misc{qwen2048player2025,
2 title={Qwen2.5-3B-2048-Player: A GRPO-trained 2048 Game Agent},
3 author={JustinJ},
4 year={2025},
5 publisher={Hugging Face},
6 howpublished={\url{https://huggingface.co/justinj92/Qwen2.5-3B-2048Player}}
7}