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
chenpangpang
transformers
Commits
948ffff4
Unverified
Commit
948ffff4
authored
Jan 19, 2024
by
Joao Gante
Committed by
GitHub
Jan 19, 2024
Browse files
RWKV: raise informative exception when attempting to manipulate `past_key_values` (#28600)
parent
9efec114
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
0 deletions
+18
-0
src/transformers/models/rwkv/modeling_rwkv.py
src/transformers/models/rwkv/modeling_rwkv.py
+18
-0
No files found.
src/transformers/models/rwkv/modeling_rwkv.py
View file @
948ffff4
...
...
@@ -778,6 +778,24 @@ class RwkvForCausalLM(RwkvPreTrainedModel):
def
set_output_embeddings
(
self
,
new_embeddings
):
self
.
head
=
new_embeddings
def
generate
(
self
,
*
args
,
**
kwargs
):
# Thin wrapper to raise exceptions when trying to generate with methods that manipulate `past_key_values`.
# RWKV is one of the few models that don't have it (it has `state` instead, which has different properties and
# usage).
try
:
gen_output
=
super
().
generate
(
*
args
,
**
kwargs
)
except
AttributeError
as
exc
:
# Expected exception: "AttributeError: '(object name)' object has no attribute 'past_key_values'"
if
"past_key_values"
in
str
(
exc
):
raise
AttributeError
(
"You tried to call `generate` with a decoding strategy that manipulates `past_key_values`. RWKV "
"doesn't have that attribute, try another generation strategy instead. For the available "
"generation strategies, check this doc: https://huggingface.co/docs/transformers/en/generation_strategies#decoding-strategies"
)
else
:
raise
exc
return
gen_output
def
prepare_inputs_for_generation
(
self
,
input_ids
,
state
=
None
,
inputs_embeds
=
None
,
**
kwargs
):
# only last token for inputs_ids if the state is passed along.
if
state
is
not
None
:
...
...
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