A fine-tuned
LoRA adapter on top of
unsloth/Qwen3.5-0.8B for
document OCR and image-to-LaTeX conversion. The model processes document or formula images and outputs their LaTeX representation.
Trained with
16-bit LoRA (chosen over QLoRA for superior stability on Qwen3.5 vision architectures) on an
NVIDIA A100-SXM4-80GB via
Lightning.ai, using
Unsloth for 2x faster fine-tuning.
Qwen3.5 Vision uses specialized convolutional layers that are currently unstable under 4-bit quantization at training time. Switching to 16-bit LoRA avoids this instability while still being far more memory-efficient than full fine-tuning.
1from unsloth import FastVisionModel
2from PIL import Image
3
4model, tokenizer = FastVisionModel.from_pretrained(
5 model_name="Mustafaege/Qwen3.5-0.8B-vision-LORA-16bit",
6)
7FastVisionModel.for_inference(model)
8
9image = Image.open("formula.png")
10
11messages = [
12 {
13 "role": "user",
14 "content": [
15 {"type": "image"},
16 {"type": "text", "text": "Write the LaTeX representation for this image."},
17 ],
18 }
19]
20
21input_text = tokenizer.apply_chat_template(messages, add_generation_prompt=True)
22inputs = tokenizer(image, input_text, return_tensors="pt").to("cuda")
23
24outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7)
25result = tokenizer.decode(outputs[0], skip_special_tokens=True)
26print(result)
27# Example: \frac{d}{dx}\left(e^{x}\right) = e^{x}
1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3
4base_model_id = "unsloth/Qwen3.5-0.8B"
5adapter_id = "Mustafaege/Qwen3.5-0.8B-vision-LORA-16bit"
6
7tokenizer = AutoTokenizer.from_pretrained(base_model_id)
8model = AutoModelForCausalLM.from_pretrained(
9 base_model_id,
10 torch_dtype="auto",
11 device_map="auto",
12)
13model = PeftModel.from_pretrained(model, adapter_id)
14model.eval()
1from unsloth import FastVisionModel
2
3model, tokenizer = FastVisionModel.from_pretrained(
4 model_name="Mustafaege/Qwen3.5-0.8B-vision-LORA-16bit",
5)
6
7# Merge LoRA into base weights
8model.save_pretrained_merged("Qwen3.5-0.8B-vision-OCR-merged", tokenizer)
Fine-tuned on
Mustafaege/qwen3.5-vision-ocr-v1 — a multimodal OCR dataset containing document and formula images paired with LaTeX ground-truth annotations.
1@misc{mustafaege2026qwen35visionocr,
2 title = {Qwen3.5-0.8B Vision OCR: 16-bit LoRA Adapter for Image-to-LaTeX},
3 author = {Mustafaege},
4 year = {2026},
5 url = {https://huggingface.co/Mustafaege/Qwen3.5-0.8B-vision-LORA-16bit}
6}
7
8@misc{qwen3_5,
9 title = {Qwen3.5 Technical Report},
10 author = {Qwen Team},
11 year = {2025},
12 publisher = {Alibaba Cloud}
13}