Instructions to use zhenliuu/K12-Reasoner-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use zhenliuu/K12-Reasoner-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="zhenliuu/K12-Reasoner-4B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("zhenliuu/K12-Reasoner-4B") model = AutoModelForMultimodalLM.from_pretrained("zhenliuu/K12-Reasoner-4B", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.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=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use zhenliuu/K12-Reasoner-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "zhenliuu/K12-Reasoner-4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "zhenliuu/K12-Reasoner-4B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/zhenliuu/K12-Reasoner-4B
- SGLang
How to use zhenliuu/K12-Reasoner-4B 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 "zhenliuu/K12-Reasoner-4B" \ --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": "zhenliuu/K12-Reasoner-4B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "zhenliuu/K12-Reasoner-4B" \ --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": "zhenliuu/K12-Reasoner-4B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use zhenliuu/K12-Reasoner-4B with Docker Model Runner:
docker model run hf.co/zhenliuu/K12-Reasoner-4B
K12-Reasoner-4B
K12-Reasoner-4B 是基于 Qwen3.5-4B 进行 DAPO 后训练的多模态模型,使用本项目整理的数学与物理训练集,面向图文题目理解、学科推理与答案生成。
模型概况
| 项目 | 配置 |
|---|---|
| 基础模型 | Qwen3.5-4B |
| 参数规模 | 4B 级 |
| 输入 / 输出 | 文本与图片 / 文本 |
| 后训练 | DAPO,基于 TRL |
| 训练数据 | 数学与物理训练集,1,160 题 |
| 权重格式 | BF16,Safetensors |
快速使用
安装支持本模型的 Transformers 与 PyTorch 环境,下载模型后使用随附的infer.py:
pip install "torch==2.10.0" "transformers==5.15.0" "accelerate==1.13.0" "Pillow==12.2.0"
hf download zhenliuu/K12-Reasoner-4B --local-dir K12-Reasoner-4B
python K12-Reasoner-4B/infer.py --model ./K12-Reasoner-4B \
--subject 数学 --question "求方程 2x + 3 = 11 的解。"
图片题通过--image传入本地图片,题干与选项通过--question传入;重复--image可提供多张图片:
python K12-Reasoner-4B/infer.py --model ./K12-Reasoner-4B \
--subject 物理 --image question.png --question "根据图示,判断物体所受合力的方向。"
默认使用单张CUDA GPU、BF16与贪心解码,关闭thinking,最大输出8,192 tokens。脚本支持--device cpu以及本地模型路径。PyTorch的CUDA构建需与运行环境匹配。模型使用基础架构的processor与chat template,输出包含简洁解题过程和末行“最终答案:”。
评测结果
我们在以下多模态数学与物理基准上,将 K12-Reasoner-4B 与基础模型 Qwen3.5-4B 进行对比。指标为准确率,提升以百分点(pp)表示。
| 基准 | 可计分题数 / 测试题数 | Qwen3.5-4B | K12-Reasoner-4B | 提升(pp) |
|---|---|---|---|---|
| OlympiadBench | 4,055 / 4,869 | 31.89% | 40.12% | +8.24 |
| MMSciBench | 710 / 1,167 | 63.24% | 69.58% | +6.34 |
| LiveK12Bench | 1,168 / 1,168 | 48.72% | 54.71% | +5.99 |
| MM-MATH | 5,881 / 5,901 | 67.40% | 71.96% | +4.56 |
| PhyX | 6,000 / 6,000 | 43.30% | 47.78% | +4.48 |
| PhysUniBench | 1,247 / 3,304 | 38.89% | 41.94% | +3.05 |
评测设置: 两模型使用相同输入模板、解码设置和自动判分程序;关闭 thinking,采用贪心解码,最大输出长度为 8,192 tokens。准确率按可计分题目计算:MMSciBench、PhysUniBench 使用选择题,OlympiadBench 使用非证明题。结果基于项目统一评测协议。
完整提示词和计分口径见 评测说明,训练配置见项目训练文档。
使用范围
模型面向教育图文推理研究与应用开发。涉及重要教学结论时,应结合参考答案与专业知识复核模型输出。
- Downloads last month
- 13