[PR #10185] [MERGED] Fix nondeterministic model unload order #23711

Closed
opened 2026-04-19 17:09:51 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/10185
Author: @IreGaddr
Created: 4/9/2025
Status: Merged
Merged: 4/9/2025
Merged by: @dhiltgen

Base: mainHead: fix-deterministic-unload


📝 Commits (1)

  • d5fe200 fix(scheduler): make model unload order deterministic

📊 Changes

1 file changed (+14 additions, -8 deletions)

View changed files

📝 server/sched.go (+14 -8)

📄 Description

Fix nondeterministic model unload order in scheduler
Summary
This pull request fixes a bug where Ollama's model scheduler sometimes failed to unload models predictably, leading to inconsistent memory release and occasional request failures, especially on Linux.

Root Cause
The scheduler iterated over Go maps (which are unordered) when selecting a model to unload. When multiple models had the same session duration, the unload choice was nondeterministic, varying across runs and platforms. This caused inconsistent unload behavior and resource management issues.

Fix
The unload selection logic was updated to:

Sort runners primarily by session duration (as before).
Add a secondary sort key: model path (string).
This ensures a deterministic unload order even when durations are equal, eliminating nondeterminism caused by map iteration order.

Impact
Model unload behavior is now consistent and predictable across platforms.
Fixes occasional failures to release models or accept new requests.
Tested on Linux with NVIDIA GPU, confirmed models unload deterministically and GPU memory is released as expected.


🔄 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/10185 **Author:** [@IreGaddr](https://github.com/IreGaddr) **Created:** 4/9/2025 **Status:** ✅ Merged **Merged:** 4/9/2025 **Merged by:** [@dhiltgen](https://github.com/dhiltgen) **Base:** `main` ← **Head:** `fix-deterministic-unload` --- ### 📝 Commits (1) - [`d5fe200`](https://github.com/ollama/ollama/commit/d5fe200a221a67130a8aec2db244def340dc863e) fix(scheduler): make model unload order deterministic ### 📊 Changes **1 file changed** (+14 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `server/sched.go` (+14 -8) </details> ### 📄 Description Fix nondeterministic model unload order in scheduler Summary This pull request fixes a bug where Ollama's model scheduler sometimes failed to unload models predictably, leading to inconsistent memory release and occasional request failures, especially on Linux. Root Cause The scheduler iterated over Go maps (which are unordered) when selecting a model to unload. When multiple models had the same session duration, the unload choice was nondeterministic, varying across runs and platforms. This caused inconsistent unload behavior and resource management issues. Fix The unload selection logic was updated to: Sort runners primarily by session duration (as before). Add a secondary sort key: model path (string). This ensures a deterministic unload order even when durations are equal, eliminating nondeterminism caused by map iteration order. Impact Model unload behavior is now consistent and predictable across platforms. Fixes occasional failures to release models or accept new requests. Tested on Linux with NVIDIA GPU, confirmed models unload deterministically and GPU memory is released as expected. --- <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-19 17:09:51 -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#23711