Image-Text-to-Text
Safetensors
Transformers
English
Chinese
multilingual
dots_mocr
dots_ocr
text-generation
image-to-text
ocr
document-parse
layout
table
formula
custom_code
conversational
Eval Results
Instructions to use rednote-hilab/dots.mocr with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use rednote-hilab/dots.mocr with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="rednote-hilab/dots.mocr", trust_remote_code=True) 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 AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("rednote-hilab/dots.mocr", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use rednote-hilab/dots.mocr with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "rednote-hilab/dots.mocr" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "rednote-hilab/dots.mocr", "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/rednote-hilab/dots.mocr
- SGLang
How to use rednote-hilab/dots.mocr 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 "rednote-hilab/dots.mocr" \ --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": "rednote-hilab/dots.mocr", "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 "rednote-hilab/dots.mocr" \ --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": "rednote-hilab/dots.mocr", "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 rednote-hilab/dots.mocr with Docker Model Runner:
docker model run hf.co/rednote-hilab/dots.mocr
| from typing import Any, Optional | |
| from transformers.configuration_utils import PretrainedConfig | |
| from transformers.models.qwen2 import Qwen2Config | |
| from transformers import Qwen2_5_VLProcessor, AutoProcessor | |
| from transformers.models.auto.configuration_auto import CONFIG_MAPPING | |
| class DotsVisionConfig(PretrainedConfig): | |
| model_type: str = "dots_vit" | |
| def __init__( | |
| self, | |
| embed_dim: int = 1536, # vision encoder embed size | |
| hidden_size: int = 1536, # after merger hidden size | |
| intermediate_size: int = 4224, | |
| num_hidden_layers: int = 42, | |
| num_attention_heads: int = 12, | |
| num_channels: int = 3, | |
| patch_size: int = 14, | |
| spatial_merge_size: int = 2, | |
| temporal_patch_size: int = 1, | |
| rms_norm_eps: float = 1e-5, | |
| use_bias: bool = False, | |
| attn_implementation="flash_attention_2", # "eager","sdpa","flash_attention_2" | |
| initializer_range=0.02, | |
| init_merger_std=0.02, | |
| is_causal=False, # ve causal forward | |
| post_norm=True, | |
| gradient_checkpointing=False, | |
| **kwargs: Any, | |
| ): | |
| super().__init__(**kwargs) | |
| self.embed_dim = embed_dim | |
| self.hidden_size = hidden_size | |
| self.intermediate_size = intermediate_size | |
| self.num_hidden_layers = num_hidden_layers | |
| self.num_attention_heads = num_attention_heads | |
| self.num_channels = num_channels | |
| self.patch_size = patch_size | |
| self.spatial_merge_size = spatial_merge_size | |
| self.temporal_patch_size = temporal_patch_size | |
| self.rms_norm_eps = rms_norm_eps | |
| self.use_bias = use_bias | |
| self.attn_implementation = attn_implementation | |
| self.initializer_range = initializer_range | |
| self.init_merger_std = init_merger_std | |
| self.is_causal = is_causal | |
| self.post_norm = post_norm | |
| self.gradient_checkpointing = gradient_checkpointing | |
| class DotsOCRConfig(Qwen2Config): | |
| model_type = "dots_ocr" | |
| def __init__(self, | |
| image_token_id = 151665, | |
| video_token_id = 151656, | |
| vision_config: Optional[dict] = None, *args, **kwargs): | |
| super().__init__(*args, **kwargs) | |
| self.image_token_id = image_token_id | |
| self.video_token_id = video_token_id | |
| self.vision_config = DotsVisionConfig(**(vision_config or {})) | |
| def save_pretrained(self, save_directory, **kwargs): | |
| self._auto_class = None | |
| super().save_pretrained(save_directory, **kwargs) | |
| class DotsVLProcessor(Qwen2_5_VLProcessor): | |
| def __init__(self, image_processor=None, tokenizer=None, video_processor=None, chat_template=None, **kwargs): | |
| super().__init__(image_processor, tokenizer, video_processor, chat_template=chat_template) | |
| self.image_token = "<|imgpad|>" if not hasattr(tokenizer, "image_token") else tokenizer.image_token | |
| self.image_token_id = 151665 | |
| self.video_token = "<|video_pad|>" if not hasattr(tokenizer, "video_token") else tokenizer.video_token | |
| self.video_token_id = 151656 | |
| AutoProcessor.register("dots_ocr", DotsVLProcessor) | |
| CONFIG_MAPPING.register("dots_ocr", DotsOCRConfig) | |