This repository contains the
v3 LoRA adapter for a compact mathematical
statement judgment and correction engine fine-tuned from
Qwen/Qwen2.5-7B-Instruct.
The adapter is intended for Windows / Linux NVIDIA inference, merging, and
retraining. For direct Apple Silicon inference, use the MLX 4-bit release:
dots123/qwen-7b-theorem-engine-v3-mlx-q4.
1User: Every continuous function is differentiable.
2Assistant: Every differentiable function is continuous.
3
4User: A continuous function on an interval achieves its maximum and minimum.
5Assistant: Every continuous function on a closed and bounded interval achieves its maximum and minimum.
6
7User: Pythagorean: a sqrd plus b sqrd is c sqrd in a right triangle.
8Assistant: If \(a\) and \(b\) are the lengths of the legs of a right triangle and \(c\) is the length of the hypotenuse, then \(a^2 + b^2 = c^2\).
9
10User: Let thing be valid then A iff B maybe with x.
11Assistant: Cannot identify the intended theorem.
1hf download Qwen/Qwen2.5-7B-Instruct \
2 --local-dir models/Qwen2.5-7B-Instruct
3
4hf download dots123/qwen-7b-theorem-engine-v3 \
5 --local-dir outputs/qwen_7b_v3
1import re
2import torch
3from peft import PeftModel
4from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
5
6BASE = "models/Qwen2.5-7B-Instruct"
7ADAPTER = "outputs/qwen_7b_v3"
8
9SYSTEM_PROMPT = """# Role
10You are a mathematical statement judgment and correction engine.
11
12# Task
13First decide whether the user's mathematical statement is:
14CORRECT, FALSE, INCOMPLETE, GARBLED_BUT_IDENTIFIABLE, or UNCLEAR.
15
16# Output rules
171. You MUST first write a concise internal judgment inside a <think>...</think> block.
182. If CORRECT, output the clean mathematical statement only.
193. If FALSE, output the correct theorem or statement.
204. If INCOMPLETE, output the complete rigorous theorem with missing assumptions.
215. If GARBLED_BUT_IDENTIFIABLE, infer the intended theorem and rewrite it fully.
226. If UNCLEAR, output exactly: Cannot identify the intended theorem.
237. Never repeat malformed mathematical text unchanged.
248. Use standard LaTeX formatting for formulas ($...$ or $$...$$).
25"""
26
27tokenizer = AutoTokenizer.from_pretrained(BASE, trust_remote_code=True)
28bnb_config = BitsAndBytesConfig(
29 load_in_4bit=True,
30 bnb_4bit_quant_type="nf4",
31 bnb_4bit_compute_dtype=torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float16,
32 bnb_4bit_use_double_quant=True,
33)
34
35base_model = AutoModelForCausalLM.from_pretrained(
36 BASE,
37 quantization_config=bnb_config,
38 device_map="auto",
39 trust_remote_code=True,
40)
41model = PeftModel.from_pretrained(base_model, ADAPTER)
42model.eval()
43
44messages = [
45 {"role": "system", "content": SYSTEM_PROMPT},
46 {"role": "user", "content": "Every continuous function is differentiable."},
47]
48prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
49inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
50
51with torch.no_grad():
52 output_ids = model.generate(
53 **inputs,
54 max_new_tokens=256,
55 do_sample=True,
56 temperature=0.3,
57 top_p=0.85,
58 repetition_penalty=1.05,
59 eos_token_id=tokenizer.eos_token_id,
60 pad_token_id=tokenizer.eos_token_id,
61 )
62
63text = tokenizer.decode(output_ids[0][inputs.input_ids.shape[-1]:], skip_special_tokens=True)
64answer = re.sub(r"<think>.*?</think>", "", text, flags=re.DOTALL).strip()
65answer = answer.replace("无法识别其意图定理。", "Cannot identify the intended theorem.")
66print(answer)
All smoke-test cases passed the expected output-pattern checks.
No standalone license has been selected for this release yet. The base model is
subject to the license terms of
Qwen/Qwen2.5-7B-Instruct.
If you use this adapter, please cite the base model and link back to this model
repository and the public training dataset.