Model reference · open weights
mgp-str is an open-weight language model from alibaba-damo. mgp-str-base (FP32) weighs 296 MB; the smallest configuration that runs it is RTX 3060 12 GB.
Summary of the alibaba-damo/mgp-str-base model card, 2026-10-01
What it is
| Released by | alibaba-damo |
|---|---|
| Released | 2022-11-23 |
| Parameters | 148M |
| VRAM | 296 MB for the weights |
What it runs on
| Card | Requests at once | Context max | Memory | |
|---|---|---|---|---|
| 8K each | 32K each | |||
| RTX 3060 12 GB | 35 | 8 | 128K | 11.6 GB |
| RTX 4060 Ti 16 GB | 48 | 12 | 128K | 15.4 GB |
| RTX 3090 24 GB | 74 | 18 | 128K | 23.4 GB |
| RTX 4090 24 GB | 74 | 18 | 128K | 23.4 GB |
| RTX 5090 32 GB | 99 | 24 | 128K | 31.0 GB |
| L40S 48 GB | 142 | 35 | 128K | 44.0 GB |
| A100 80 GB | 255 | 63 | 128K | 78.2 GB |
| H100 80 GB | 243 | 60 | 128K | 78.1 GB |
| RTX PRO 6000 Blackwell 96 GB | 295 | 73 | 128K | 93.8 GB |
| DGX Spark (GB10) 128 GB unified | 340 | 85 | 128K | 107 GB |
| H200 141 GB | 441 | 110 | 128K | 138 GB |
| B200 180 GB | 567 | 141 | 128K | 176 GB |
| Requests at once | 8K tokens each | 32K tokens each |
|---|---|---|
| 1 | 1.2 GB | 2.1 GB |
| 5 | 2.4 GB | 6.9 GB |
| 8 | 3.3 GB | 10.6 GB |
| 16 | 5.7 GB | 20.2 GB |
| 32 | 10.6 GB | 39.5 GB |
| 64 | 20.2 GB | 78.2 GB |
One card, with vLLM's small-card settings.
From the model card
MGP-STR base-sized model is trained on MJSynth and SynthText. It was introduced in the paper Multi-Granularity Prediction for Scene Text Recognition and first released in this repository.
MGP-STR is pure vision STR model, consisting of ViT and specially designed A^3 modules. The ViT module was initialized from the weights of DeiT-base, except the patch embedding model, due to the inconsistent input size.
Images (32x128) are presented to the model as a sequence of fixed-size patches (resolution 4x4), which are linearly embedded. One also adds absolute position embeddings before feeding the sequence to the layers of the ViT module. Next, A^3 module selects a meaningful combination from the tokens of ViT output and integrates them into one output token corresponding to a specific character. Moreover, subword classification heads based on BPE A^3 module and WordPiece A^3 module are devised for subword predictions, so that the language information can be implicitly modeled. Finally, these multi-granularity predictions (character, subword and even word) are merged via a simple and effective fusion strategy.
You can use the raw model for optical character recognition (OCR) on text images. See the model hub to look for fine-tuned versions on a task that interests you.
Here is how to use this model in PyTorch:
from transformers import MgpstrProcessor, MgpstrForSceneTextRecognition
import requests
from PIL import Image
processor = MgpstrProcessor.from_pretrained('alibaba-damo/mgp-str-base')
model = MgpstrForSceneTextRecognition.from_pretrained('alibaba-damo/mgp-str-base')
# load image from the IIIT-5k dataset
url = "https://i.postimg.cc/ZKwLg2Gw/367-14.png"
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
pixel_values = processor(images=image, return_tensors="pt").pixel_values
outputs = model(pixel_values)
generated_text = processor.batch_decode(outputs.logits)['generated_text']
@inproceedings{ECCV2022mgp_str,
title={Multi-Granularity Prediction for Scene Text Recognition},
author={Peng Wang, Cheng Da, and Cong Yao},
booktitle = {ECCV},
year={2022}
}
Quoted from the model card on Hugging Face. The full card is behind the Hugging Face link above.