Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ollama
Commits
82ddc3e4
Unverified
Commit
82ddc3e4
authored
Mar 07, 2024
by
Daniel Hiltgen
Committed by
GitHub
Mar 07, 2024
Browse files
Merge pull request #2964 from dhiltgen/mem_limit_var
Allow setting max vram for workarounds
parents
d481fb3c
be330174
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
gpu/gpu.go
gpu/gpu.go
+9
-0
gpu/gpu_darwin.go
gpu/gpu_darwin.go
+15
-0
No files found.
gpu/gpu.go
View file @
82ddc3e4
...
...
@@ -242,6 +242,15 @@ func getCPUMem() (memInfo, error) {
}
func
CheckVRAM
()
(
int64
,
error
)
{
userLimit
:=
os
.
Getenv
(
"OLLAMA_MAX_VRAM"
)
if
userLimit
!=
""
{
avail
,
err
:=
strconv
.
ParseInt
(
userLimit
,
10
,
64
)
if
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"Invalid OLLAMA_MAX_VRAM setting %s: %s"
,
userLimit
,
err
)
}
slog
.
Info
(
fmt
.
Sprintf
(
"user override OLLAMA_MAX_VRAM=%d"
,
avail
))
return
avail
,
nil
}
gpuInfo
:=
GetGPUInfo
()
if
gpuInfo
.
FreeMemory
>
0
&&
(
gpuInfo
.
Library
==
"cuda"
||
gpuInfo
.
Library
==
"rocm"
)
{
// leave 10% or 1024MiB of VRAM free per GPU to handle unaccounted for overhead
...
...
gpu/gpu_darwin.go
View file @
82ddc3e4
//go:build darwin
package
gpu
/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Foundation -framework CoreGraphics -framework Metal
...
...
@@ -8,11 +9,25 @@ package gpu
*/
import
"C"
import
(
"fmt"
"log/slog"
"os"
"runtime"
"strconv"
)
// CheckVRAM returns the free VRAM in bytes on Linux machines with NVIDIA GPUs
func
CheckVRAM
()
(
int64
,
error
)
{
userLimit
:=
os
.
Getenv
(
"OLLAMA_MAX_VRAM"
)
if
userLimit
!=
""
{
avail
,
err
:=
strconv
.
ParseInt
(
userLimit
,
10
,
64
)
if
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"Invalid OLLAMA_MAX_VRAM setting %s: %s"
,
userLimit
,
err
)
}
slog
.
Info
(
fmt
.
Sprintf
(
"user override OLLAMA_MAX_VRAM=%d"
,
avail
))
return
avail
,
nil
}
if
runtime
.
GOARCH
==
"amd64"
{
// gpu not supported, this may not be metal
return
0
,
nil
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment