Views
No views yet
<rationale>...</rationale>: a short explanation (or short PV line depending on the prompt)<uci_move>...</uci_move>: the move to play in UCI formatuv with pyproject.toml.uv syncpip install -U torch transformers accelerate python-chess1uv run python - <<'PY'
2import chess
3import torch
4from transformers import AutoModelForCausalLM, AutoTokenizer
5
6from src.prompts import system_msg, user_msg
7from src.tokenizer_utils import ensure_chat_template
8
9MODEL_ID = "alexneakameni/Qwen2.5-Coder-0.5B-Instruct-chess-grpo"
10FEN = "r2q1rk1/ppp2pbp/2np1np1/4P3/4PB2/2N2B2/PPPQ1PPP/2KR3R b - - 0 3"
11
12# Tokenizer
13# (Some models need fix_mistral_regex=True; it is safe to keep it here.)
14tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, fix_mistral_regex=True)
15tokenizer = ensure_chat_template(tokenizer)
16if tokenizer.pad_token is None:
17 tokenizer.pad_token = tokenizer.eos_token
18
19# Model
20model = AutoModelForCausalLM.from_pretrained(
21 MODEL_ID,
22 torch_dtype=torch.bfloat16,
23 device_map={"": 0} if torch.cuda.is_available() else None,
24)
25
26board = chess.Board(FEN)
27side_to_move = "White" if board.turn == chess.WHITE else "Black"
28legal_moves_uci = " ".join(m.uci() for m in board.legal_moves)
29
30prompt = user_msg.format(
31 FEN=board.fen(),
32 side_to_move=side_to_move,
33 legal_moves_uci=legal_moves_uci,
34)
35
36messages = [
37 {"role": "system", "content": system_msg},
38 {"role": "user", "content": prompt},
39]
40
41chat = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
42inputs = tokenizer(chat, return_tensors="pt").to(model.device)
43
44with torch.no_grad():
45 out = model.generate(
46 **inputs,
47 max_new_tokens=64,
48 do_sample=True,
49 temperature=1.0,
50 top_p=0.95,
51 top_k=64,
52 pad_token_id=tokenizer.pad_token_id,
53 eos_token_id=tokenizer.eos_token_id,
54 )
55
56completion = tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
57print(completion)
58PY<uci_move>...</uci_move>.1cd global-chess-challenge-2025-starter-kit/player_agents
2MODEL_NAME_OR_PATH="alexneakameni/Qwen2.5-Coder-0.5B-Instruct-chess-grpo" bash run_vllm.shhttp://localhost:5000/v1 with served model name aicrowd-chess-model.1cd global-chess-challenge-2025-starter-kit
2uv run python local_evaluation.py --endpoint http://localhost:5000/v1 \
3 --template-file player_agents/qwen_prompt.jinja \
4 --games-per-opponent 10<uci_move>...</uci_move>.MODEL_NAME_OR_PATH="../../models/chess-grpo-sequences" when launching vLLM.--gpu-memory-utilization in global-chess-challenge-2025-starter-kit/player_agents/run_vllm.sh.