[PR #9896] [MERGED] Pass input tensor instead of raw data to models #18358

Closed
opened 2026-04-16 06:32:47 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/9896
Author: @jessegross
Created: 3/19/2025
Status: Merged
Merged: 3/20/2025
Merged by: @jessegross

Base: mainHead: jessegross/inputs


📝 Commits (2)

  • 1d87a4a input: Rename Options to Batch
  • a310fa7 model: Pass input tensor instead of raw data to models

📊 Changes

14 files changed (+81 additions, -79 deletions)

View changed files

📝 kvcache/cache.go (+1 -1)
📝 kvcache/causal.go (+6 -6)
📝 kvcache/causal_test.go (+1 -1)
📝 kvcache/encoder.go (+3 -3)
📝 kvcache/wrapper.go (+4 -4)
📝 model/input/input.go (+21 -6)
📝 model/model.go (+13 -7)
📝 model/model_test.go (+1 -1)
📝 model/models/gemma2/model.go (+4 -9)
📝 model/models/gemma3/model.go (+4 -9)
📝 model/models/gemma3/model_text.go (+2 -2)
📝 model/models/llama/model.go (+4 -9)
📝 model/models/mllama/model.go (+6 -11)
📝 runner/ollamarunner/runner.go (+11 -10)

📄 Description

Rather than directly giving the input data to models, we can pass a tensor instead. In the short term, this saves some duplicated code.

Longer term, we will want to overlap setting up the next batch with processing of the current one. In this case, we will only have the shape of the tensor but it will not be loaded with data at the time of graph generation. By passing only a tensor to models now, we set up this possibility and prevent them from relying on data that they won't have in the future.

Although the same could be done for Positions and Outputs, in some cases we either need the raw input data or don't use them at all. Therefore, for now we leave them as they are and allow models to convert them to tensors as needed.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/9896 **Author:** [@jessegross](https://github.com/jessegross) **Created:** 3/19/2025 **Status:** ✅ Merged **Merged:** 3/20/2025 **Merged by:** [@jessegross](https://github.com/jessegross) **Base:** `main` ← **Head:** `jessegross/inputs` --- ### 📝 Commits (2) - [`1d87a4a`](https://github.com/ollama/ollama/commit/1d87a4a2e095deb9900ed9a69a46cd355125eb66) input: Rename Options to Batch - [`a310fa7`](https://github.com/ollama/ollama/commit/a310fa7ec67ebd68cd8cafaf96a16fec110569f2) model: Pass input tensor instead of raw data to models ### 📊 Changes **14 files changed** (+81 additions, -79 deletions) <details> <summary>View changed files</summary> 📝 `kvcache/cache.go` (+1 -1) 📝 `kvcache/causal.go` (+6 -6) 📝 `kvcache/causal_test.go` (+1 -1) 📝 `kvcache/encoder.go` (+3 -3) 📝 `kvcache/wrapper.go` (+4 -4) 📝 `model/input/input.go` (+21 -6) 📝 `model/model.go` (+13 -7) 📝 `model/model_test.go` (+1 -1) 📝 `model/models/gemma2/model.go` (+4 -9) 📝 `model/models/gemma3/model.go` (+4 -9) 📝 `model/models/gemma3/model_text.go` (+2 -2) 📝 `model/models/llama/model.go` (+4 -9) 📝 `model/models/mllama/model.go` (+6 -11) 📝 `runner/ollamarunner/runner.go` (+11 -10) </details> ### 📄 Description Rather than directly giving the input data to models, we can pass a tensor instead. In the short term, this saves some duplicated code. Longer term, we will want to overlap setting up the next batch with processing of the current one. In this case, we will only have the shape of the tensor but it will not be loaded with data at the time of graph generation. By passing only a tensor to models now, we set up this possibility and prevent them from relying on data that they won't have in the future. Although the same could be done for Positions and Outputs, in some cases we either need the raw input data or don't use them at all. Therefore, for now we leave them as they are and allow models to convert them to tensors as needed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-16 06:32:47 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#18358