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
ef202789
Unverified
Commit
ef202789
authored
May 15, 2025
by
Michael Yang
Committed by
GitHub
May 15, 2025
Browse files
fix pixel values padding (#10718)
* panic if trying to pad 4d * fix pixel values padding
parent
55760195
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
3 deletions
+10
-3
ml/backend/ggml/ggml.go
ml/backend/ggml/ggml.go
+2
-0
model/models/mllama/model.go
model/models/mllama/model.go
+8
-3
No files found.
ml/backend/ggml/ggml.go
View file @
ef202789
...
...
@@ -915,6 +915,8 @@ func (t *Tensor) RMSNorm(ctx ml.Context, w ml.Tensor, eps float32) ml.Tensor {
func
(
t
*
Tensor
)
Pad
(
ctx
ml
.
Context
,
shape
...
int
)
ml
.
Tensor
{
if
len
(
shape
)
!=
4
{
panic
(
"expected 4 dimensions"
)
}
else
if
shape
[
3
]
!=
0
{
panic
(
"cuda does not support 4d tensors"
)
}
return
&
Tensor
{
...
...
model/models/mllama/model.go
View file @
ef202789
...
...
@@ -3,6 +3,7 @@ package mllama
import
(
"bytes"
"image"
"slices"
"github.com/ollama/ollama/fs"
"github.com/ollama/ollama/kvcache"
...
...
@@ -73,13 +74,17 @@ func (m *Model) EncodeMultimodal(ctx ml.Context, multimodalData []byte) (any, er
return
nil
,
err
}
pixelValues
,
err
:=
ctx
.
Input
()
.
FromFloatSlice
(
f32s
,
m
.
imageSize
,
m
.
imageSize
,
m
.
numChannels
,
ratio
.
numTiles
())
if
ratio
.
numTiles
()
<
m
.
maxNumTiles
{
// Pad tiles to maxNumTiles
f32s
=
slices
.
Grow
(
f32s
,
m
.
imageSize
*
m
.
imageSize
*
m
.
numChannels
*
m
.
maxNumTiles
)
f32s
=
f32s
[
:
m
.
imageSize
*
m
.
imageSize
*
m
.
numChannels
*
m
.
maxNumTiles
]
}
pixelValues
,
err
:=
ctx
.
Input
()
.
FromFloatSlice
(
f32s
,
m
.
imageSize
,
m
.
imageSize
,
m
.
numChannels
,
m
.
maxNumTiles
)
if
err
!=
nil
{
return
nil
,
err
}
pixelValues
=
pixelValues
.
Pad
(
ctx
,
0
,
0
,
0
,
m
.
ImageProcessor
.
maxNumTiles
-
ratio
.
numTiles
())
aspectRatio
,
err
:=
ctx
.
Input
()
.
FromIntSlice
([]
int32
{
int32
(
ratio
.
rank
)},
1
)
if
err
!=
nil
{
return
nil
,
err
...
...
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