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
ec9eb28f
"vscode:/vscode.git/clone" did not exist on "55bd4fed7da83a566dca08b0bb29dbc5929a90eb"
Unverified
Commit
ec9eb28f
authored
Oct 27, 2025
by
Michael Yang
Committed by
GitHub
Oct 27, 2025
Browse files
gemma3: make embedding non-causal (#12297)
parent
5d347f6d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
16 deletions
+12
-16
model/models/gemma3/embed.go
model/models/gemma3/embed.go
+0
-6
model/models/gemma3/model_text.go
model/models/gemma3/model_text.go
+12
-10
No files found.
model/models/gemma3/embed.go
View file @
ec9eb28f
...
...
@@ -2,7 +2,6 @@ package gemma3
import
(
"github.com/ollama/ollama/fs"
"github.com/ollama/ollama/kvcache"
"github.com/ollama/ollama/ml"
"github.com/ollama/ollama/ml/nn"
"github.com/ollama/ollama/ml/nn/pooling"
...
...
@@ -53,10 +52,5 @@ func newEmbedModel(c fs.Config) (model.Model, error) {
poolingType
:
pooling
.
Type
(
c
.
Uint
(
"pooling_type"
,
0
)),
}
m
.
Cache
=
kvcache
.
NewWrapperCache
(
kvcache
.
NewSWACache
(
int32
(
c
.
Uint
(
"attention.sliding_window"
)),
m
.
Shift
),
kvcache
.
NewCausalCache
(
m
.
Shift
),
)
return
m
,
nil
}
model/models/gemma3/model_text.go
View file @
ec9eb28f
...
...
@@ -182,16 +182,18 @@ func (m *TextModel) Forward(ctx ml.Context, batch input.Batch, cache kvcache.Cac
for
i
,
layer
:=
range
m
.
Layers
{
// gemma alternates between the sliding window (local) and causal (global)
// kv cache every 6 layers
cacheType
:=
cacheTypeSWA
if
(
i
+
1
)
%
gemmaGlobalCacheCount
==
0
{
cacheType
=
cacheTypeCausal
}
cache
.
SetLayer
(
i
)
wc
:=
cache
.
(
*
kvcache
.
WrapperCache
)
wc
.
SetLayerType
(
cacheType
)
if
causal
,
ok
:=
wc
.
UnderlyingCache
()
.
(
*
kvcache
.
Causal
);
ok
{
causal
.
SetCausal
(
ctx
,
kvcache
.
CausalOptions
{
Except
:
except
})
if
cache
!=
nil
{
cacheType
:=
cacheTypeSWA
if
(
i
+
1
)
%
gemmaGlobalCacheCount
==
0
{
cacheType
=
cacheTypeCausal
}
cache
.
SetLayer
(
i
)
wc
:=
cache
.
(
*
kvcache
.
WrapperCache
)
wc
.
SetLayerType
(
cacheType
)
if
causal
,
ok
:=
wc
.
UnderlyingCache
()
.
(
*
kvcache
.
Causal
);
ok
{
causal
.
SetCausal
(
ctx
,
kvcache
.
CausalOptions
{
Except
:
except
})
}
}
var
lastLayerOutputs
ml
.
Tensor
...
...
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