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
LoRA config used for training
Is it possible to share the LoRA config used for training the base and instruction-tuned model ? I could not find details on the paper.
lora_config stage 1:
{
lora_alpha: 16,
lora_dropout: 0.1,
r: 64,
bias: "none",
}
lora config stage 2:
{
lora_alpha: 16,
lora_dropout: 0.1,
r: 64,
bias: "none",
init_lora_weights: "gaussian",
}
lora_config stage 3 (intruction-tuned):
{
lora_alpha: 16,
lora_dropout: 0.1,
r: 64,
bias: "none",
init_lora_weights: "gaussian",
use_dora: True,
}
thanks for sharing this!
do this apply for all params or just '.(text_model|modality_projection|perceiver_resampler).(down_proj|gate_proj|up_proj|k_proj|q_proj|v_proj|o_proj).*$' ?
@Leyo
Stage 1:
All the projection/mlp layers of the LLM and the vision encoder were loraified. Only embeddings and lm_head were frozen (with the exception of the new image-related embeddings which we trained fully). The perceiver, and the modality projection were fully trained.
Stage 2:
All the projection/mlp layers of the LLM and the vision encoder were loraified. LLM embeddings and lm_head were frozen (with the exception of the new image-related embeddings which we trained fully). The vision encoder embeddings, the perceiver and the modality projection, were fully trained.
Stage 3 (instruction-tuning):
All the projection/mlp layers of the LLM, the vision encoder and the perceiver were loraified as well as the lm_head and the embeddings (with the exception of the new image-related embeddings which we trained fully). The Perceiver latents and vision encoder embeddings, were fully trained. So only the LLM text embeddings that were trained were frozen.
Not everything was perfectly ablated because unfreezing/freezing some parameters made little difference most of the time. We usually tried to unfreeze/loraify as much as could.