Instructions to use HuggingFaceM4/idefics2-8b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HuggingFaceM4/idefics2-8b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="HuggingFaceM4/idefics2-8b")# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("HuggingFaceM4/idefics2-8b") model = AutoModelForImageTextToText.from_pretrained("HuggingFaceM4/idefics2-8b") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use HuggingFaceM4/idefics2-8b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "HuggingFaceM4/idefics2-8b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "HuggingFaceM4/idefics2-8b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/HuggingFaceM4/idefics2-8b
- SGLang
How to use HuggingFaceM4/idefics2-8b 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 "HuggingFaceM4/idefics2-8b" \ --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": "HuggingFaceM4/idefics2-8b", "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 "HuggingFaceM4/idefics2-8b" \ --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": "HuggingFaceM4/idefics2-8b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use HuggingFaceM4/idefics2-8b with Docker Model Runner:
docker model run hf.co/HuggingFaceM4/idefics2-8b
Dedicated Inference Endpoints for Idefics2-8b
Hey team,
I'm running into the following error when attempting to deploy a dedicated inference endpoint:
Warning: deploying this model may fail because a "handler.py" file was not found in the repository. Try selecting a different model or creating a custom handler.
What would be the appropriate approach to making/getting a handler.py file that can handle text-image input?
Same case for here.
Besides, I got this error: ValueError: The checkpoint you are trying to load has model type idefics2 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.
Have you upgraded Transformers to the latest version?
The fact is that I am trying to implement it in huggingface inference service. According to the model description, it supports the huggingface inference service. I can't modify the transformer version because of that.
It is true that I have the notification that the model repository does not have a handle.py file.
I honestly don't know if there is a good tutorial on how to create your own handle.py file and put a model into production. I have no idea how to do it.
It is true that I have the notification that the model repository does not have a handle.py file.
yes you need to create a custom handler @damianGil .
https://huggingface.co/docs/inference-endpoints/guides/custom_handler would be a good place to start!
I managed to deploy a dedicated inference endpoint for idefics2 by opening up the Advanced section and setting the task to Text Generation. You don’t need a custom handler for this.
As of today, the default docker image offered for TGI is too old, you will get an error like:
Endpoint failed to start
KeyError: 'idefics2'
To solve that, you can provide a custom docker image so it will be the latest TGI.
- Change the Container type from Default to Custom
- Set the image to: http://ghcr.io/huggingface/text-generation-inference:latest
- Set these environmental variables:
"MAX_BATCH_PREFILL_TOKENS": "4096",
"MAX_INPUT_LENGTH": "3072",
"MAX_TOTAL_TOKENS": "3584",
"MODEL_ID": "/repository"
Awesome! Thanks!