Image-Text-to-Text
Transformers
Safetensors
llava_onevision2_5
text-generation
multimodal
video-understanding
streaming
llava-onevision
conversational
custom_code
Instructions to use lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct", trust_remote_code=True) messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct
- SGLang
How to use lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct 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 "lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct with Docker Model Runner:
docker model run hf.co/lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct
Download chat_template.jinja from lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct: direct link, hf CLI and curl.
- Browser
- Download file 3.21 kB
-
https://huggingface.co/lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct/resolve/main/chat_template.jinja
- Command line
-
hf download hf://lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct/chat_template.jinja
-
curl -L -o chat_template.jinja https://huggingface.co/lmms-lab-encoder/LLaVA-OneVision-2.5-4B-Instruct/resolve/main/chat_template.jinja
3.21 kB
| {#- OV2.5 Qwen3.5 chat template with two modes, aligned with the training renderer (`qwen2-vl` | |
| template + canvas timestamps). Pick the mode per call: | |
| processor.apply_chat_template(messages, ...) -> offline (default) | |
| processor.apply_chat_template(messages, ..., streaming=True) -> streaming | |
| The modes differ only in the default system turn, exactly as in training: offline samples get | |
| the qwen2-vl default system, data_type=streaming samples get the streaming prompt. An explicit | |
| system message always wins. | |
| Layout: <|im_start|>system\n{system}<|im_end|>\n then per turn <|im_start|>{role}\n{content}<|im_end|>\n. | |
| - String content is emitted verbatim (callers that pre-render "<T seconds><|vision_start|>..."). | |
| - An image item may carry "timestamp" (seconds = frame_index / fps); it is rendered as the trainer | |
| does, "<T.T seconds>" right before <|vision_start|>. Video frames get timestamps in both modes; | |
| single images have none. Put the trained "\n" after a frame as a text item, e.g. | |
| [{"type":"image","timestamp":4.0},{"type":"text","text":"\n"}]. | |
| - The processor expands each <|image_pad|> to the frame's merged patch count; a <|video_pad|> | |
| block is expanded by the processor into per-frame "<X.X seconds>" blocks (offline video path). -#} | |
| {%- set image_count = namespace(value=0) %} | |
| {%- set video_count = namespace(value=0) %} | |
| {%- if streaming is defined and streaming %} | |
| {%- set default_system = 'You are a real-time streaming video assistant.' %} | |
| {%- else %} | |
| {%- set default_system = 'You are a helpful assistant.' %} | |
| {%- endif %} | |
| {%- for message in messages %} | |
| {%- if loop.first and message['role'] != 'system' %} | |
| {{- '<|im_start|>system\n' + default_system + '<|im_end|>\n' }} | |
| {%- endif %} | |
| {{- '<|im_start|>' + message['role'] + '\n' }} | |
| {%- if message['content'] is string %} | |
| {{- message['content'] }} | |
| {%- else %} | |
| {%- for content in message['content'] %} | |
| {%- if content['type'] == 'image' or 'image' in content or 'image_url' in content %} | |
| {%- set image_count.value = image_count.value + 1 %} | |
| {%- if add_vision_id %} | |
| {{- 'Picture ' + image_count.value|string + ': ' }} | |
| {%- endif %} | |
| {%- if content['timestamp'] is defined and content['timestamp'] is not none %} | |
| {{- '<' + '%.1f'|format(content['timestamp']|float) + ' seconds>' }} | |
| {%- endif %} | |
| {{- '<|vision_start|><|image_pad|><|vision_end|>' }} | |
| {%- elif content['type'] == 'video' or 'video' in content %} | |
| {%- set video_count.value = video_count.value + 1 %} | |
| {%- if add_vision_id %} | |
| {{- 'Video ' + video_count.value|string + ': ' }} | |
| {%- endif %} | |
| {{- '<|vision_start|><|video_pad|><|vision_end|>' }} | |
| {%- elif 'text' in content %} | |
| {{- content['text'] }} | |
| {%- endif %} | |
| {%- endfor %} | |
| {%- endif %} | |
| {{- '<|im_end|>\n' }} | |
| {%- endfor %} | |
| {%- if add_generation_prompt %} | |
| {{- '<|im_start|>assistant\n' }} | |
| {%- endif %} | |