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
change
sglang
Commits
f414352a
Unverified
Commit
f414352a
authored
Aug 30, 2024
by
Ke Bao
Committed by
GitHub
Aug 30, 2024
Browse files
Transpose mla weight offline (#1261)
Co-authored-by:
Yineng Zhang
<
me@zhyncs.com
>
parent
a362340b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
7 deletions
+13
-7
python/sglang/srt/models/deepseek_v2.py
python/sglang/srt/models/deepseek_v2.py
+13
-7
No files found.
python/sglang/srt/models/deepseek_v2.py
View file @
f414352a
...
...
@@ -417,12 +417,8 @@ class DeepseekV2AttentionMLA(nn.Module):
v_head_dim
=
self
.
kv_lora_rank
,
)
kv_b_proj
=
self
.
kv_b_proj
w_kc
,
w_vc
=
kv_b_proj
.
weight
.
unflatten
(
0
,
(
-
1
,
qk_nope_head_dim
+
v_head_dim
)
).
split
([
qk_nope_head_dim
,
v_head_dim
],
dim
=
1
)
self
.
w_kc
=
w_kc
self
.
w_vc
=
w_vc
self
.
w_kc
=
None
self
.
w_vc
=
None
def
forward
(
self
,
...
...
@@ -464,7 +460,7 @@ class DeepseekV2AttentionMLA(nn.Module):
)
torch
.
bmm
(
attn_output
.
transpose
(
0
,
1
),
self
.
w_vc
.
transpose
(
1
,
2
).
contiguous
()
,
self
.
w_vc
,
out
=
attn_bmm_output
.
transpose
(
0
,
1
),
)
...
...
@@ -715,5 +711,15 @@ class DeepseekV2ForCausalLM(nn.Module):
)
weight_loader
(
param
,
loaded_weight
)
if
global_server_args_dict
[
"enable_mla"
]:
for
layer_id
in
range
(
self
.
config
.
num_hidden_layers
):
self_attn
=
self
.
model
.
layers
[
layer_id
].
self_attn
w_kc
,
w_vc
=
self_attn
.
kv_b_proj
.
weight
.
unflatten
(
0
,
(
-
1
,
self_attn
.
qk_nope_head_dim
+
self_attn
.
v_head_dim
)
).
split
([
self_attn
.
qk_nope_head_dim
,
self_attn
.
v_head_dim
],
dim
=
1
)
self_attn
.
w_kc
=
w_kc
.
contiguous
()
self_attn
.
w_vc
=
w_vc
.
transpose
(
1
,
2
).
contiguous
()
del
self_attn
.
kv_b_proj
EntryClass
=
DeepseekV2ForCausalLM
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