Instructions to use stepfun-ai/GOT-OCR-2.0-hf with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use stepfun-ai/GOT-OCR-2.0-hf with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="stepfun-ai/GOT-OCR-2.0-hf")# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("stepfun-ai/GOT-OCR-2.0-hf") model = AutoModelForMultimodalLM.from_pretrained("stepfun-ai/GOT-OCR-2.0-hf") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use stepfun-ai/GOT-OCR-2.0-hf with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "stepfun-ai/GOT-OCR-2.0-hf" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "stepfun-ai/GOT-OCR-2.0-hf", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/stepfun-ai/GOT-OCR-2.0-hf
- SGLang
How to use stepfun-ai/GOT-OCR-2.0-hf 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 "stepfun-ai/GOT-OCR-2.0-hf" \ --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": "stepfun-ai/GOT-OCR-2.0-hf", "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 "stepfun-ai/GOT-OCR-2.0-hf" \ --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": "stepfun-ai/GOT-OCR-2.0-hf", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use stepfun-ai/GOT-OCR-2.0-hf with Docker Model Runner:
docker model run hf.co/stepfun-ai/GOT-OCR-2.0-hf
Is it really huggingface model?
Is it compatible with transformers, really? Look at the error below:
>>> model = AutoModelForImageTextToText.from_pretrained("stepfun-ai/GOT-OCR-2.0-hf", device_map=device)
Traceback (most recent call last):
File "C:\Users\jawad\.env\llm\Lib\site-packages\transformers\models\auto\configuration_auto.py", line 1071, in from_pretrained
config_class = CONFIG_MAPPING[config_dict["model_type"]]
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\jawad\.env\llm\Lib\site-packages\transformers\models\auto\configuration_auto.py", line 773, in __getitem__
raise KeyError(key)
KeyError: 'got_ocr2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<python-input-7>", line 1, in <module>
model = AutoModelForImageTextToText.from_pretrained("stepfun-ai/GOT-OCR-2.0-hf", device_map=device)
File "C:\Users\jawad\.env\llm\Lib\site-packages\transformers\models\auto\auto_factory.py", line 526, in from_pretrained
config, kwargs = AutoConfig.from_pretrained(
~~~~~~~~~~~~~~~~~~~~~~~~~~^
pretrained_model_name_or_path,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<5 lines>...
**kwargs,
^^^^^^^^^
)
^
File "C:\Users\jawad\.env\llm\Lib\site-packages\transformers\models\auto\configuration_auto.py", line 1073, in from_pretrained
raise ValueError(
...<8 lines>...
)
ValueError: The checkpoint you are trying to load has model type `got_ocr2` but Transformers does not recognize this architecture. This could be because of an issue with the checkpoint, or because your version of Transformers is out of date.
You can update Transformers with the command `pip install --upgrade transformers`. If this does not work, and the checkpoint is very new, then there may not be a release version that supports this model yet. In this case, you can get the most up-to-date code by installing Transformers from source with the command `pip install git+https://github.com/huggingface/transformers.git`
I got latest transformers:
>>> import transformers
>>> transformers.__version__
'4.48.3'
i got same error
Yes that's expected, it will be included in the next transformers version. For now if you want to use it you have to install transformers from source :). Hope that helps!
Building small packages is a pain, I'll just wait for next drop. Thanks
i did the same--installed with pip install git+https://github.com/huggingface/transformers.git
but i still seeing the same issue,
Traceback (most recent call last):
File "/home/prasanna/.local/lib/python3.10/site-packages/transformers/models/auto/configuration_auto.py", line 1071, in from_pretrained
config_class = CONFIG_MAPPING[config_dict["model_type"]]
File "/home/prasanna/.local/lib/python3.10/site-packages/transformers/models/auto/configuration_auto.py", line 773, in __getitem__
raise KeyError(key)
KeyError: 'got_ocr2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/prasanna/Desktop/suryaocr-hybrid-updated/suryaocr-hybrid/test.py", line 16, in <module>
agent = SuryaOCRAgent()
File "/home/prasanna/Desktop/suryaocr-hybrid-updated/suryaocr-hybrid/suryaocr_got.py", line 191, in __init__
self.ocr = SuryaOCR()
File "/home/prasanna/Desktop/suryaocr-hybrid-updated/suryaocr-hybrid/suryaocr_got.py", line 32, in __init__
self.model = AutoModelForImageTextToText.from_pretrained("stepfun-ai/GOT-OCR-2.0-hf", device_map='cuda')
File "/home/prasanna/.local/lib/python3.10/site-packages/transformers/models/auto/auto_factory.py", line 526, in from_pretrained
config, kwargs = AutoConfig.from_pretrained(
File "/home/prasanna/.local/lib/python3.10/site-packages/transformers/models/auto/configuration_auto.py", line 1073, in from_pretrained
raise ValueError(
ValueError: The checkpoint you are trying to load has model type `got_ocr2` but Transformers does not recognize this architecture. This could be because of an issue with the checkpoint, or because your version of Transformers is out of date.
You can update Transformers with the command `pip install --upgrade transformers`. If this does not work, and the checkpoint is very new, then there may not be a release version that supports this model yet. In this case, you can get the most up-to-date code by installing Transformers from source with the command `pip install git+https://github.com/huggingface/transformers.git`
@nnpy sometimes the best thing to do is wait.
Wait until it is officially supported, debugging will be project on its own.