Ollama

Ollama 新引擎赋能多模态模型

2025年5月15日

多模态 Ollama

Ollama 现在通过 Ollama 的新引擎支持多模态模型,首先是新的视觉多模态模型:

通用多模态理解与推理

Llama 4 Scout

ollama run llama4:scout

(注意:这是一个 1090 亿参数的 mixture-of-experts 模型。) 示例:提出关于视频帧的基于位置的问题: 视频帧分析示例 视频帧分析示例答案 然后你可以提出后续问题:

ollama@ollamas-computer ~ % ollama run llama4:scout
>>> what do you see in this image? /Users/ollama/Downloads/multimodal-example1.png 
Added image '/Users/ollama/Downloads/multimodal-example1.png'
The image depicts a scenic waterfront area with a prominent clock tower at its center. The clock tower, likely the Ferry Building Clock Tower in San Francisco, features a tall structure with a clock face on each side and an American flag flying atop. 
In the foreground, there are several buildings, including what appears to be a marketplace or shopping center, with a parking lot and a street lined with cars. The background showcases a large body of water, possibly a bay or harbor, with a bridge visible in the distance. The sky above is blue with white clouds, suggesting a daytime setting with pleasant weather conditions.
Overall, the image presents a picturesque view of a waterfront area, highlighting the iconic clock tower and the surrounding architecture, as well as the natural beauty of the bay and sky.
>>> how far is this building from the stanford campus in palo alto? 
The distance between the Ferry Building in San Francisco and the Stanford University campus in Palo Alto is approximately 35 miles (56 kilometers). The drive typically takes around 45-60 minutes, depending on traffic conditions.
>>> what's the best way to get there? 
The best way to get to Stanford University from the Ferry Building in San Francisco depends on your preferences and budget. Here are a few options:
1. **By Car**: Take US-101 South to CA-85 South, then continue on CA-101 South. The journey takes around 45-60 minutes, depending on traffic.
2. **By Train and Shuttle**: Take Caltrain from the San Francisco Station (4th and King Streets) to the Palo Alto Station. From there, you can take the Stanford University shuttle (Red and White) to campus. The total travel time is around 1 hour and 15 minutes.
3. **By Ride-hailing Services**: Uber or Lyft from San Francisco to Stanford University takes around 45-60 minutes, depending on traffic.
Please check for any service disruptions or schedule changes before your trip.

Gemma 3

ollama run gemma3

给出多个图像并询问它们之间关系的示例。 这演示了用户如何一次输入多个图像,或者通过后续提示进行输入,并询问有关图像的信息。 多张图片 Gemma 3 答案

ollama@ollamas-computer ~ % ollama run gemma3
>>> /Users/ollama/Downloads/img1.png /Users/ollama/Downloads/img2.png /Users/ollama/Downloads/img3.png /Users/
... ollama/Downloads/img4.png tell me what animal appears in all 4 images? 
Added image '/Users/ollama/Downloads/img1.png'
Added image '/Users/ollama/Downloads/img2.png'
Added image '/Users/ollama/Downloads/img3.png'
Added image '/Users/ollama/Downloads/img4.png'
The animal featured in all four images is a **llama**.
>>> is there a marine mammal in one of the images? 
Yes! You are absolutely right to spot that. 
In the first image, there’s a **dolphin** (whale) boxing with the llama.
>>> in the boxing image, is the llama more likely to win or the whale? 
That’s a fantastic question! Given the image, the llama is *much* more likely to win. 
Here’s why:
*  **Punching Power:** The llama is clearly throwing a punch with a closed fist, demonstrating intent and force.
*  **Whale’s Reaction:** The whale is clearly recoiling in pain and fear.
It's a comical mismatch, but the llama has the upper hand in this boxing match!

文档扫描

Qwen 2.5 VL

ollama run qwen2.5vl

使用 Qwen 2.5 VL 进行字符识别的示例。 检查示例 检查答案 理解并将中文春联翻译成英文的示例。 春联示例 春联答案

Ollama 的新多模态引擎

Ollama 的新车

Ollama 至今一直依赖 ggml-org/llama.cpp 项目来提供模型支持,并专注于易用性和模型可移植性。

随着主要研究实验室发布越来越多的多模态模型,以 Ollama 期望的方式支持这些模型的任务变得越来越具有挑战性。

我们着手支持一种新的引擎,该引擎使多模态模型成为一等公民,并让 Ollama 的合作伙伴更直接地为社区做出贡献 - GGML 张量库。

这意味着什么?

总而言之,这项工作是为了提高 Ollama 本地推理的可靠性和准确性,并为支持具有更多功能的未来模式(即语音、图像生成、视频生成、更长的上下文大小、改进的模型工具支持)奠定基础。

让我们分解几个具体领域:

模型模块化

我们的目标是将每个模型的“爆炸半径”限制在自身内部——提高可靠性,并使创建者和开发人员更容易集成新模型。

如今,ggml/llama.cpp 为纯文本模型提供一流的支持。 然而,对于多模态系统,文本解码器视觉编码器被分成单独的模型并独立执行。 因此,将图像嵌入从视觉模型传递到文本模型需要在编排层中使用特定于模型的逻辑,而该逻辑可能会破坏特定的模型实现。

在 Ollama 中,每个模型都是完全独立的,并且可以公开自己的投影层,与该模型的训练方式对齐。 这种隔离使模型创建者可以实现和发布他们的代码,而无需修补多个文件或添加级联 if 语句。 他们不再需要理解共享的多模态投影函数,也不必担心破坏其他模型——他们可以只专注于自己的模型及其训练。

有关如何实现某些模型的示例,请参见 Ollama 的 GitHub 仓库

准确性

大型图像会产生大量 token,这可能会超过批量大小。 正确处理具有正确位置信息的 token 具有挑战性,尤其是在单个图像跨越边界时。

Ollama 在处理图像时添加元数据,以帮助提高准确性。

一些例子:

许多其他本地推理工具以不同的方式实现这一点; 虽然可以获得类似的结果,但它并不遵循模型的设计和训练方式。

内存管理

图像缓存

处理完图像后,Ollama 会对其进行缓存,以便以后的提示更快; 图像在使用时会保留在缓存中,并且不会因内存清理限制而被丢弃。

内存估算和 KV 缓存优化

Ollama 与硬件制造商和操作系统合作伙伴合作,以确保检测到正确的硬件元数据,以便 Ollama 更好地估算和优化内存使用。 对于许多固件版本,合作伙伴将针对 Ollama 进行验证/测试,以最大程度地减少回归并针对新功能进行基准测试。

Ollama 有一些 KV 缓存优化,可以改进内存的有效使用方式。 Ollama 在单个模型级别配置因果注意力,而不是作为一组进行配置。

例子:

如果模型的注意力层未完全实现,例如滑动窗口注意力或分块注意力,它可能仍然“有效”。 然而,由于这不是模型的训练方式,因此最终用户可能会开始看到模型本身随着时间的推移产生不稳定或降级的输出。 由于级联效应,上下文/序列越长,这一点就越突出。

接下来是什么

致谢

模型

感谢各个团队努力发布公开可用的强大视觉模型 - Google DeepMind、Meta Llama、Alibaba Qwen、Mistral、IBM Granite 以及社区中无数的人和实验室。

GGML

感谢 GGML 团队提供的张量库,该库为 Ollama 的推理提供支持——直接从 Go 访问 GGML 提供了一种可移植的方式来设计自定义推理图,并处理以前在 Ollama 中不可用的更难的模型架构。

硬件合作伙伴

感谢硬件合作伙伴的合作与帮助,以改善大量设备上的推理 - NVIDIA、AMD、Qualcomm、Intel 和 Microsoft。

© 2025 Oll