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
554e7ada
Unverified
Commit
554e7ada
authored
Feb 28, 2024
by
jiqing-feng
Committed by
GitHub
Feb 28, 2024
Browse files
check if position_ids exists before using it (#29306)
Co-authored-by:
Joao Gante
<
joao@huggingface.co
>
parent
d3a4b475
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
4 deletions
+8
-4
src/transformers/models/gemma/modeling_gemma.py
src/transformers/models/gemma/modeling_gemma.py
+4
-2
src/transformers/models/llama/modeling_llama.py
src/transformers/models/llama/modeling_llama.py
+4
-2
No files found.
src/transformers/models/gemma/modeling_gemma.py
View file @
554e7ada
...
@@ -1168,7 +1168,9 @@ class GemmaForCausalLM(GemmaPreTrainedModel):
...
@@ -1168,7 +1168,9 @@ class GemmaForCausalLM(GemmaPreTrainedModel):
# TODO @gante we should only keep a `cache_position` in generate, and do +=1.
# TODO @gante we should only keep a `cache_position` in generate, and do +=1.
# same goes for position ids. Could also help with continued generation.
# same goes for position ids. Could also help with continued generation.
cache_position
=
torch
.
arange
(
past_length
,
past_length
+
position_ids
.
shape
[
-
1
],
device
=
position_ids
.
device
)
input_length
=
position_ids
.
shape
[
-
1
]
if
position_ids
is
not
None
else
input_ids
.
shape
[
-
1
]
cache_position
=
torch
.
arange
(
past_length
,
past_length
+
input_length
,
device
=
input_ids
.
device
)
position_ids
=
position_ids
.
contiguous
()
if
position_ids
is
not
None
else
None
# if `inputs_embeds` are passed, we only want to use them in the 1st generation step
# if `inputs_embeds` are passed, we only want to use them in the 1st generation step
if
inputs_embeds
is
not
None
and
past_key_values
is
None
:
if
inputs_embeds
is
not
None
and
past_key_values
is
None
:
...
@@ -1181,7 +1183,7 @@ class GemmaForCausalLM(GemmaPreTrainedModel):
...
@@ -1181,7 +1183,7 @@ class GemmaForCausalLM(GemmaPreTrainedModel):
model_inputs
.
update
(
model_inputs
.
update
(
{
{
"position_ids"
:
position_ids
.
contiguous
()
,
"position_ids"
:
position_ids
,
"cache_position"
:
cache_position
,
"cache_position"
:
cache_position
,
"past_key_values"
:
past_key_values
,
"past_key_values"
:
past_key_values
,
"use_cache"
:
kwargs
.
get
(
"use_cache"
),
"use_cache"
:
kwargs
.
get
(
"use_cache"
),
...
...
src/transformers/models/llama/modeling_llama.py
View file @
554e7ada
...
@@ -1284,7 +1284,9 @@ class LlamaForCausalLM(LlamaPreTrainedModel):
...
@@ -1284,7 +1284,9 @@ class LlamaForCausalLM(LlamaPreTrainedModel):
# TODO @gante we should only keep a `cache_position` in generate, and do +=1.
# TODO @gante we should only keep a `cache_position` in generate, and do +=1.
# same goes for position ids. Could also help with continued generation.
# same goes for position ids. Could also help with continued generation.
cache_position
=
torch
.
arange
(
past_length
,
past_length
+
position_ids
.
shape
[
-
1
],
device
=
position_ids
.
device
)
input_length
=
position_ids
.
shape
[
-
1
]
if
position_ids
is
not
None
else
input_ids
.
shape
[
-
1
]
cache_position
=
torch
.
arange
(
past_length
,
past_length
+
input_length
,
device
=
input_ids
.
device
)
position_ids
=
position_ids
.
contiguous
()
if
position_ids
is
not
None
else
None
# if `inputs_embeds` are passed, we only want to use them in the 1st generation step
# if `inputs_embeds` are passed, we only want to use them in the 1st generation step
if
inputs_embeds
is
not
None
and
past_key_values
is
None
:
if
inputs_embeds
is
not
None
and
past_key_values
is
None
:
...
@@ -1297,7 +1299,7 @@ class LlamaForCausalLM(LlamaPreTrainedModel):
...
@@ -1297,7 +1299,7 @@ class LlamaForCausalLM(LlamaPreTrainedModel):
model_inputs
.
update
(
model_inputs
.
update
(
{
{
"position_ids"
:
position_ids
.
contiguous
()
,
"position_ids"
:
position_ids
,
"cache_position"
:
cache_position
,
"cache_position"
:
cache_position
,
"past_key_values"
:
past_key_values
,
"past_key_values"
:
past_key_values
,
"use_cache"
:
kwargs
.
get
(
"use_cache"
),
"use_cache"
:
kwargs
.
get
(
"use_cache"
),
...
...
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