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
change
sglang
Commits
681e7af3
Unverified
Commit
681e7af3
authored
May 24, 2025
by
Chang Su
Committed by
GitHub
May 24, 2025
Browse files
[OAI] Support non-normalized logprobs in OpenAI server (#5961)
parent
681fdc26
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
9 deletions
+4
-9
python/sglang/srt/layers/sampler.py
python/sglang/srt/layers/sampler.py
+4
-9
No files found.
python/sglang/srt/layers/sampler.py
View file @
681e7af3
...
...
@@ -86,11 +86,9 @@ class Sampler(nn.Module):
# NOTE: the top_p_renorm_prob from flashinfer has numerical problems,
# https://github.com/flashinfer-ai/flashinfer/issues/708
# so we use the torch implementation.
# clamp to avoid -inf
logprobs
=
torch
.
log
(
top_p_normalize_probs_torch
(
probs
,
sampling_info
.
top_ps
)
).
clamp
(
min
=
torch
.
finfo
(
probs
.
dtype
).
min
)
# NOTE: OpenAI's logprobs is independent of top-p, we use the
# same rule.
logprobs
=
torch
.
log
(
probs
).
clamp
(
min
=
torch
.
finfo
(
probs
.
dtype
).
min
)
max_top_k_round
,
batch_size
=
32
,
probs
.
shape
[
0
]
if
sampling_info
.
need_min_p_sampling
:
...
...
@@ -121,10 +119,7 @@ class Sampler(nn.Module):
)
if
return_logprob
:
# clamp to avoid -inf
logprobs
=
torch
.
log
(
top_p_normalize_probs_torch
(
probs
,
sampling_info
.
top_ps
)
).
clamp
(
min
=
torch
.
finfo
(
probs
.
dtype
).
min
)
logprobs
=
torch
.
log
(
probs
).
clamp
(
min
=
torch
.
finfo
(
probs
.
dtype
).
min
)
else
:
raise
ValueError
(
f
"Invalid sampling backend:
{
global_server_args_dict
[
'sampling_backend'
]
}
"
...
...
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