Last active
February 6, 2026 07:01
-
-
Save maycuatroi1/1310b370c6764565f612b5f64c1cbda3 to your computer and use it in GitHub Desktop.
Sample DeepSeek V2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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