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
4a63bc32
Unverified
Commit
4a63bc32
authored
Mar 30, 2025
by
Baizhou Zhang
Committed by
GitHub
Mar 30, 2025
Browse files
[Fix] Add torch compile for torch.clamp back (#4936)
parent
a303325f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
1 deletion
+7
-1
python/sglang/srt/model_executor/forward_batch_info.py
python/sglang/srt/model_executor/forward_batch_info.py
+7
-1
No files found.
python/sglang/srt/model_executor/forward_batch_info.py
View file @
4a63bc32
...
...
@@ -39,6 +39,7 @@ import triton
import
triton.language
as
tl
from
sglang.srt.layers.rotary_embedding
import
MRotaryEmbedding
from
sglang.srt.utils
import
get_compiler_backend
if
TYPE_CHECKING
:
from
sglang.srt.layers.attention.base_attn_backend
import
AttentionBackend
...
...
@@ -299,7 +300,7 @@ class ForwardBatch:
# Init position information
if
ret
.
forward_mode
.
is_decode
():
if
ret
.
positions
is
None
:
ret
.
positions
=
torch
.
clamp
(
(
batch
.
seq_lens
-
1
),
min
=
0
).
to
(
torch
.
int64
)
ret
.
positions
=
clamp_position
(
batch
.
seq_lens
)
else
:
ret
.
extend_seq_lens
=
torch
.
tensor
(
batch
.
extend_seq_lens
,
dtype
=
torch
.
int32
...
...
@@ -519,3 +520,8 @@ def compute_position_torch(
extend_start_loc
=
torch
.
zeros_like
(
extend_seq_lens
)
extend_start_loc
[
1
:]
=
torch
.
cumsum
(
extend_seq_lens
[:
-
1
],
dim
=
0
)
return
positions
.
to
(
torch
.
int64
),
extend_start_loc
@
torch
.
compile
(
dynamic
=
True
,
backend
=
get_compiler_backend
())
def
clamp_position
(
seq_lens
):
return
torch
.
clamp
((
seq_lens
-
1
),
min
=
0
).
to
(
torch
.
int64
)
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