mirror of
https://github.com/jmorganca/ollama
synced 2025-10-06 00:32:49 +02:00
This revamps how we discover GPUs in the system by leveraging the Ollama runner. This should eliminate inconsistency between our GPU discovery and the runners capabilities at runtime, particularly for cases where we try to filter out unsupported GPUs. Now the runner does that implicitly based on the actual device list. In some cases free VRAM reporting can be unreliable which can leaad to scheduling mistakes, so this also includes a patch to leverage more reliable VRAM reporting libraries if available. Automatic workarounds have been removed as only one GPU leveraged this, which is now documented. This GPU will soon fall off the support matrix with the next ROCm bump. Additional cleanup of the scheduler and discovery packages can be done in the future once we have switched on the new memory management code, and removed support for the llama runner.
109 lines
2.4 KiB
Go
109 lines
2.4 KiB
Go
package discover
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/ollama/ollama/app/lifecycle"
|
|
)
|
|
|
|
func init() {
|
|
lifecycle.InitLogging()
|
|
}
|
|
|
|
func TestFilterOverlapByLibrary(t *testing.T) {
|
|
type testcase struct {
|
|
name string
|
|
inp map[string]map[string]map[string]int
|
|
exp []bool
|
|
}
|
|
for _, tc := range []testcase{
|
|
{
|
|
name: "empty",
|
|
inp: map[string]map[string]map[string]int{},
|
|
exp: []bool{}, // needs deletion
|
|
},
|
|
{
|
|
name: "single no overlap",
|
|
inp: map[string]map[string]map[string]int{
|
|
"CUDA": {
|
|
"cuda_v12": {
|
|
"GPU-d7b00605-c0c8-152d-529d-e03726d5dc52": 0,
|
|
},
|
|
},
|
|
},
|
|
exp: []bool{false},
|
|
},
|
|
{
|
|
name: "100% overlap pick 2nd",
|
|
inp: map[string]map[string]map[string]int{
|
|
"CUDA": {
|
|
"cuda_v12": {
|
|
"GPU-d7b00605-c0c8-152d-529d-e03726d5dc52": 0,
|
|
"GPU-cd6c3216-03d2-a8eb-8235-2ffbf571712e": 1,
|
|
},
|
|
"cuda_v13": {
|
|
"GPU-d7b00605-c0c8-152d-529d-e03726d5dc52": 2,
|
|
"GPU-cd6c3216-03d2-a8eb-8235-2ffbf571712e": 3,
|
|
},
|
|
},
|
|
},
|
|
exp: []bool{true, true, false, false},
|
|
},
|
|
{
|
|
name: "100% overlap pick 1st",
|
|
inp: map[string]map[string]map[string]int{
|
|
"CUDA": {
|
|
"cuda_v13": {
|
|
"GPU-d7b00605-c0c8-152d-529d-e03726d5dc52": 0,
|
|
"GPU-cd6c3216-03d2-a8eb-8235-2ffbf571712e": 1,
|
|
},
|
|
"cuda_v12": {
|
|
"GPU-d7b00605-c0c8-152d-529d-e03726d5dc52": 2,
|
|
"GPU-cd6c3216-03d2-a8eb-8235-2ffbf571712e": 3,
|
|
},
|
|
},
|
|
},
|
|
exp: []bool{false, false, true, true},
|
|
},
|
|
{
|
|
name: "partial overlap pick older",
|
|
inp: map[string]map[string]map[string]int{
|
|
"CUDA": {
|
|
"cuda_v13": {
|
|
"GPU-d7b00605-c0c8-152d-529d-e03726d5dc52": 0,
|
|
},
|
|
"cuda_v12": {
|
|
"GPU-d7b00605-c0c8-152d-529d-e03726d5dc52": 1,
|
|
"GPU-cd6c3216-03d2-a8eb-8235-2ffbf571712e": 2,
|
|
},
|
|
},
|
|
},
|
|
exp: []bool{true, false, false},
|
|
},
|
|
{
|
|
name: "no overlap",
|
|
inp: map[string]map[string]map[string]int{
|
|
"CUDA": {
|
|
"cuda_v13": {
|
|
"GPU-d7b00605-c0c8-152d-529d-e03726d5dc52": 0,
|
|
},
|
|
"cuda_v12": {
|
|
"GPU-cd6c3216-03d2-a8eb-8235-2ffbf571712e": 1,
|
|
},
|
|
},
|
|
},
|
|
exp: []bool{false, false},
|
|
},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
needsDelete := make([]bool, len(tc.exp))
|
|
filterOverlapByLibrary(tc.inp, needsDelete)
|
|
for i, exp := range tc.exp {
|
|
if needsDelete[i] != exp {
|
|
t.Fatalf("expected: %v\ngot: %v", tc.exp, needsDelete)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|