Text Generation
Transformers
Safetensors
English
qwen3
lean4
autoformalization
mathematics
formal-verification
reasoning
conversational
text-generation-inference
Instructions to use openbmb/MathForm-8B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openbmb/MathForm-8B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openbmb/MathForm-8B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("openbmb/MathForm-8B") model = AutoModelForCausalLM.from_pretrained("openbmb/MathForm-8B", 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 openbmb/MathForm-8B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openbmb/MathForm-8B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openbmb/MathForm-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/openbmb/MathForm-8B
- SGLang
How to use openbmb/MathForm-8B 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 "openbmb/MathForm-8B" \ --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": "openbmb/MathForm-8B", "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 "openbmb/MathForm-8B" \ --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": "openbmb/MathForm-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use openbmb/MathForm-8B with Docker Model Runner:
docker model run hf.co/openbmb/MathForm-8B
File size: 4,816 Bytes
d1c4917 9a828a5 8f6d09e 9a828a5 d1c4917 9a828a5 8f6d09e 9a828a5 8f6d09e 9a828a5 8f6d09e 9a828a5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | ---
license: apache-2.0
language:
- en
base_model:
- Qwen/Qwen3-8B
datasets:
- openbmb/FormalVerse
pipeline_tag: text-generation
library_name: transformers
tags:
- arxiv:2608.14221
- lean4
- autoformalization
- mathematics
- formal-verification
- reasoning
---
<div align="center">
<h1>MathForm: Scaling Mathematical Autoformalization with Knowledge Retrieval and Verification-Guided Refinement</h1>
</div>
<div align="center" style="line-height: 1;">
<a href="https://arxiv.org/abs/2608.14221" style="margin: 2px;"><img src="https://img.shields.io/badge/Paper-arXiv-b31b1b.svg" alt="Paper" style="display: inline-block; vertical-align: middle;" /></a>
<a href="https://github.com/OpenBMB/MathForm" style="margin: 2px;"><img src="https://img.shields.io/badge/GitHub-MathForm-181717.svg" alt="Code" style="display: inline-block; vertical-align: middle;" /></a>
<a href="https://huggingface.co/datasets/openbmb/FormalVerse" style="margin: 2px;"><img src="https://img.shields.io/badge/%F0%9F%A4%97%20Dataset-FormalVerse-yellow.svg" alt="FormalVerse Dataset" style="display: inline-block; vertical-align: middle;" /></a>
</div>
**MathForm-8B** is an autoformalization model that translates natural-language
mathematical statements into Lean 4. It is released with the paper *MathForm:
Scaling Mathematical Autoformalization with Knowledge Retrieval and
Verification-Guided Refinement*.
The model is trained on [FormalVerse](https://huggingface.co/datasets/openbmb/FormalVerse) through supervised
fine-tuning followed by reinforcement learning using Lean compilation and
semantic-consistency feedback.
<p align="center">
<img src="./assets/data-pipeline.png" width="800" alt="MathForm data construction and training pipeline">
<br>
<em>Figure 1: Overview of the MathForm data construction and training pipeline. The system combines Mathlib knowledge retrieval, compilation and semantic verification, and iterative refinement to generate reliable formal data, followed by trajectory reconstruction and training of MathForm-8B.</em>
</p>
## Results
<p align="center">
<img src="./assets/results.png" width="900" alt="Pass@8 results on six benchmarks">
<br>
<em>Figure 2: Pass@8 pass rates (%) under Syntax Check (SC) and Consistency Check (CC) for specialized autoformalizers on six benchmarks. AVG is the equally weighted macro-average across all six benchmarks. For each column, the best result is shown in bold and the second best is underlined.</em>
</p>
## Usage
### Transformers
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "openbmb/MathForm-8B"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id, torch_dtype=torch.bfloat16, device_map="auto"
)
prompt = (
"Please convert the following informal math problem to a formal one in Lean 4 with a header. "
"Use the following theorem names: my_favorite_theorem.\n\n"
"Show that for every real number x, x^2 is non-negative."
)
messages = [{"role": "user", "content": prompt}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs, max_new_tokens=16384, temperature=0.6, top_p=0.95
)
print(tokenizer.decode(outputs[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True))
```
### vLLM
```bash
vllm serve openbmb/MathForm-8B \
--served-model-name MathForm-8B \
--dtype bfloat16 \
--max-model-len 16384
```
### SGLang
```bash
python -m sglang.launch_server \
--model-path openbmb/MathForm-8B \
--served-model-name MathForm-8B \
--dtype bfloat16 \
--context-length 16384
```
Both servers expose an OpenAI-compatible API at
`http://localhost:8000/v1/chat/completions`.
### Recommended Settings
| Setting | Value |
| --- | --- |
| `temperature` | 0.6 |
| `top_p` | 0.95 |
| `max_new_tokens` | 16384 |
## Evaluation
The evaluation pipeline, benchmark files, and Pass@k scripts are available in
the [MathForm repository](https://github.com/OpenBMB/MathForm). Compilation checks require a running
Kimina Lean Server. The experiments use Lean 4.21.0.
## License
This project is licensed under the Apache License 2.0.
## Citation
```bibtex
@misc{pu2026mathformscalingmathematicalautoformalization,
title={MathForm: Scaling Mathematical Autoformalization with Knowledge Retrieval and Verification-Guided Refinement},
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},
year={2026},
eprint={2608.14221},
archivePrefix={arXiv},
primaryClass={cs.AI},
url={https://arxiv.org/abs/2608.14221},
}
```
|