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
530ae1bd
"...git@developer.sourcefind.cn:OpenDAS/detectron2.git" did not exist on "63e10e00f1d690f134342ea32fbe0af1645ccb0b"
Unverified
Commit
530ae1bd
authored
Nov 11, 2024
by
Lianmin Zheng
Committed by
GitHub
Nov 11, 2024
Browse files
Fix weight loading for tied word embedding when TP > 1 (#2009)
parent
befc6beb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
6 deletions
+11
-6
python/sglang/srt/models/llama.py
python/sglang/srt/models/llama.py
+11
-6
No files found.
python/sglang/srt/models/llama.py
View file @
530ae1bd
...
@@ -380,6 +380,12 @@ class LlamaForCausalLM(nn.Module):
...
@@ -380,6 +380,12 @@ class LlamaForCausalLM(nn.Module):
]
]
params_dict
=
dict
(
self
.
named_parameters
())
params_dict
=
dict
(
self
.
named_parameters
())
load_tie_word_embeddings
=
(
hasattr
(
self
.
config
,
"tie_word_embeddings"
)
and
self
.
config
.
tie_word_embeddings
and
"lm_head.weight"
in
params_dict
)
for
name
,
loaded_weight
in
weights
:
for
name
,
loaded_weight
in
weights
:
if
"rotary_emb.inv_freq"
in
name
or
"projector"
in
name
:
if
"rotary_emb.inv_freq"
in
name
or
"projector"
in
name
:
continue
continue
...
@@ -412,15 +418,14 @@ class LlamaForCausalLM(nn.Module):
...
@@ -412,15 +418,14 @@ class LlamaForCausalLM(nn.Module):
weight_loader
=
getattr
(
param
,
"weight_loader"
,
default_weight_loader
)
weight_loader
=
getattr
(
param
,
"weight_loader"
,
default_weight_loader
)
weight_loader
(
param
,
loaded_weight
)
weight_loader
(
param
,
loaded_weight
)
if
(
if
load_tie_word_embeddings
and
name
==
"model.embed_tokens.weight"
:
hasattr
(
self
.
config
,
"tie_word_embeddings"
)
embed_tokens_weight
=
loaded_weight
and
self
.
config
.
tie_word_embeddings
and
"lm_head.weight"
in
params_dict
if
load_tie_word_embeddings
:
):
# Tie output embedding layer to input embedding layer, to solve issues where lm_head.weight is missing
# Tie output embedding layer to input embedding layer, to solve issues where lm_head.weight is missing
param
=
self
.
lm_head
.
weight
param
=
self
.
lm_head
.
weight
weight_loader
=
getattr
(
param
,
"weight_loader"
,
default_weight_loader
)
weight_loader
=
getattr
(
param
,
"weight_loader"
,
default_weight_loader
)
weight_loader
(
param
,
self
.
model
.
embed_tokens
.
weight
)
weight_loader
(
param
,
embed_tokens
_
weight
)
apply_torchao_config_
(
self
,
params_dict
,
set
([
"proj.weight"
]))
apply_torchao_config_
(
self
,
params_dict
,
set
([
"proj.weight"
]))
...
...
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