dr3z/chess-reasoning
Preview • Updated • 8
How to use dr3z/HRM-Chess-Reasoning-0.3B with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="dr3z/HRM-Chess-Reasoning-0.3B") # pip install -U transformers accelerate
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("dr3z/HRM-Chess-Reasoning-0.3B")
model = AutoModelForCausalLM.from_pretrained("dr3z/HRM-Chess-Reasoning-0.3B", device_map="auto")How to use dr3z/HRM-Chess-Reasoning-0.3B with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "dr3z/HRM-Chess-Reasoning-0.3B"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "dr3z/HRM-Chess-Reasoning-0.3B",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/dr3z/HRM-Chess-Reasoning-0.3B
How to use dr3z/HRM-Chess-Reasoning-0.3B with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "dr3z/HRM-Chess-Reasoning-0.3B" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "dr3z/HRM-Chess-Reasoning-0.3B",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "dr3z/HRM-Chess-Reasoning-0.3B" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "dr3z/HRM-Chess-Reasoning-0.3B",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use dr3z/HRM-Chess-Reasoning-0.3B with Docker Model Runner:
docker model run hf.co/dr3z/HRM-Chess-Reasoning-0.3B
This is a pet-project attempting to train a HRM-Text model to play chess. Given the initial board, it generates reasoning traces and the board after the next move. In combination with a Stockfish evaluation to choose the move from generated samples, it can win in the game against the Stockfish 1350 ELO.
[Event "?"]
[Site "?"]
[Date "2026.06.15"]
[Round "?"]
[White "HRM-Chess-Reasoning-0.3B - 12 samples with Stockfish searchtime for 3 seconds"]
[Black "Stockfish 1350 ELO"]
[Result "1-0"]
1. e4 e6 2. d4 d5 3. exd5 Nf6 4. Nf3 Nxd5 5. c4 Nf6 6. Nc3 h6 7. Bf4 Bd6 8. Ne5 Nc6 9. a3 a6 10. Nxc6 Bxf4 11. Nxd8 e5 12. g3 exd4 13. Ne6 fxe6 14. gxf4 Ke7 15. Qxd4 Rd8 16. Qe3 Ng4 17. Qe4 Kf8 18. f3 Nf2 19. Kxf2 b5 20. Bd3 b4 21. axb4 a5 22. Qg6 e5 23. fxe5 Bg4 24. fxg4 h5 25. e6 axb4 26. g5 Kg8 27. Ne4 Ra4 28. Nf6+ Kf8 29. Qf7# 1-0
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_name = "dr3z/HRM-Chess-Reasoning-0.3B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, dtype=torch.bfloat16).cuda().eval()
TEMPLATE = """<|im_start|><|object_ref_start|>
You are a Chess Grandmaster.
Given a chessboard position, you must:
1. Think deeply about the justification of your move.
2. Derive the move step‑by‑step, explaining your reasoning internally, but **do not reveal the move until you have finished the analysis**.
3. After the analysis, play the chosen move and output **only** the resulting board state in the following format:
'''
<answer>
[board representation]
</answer>
'''
No additional commentary, explanations, or text should appear outside of the `<answer>` tags.
{source}<|im_end|><think>"""
CURRENT_STATE = """
8 | _ _ _ _ _ _ _ _ |
7 | _ _ p _ _ k _ p |
6 | _ _ _ p _ n p _ |
5 | _ _ _ P _ p _ _ |
4 | _ _ _ P _ _ _ _ |
3 | _ P _ K _ P P _ |
2 | _ _ B _ _ _ _ P |
1 | _ _ _ _ _ _ _ _ |
a b c d e f g h
White moves
"""
inp = tokenizer(TEMPLATE.format(source=CURRENT_STATE), return_tensors="pt")
inp["token_type_ids"] = torch.ones_like(inp["input_ids"])
out = model.generate(**inp.to(model.device), max_new_tokens=6000, temperature=0.2, do_sample=True, num_return_sequences=1)
out = [tokenizer.decode(c) for c in out]
for text in out:
print(text)