Instructions to use ATH-MaaS/Ovis-VL-Embedding-2B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ATH-MaaS/Ovis-VL-Embedding-2B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="ATH-MaaS/Ovis-VL-Embedding-2B")# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("ATH-MaaS/Ovis-VL-Embedding-2B") model = AutoModelForMultimodalLM.from_pretrained("ATH-MaaS/Ovis-VL-Embedding-2B", device_map="auto") - sentence-transformers
How to use ATH-MaaS/Ovis-VL-Embedding-2B with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("ATH-MaaS/Ovis-VL-Embedding-2B") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
Integrate with Sentence Transformers
Hello @wl1982 @yanwj @kevinke !
I've been integrating this model and its 9B sibling into the Sentence Transformers framework, although I've struggled as there's no recommended inference snippet, I can't be sure that it reproduces the expected outputs.
Pull Request overview
- Add Sentence Transformers support for text, images, video, and interleaved inputs.
- Document text retrieval and image-text similarity examples.
Details
I've added configuration files so the model can be loaded directly with SentenceTransformer("ATH-MaaS/Ovis-VL-Embedding-2B"). The integration loads the backbone from model/, applies last-token pooling, and L2-normalizes the resulting 2048-dimensional embeddings. Both query and document encoding use Represent the user's input. by default, with support for task-specific instructions.
I've based the inline embedding template on the qwen3_5_emb template selected in model/args.json. It reproduces the native formatting with an empty assistant thinking block and appends <|endoftext|>, following the suffix defined in MS-SWIFT: https://github.com/modelscope/ms-swift/blob/main/swift/template/templates/qwen.py.
I've verified loading and encoding with Sentence Transformers 5.4.0 and Transformers 5.12.1. Float32 checks cover text, images, both image/text orders, and video frames. Compared with a reference using the native processor template plus <|endoftext|>, the maximum embedding difference was 5.7e-7 and the maximum cosine similarity difference was 5.4e-7. These checks validate the integration against that reconstructed reference, but do not independently verify the extra token. I've also run the README example below with the default bfloat16 weights and checked image URLs, local paths, and custom instructions.
Install with pip install "sentence-transformers[image]>=5.4.0" "transformers>=5.12.1":
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("ATH-MaaS/Ovis-VL-Embedding-2B", revision="refs/pr/1")
query = "Which planet is known as the Red Planet?"
documents = [
"Venus is often called Earth's twin because of its similar size and proximity.",
"Mars, known for its reddish appearance, is often referred to as the Red Planet.",
"Jupiter, the largest planet in our solar system, has a prominent red spot.",
"Saturn, famous for its rings, is sometimes mistaken for the Red Planet.",
]
query_embedding = model.encode_query(query)
document_embeddings = model.encode_document(documents)
print(query_embedding.shape, document_embeddings.shape)
# (2048,) (4, 2048)
print(model.similarity(query_embedding, document_embeddings))
# tensor([[0.6870, 0.8412, 0.7255, 0.7707]])
# And a multimodal example:
text_embeddings = model.encode(["Ovis logo", "A green car", "children playing"])
image_embeddings = model.encode(
"https://huggingface.co/ATH-MaaS/Ovis-VL-Embedding-2B/resolve/main/figures/ovis_logo.png"
)
print(text_embeddings.shape, image_embeddings.shape)
# (3, 2048) (2048,)
print(model.similarity(image_embeddings, text_embeddings))
# tensor([[0.6588, 0.4354, 0.4712]])
Note that the revision="refs/pr/1" allows you to run this code before even merging it, so you can compare against your reference implementation. Please check and let me know what your implementation produces, so I can make sure it matches.
I think it's such a shame that you've got this excellent model on the benchmarks, but users aren't sure how to use it (correctly).
- Tom Aarsen
@wl1982 Thanks for merging!
I also have a draft for https://huggingface.co/ATH-MaaS/Ovis-Omni-Embedding-3B, but I'm a bit bottlenecked as I couldn't figure out what chat template or instruction prompts qwen2_5_omni_emb is referring to: https://huggingface.co/ATH-MaaS/Ovis-Omni-Embedding-3B/blob/main/model/args.json#L3. I do have some theories (e.g. qwen2_5_omni template + <|endoftext|>).
If you don't have a link/copy of the source, perhaps easiest is if you run the model for these inputs:
queries = ["Ovis logo", "A green car", "children playing"]
images = ["https://huggingface.co/ATH-MaaS/Ovis-VL-Embedding-2B/resolve/main/figures/ovis_logo.png"]
And then print e.g. embeddings[:,:5] so I can check if any of my likely template options are correct. But if you have e.g. https://github.com/modelscope/ms-swift/blob/9a1155e53a0ba136c4cbeebf4dd9fb7e9b80b541/swift/template/templates/qwen.py#L853-L861 for the Omni model, then that's even better 🤗
- Tom Aarsen
Thanks for looking into this! Your guess is essentially correct: qwen2_5_omni_emb inherits the Qwen2.5-Omni multimodal template, with an embedding-specific system prompt and suffix.
The relevant implementation in our ms-swift training code is:
class Qwen2_5OmniEmbTemplate(Qwen2_5OmniTemplate):
def _preprocess_inputs(self, inputs):
super()._preprocess_inputs(inputs)
if len(inputs.messages) % 2 == 1 and inputs.messages[-1]['role'] != 'assistant':
inputs.messages.append({'role': 'assistant', 'content': ''})
register_template(
QwenTemplateMeta(
template_type=MLLMTemplateType.qwen2_5_omni_emb,
default_system="Represent the user's input.",
suffix=['<|endoftext|>'],
template_cls=Qwen2_5OmniEmbTemplate,
))
For example, without a custom system instruction, "Ovis logo" is rendered as:
<|im_start|>system
Represent the user's input.<|im_end|>
<|im_start|>user
Ovis logo<|im_end|>
<|im_start|>assistant
<|endoftext|>
The assistant content is empty—there is no additional <|im_end|> or block before <|endoftext|>.
For multimodal inputs, the native Qwen2.5-Omni media preprocessing and token expansion are retained.
Our default embedding path takes the final-layer hidden state at the last non-padding token—<|endoftext|> in this example—and applies L2 normalization.
So <|endoftext|> is part of the model input and serves as the pooling anchor, rather than merely a generation stop token.
Perfect, that's just what I needed, thanks a lot. I've used that info to open https://huggingface.co/ATH-MaaS/Ovis-Omni-Embedding-3B/discussions/2.
There's one small inconvenience there: the config.json and model are the 'full model' instead of just the Thinker component. Sentence Transformers loads only the Thinker component with AutoModelForMultimodalLM.from_pretrained which is nice, but the AutoConfig still loads the full model config. There doesn't seem to be a nice kwarg to tell AutoConfig.from_pretrained to load only a specific subconfig, so instead I point to a new thinker_config.json which is an exact copy of the thinker subconfig in config.json.
The only other fixes I can think of are 1) adding a custom module and requiring trust_remote_code=True when loading the model, which is not ideal, or 2) updating both the model weights and config.json etc. to only point to the thinker.
- Tom Aarsen