Skip to content

Instantly share code, notes, and snippets.

@maycuatroi1
Last active February 6, 2026 07:01
Show Gist options
  • Select an option

  • Save maycuatroi1/1310b370c6764565f612b5f64c1cbda3 to your computer and use it in GitHub Desktop.

Select an option

Save maycuatroi1/1310b370c6764565f612b5f64c1cbda3 to your computer and use it in GitHub Desktop.
Sample DeepSeek V2
from transformers import AutoModel, AutoTokenizer
import torch
model_name = 'deepseek-ai/DeepSeek-OCR-2'
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModel.from_pretrained(
model_name,
trust_remote_code=True,
_attn_implementation='flash_attention_2',
use_safetensors=True
)
model = model.eval().cuda().to(torch.bfloat16)
# Document mode with grounding
prompt = "<image>\n<|grounding|>Convert the document to markdown."
result = model.infer(
tokenizer,
prompt=prompt,
image_file='test.jpg',
output_path='output/',
base_size=1024,
image_size=768,
crop_mode=True,
save_results=True
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment