Instructions to use microsoft/kosmos-2.5 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use microsoft/kosmos-2.5 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="microsoft/kosmos-2.5")# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("microsoft/kosmos-2.5") model = AutoModelForImageTextToText.from_pretrained("microsoft/kosmos-2.5") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use microsoft/kosmos-2.5 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "microsoft/kosmos-2.5" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "microsoft/kosmos-2.5", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/microsoft/kosmos-2.5
- SGLang
How to use microsoft/kosmos-2.5 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/kosmos-2.5" \ --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/kosmos-2.5", "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/kosmos-2.5" \ --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/kosmos-2.5", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use microsoft/kosmos-2.5 with Docker Model Runner:
docker model run hf.co/microsoft/kosmos-2.5
Error: 'Kosmos2_5ForConditionalGeneration' from 'transformers' when using the latest transformer version
When using transformer version transformers==4.43.0.dev0 both Kosmos2_5ForConditionalGeneration and AutoModelForVision2Seq were loaded without errors and inferencing of the Kosmos model was possible. However, they are not working on the latest version of transformers 4.43.2 as well as the previous 2 releases, 4.32.1 and 4.43.0.
same probleem for me!
How did you download transformer version transformers==4.43.0.dev0?
The version on the requirements.txt is 4.32.0.dev0 (git+https://github.com/Dod-o/kosmos2.5_tools.git@transformers)?
use pip install git+https://github.com/tic-top/transformers.git (transformers==4.44.0.dev0) and it works.
A similar problem here on transformers==4.44.0. Works fine when using git+https://github.com/tic-top/transformers.git (transformers==4.44.dev0)
ValueError: The checkpoint you are trying to load has model type `kosmos-2.5` 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.
Issue still exists. For MacOS, the command is:
pip install git+https://github.com/tic-top/transformers.git 'transformers==4.46.0.dev0'
it was working for me but when today i am using this - pip install git+https://github.com/tic-top/transformers.git 'transformers==4.46.0.dev0' then i am getting error.
this worked for me:
pip install git+https://github.com/tic-top/transformers.git@main
one can also check this : https://github.com/huggingface/transformers/pull/31711
but i am still searching for stable version of kosmos 2.5, is it dev version?? when will you release fine tuning script for kosmos 2.5??
It worked! thx 4 the help :)
None of these solutions are working now. What version of the transformers should I use, and whats the refrence inference code for kosmos 2.5?
@hrithiksagar-tih, i think you should check again, it is integrated now.
more info: https://x.com/NielsRogge/status/1961052607826251899