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
de4ded68
Unverified
Commit
de4ded68
authored
Apr 25, 2024
by
Michael Yang
Committed by
GitHub
Apr 25, 2024
Browse files
Merge pull request #3923 from ollama/mxyng/mem
only count output tensors
parents
9b5a3c59
7bb7cb8a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
9 deletions
+18
-9
llm/memory.go
llm/memory.go
+18
-9
No files found.
llm/memory.go
View file @
de4ded68
...
...
@@ -5,7 +5,6 @@ import (
"log/slog"
"os"
"strconv"
"strings"
"github.com/ollama/ollama/api"
"github.com/ollama/ollama/format"
...
...
@@ -100,8 +99,22 @@ func EstimateGPULayers(gpus []gpu.GpuInfo, ggml *GGML, projectors []string, opts
return
0
,
0
}
var
layerCount
int
layers
:=
ggml
.
Tensors
()
.
Layers
()
var
memoryLayerOutput
uint64
for
k
,
v
:=
range
layers
{
if
k
==
"output"
||
k
==
"output_norm"
{
memoryLayerOutput
+=
v
.
size
()
}
}
if
gpus
[
0
]
.
Library
==
"metal"
&&
opts
.
UseMMap
{
// memory is preallocated for output tensors
memoryRequiredTotal
+=
memoryLayerOutput
memoryRequiredPartial
+=
memoryLayerOutput
}
var
layerCount
int
for
i
:=
0
;
i
<
int
(
ggml
.
KV
()
.
BlockCount
());
i
++
{
memoryLayer
:=
layers
[
fmt
.
Sprintf
(
"blk.%d"
,
i
)]
.
size
()
...
...
@@ -115,15 +128,11 @@ func EstimateGPULayers(gpus []gpu.GpuInfo, ggml *GGML, projectors []string, opts
}
}
var
memoryLayerOutput
uint64
for
k
,
v
:=
range
layers
{
if
!
strings
.
HasPrefix
(
k
,
"blk."
)
{
memoryLayerOutput
+=
v
.
size
()
}
if
gpus
[
0
]
.
Library
!=
"metal"
||
!
opts
.
UseMMap
{
// memory was not preallocated for output tensors
memoryRequiredTotal
+=
memoryLayerOutput
}
memoryRequiredTotal
+=
memoryLayerOutput
if
memoryAvailable
>
memoryRequiredTotal
{
layerCount
=
int
(
ggml
.
KV
()
.
BlockCount
())
+
1
memoryRequiredPartial
=
memoryRequiredTotal
...
...
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