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
d4796653
Unverified
Commit
d4796653
authored
Mar 12, 2024
by
Joao Gante
Committed by
GitHub
Mar 12, 2024
Browse files
Examples: check `max_position_embeddings` in the translation example (#29600)
check max_position_embeddings
parent
6b660d5e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
0 deletions
+13
-0
examples/pytorch/translation/run_translation.py
examples/pytorch/translation/run_translation.py
+13
-0
No files found.
examples/pytorch/translation/run_translation.py
View file @
d4796653
...
@@ -469,6 +469,19 @@ def main():
...
@@ -469,6 +469,19 @@ def main():
source_lang
=
data_args
.
source_lang
.
split
(
"_"
)[
0
]
source_lang
=
data_args
.
source_lang
.
split
(
"_"
)[
0
]
target_lang
=
data_args
.
target_lang
.
split
(
"_"
)[
0
]
target_lang
=
data_args
.
target_lang
.
split
(
"_"
)[
0
]
# Check the whether the source target length fits in the model, if it has absolute positional embeddings
if
(
hasattr
(
model
.
config
,
"max_position_embeddings"
)
and
not
hasattr
(
model
.
config
,
"relative_attention_max_distance"
)
and
model
.
config
.
max_position_embeddings
<
data_args
.
max_source_length
):
raise
ValueError
(
f
"`--max_source_length` is set to
{
data_args
.
max_source_length
}
, but the model only has"
f
"
{
model
.
config
.
max_position_embeddings
}
position encodings. Consider either reducing"
f
" `--max_source_length` to
{
model
.
config
.
max_position_embeddings
}
or using a model with larger position "
"embeddings"
)
# Temporarily set max_target_length for training.
# Temporarily set max_target_length for training.
max_target_length
=
data_args
.
max_target_length
max_target_length
=
data_args
.
max_target_length
padding
=
"max_length"
if
data_args
.
pad_to_max_length
else
False
padding
=
"max_length"
if
data_args
.
pad_to_max_length
else
False
...
...
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