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
norm
vllm
Commits
cbf8779a
Unverified
Commit
cbf8779a
authored
Feb 24, 2023
by
Woosuk Kwon
Committed by
GitHub
Feb 24, 2023
Browse files
Fix a bug in tying OPT embeddings (#1)
parent
c84c708a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
2 deletions
+25
-2
cacheflow/models/model_utils.py
cacheflow/models/model_utils.py
+3
-2
cacheflow/models/opt.py
cacheflow/models/opt.py
+22
-0
No files found.
cacheflow/models/model_utils.py
View file @
cbf8779a
...
@@ -25,7 +25,8 @@ def get_model(
...
@@ -25,7 +25,8 @@ def get_model(
torch_dtype
=
STR_DTYPE_TO_TORCH_DTYPE
[
dtype
.
lower
()]
torch_dtype
=
STR_DTYPE_TO_TORCH_DTYPE
[
dtype
.
lower
()]
else
:
else
:
torch_dtype
=
dtype
torch_dtype
=
dtype
for
model_class
,
model
in
MODEL_CLASSES
.
items
():
for
model_class
,
hf_
model
in
MODEL_CLASSES
.
items
():
if
model_class
in
model_name
:
if
model_class
in
model_name
:
return
model
.
from_pretrained
(
model_name
,
torch_dtype
=
torch_dtype
)
model
=
hf_model
.
from_pretrained
(
model_name
,
torch_dtype
=
torch_dtype
)
return
model
.
eval
()
raise
ValueError
(
f
'Invalid model name:
{
model_name
}
'
)
raise
ValueError
(
f
'Invalid model name:
{
model_name
}
'
)
cacheflow/models/opt.py
View file @
cbf8779a
...
@@ -232,6 +232,28 @@ class OPTForCausalLM(OPTPreTrainedModel):
...
@@ -232,6 +232,28 @@ class OPTForCausalLM(OPTPreTrainedModel):
# Initialize weights and apply final processing
# Initialize weights and apply final processing
self
.
post_init
()
self
.
post_init
()
# NOTE(woosuk): While the following methods are not called in the model code,
# they may be internally used by the transformers library.
# For example, tie_weights() does not work without these methods.
# Thus, do not delete these methods.
def
get_input_embeddings
(
self
):
return
self
.
model
.
decoder
.
embed_tokens
def
set_input_embeddings
(
self
,
value
):
self
.
model
.
decoder
.
embed_tokens
=
value
def
get_output_embeddings
(
self
):
return
self
.
lm_head
def
set_output_embeddings
(
self
,
new_embeddings
):
self
.
lm_head
=
new_embeddings
def
set_decoder
(
self
,
decoder
):
self
.
model
.
decoder
=
decoder
def
get_decoder
(
self
):
return
self
.
model
.
decoder
def
forward
(
def
forward
(
self
,
self
,
input_ids
:
torch
.
LongTensor
,
input_ids
:
torch
.
LongTensor
,
...
...
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