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
OpenDAS
text-generation-inference
Commits
4f6d038c
Commit
4f6d038c
authored
May 11, 2023
by
OlivierDehaene
Browse files
fix(server): fix multinomial implem in Sampling
parent
a6c18c39
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
3 deletions
+3
-3
server/text_generation_server/utils/tokens.py
server/text_generation_server/utils/tokens.py
+3
-3
No files found.
server/text_generation_server/utils/tokens.py
View file @
4f6d038c
...
@@ -25,10 +25,10 @@ class Sampling:
...
@@ -25,10 +25,10 @@ class Sampling:
def
__call__
(
self
,
logits
):
def
__call__
(
self
,
logits
):
probs
=
torch
.
nn
.
functional
.
softmax
(
logits
,
-
1
)
probs
=
torch
.
nn
.
functional
.
softmax
(
logits
,
-
1
)
# Avoid GPU<->CPU sync done by torch multinomial
# See: https://github.com/pytorch/pytorch/blob/925a3788ec5c06db62ca732a0e9425a26a00916f/aten/src/ATen/native/Distributions.cpp#L631-L637
# See: https://github.com/pytorch/pytorch/blob/925a3788ec5c06db62ca732a0e9425a26a00916f/aten/src/ATen/native/Distributions.cpp#L631-L637
q
=
torch
.
empty_like
(
probs
).
exponential_
(
1
,
generator
=
self
.
generator
).
div_
(
probs
)
q
=
torch
.
empty_like
(
probs
).
exponential_
(
1
,
generator
=
self
.
generator
)
return
probs
.
div_
(
q
).
argmax
()
return
q
.
argmax
()
class
Greedy
:
class
Greedy
:
...
...
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