unsloth/LaTeX_OCR
Viewer • Updated • 76.3k • 3.68k • 85
How to use MMoshtaghi/Qwen2-VL-7B-Instruct-LoRAAdpt-MathOCR with Transformers:
# Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("MMoshtaghi/Qwen2-VL-7B-Instruct-LoRAAdpt-MathOCR", dtype="auto")How to use MMoshtaghi/Qwen2-VL-7B-Instruct-LoRAAdpt-MathOCR with Unsloth Studio:
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for MMoshtaghi/Qwen2-VL-7B-Instruct-LoRAAdpt-MathOCR to start chatting
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for MMoshtaghi/Qwen2-VL-7B-Instruct-LoRAAdpt-MathOCR to start chatting
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for MMoshtaghi/Qwen2-VL-7B-Instruct-LoRAAdpt-MathOCR to start chatting
pip install unsloth
from unsloth import FastModel
model, tokenizer = FastModel.from_pretrained(
model_name="MMoshtaghi/Qwen2-VL-7B-Instruct-LoRAAdpt-MathOCR",
max_seq_length=2048,
)from datasets import load_dataset
from unsloth import FastVisionModel
model, tokenizer = FastVisionModel.from_pretrained(
model_name = "MMoshtaghi/Qwen2-VL-7B-Instruct-LoRAAdpt-MathOCR",
load_in_4bit = True,
)
FastVisionModel.for_inference(model) # Enable for inference!
dataset = load_dataset("unsloth/LaTeX_OCR", split = "train")
image = dataset[0]["image"]
instruction = "Write the LaTeX representation for this image."
messages = [
{"role": "user", "content": [
{"type": "image"},
{"type": "text", "text": instruction}
]}
]
input_text = tokenizer.apply_chat_template(messages, add_generation_prompt = True)
inputs = tokenizer(
image,
input_text,
add_special_tokens = False,
return_tensors = "pt",
).to("cuda")
from transformers import TextStreamer
text_streamer = TextStreamer(tokenizer, skip_prompt = True)
_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 128,
use_cache = True, temperature = 1.5, min_p = 0.1)
This VLM model was trained 2x faster with Unsloth and Huggingface's TRL library.