From 8149a3c86e3dca30b4883bf581757402e2f246f5 Mon Sep 17 00:00:00 2001 From: Jesse Gross Date: Tue, 2 Sep 2025 10:47:33 -0700 Subject: [PATCH] llm: Avoid underflow in free memory logging If a GPU's free memory is less than the reserved amount, we might get an underflow. Since it is an unsigned uint64, we print this as a large number rather than the more correct 0. This only affects logging, the actual layout code already handles this correctly. Bug #12138 --- llm/server.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/llm/server.go b/llm/server.go index b9ffdc6c..b8d3cdd3 100644 --- a/llm/server.go +++ b/llm/server.go @@ -678,8 +678,12 @@ func (s *ollamaServer) Load(ctx context.Context, gpus discover.GpuInfoList, requ if !(len(gpus) == 1 && gpus[0].Library == "cpu") { for _, gpu := range gpus { + available := gpu.FreeMemory - envconfig.GpuOverhead() - gpu.MinimumMemory + if gpu.FreeMemory < envconfig.GpuOverhead()+gpu.MinimumMemory { + available = 0 + } slog.Info("gpu memory", "id", gpu.ID, - "available", format.HumanBytes2(gpu.FreeMemory-envconfig.GpuOverhead()-gpu.MinimumMemory), + "available", format.HumanBytes2(available), "free", format.HumanBytes2(gpu.FreeMemory), "minimum", format.HumanBytes2(gpu.MinimumMemory), "overhead", format.HumanBytes2(envconfig.GpuOverhead()))