Image-Text-to-Text
Transformers
Safetensors
English
ovis
text-generation
MLLM
conversational
custom_code
Instructions to use AIDC-AI/Ovis1.6-Gemma2-9B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AIDC-AI/Ovis1.6-Gemma2-9B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="AIDC-AI/Ovis1.6-Gemma2-9B", 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)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("AIDC-AI/Ovis1.6-Gemma2-9B", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use AIDC-AI/Ovis1.6-Gemma2-9B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "AIDC-AI/Ovis1.6-Gemma2-9B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AIDC-AI/Ovis1.6-Gemma2-9B", "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/AIDC-AI/Ovis1.6-Gemma2-9B
- SGLang
How to use AIDC-AI/Ovis1.6-Gemma2-9B 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 "AIDC-AI/Ovis1.6-Gemma2-9B" \ --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": "AIDC-AI/Ovis1.6-Gemma2-9B", "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 "AIDC-AI/Ovis1.6-Gemma2-9B" \ --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": "AIDC-AI/Ovis1.6-Gemma2-9B", "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 AIDC-AI/Ovis1.6-Gemma2-9B with Docker Model Runner:
docker model run hf.co/AIDC-AI/Ovis1.6-Gemma2-9B
Support transformers>=4.46.0
Browse files- modeling_ovis.py +33 -14
modeling_ovis.py
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
import logging
|
| 2 |
import os
|
|
|
|
| 3 |
from importlib import import_module
|
| 4 |
from typing import List, Callable, Union, Optional, Dict
|
| 5 |
|
| 6 |
import PIL.Image
|
| 7 |
import torch
|
|
|
|
| 8 |
from torch import Tensor
|
| 9 |
from torch.nn import init
|
| 10 |
from torch.nn.functional import softmax, gumbel_softmax, pad
|
|
@@ -552,29 +554,46 @@ class Ovis(OvisPreTrainedModel):
|
|
| 552 |
self.get_text_tokenizer().save_pretrained(save_directory)
|
| 553 |
self.get_visual_tokenizer().get_image_processor().save_pretrained(save_directory)
|
| 554 |
|
| 555 |
-
def _get_hybrid_cache_for_llm(self,
|
| 556 |
cache_cls = HybridCache
|
| 557 |
llm = self.get_llm()
|
| 558 |
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
|
| 566 |
if need_new_cache:
|
| 567 |
if hasattr(llm.config, "_pre_quantization_dtype"):
|
| 568 |
cache_dtype = llm.config._pre_quantization_dtype
|
| 569 |
else:
|
| 570 |
cache_dtype = llm.dtype
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 578 |
else:
|
| 579 |
llm._cache.reset()
|
| 580 |
return llm._cache
|
|
|
|
| 1 |
import logging
|
| 2 |
import os
|
| 3 |
+
from packaging import version
|
| 4 |
from importlib import import_module
|
| 5 |
from typing import List, Callable, Union, Optional, Dict
|
| 6 |
|
| 7 |
import PIL.Image
|
| 8 |
import torch
|
| 9 |
+
import transformers
|
| 10 |
from torch import Tensor
|
| 11 |
from torch.nn import init
|
| 12 |
from torch.nn.functional import softmax, gumbel_softmax, pad
|
|
|
|
| 554 |
self.get_text_tokenizer().save_pretrained(save_directory)
|
| 555 |
self.get_visual_tokenizer().get_image_processor().save_pretrained(save_directory)
|
| 556 |
|
| 557 |
+
def _get_hybrid_cache_for_llm(self, batch_size: int, max_cache_len: int):
|
| 558 |
cache_cls = HybridCache
|
| 559 |
llm = self.get_llm()
|
| 560 |
|
| 561 |
+
if version.parse(transformers.__version__) >= version.parse("4.46.0"):
|
| 562 |
+
need_new_cache = (
|
| 563 |
+
not hasattr(llm, "_cache")
|
| 564 |
+
or (not isinstance(llm._cache, cache_cls))
|
| 565 |
+
or llm._cache.batch_size != batch_size
|
| 566 |
+
or llm._cache.max_cache_len < max_cache_len
|
| 567 |
+
)
|
| 568 |
+
else:
|
| 569 |
+
need_new_cache = (
|
| 570 |
+
not hasattr(llm, "_cache")
|
| 571 |
+
or (not isinstance(llm._cache, cache_cls))
|
| 572 |
+
or llm._cache.max_batch_size != batch_size
|
| 573 |
+
or llm._cache.max_cache_len < max_cache_len
|
| 574 |
+
)
|
| 575 |
|
| 576 |
if need_new_cache:
|
| 577 |
if hasattr(llm.config, "_pre_quantization_dtype"):
|
| 578 |
cache_dtype = llm.config._pre_quantization_dtype
|
| 579 |
else:
|
| 580 |
cache_dtype = llm.dtype
|
| 581 |
+
if version.parse(transformers.__version__) >= version.parse("4.46.0"):
|
| 582 |
+
llm._cache = cache_cls(
|
| 583 |
+
config=llm.config,
|
| 584 |
+
batch_size=batch_size,
|
| 585 |
+
max_cache_len=max_cache_len,
|
| 586 |
+
device=llm.device,
|
| 587 |
+
dtype=cache_dtype,
|
| 588 |
+
)
|
| 589 |
+
else:
|
| 590 |
+
llm._cache = cache_cls(
|
| 591 |
+
config=llm.config,
|
| 592 |
+
max_batch_size=batch_size,
|
| 593 |
+
max_cache_len=max_cache_len,
|
| 594 |
+
device=llm.device,
|
| 595 |
+
dtype=cache_dtype,
|
| 596 |
+
)
|
| 597 |
else:
|
| 598 |
llm._cache.reset()
|
| 599 |
return llm._cache
|