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
c9f6e5e3
Unverified
Commit
c9f6e5e3
authored
Apr 01, 2024
by
Joao Gante
Committed by
GitHub
Apr 01, 2024
Browse files
Generate: move misplaced test (#29902)
parent
e4f5b57a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
11 deletions
+13
-11
tests/generation/test_utils.py
tests/generation/test_utils.py
+13
-11
No files found.
tests/generation/test_utils.py
View file @
c9f6e5e3
...
...
@@ -1467,17 +1467,6 @@ class GenerationTesterMixin:
past_kv
[
i
][
1
].
shape
,
(
batch_size
,
num_attention_heads
,
seq_length
,
per_head_embed_dim
)
)
def
test_generate_from_inputs_embeds_with_bos_token_id_is_none
(
self
):
article
=
"Today a dragon flew over Paris."
model
=
AutoModelForCausalLM
.
from_pretrained
(
"hf-internal-testing/tiny-random-gpt2"
).
to
(
torch_device
)
tokenizer
=
AutoTokenizer
.
from_pretrained
(
"hf-internal-testing/tiny-random-gpt2"
)
input_ids
=
tokenizer
(
article
,
return_tensors
=
"pt"
).
input_ids
.
to
(
torch_device
)
inputs_embeds
=
model
.
get_input_embeddings
()(
input_ids
)
model
.
generate
(
inputs_embeds
=
inputs_embeds
,
max_length
=
20
,
bos_token_id
=
None
)
with
self
.
assertRaises
(
ValueError
):
model
.
generate
(
max_length
=
20
,
bos_token_id
=
None
)
def
test_generate_from_inputs_embeds_decoder_only
(
self
):
# When supported, tests that the decoder model can generate from `inputs_embeds` instead of `input_ids`
# if fails, you should probably update the `prepare_inputs_for_generation` function
...
...
@@ -2817,3 +2806,16 @@ class GenerationIntegrationTests(unittest.TestCase, GenerationIntegrationTestsMi
self
.
assertTrue
(
y_prob
>
0.001
and
n_prob
>
0.001
)
self
.
assertTrue
(
y_prob
<=
1.0
and
n_prob
<=
1.0
)
def
test_generate_from_inputs_embeds_with_bos_token_id_is_none
(
self
):
article
=
"Today a dragon flew over Paris."
model
=
AutoModelForCausalLM
.
from_pretrained
(
"hf-internal-testing/tiny-random-gpt2"
).
to
(
torch_device
)
tokenizer
=
AutoTokenizer
.
from_pretrained
(
"hf-internal-testing/tiny-random-gpt2"
)
input_ids
=
tokenizer
(
article
,
return_tensors
=
"pt"
).
input_ids
.
to
(
torch_device
)
inputs_embeds
=
model
.
get_input_embeddings
()(
input_ids
)
model
.
generate
(
inputs_embeds
=
inputs_embeds
,
max_length
=
20
,
bos_token_id
=
None
)
# bos_token_id is required when no input ids nor inputs_embeds is passed
with
self
.
assertRaises
(
ValueError
):
model
.
generate
(
max_length
=
20
,
bos_token_id
=
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