linxy/LaTeX_OCR
Viewer • Updated • 269k • 708 • 179
How to use FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("image-text-to-text", model="FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR")
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) # Load model directly
from transformers import AutoProcessor, AutoModelForMultimodalLM
processor = AutoProcessor.from_pretrained("FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR")
model = AutoModelForMultimodalLM.from_pretrained("FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR", 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=40)
print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR",
"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 run hf.co/FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR
How to use FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR" \
--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": "FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR",
"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 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 "FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR" \
--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": "FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR",
"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"
}
}
]
}
]
}'How to use FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR with Docker Model Runner:
docker model run hf.co/FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR
A fine-tuned version of Qwen/Qwen3.5-35B-A3B for LaTeX OCR tasks, specialized in recognizing handwritten mathematical expressions.
This model is designed for:
CUDA_VISIBLE_DEVICES=0,1,2,3 \
swift infer \
--model FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR \
--use_hf true \
--stream true \
--experts_impl grouped_mm \
--device_map auto \
--max_new_tokens 2048
from transformers import AutoModelForCausalLM, AutoProcessor
model = AutoModelForCausalLM.from_pretrained(
"FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR",
torch_dtype="bfloat16",
device_map="auto",
trust_remote_code=True
)
processor = AutoProcessor.from_pretrained(
"FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR",
trust_remote_code=True
)
# Example usage with an image
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": "path/to/math_image.png"},
{"type": "text", "text": "Convert this handwritten math to LaTeX."}
]
}
]
inputs = processor(messages, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512)
result = processor.decode(outputs[0], skip_special_tokens=True)
print(result)
device_map auto (single-process multi-GPU, no DeepSpeed)| Metric | Value |
|---|---|
| Final Train Loss | ~0.001 |
| Final Token Accuracy | ~100% |
| Eval Loss | ~0.0006 |
@misc{qwen3.5-latex-ocr-2026,
author = {FutureMa},
title = {Qwen3.5-35B-A3B-LaTeX-OCR: Fine-tuned Qwen3.5 for Handwritten LaTeX OCR},
year = {2026},
publisher = {Hugging Face},
url = {https://huggingface.co/FutureMa/Qwen3.5-35B-A3B-LaTeX-OCR}
}
For questions or issues, please open an issue on the model repository.