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
norm
vllm
Commits
a90c97d7
Unverified
Commit
a90c97d7
authored
Mar 31, 2023
by
Woosuk Kwon
Committed by
GitHub
Mar 31, 2023
Browse files
Use FP32 for log probabilities (#19)
parent
e3f00d19
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
1 deletion
+2
-1
cacheflow/models/sample.py
cacheflow/models/sample.py
+2
-1
No files found.
cacheflow/models/sample.py
View file @
a90c97d7
...
@@ -36,10 +36,11 @@ class Sampler(nn.Module):
...
@@ -36,10 +36,11 @@ class Sampler(nn.Module):
# Use in-place division to avoid creating a new tensor.
# Use in-place division to avoid creating a new tensor.
logits
.
div_
(
t
.
unsqueeze
(
dim
=
1
))
logits
.
div_
(
t
.
unsqueeze
(
dim
=
1
))
# We use float32 for probabilities and log probabilities.
# Compute the probabilities.
# Compute the probabilities.
probs
=
torch
.
softmax
(
logits
,
dim
=-
1
,
dtype
=
torch
.
float
)
probs
=
torch
.
softmax
(
logits
,
dim
=-
1
,
dtype
=
torch
.
float
)
# Compute the log probabilities (before applying top-p).
# Compute the log probabilities (before applying top-p).
logprobs
=
torch
.
log
(
probs
,
out
=
logits
)
logprobs
=
torch
.
log
(
probs
)
# Apply top-p truncation.
# Apply top-p truncation.
top_ps
=
_get_top_ps
(
input_metadata
)
top_ps
=
_get_top_ps
(
input_metadata
)
...
...
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