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
ox696c
ktransformers
Commits
ecc01cda
You need to sign in or sign up before continuing.
Commit
ecc01cda
authored
May 14, 2025
by
qiyuxinlin
Browse files
update norm cpu kernel
parent
64742bec
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
0 deletions
+31
-0
ktransformers/operators/layernorm.py
ktransformers/operators/layernorm.py
+31
-0
No files found.
ktransformers/operators/layernorm.py
View file @
ecc01cda
...
...
@@ -163,3 +163,34 @@ class KQwen3MoeRMSNorm(Qwen3MoeRMSNorm, BaseInjectedModule):
variance
=
hidden_states
.
pow
(
2
).
mean
(
-
1
,
keepdim
=
True
)
hidden_states
=
hidden_states
*
torch
.
rsqrt
(
variance
+
self
.
variance_epsilon
)
return
self
.
weight
*
hidden_states
.
to
(
input_dtype
)
class
DeepseekV3RMSNormTorch
(
DeepseekV3RMSNorm
,
BaseInjectedModule
):
def
__init__
(
self
,
key
:
str
,
gguf_loader
:
GGUFLoader
,
config
:
PretrainedConfig
,
orig_module
:
nn
.
Module
,
prefill_device
:
str
=
"cuda"
,
generate_device
:
str
=
"cuda"
,
**
kwargs
):
BaseInjectedModule
.
__init__
(
self
,
key
,
gguf_loader
,
config
,
orig_module
,
prefill_device
,
**
kwargs
)
self
.
orig_module
.
__init__
(
orig_module
.
hidden_size
,
orig_module
.
variance_epsilon
)
def
forward
(
self
,
x
,
batch_size_tensor
:
torch
.
Tensor
=
None
,
residual
:
Optional
[
torch
.
Tensor
]
=
None
,
)
->
Union
[
torch
.
Tensor
,
Tuple
[
torch
.
Tensor
,
torch
.
Tensor
]]:
if
residual
is
not
None
:
x
=
x
+
residual
residual
=
x
# range batch_size_tensor for x
input_dtype
=
x
.
dtype
x
=
x
.
to
(
torch
.
float32
)
variance
=
x
.
pow
(
2
).
mean
(
-
1
,
keepdim
=
True
)
x
=
x
*
torch
.
rsqrt
(
variance
+
self
.
variance_epsilon
)
if
residual
is
not
None
:
return
self
.
weight
*
x
.
to
(
input_dtype
),
residual
return
self
.
weight
*
x
.
to
(
input_dtype
)
\ No newline at end of file
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