Image-Text-to-Text
MLX
Safetensors
Chinese
English
qwen2_5_vl
ocr
document-parsing
multimodal
mxfp8
apple-silicon
conversational
custom_code
8-bit precision
Run this model with HF Jobs
Run sahilchachra/TeleOCR-MXFP8 on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/sahilchachra/TeleOCR-MXFP8. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/sahilchachra/TeleOCR-MXFP8 on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/sahilchachra/TeleOCR-MXFP8. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Instructions to use sahilchachra/TeleOCR-MXFP8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use sahilchachra/TeleOCR-MXFP8 with MLX:
# Make sure mlx-vlm is installed # pip install --upgrade mlx-vlm from mlx_vlm import load, generate from mlx_vlm.prompt_utils import apply_chat_template from mlx_vlm.utils import load_config # Load the model model, processor = load("sahilchachra/TeleOCR-MXFP8") config = load_config("sahilchachra/TeleOCR-MXFP8") # Prepare input image = ["http://images.cocodataset.org/val2017/000000039769.jpg"] prompt = "Describe this image." # Apply chat template formatted_prompt = apply_chat_template( processor, config, prompt, num_images=1 ) # Generate output output = generate(model, processor, formatted_prompt, image) print(output) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Atomic Chat
Upload patch_qwen25vl_qknorm.py with huggingface_hub
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117"""TeleOCR uses a Qwen2.5-VL vision tower + Qwen2.5-VL mrope, but its textattention is patched with per-head QK-RMSNorm (Qwen3-style) and no qkv bias(confirmed against raw/modeling_naviocr.py: Qwen2_5_VLAttention, lines ~615-711).mlx-vlm's stock qwen2_5_vl.language.Attention has neither. Monkeypatch it here,import before any load_model()/load_config() call for this model."""from dataclasses import dataclassfrom typing import Optional
import mlx.core as mximport mlx.nn as nn
import mlx_vlm.models.qwen2_5_vl as qwen2_5_vl_pkgimport mlx_vlm.models.qwen2_5_vl.config as qconfigimport mlx_vlm.models.qwen2_5_vl.language as languageimport mlx_vlm.models.qwen2_5_vl.qwen2_5_vl as qwen2_5_vl_modulefrom mlx_vlm.models.cache import KVCache
@dataclassclass TextConfigWithHeadDim(qconfig.TextConfig): head_dim: Optional[int] = None
qconfig.TextConfig = TextConfigWithHeadDimqwen2_5_vl_module.TextConfig = TextConfigWithHeadDimqwen2_5_vl_pkg.TextConfig = TextConfigWithHeadDimlanguage.TextConfig = TextConfigWithHeadDim
class QKNormAttention(nn.Module): def __init__(self, args): super().__init__()
dim = args.hidden_size self.n_heads = n_heads = args.num_attention_heads assert args.num_key_value_heads is not None self.n_kv_heads = n_kv_heads = args.num_key_value_heads
self.head_dim = head_dim = getattr( args, "head_dim", args.hidden_size // n_heads ) self.scale = head_dim**-0.5
self.q_proj = nn.Linear(dim, n_heads * head_dim, bias=False) self.k_proj = nn.Linear(dim, n_kv_heads * head_dim, bias=False) self.v_proj = nn.Linear(dim, n_kv_heads * head_dim, bias=False) self.o_proj = nn.Linear(n_heads * head_dim, dim, bias=False)
self.q_norm = nn.RMSNorm(head_dim, eps=args.rms_norm_eps) self.k_norm = nn.RMSNorm(head_dim, eps=args.rms_norm_eps)
self.rope_scaling = args.rope_scaling
self.rotary_emb = language.Qwen2RotaryEmbedding( head_dim, max_position_embeddings=args.max_position_embeddings, base=args.rope_theta, rope_scaling=args.rope_scaling, )
def __call__( self, x: mx.array, mask: Optional[mx.array] = None, cache: Optional[KVCache] = None, position_ids: Optional[mx.array] = None, position_embeddings: Optional[tuple] = None, ) -> mx.array: B, L, D = x.shape
queries, keys, values = self.q_proj(x), self.k_proj(x), self.v_proj(x)
queries = self.q_norm( queries.reshape(B, L, self.n_heads, self.head_dim) ).transpose(0, 2, 1, 3) keys = self.k_norm( keys.reshape(B, L, self.n_kv_heads, self.head_dim) ).transpose(0, 2, 1, 3) values = values.reshape(B, L, self.n_kv_heads, self.head_dim).transpose( 0, 2, 1, 3 )
kv_seq_len = keys.shape[-2]
if position_ids is None: kv_seq_len += cache.offset + 1 position_ids = mx.arange(cache.offset, cache.offset + L) position_ids = mx.expand_dims(position_ids, axis=0) position_ids = mx.tile(position_ids, (3, B, 1)) else: kv_seq_len += cache.offset + 1 if cache is not None else 0
if position_embeddings is None: queries, keys = self.rotary_emb.apply_rotary( queries, keys, position_ids, unsqueeze_dim=1, ) else: cos, sin = position_embeddings queries, keys = language.apply_multimodal_rotary_pos_emb( queries, keys, cos, sin, unqueeze_dim=1 )
if mask is not None and isinstance(mask, mx.array): mask = mask[..., : keys.shape[-2]]
if cache is not None: keys, values = cache.update_and_fetch(keys, values)
output = language.scaled_dot_product_attention( queries, keys, values, cache, scale=self.scale, mask=mask ) output = output.transpose(0, 2, 1, 3).reshape(B, L, -1) return self.o_proj(output)
language.Attention = QKNormAttentionpatch_qwen25vl_qknorm.pyAdded+117