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
1ae84bc2
Unverified
Commit
1ae84bc2
authored
Nov 09, 2023
by
Bruce MacDonald
Committed by
GitHub
Nov 09, 2023
Browse files
skip gpu if less than 2GB VRAM are available (#1059)
parent
db8bf336
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
5 deletions
+8
-5
llm/llama.go
llm/llama.go
+8
-5
No files found.
llm/llama.go
View file @
1ae84bc2
...
@@ -196,7 +196,10 @@ type llama struct {
...
@@ -196,7 +196,10 @@ type llama struct {
Running
Running
}
}
var
errNoGPU
=
errors
.
New
(
"nvidia-smi command failed"
)
var
(
errNvidiaSMI
=
errors
.
New
(
"nvidia-smi command failed"
)
errAvailableVRAM
=
errors
.
New
(
"not enough VRAM available, falling back to CPU only"
)
)
// CheckVRAM returns the free VRAM in bytes on Linux machines with NVIDIA GPUs
// CheckVRAM returns the free VRAM in bytes on Linux machines with NVIDIA GPUs
func
CheckVRAM
()
(
int64
,
error
)
{
func
CheckVRAM
()
(
int64
,
error
)
{
...
@@ -205,7 +208,7 @@ func CheckVRAM() (int64, error) {
...
@@ -205,7 +208,7 @@ func CheckVRAM() (int64, error) {
cmd
.
Stdout
=
&
stdout
cmd
.
Stdout
=
&
stdout
err
:=
cmd
.
Run
()
err
:=
cmd
.
Run
()
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
errN
oGPU
return
0
,
errN
vidiaSMI
}
}
var
freeMiB
int64
var
freeMiB
int64
...
@@ -226,8 +229,8 @@ func CheckVRAM() (int64, error) {
...
@@ -226,8 +229,8 @@ func CheckVRAM() (int64, error) {
freeBytes
:=
freeMiB
*
1024
*
1024
freeBytes
:=
freeMiB
*
1024
*
1024
if
freeBytes
<
2
*
format
.
GigaByte
{
if
freeBytes
<
2
*
format
.
GigaByte
{
log
.
Printf
(
"less than 2 GB VRAM available
, falling back to CPU only
"
)
log
.
Printf
(
"less than 2 GB VRAM available"
)
f
re
eMiB
=
0
re
turn
0
,
errAvailableVRAM
}
}
return
freeBytes
,
nil
return
freeBytes
,
nil
...
@@ -240,7 +243,7 @@ func NumGPU(numLayer, fileSizeBytes int64, opts api.Options) int {
...
@@ -240,7 +243,7 @@ func NumGPU(numLayer, fileSizeBytes int64, opts api.Options) int {
if
runtime
.
GOOS
==
"linux"
{
if
runtime
.
GOOS
==
"linux"
{
freeBytes
,
err
:=
CheckVRAM
()
freeBytes
,
err
:=
CheckVRAM
()
if
err
!=
nil
{
if
err
!=
nil
{
if
err
.
Error
()
!=
"nvidia-smi command failed"
{
if
!
err
ors
.
Is
(
err
,
errNvidiaSMI
)
{
log
.
Print
(
err
.
Error
())
log
.
Print
(
err
.
Error
())
}
}
// nvidia driver not installed or no nvidia GPU found
// nvidia driver not installed or no nvidia GPU found
...
...
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