Instructions to use mlabonne/LFM2.5-230M-Chess with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mlabonne/LFM2.5-230M-Chess with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="mlabonne/LFM2.5-230M-Chess") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("mlabonne/LFM2.5-230M-Chess") model = AutoModelForCausalLM.from_pretrained("mlabonne/LFM2.5-230M-Chess", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use mlabonne/LFM2.5-230M-Chess with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mlabonne/LFM2.5-230M-Chess" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlabonne/LFM2.5-230M-Chess", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/mlabonne/LFM2.5-230M-Chess
- SGLang
How to use mlabonne/LFM2.5-230M-Chess with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "mlabonne/LFM2.5-230M-Chess" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlabonne/LFM2.5-230M-Chess", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
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 "mlabonne/LFM2.5-230M-Chess" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlabonne/LFM2.5-230M-Chess", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use mlabonne/LFM2.5-230M-Chess with Docker Model Runner:
docker model run hf.co/mlabonne/LFM2.5-230M-Chess
LFM2.5-230M-Chess
A 230M chess engine with a language model interface, fine-tuned from LFM2.5-230M-Base using Stockfish distillation.
Every possible chess move is a single token in the vocabulary. The model reads a position as a fixed 80-token prompt, predicts its own win probability, then predicts one move token. The host masks the move logits to the legal moves, so the model can never play an illegal move.
It plays at roughly 2004 Elo with a shallow depth-3 search on top, and roughly 1500 with the raw one-pass policy.
Demo: Play it in your browser with the ChessLFM Space.
Usage
import json
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("mlabonne/LFM2.5-230M-Chess")
token_ids = json.load(open("token_ids.json"))
Each move takes two short forward passes:
- Build the 80-token prompt from the FEN. It encodes the 64 squares, side to move, castling rights, en passant file, halfmove clock, repetition count, and the last 8 plies.
- Argmax over the 64 value tokens gives the model evaluation, where
<v:k>means a win probability in[k/64, (k+1)/64). - Append that value token and
<|bestmove|>, mask the move logits to the legal moves, and take the argmax.
You can find the 2,106 added token IDs in token_ids.json (it starts at 64402).
- Downloads last month
- -
