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
dba39b2e
Unverified
Commit
dba39b2e
authored
Sep 19, 2025
by
Patrick Devine
Committed by
GitHub
Sep 19, 2025
Browse files
gemma: fix rope scaling for qat models (#12348)
* gemma: fix rope scaling for qat models * gofumpt yourself
parent
9f3a37fd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
3 deletions
+6
-3
model/models/gemma2/model.go
model/models/gemma2/model.go
+1
-1
model/models/gemma3/model_text.go
model/models/gemma3/model_text.go
+5
-2
No files found.
model/models/gemma2/model.go
View file @
dba39b2e
...
...
@@ -128,7 +128,7 @@ func (sa *SelfAttention) Forward(ctx ml.Context, hiddenState, positionIDs ml.Ten
}
func
(
m
*
Model
)
Shift
(
ctx
ml
.
Context
,
layer
int
,
key
,
shift
ml
.
Tensor
)
(
ml
.
Tensor
,
error
)
{
return
fast
.
RoPE
(
ctx
,
key
,
shift
,
m
.
Options
.
attnKeyLen
,
m
.
Options
.
ropeBase
,
m
.
Options
.
ropeScale
,
rope
.
WithTypeNeoX
()),
nil
return
fast
.
RoPE
(
ctx
,
key
,
shift
,
m
.
Options
.
attnKeyLen
,
m
.
Options
.
ropeBase
,
1
/
m
.
Options
.
ropeScale
,
rope
.
WithTypeNeoX
()),
nil
}
type
MLP
struct
{
...
...
model/models/gemma3/model_text.go
View file @
dba39b2e
...
...
@@ -53,7 +53,10 @@ func newTextModel(c fs.Config) *TextModel {
eps
:
c
.
Float
(
"attention.layer_norm_rms_epsilon"
,
1e-06
),
ropeLocalBase
:
c
.
Float
(
"rope.local.freq_base"
,
10000.0
),
ropeGlobalBase
:
c
.
Float
(
"rope.global.freq_base"
,
1000000.0
),
ropeScale
:
c
.
Float
(
"rope.scaling.factor"
,
1.0
),
ropeScale
:
1
,
// NOTE: the rope.scaling.factor is set incorrectly in the official QAT weights
// (8 instead of 1)
// ropeScale: c.Float("rope.scaling.factor", 1.0),
},
}
...
...
@@ -113,7 +116,7 @@ func (m *TextModel) Shift(ctx ml.Context, layer int, key, shift ml.Tensor) (ml.T
ropeBase
=
m
.
TextConfig
.
ropeGlobalBase
}
return
fast
.
RoPE
(
ctx
,
key
,
shift
,
m
.
TextConfig
.
attnKeyLen
,
ropeBase
,
m
.
TextConfig
.
ropeScale
,
rope
.
WithTypeNeoX
()),
nil
return
fast
.
RoPE
(
ctx
,
key
,
shift
,
m
.
TextConfig
.
attnKeyLen
,
ropeBase
,
1
/
m
.
TextConfig
.
ropeScale
,
rope
.
WithTypeNeoX
()),
nil
}
type
TextMLP
struct
{
...
...
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