Ollama 新引擎赋能多模态模型
Ollama 新引擎赋能多模态模型
2025年5月15日
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
给出多个图像并询问它们之间关系的示例。
这演示了用户如何一次输入多个图像,或者通过后续提示进行输入,并询问有关图像的信息。
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 至今一直依赖 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 的 Gemma 3 利用滑动窗口注意力,Ollama 可以利用它来分配模型上下文长度的子集或一部分,以提高性能,并且由于内存效率,这意味着我们可以在同一系统上增加模型的上下文长度,或者将剩余内存用于更高的并发性。
- 为了唯一地支持 Meta 的 Llama 4 Scout 和 Maverick 模型,Ollama 实现了分块注意力、注意力调整以支持更长的上下文大小、特定的 2D 旋转嵌入以及在 mixture-of-experts 类型的模型中。
如果模型的注意力层未完全实现,例如滑动窗口注意力或分块注意力,它可能仍然“有效”。 然而,由于这不是模型的训练方式,因此最终用户可能会开始看到模型本身随着时间的推移产生不稳定或降级的输出。 由于级联效应,上下文/序列越长,这一点就越突出。
接下来是什么
- 支持更长的上下文大小
- 支持思考/推理
- 具有流式响应的工具调用
- 启用计算机使用
致谢
模型
感谢各个团队努力发布公开可用的强大视觉模型 - Google DeepMind、Meta Llama、Alibaba Qwen、Mistral、IBM Granite 以及社区中无数的人和实验室。
GGML
感谢 GGML 团队提供的张量库,该库为 Ollama 的推理提供支持——直接从 Go 访问 GGML 提供了一种可移植的方式来设计自定义推理图,并处理以前在 Ollama 中不可用的更难的模型架构。
硬件合作伙伴
感谢硬件合作伙伴的合作与帮助,以改善大量设备上的推理 - NVIDIA、AMD、Qualcomm、Intel 和 Microsoft。
© 2025 Oll