The model is trained on
FormalVerse through supervised
fine-tuning followed by reinforcement learning using Lean compilation and
semantic-consistency feedback.
1import torch
2from transformers import AutoModelForCausalLM, AutoTokenizer
3
4model_id = "openbmb/MathForm-8B"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForCausalLM.from_pretrained(
7 model_id, torch_dtype=torch.bfloat16, device_map="auto"
8)
9
10prompt = (
11 "Please convert the following informal math problem to a formal one in Lean 4 with a header. "
12 "Use the following theorem names: my_favorite_theorem.\n\n"
13 "Show that for every real number x, x^2 is non-negative."
14)
15
16messages = [{"role": "user", "content": prompt}]
17text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
18inputs = tokenizer(text, return_tensors="pt").to(model.device)
19
20outputs = model.generate(
21 **inputs, max_new_tokens=16384, temperature=0.6, top_p=0.95
22)
23print(tokenizer.decode(outputs[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True))
1vllm serve openbmb/MathForm-8B \
2 --served-model-name MathForm-8B \
3 --dtype bfloat16 \
4 --max-model-len 16384
1python -m sglang.launch_server \
2 --model-path openbmb/MathForm-8B \
3 --served-model-name MathForm-8B \
4 --dtype bfloat16 \
5 --context-length 16384
The evaluation pipeline, benchmark files, and Pass@k scripts are available in
the
MathForm repository. Compilation checks require a running
Kimina Lean Server. The experiments use Lean 4.21.0.
This project is licensed under the Apache License 2.0.
1@misc{pu2026mathformscalingmathematicalautoformalization,
2 title={MathForm: Scaling Mathematical Autoformalization with Knowledge Retrieval and Verification-Guided Refinement},
3 author={Lushi Pu and Weiming Zhang and Xinheng Xie and Zixuan Fu and Bingxiang He and Hengyu Zhao and Hongya Lyu and Xin Li and Jie Zhou and Yudong Wang},
4 year={2026},
5 eprint={2608.14221},
6 archivePrefix={arXiv},
7 primaryClass={cs.AI},
8 url={https://arxiv.org/abs/2608.14221},
9}