Running Image Inference with Llama 3.2 90B Vision Using LiteLLM
To perform image inference using the Llama 3.2 90B Vision model through LiteLLM, you'll need to follow these steps. This guide will help you set up and run inference on images to leverage the model's visual understanding capabilities.
Setup Process
Step 1: Install LiteLLM
First, install the LiteLLM package using pip:
pip install litellm
Step 2: Set Your Hugging Face Token
You'll need a Hugging Face token to access the Llama 3.2 90B Vision model:
import os
from litellm import completion
# Set your Hugging Face Token
os.environ["HF_TOKEN"] = "hf_xxxxxx" # Replace with your actual token
Running Inference on Images
Basic Image Analysis Code
Here's a complete example for running inference on an image:
from litellm import completion
import os
# Set your Hugging Face Token
os.environ["HF_TOKEN"] = "hf_xxxxxx" # Replace with your actual token
# Prepare the messages with image
messages = [
{
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{
"type": "image_url",
"image_url": {
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
}
}
]
}
]
# Run inference
response = completion(
model="huggingface/sambanova/meta-llama/Llama-3.2-90B-Vision-Instruct",
messages=messages,
)
print(response.choices)
Using Different Service Providers
You can run inference through different providers that host the Llama 3.2 90B Vision model:
# Using Sambanova
response = completion(
model="huggingface/sambanova/meta-llama/Llama-3.2-90B-Vision-Instruct",
messages=messages,
)
# Or using a TGI endpoint (Text Generation Inference)
response = completion(
model="huggingface/tgi",
messages=messages,
api_base="https://your-endpoint.endpoints.huggingface.cloud/v1/"
)
Model Capabilities and Considerations
Llama 3.2 90B Vision is a powerful multimodal model that can:
- Process both text and images to generate text responses[1][2]
- Perform visual question answering (VQA)[2][5]
- Generate detailed image captions[1][3]
- Conduct visual reasoning and document understanding[5][8]
Important Limitations
- Single Image Only: The model performs best with single images and doesn't work reliably with multiple images in one request[7]
- Image Format: If using through AWS Bedrock, the model only supports PNG format (requires conversion from JPEG)[10]
- Memory Requirements: Running this model locally requires substantial GPU memory (at least 40GB)[8]
Advanced Usage
Streaming Responses
For streaming responses when working with images:
response = completion(
model="huggingface/sambanova/meta-llama/Llama-3.2-90B-Vision-Instruct",
messages=messages,
stream=True,
)
for chunk in response:
print(chunk)
Using Local Image Files
To use a local image file:
import base64
# Convert local image to base64
with open("your_image.png", "rb") as image_file:
base64_image = base64.b64encode(image_file.read()).decode('utf-8')
messages = [
{
"role": "user",
"content": [
{"type": "text", "text": "Describe this image in detail"},
{
"type": "image_url",
"image_url": {
"url": f"data:image/png;base64,{base64_image}"
}
}
]
}
]
response = completion(
model="huggingface/sambanova/meta-llama/Llama-3.2-90B-Vision-Instruct",
messages=messages,
)
This setup allows you to leverage Llama 3.2 90B Vision's powerful capabilities for analyzing images, generating descriptions, and answering questions about visual content.