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
65b88c54
Commit
65b88c54
authored
Mar 13, 2025
by
Michael Yang
Browse files
fix divide by zero
parent
a422ba39
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
4 deletions
+14
-4
fs/ggml/ggml.go
fs/ggml/ggml.go
+14
-4
No files found.
fs/ggml/ggml.go
View file @
65b88c54
...
@@ -579,6 +579,10 @@ func (f GGML) GraphSize(context, batch uint64, kvCacheType string) (kv, partialO
...
@@ -579,6 +579,10 @@ func (f GGML) GraphSize(context, batch uint64, kvCacheType string) (kv, partialO
}
}
func
(
llm
GGML
)
VisionGraphSize
()
(
weights
,
graphSize
uint64
)
{
func
(
llm
GGML
)
VisionGraphSize
()
(
weights
,
graphSize
uint64
)
{
if
llm
.
KV
()
.
Uint
(
"vision.block_count"
)
==
0
{
return
}
for
name
,
layer
:=
range
llm
.
Tensors
()
.
GroupLayers
()
{
for
name
,
layer
:=
range
llm
.
Tensors
()
.
GroupLayers
()
{
if
strings
.
HasPrefix
(
name
,
"v."
)
{
if
strings
.
HasPrefix
(
name
,
"v."
)
{
for
_
,
tensor
:=
range
layer
{
for
_
,
tensor
:=
range
layer
{
...
@@ -589,6 +593,12 @@ func (llm GGML) VisionGraphSize() (weights, graphSize uint64) {
...
@@ -589,6 +593,12 @@ func (llm GGML) VisionGraphSize() (weights, graphSize uint64) {
imageSize
:=
uint64
(
llm
.
KV
()
.
Uint
(
"vision.image_size"
))
imageSize
:=
uint64
(
llm
.
KV
()
.
Uint
(
"vision.image_size"
))
patchSize
:=
uint64
(
llm
.
KV
()
.
Uint
(
"vision.patch_size"
))
patchSize
:=
uint64
(
llm
.
KV
()
.
Uint
(
"vision.patch_size"
))
if
patchSize
==
0
{
slog
.
Warn
(
"unknown patch size for vision model"
)
return
}
numChannels
:=
uint64
(
llm
.
KV
()
.
Uint
(
"vision.num_channels"
))
numPatches
:=
(
imageSize
/
patchSize
)
*
(
imageSize
/
patchSize
)
numPatches
:=
(
imageSize
/
patchSize
)
*
(
imageSize
/
patchSize
)
if
_
,
ok
:=
llm
.
Tensors
()
.
GroupLayers
()[
"v"
][
"class_embd"
];
ok
{
if
_
,
ok
:=
llm
.
Tensors
()
.
GroupLayers
()[
"v"
][
"class_embd"
];
ok
{
...
@@ -596,15 +606,13 @@ func (llm GGML) VisionGraphSize() (weights, graphSize uint64) {
...
@@ -596,15 +606,13 @@ func (llm GGML) VisionGraphSize() (weights, graphSize uint64) {
}
}
headCount
:=
uint64
(
llm
.
KV
()
.
Uint
(
"vision.attention.head_count"
))
headCount
:=
uint64
(
llm
.
KV
()
.
Uint
(
"vision.attention.head_count"
))
embeddingLength
:=
uint64
(
llm
.
KV
()
.
Uint
(
"vision.embedding_length"
))
switch
llm
.
KV
()
.
Architecture
()
{
switch
llm
.
KV
()
.
Architecture
()
{
case
"mllama"
:
case
"mllama"
:
numPaddedPatches
:=
numPatches
+
8
-
(
numPatches
%
8
)
%
8
numPaddedPatches
:=
numPatches
+
8
-
(
numPatches
%
8
)
%
8
maxNumTiles
:=
uint64
(
llm
.
KV
()
.
Uint
(
"vision.max_num_tiles"
))
maxNumTiles
:=
uint64
(
llm
.
KV
()
.
Uint
(
"vision.max_num_tiles"
))
numChannels
:=
uint64
(
llm
.
KV
()
.
Uint
(
"vision.num_channels"
))
embeddingLength
:=
uint64
(
llm
.
KV
()
.
Uint
(
"vision.embedding_length"
))
graphSize
=
4
*
(
8
+
graphSize
=
4
*
(
8
+
imageSize
*
imageSize
*
numChannels
*
maxNumTiles
+
imageSize
*
imageSize
*
numChannels
*
maxNumTiles
+
...
@@ -612,7 +620,9 @@ func (llm GGML) VisionGraphSize() (weights, graphSize uint64) {
...
@@ -612,7 +620,9 @@ func (llm GGML) VisionGraphSize() (weights, graphSize uint64) {
9
*
embeddingLength
*
numPaddedPatches
*
maxNumTiles
+
9
*
embeddingLength
*
numPaddedPatches
*
maxNumTiles
+
numPaddedPatches
*
maxNumTiles
*
numPaddedPatches
*
maxNumTiles
*
headCount
)
numPaddedPatches
*
maxNumTiles
*
numPaddedPatches
*
maxNumTiles
*
headCount
)
case
"gemma3"
:
case
"gemma3"
:
graphSize
=
4
*
(
numPatches
*
numPatches
*
headCount
)
graphSize
=
4
*
(
imageSize
*
imageSize
*
numChannels
+
embeddingLength
*
patchSize
+
numPatches
*
numPatches
*
headCount
)
}
}
return
weights
,
graphSize
return
weights
,
graphSize
...
...
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