Image-Text-to-Text
Transformers
Safetensors
English
idefics2
multimodal
vision
text-generation-inference
Run this model with HF Jobs
Run HuggingFaceM4/idefics2-8b-base on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/HuggingFaceM4/idefics2-8b-base. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/HuggingFaceM4/idefics2-8b-base on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/HuggingFaceM4/idefics2-8b-base. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/HuggingFaceM4/idefics2-8b-base. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use HuggingFaceM4/idefics2-8b-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use HuggingFaceM4/idefics2-8b-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="HuggingFaceM4/idefics2-8b-base")# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("HuggingFaceM4/idefics2-8b-base") model = AutoModelForMultimodalLM.from_pretrained("HuggingFaceM4/idefics2-8b-base", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use HuggingFaceM4/idefics2-8b-base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "HuggingFaceM4/idefics2-8b-base" # 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-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/HuggingFaceM4/idefics2-8b-base
- SGLang
How to use HuggingFaceM4/idefics2-8b-base 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-base" \ --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-base", "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-base" \ --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-base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use HuggingFaceM4/idefics2-8b-base with Docker Model Runner:
docker model run hf.co/HuggingFaceM4/idefics2-8b-base
Commit Β·
dcb5a04
1
Parent(s): 13bf038
hop
Browse files8 unmodified lines9101112131437 unmodified lines525354555657582 unmodified lines616263646566673 unmodified lines717273747576122 unmodified lines19920020120220320420522 unmodified lines2282292302312322332348 unmodified lines- pixparse/pdfa-eng-wds- wendlerc/RenderedText- HuggingFaceM4/the_cauldronlanguage:- entags:37 unmodified linesAs a starting point, we provide fine-tuning codes that can be adapted for one's particular scenario:- With the [TRL library](https://github.com/huggingface/trl): TODO- With the [Hugging Face Trainer](https://huggingface.co/docs/transformers/main/en/main_classes/trainer#api-reference%20][%20transformers.Trainer): TODO# Technical summary2 unmodified lines<details><summary>For more details, expand the result table.</summary>TODO: performance table</details>3 unmodified lines- We departed from the IDEFICS-1's architecture (gated cross-attentions) and **simplified the integration of visual features** into the language backbone. The images are fed to the vision encoder followed by a learned [Perceiver](https://arxiv.org/abs/2103.03206) pooling and a MLP modality projection. That pooled sequence is then concatenated with the text embeddings to obtain an (interleaved) sequence of image(s) and text(s).- All of these improvements along with better pre-trained backbones yield a significant jump in performance over IDEFICS-1 for a model that is **10x smaller**.More details (training procedure, data selection, hyper-parameters, etc.) along with lessons learned from our ablations will be available in an upcoming technical report.122 unmodified lines</details>**4 bit quantization and module fusing**<details><summary>Click to expand.</summary>22 unmodified lines).to(DEVICE)```</details># Bias, Risks, and Limitations8 unmodified lines9101112131415161718192021222337 unmodified lines616263646566672 unmodified lines7071727374757677787980818283848586878889903 unmodified lines949596979899100101102103104105106107108109110111112113114122 unmodified lines23723823924024124224322 unmodified lines2662672682692702712728 unmodified lines- pixparse/pdfa-eng-wds- wendlerc/RenderedText- HuggingFaceM4/the_cauldron- teknium/OpenHermes-2.5- GAIR/lima- databricks/databricks-dolly-15k- meta-math/MetaMathQA- TIGER-Lab/MathInstruct- microsoft/orca-math-word-problems-200k- camel-ai/math- AtlasUnified/atlas-math-sets- tiedong/goatlanguage:- entags:37 unmodified linesAs a starting point, we provide fine-tuning codes that can be adapted for one's particular scenario:- With the [TRL library](https://github.com/huggingface/trl): TODO- With the [Hugging Face Trainer](https://huggingface.co/docs/transformers/main/en/main_classes/trainer#api-reference%20][%20transformers.Trainer): [Tutorial notebook](https://colab.research.google.com/drive/1rm3AGquGEYXfeeizE40bbDtcWh5S4Nlq?usp=sharing)# Technical summary2 unmodified lines<details><summary>For more details, expand the result table.</summary>| Model | Open weights | Size | # tokens per image | MMMU (val/test) | MathVista (testmini) | TextVQA (val) | MMBench (test)| VQAv2 (test-dev) | DocVQA (test)|--------------|-------------|------|--------------------|-----------|-----------|---------|---------|---------|---------|| DeepSeek-VL | β | 7B | 576 | 36.6/- | 36.1 | - | 73.2 | - | - || LLaVa-NeXT-13B | β | 13B | 2880 | 36.2/- | 35.3 | 67.1 | 70.0 | 82.8 | - || LLaVa-NeXT-34B | β | 34B | 2880 | 51.1/44.7 | 46.5 | 69.5 | 79.3 | 83.7 | - | - || MM1-Chat-7B | β | 7B | 720 | 37.0/35.6 | 35.9 | 72.8 | 72.3 | - | - || MM1-Chat-30B | β | 30B | 720 | 44.7/40.3 | 39.4 | 73.5 | 75.1 | 83.7 | || Gemini 1.0 Pro | β | ? | ? | 47.9/- | 45.2 | 74.6 | - | 71.2 | 88.1 || Gemini 1.5 Pro | β | ? | ? | 58.5/- | 52.1 | 73.5 | - | 73.2 | 86.5 || Claude 3 Haiku | β |? | ? | 50.2/- | 46.4 | - | - | - | 88.8 || | | | | | | || IDEFICS-1 instruct (32-shots) | β | 80B | - | - | - | 39.3 | - | 68.8 | - || | | | | | | || IDEFICS-2 (w/o image splitting) | β | 8B | 64 | 43.5/37.9 | 51.6 | 70.4 | 76.8 | 80.8 | 67.3 || IDEFICS-2 (w/ image splitting) | β | 8B | 320 | 43.0/37.7 | 51.4 | 73.0 | 76.7 | 81.2 | 74.0 |</details>3 unmodified lines- We departed from the IDEFICS-1's architecture (gated cross-attentions) and **simplified the integration of visual features** into the language backbone. The images are fed to the vision encoder followed by a learned [Perceiver](https://arxiv.org/abs/2103.03206) pooling and a MLP modality projection. That pooled sequence is then concatenated with the text embeddings to obtain an (interleaved) sequence of image(s) and text(s).- All of these improvements along with better pre-trained backbones yield a significant jump in performance over IDEFICS-1 for a model that is **10x smaller**.IDEFICS-2 is trained in 2 stages for maximum efficiency. In a first stage, images are fed to the model at SigLIP's native resolution (squares of 384 x 384). In the second stage, images are fed to the model at their native resolution (with a maximum of 980 and a minimum of 378) and native aspect ratio. Since high resolution is necessary for OCR data, we add PDFA, Rendered-Text, and IDL to OBELICS, LAION Coco and PMD during that second stage.Following this, we perform instruction fine-tuning on [The Cauldron](https://huggingface.co/datasets/HuggingFaceM4/the_cauldron), a collection of 50 manually curated vision-language datasets along with 9 text-only instruction fine-tuning datasets:- [OpenHermes-2.5](https://huggingface.co/datasets/teknium/OpenHermes-2.5)- [lima](https://huggingface.co/datasets/GAIR/lima)- [databricks-dolly-15k](https://huggingface.co/datasets/databricks/databricks-dolly-15k)- [MetaMathQA](https://huggingface.co/datasets/meta-math/MetaMathQA)- [MathInstruct](https://huggingface.co/datasets/TIGER-Lab/MathInstruct)- [orca-math-word-problems-200k](https://huggingface.co/datasets/microsoft/orca-math-word-problems-200k)- [math](https://huggingface.co/datasets/camel-ai/math)- [atlas-math-sets](https://huggingface.co/datasets/AtlasUnified/atlas-math-sets)- [goat](https://huggingface.co/datasets/tiedong/goat)We use Lora to train the parameters initialized from pre-trained backbones and full fine-tuning for newly initialized parameters (modality connector), as we find this strategy to be more stable as long as more computationally efficient.More details (training procedure, data selection, hyper-parameters, etc.) along with lessons learned from our ablations will be available in an upcoming technical report.122 unmodified lines</details><!-- **4 bit quantization and module fusing**<details><summary>Click to expand.</summary>22 unmodified lines).to(DEVICE)```</details> --># Bias, Risks, and Limitations
README.md+42-4