Instructions to use microsoft/udop-large with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/udop-large with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="microsoft/udop-large")# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("microsoft/udop-large") model = AutoModelForMultimodalLM.from_pretrained("microsoft/udop-large") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use microsoft/udop-large with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/udop-large" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/udop-large", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/microsoft/udop-large
- SGLang
How to use microsoft/udop-large 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 "microsoft/udop-large" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/udop-large", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "microsoft/udop-large" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/udop-large", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use microsoft/udop-large with Docker Model Runner:
docker model run hf.co/microsoft/udop-large
Update README.md
Browse files
README.md
CHANGED
|
@@ -27,15 +27,21 @@ from transformers import AutoProcessor, UdopForConditionalGeneration
|
|
| 27 |
from datasets import load_dataset
|
| 28 |
|
| 29 |
# load model and processor
|
|
|
|
|
|
|
| 30 |
processor = AutoProcessor.from_pretrained("microsoft/udop-large", apply_ocr=False)
|
| 31 |
model = UdopForConditionalGeneration.from_pretrained("microsoft/udop-large")
|
| 32 |
|
|
|
|
|
|
|
| 33 |
dataset = load_dataset("nielsr/funsd-layoutlmv3", split="train")
|
| 34 |
example = dataset[0]
|
| 35 |
image = example["image"]
|
| 36 |
words = example["tokens"]
|
| 37 |
boxes = example["bboxes"]
|
| 38 |
question = "Question answering. What is the date on the form?"
|
|
|
|
|
|
|
| 39 |
encoding = processor(image, question, words, boxes=boxes, return_tensors="pt")
|
| 40 |
|
| 41 |
# autoregressive generation
|
|
|
|
| 27 |
from datasets import load_dataset
|
| 28 |
|
| 29 |
# load model and processor
|
| 30 |
+
# in this case, we already have performed OCR ourselves
|
| 31 |
+
# so we initialize the processor with `apply_ocr=False`
|
| 32 |
processor = AutoProcessor.from_pretrained("microsoft/udop-large", apply_ocr=False)
|
| 33 |
model = UdopForConditionalGeneration.from_pretrained("microsoft/udop-large")
|
| 34 |
|
| 35 |
+
# load an example image, along with the words and coordinates
|
| 36 |
+
# which were extracted using an OCR engine
|
| 37 |
dataset = load_dataset("nielsr/funsd-layoutlmv3", split="train")
|
| 38 |
example = dataset[0]
|
| 39 |
image = example["image"]
|
| 40 |
words = example["tokens"]
|
| 41 |
boxes = example["bboxes"]
|
| 42 |
question = "Question answering. What is the date on the form?"
|
| 43 |
+
|
| 44 |
+
# prepare everything for the model
|
| 45 |
encoding = processor(image, question, words, boxes=boxes, return_tensors="pt")
|
| 46 |
|
| 47 |
# autoregressive generation
|