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
2665f3c2
Unverified
Commit
2665f3c2
authored
Oct 26, 2023
by
Bruce MacDonald
Committed by
GitHub
Oct 26, 2023
Browse files
offload 75% of available vram to improve stability (#921)
parent
a79f030e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
4 deletions
+7
-4
llm/llama.go
llm/llama.go
+7
-4
No files found.
llm/llama.go
View file @
2665f3c2
...
...
@@ -243,12 +243,15 @@ func NumGPU(numLayer, fileSizeBytes int64, opts api.Options) int {
return
0
}
// Calculate bytes per layer
// TODO: this is a rough heuristic, better would be to calculate this based on number of layers and context size
/*
Calculate bytes per layer, this will roughly be the size of the model file divided by the number of layers.
We can store the model weights and the kv cache in vram,
to enable kv chache vram storage add two additional layers to the number of layers retrieved from the model file.
*/
bytesPerLayer
:=
fileSizeBytes
/
numLayer
// max number of layers we can fit in
VRAM, subtract 8% to prevent consuming all available VRAM and running out of mem
or
y
layers
:=
int
(
freeBytes
/
bytesPerLayer
)
*
92
/
100
//
75% of the absolute
max number of layers we can fit in
available VRAM, off-loading too many layers to the GPU can cause OOM err
or
s
layers
:=
int
(
freeBytes
/
bytesPerLayer
)
*
3
/
4
log
.
Printf
(
"%d MB VRAM available, loading up to %d GPU layers"
,
freeBytes
/
(
1024
*
1024
),
layers
)
return
layers
...
...
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