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
0540fef7
Unverified
Commit
0540fef7
authored
Mar 12, 2025
by
JieXin Liang
Committed by
GitHub
Mar 12, 2025
Browse files
[Fix] fix _yarn_linear_ramp_mask with device parameter (#4337)
parent
481f608b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
3 deletions
+5
-3
python/sglang/srt/layers/rotary_embedding.py
python/sglang/srt/layers/rotary_embedding.py
+5
-3
No files found.
python/sglang/srt/layers/rotary_embedding.py
View file @
0540fef7
...
@@ -403,12 +403,12 @@ def _yarn_find_correction_range(
...
@@ -403,12 +403,12 @@ def _yarn_find_correction_range(
def
_yarn_linear_ramp_mask
(
def
_yarn_linear_ramp_mask
(
low
:
float
,
high
:
float
,
dim
:
int
,
dtype
:
torch
.
dtype
low
:
float
,
high
:
float
,
dim
:
int
,
dtype
:
torch
.
dtype
,
device
:
torch
.
device
=
None
)
->
torch
.
Tensor
:
)
->
torch
.
Tensor
:
if
low
==
high
:
if
low
==
high
:
high
+=
0.001
# Prevent singularity
high
+=
0.001
# Prevent singularity
linear_func
=
(
torch
.
arange
(
dim
,
dtype
=
dtype
)
-
low
)
/
(
high
-
low
)
linear_func
=
(
torch
.
arange
(
dim
,
dtype
=
dtype
,
device
=
device
)
-
low
)
/
(
high
-
low
)
ramp_func
=
torch
.
clamp
(
linear_func
,
0
,
1
)
ramp_func
=
torch
.
clamp
(
linear_func
,
0
,
1
)
return
ramp_func
return
ramp_func
...
@@ -688,7 +688,9 @@ class DeepseekScalingRotaryEmbedding(RotaryEmbedding):
...
@@ -688,7 +688,9 @@ class DeepseekScalingRotaryEmbedding(RotaryEmbedding):
# Get n-d rotational scaling corrected for extrapolation
# Get n-d rotational scaling corrected for extrapolation
inv_freq_mask
=
(
inv_freq_mask
=
(
1
1
-
_yarn_linear_ramp_mask
(
low
,
high
,
self
.
rotary_dim
//
2
,
dtype
=
torch
.
float
)
-
_yarn_linear_ramp_mask
(
low
,
high
,
self
.
rotary_dim
//
2
,
dtype
=
torch
.
float
,
device
=
self
.
device
)
)
*
self
.
extrapolation_factor
)
*
self
.
extrapolation_factor
inv_freq
=
(
inv_freq
=
(
inv_freq_interpolation
*
(
1
-
inv_freq_mask
)
inv_freq_interpolation
*
(
1
-
inv_freq_mask
)
...
...
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