Khufu-9B
An adapter for improved math and code performance
2 min readupdated
Khufu-9B is a LoRA (a small add-on layer for a base model) for the Qwen/Qwen3.5-9B language model, built for experiments with mathematics, natural sciences, and Python programming. The adapter was trained using continued supervised fine-tuning on a small dataset and is designed for local deployment and evaluation. It is useful for researchers and developers interested in customizing open weights to solve precise logical and computational tasks.
Key features
- Built on the powerful open-weight base model Qwen/Qwen3.5-9B.
- Specialized in exact sciences, mathematical computations, and Python code.
- Trained using LoRA and weight quantization via bitsandbytes (NF4).
- Distributed under the permissive Apache 2.0 license.
What you can do
- Run local inference to solve mathematical equations and logic puzzles.
- Use the adapter to generate and check Python code snippets.
- Experiment with generation parameter settings (such as enabling reasoning mode).
Example
Example code for loading the base model with the adapter and running inference using the transformers and peft libraries:
import torch
from peft import PeftModel
from transformers import AutoTokenizer, BitsAndBytesConfig, Qwen3_5ForConditionalGeneration
base_id = "Qwen/Qwen3.5-9B"
adapter_id = "Youssef-dev/Khufu-9B"
tokenizer = AutoTokenizer.from_pretrained(base_id)
base = Qwen3_5ForConditionalGeneration.from_pretrained(
base_id,
quantization_config=BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.float16),
)
model = PeftModel.from_pretrained(base, adapter_id).eval()
prompt = "Solve 3(x - 2) = 15 and check your answer."
inputs = tokenizer(prompt, return_tensors="pt").to("cuda:0")
with torch.inference_mode():
output = model.generate(**inputs, max_new_tokens=512)
print(tokenizer.decode(output[0]))Read more
DetailsBase model: Qwen/Qwen3.5-9B
Training: 160 examples, 312 optimizer steps (about 59 minutes on two Tesla T4 GPUs)
Benchmark results: MATH-500 (95–97%), GPQA Diamond (91.5%)
Limitations: the model may produce plausible-sounding yet incorrect facts or flawed code










Comments