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
0a365c3e
Unverified
Commit
0a365c3e
authored
Aug 24, 2023
by
Joao Gante
Committed by
GitHub
Aug 24, 2023
Browse files
Generate: nudge towards `do_sample=False` when `temperature=0.0` (#25722)
parent
584eeb53
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
1 deletion
+7
-1
src/transformers/generation/logits_process.py
src/transformers/generation/logits_process.py
+7
-1
No files found.
src/transformers/generation/logits_process.py
View file @
0a365c3e
...
@@ -266,7 +266,13 @@ class TemperatureLogitsWarper(LogitsWarper):
...
@@ -266,7 +266,13 @@ class TemperatureLogitsWarper(LogitsWarper):
def
__init__
(
self
,
temperature
:
float
):
def
__init__
(
self
,
temperature
:
float
):
if
not
isinstance
(
temperature
,
float
)
or
not
(
temperature
>
0
):
if
not
isinstance
(
temperature
,
float
)
or
not
(
temperature
>
0
):
raise
ValueError
(
f
"`temperature` has to be a strictly positive float, but is
{
temperature
}
"
)
except_msg
=
(
f
"`temperature` (=
{
temperature
}
) has to be a strictly positive float, otherwise your next token "
"scores will be invalid."
)
if
isinstance
(
temperature
,
float
)
and
temperature
==
0.0
:
except_msg
+=
" If you're looking for greedy decoding strategies, set `do_sample=False`."
raise
ValueError
(
except_msg
)
self
.
temperature
=
temperature
self
.
temperature
=
temperature
...
...
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