Image-Text-to-Text
Transformers
Safetensors
English
idefics2
multimodal
vision
text-generation-inference
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")# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("HuggingFaceM4/idefics2-8b-base") model = AutoModelForImageTextToText.from_pretrained("HuggingFaceM4/idefics2-8b-base") - 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
Update README.md
Browse files
README.md
CHANGED
|
@@ -143,10 +143,6 @@ model = AutoModelForVision2Seq.from_pretrained(
|
|
| 143 |
"HuggingFaceM4/idefics2-8b-base",
|
| 144 |
).to(DEVICE)
|
| 145 |
|
| 146 |
-
BAD_WORDS_IDS = processor.tokenizer(["<image>", "<fake_token_around_image>"], add_special_tokens=False).input_ids
|
| 147 |
-
EOS_WORDS_IDS = [processor.tokenizer.eos_token_id]
|
| 148 |
-
|
| 149 |
-
|
| 150 |
# Create inputs
|
| 151 |
prompts = [
|
| 152 |
"<image>In this image, we can see the city of New York, and more specifically the Statue of Liberty.<image>In this image,",
|
|
@@ -158,7 +154,7 @@ inputs = {k: v.to(DEVICE) for k, v in inputs.items()}
|
|
| 158 |
|
| 159 |
|
| 160 |
# Generate
|
| 161 |
-
generated_ids = model.generate(**inputs,
|
| 162 |
generated_texts = processor.batch_decode(generated_ids, skip_special_tokens=True)
|
| 163 |
|
| 164 |
print(generated_texts)
|
|
@@ -176,10 +172,6 @@ model = AutoModelForVision2Seq.from_pretrained(
|
|
| 176 |
"HuggingFaceM4/idefics2-8b",
|
| 177 |
).to(DEVICE)
|
| 178 |
|
| 179 |
-
BAD_WORDS_IDS = processor.tokenizer(["<image>", "<fake_token_around_image>"], add_special_tokens=False).input_ids
|
| 180 |
-
EOS_WORDS_IDS = processor.tokenizer("<end_of_utterance>", add_special_tokens=False).input_ids + [processor.tokenizer.eos_token_id]
|
| 181 |
-
|
| 182 |
-
|
| 183 |
# Create inputs
|
| 184 |
messages = [
|
| 185 |
{
|
|
@@ -209,7 +201,7 @@ inputs = {k: v.to(DEVICE) for k, v in inputs.items()}
|
|
| 209 |
|
| 210 |
|
| 211 |
# Generate
|
| 212 |
-
generated_ids = model.generate(**inputs,
|
| 213 |
generated_texts = processor.batch_decode(generated_ids, skip_special_tokens=True)
|
| 214 |
|
| 215 |
print(generated_texts)
|
|
|
|
| 143 |
"HuggingFaceM4/idefics2-8b-base",
|
| 144 |
).to(DEVICE)
|
| 145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
# Create inputs
|
| 147 |
prompts = [
|
| 148 |
"<image>In this image, we can see the city of New York, and more specifically the Statue of Liberty.<image>In this image,",
|
|
|
|
| 154 |
|
| 155 |
|
| 156 |
# Generate
|
| 157 |
+
generated_ids = model.generate(**inputs, max_new_tokens=500)
|
| 158 |
generated_texts = processor.batch_decode(generated_ids, skip_special_tokens=True)
|
| 159 |
|
| 160 |
print(generated_texts)
|
|
|
|
| 172 |
"HuggingFaceM4/idefics2-8b",
|
| 173 |
).to(DEVICE)
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
# Create inputs
|
| 176 |
messages = [
|
| 177 |
{
|
|
|
|
| 201 |
|
| 202 |
|
| 203 |
# Generate
|
| 204 |
+
generated_ids = model.generate(**inputs, max_new_tokens=500)
|
| 205 |
generated_texts = processor.batch_decode(generated_ids, skip_special_tokens=True)
|
| 206 |
|
| 207 |
print(generated_texts)
|