Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
19d98e0c
Unverified
Commit
19d98e0c
authored
Mar 03, 2025
by
Michael Goin
Committed by
GitHub
Mar 03, 2025
Browse files
[Kernel] Optimize moe intermediate_cache usage (#13625)
Signed-off-by:
mgoin
<
mgoin64@gmail.com
>
parent
2b04c209
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
6 deletions
+11
-6
vllm/model_executor/layers/fused_moe/fused_moe.py
vllm/model_executor/layers/fused_moe/fused_moe.py
+11
-6
No files found.
vllm/model_executor/layers/fused_moe/fused_moe.py
View file @
19d98e0c
...
@@ -1240,15 +1240,20 @@ def fused_experts_impl(hidden_states: torch.Tensor,
...
@@ -1240,15 +1240,20 @@ def fused_experts_impl(hidden_states: torch.Tensor,
config
=
get_config_func
(
M
)
config
=
get_config_func
(
M
)
intermediate_cache1
=
torch
.
empty
((
M
,
top_k_num
,
N
),
# We can reuse the memory between these because by the time we need
device
=
hidden_states
.
device
,
# cache3, we're done with cache1
dtype
=
hidden_states
.
dtype
)
cache13
=
torch
.
empty
(
M
*
top_k_num
*
max
(
N
,
w2
.
shape
[
1
]),
device
=
hidden_states
.
device
,
dtype
=
hidden_states
.
dtype
)
intermediate_cache1
=
cache13
[:
M
*
top_k_num
*
N
].
view
(
(
M
,
topk_ids
.
shape
[
1
],
N
))
intermediate_cache3
=
cache13
[:
M
*
top_k_num
*
w2
.
shape
[
1
]].
view
(
(
M
,
topk_ids
.
shape
[
1
],
w2
.
shape
[
1
]))
# This needs separate memory since it's used concurrently with cache1
intermediate_cache2
=
torch
.
empty
((
M
*
top_k_num
,
N
//
2
),
intermediate_cache2
=
torch
.
empty
((
M
*
top_k_num
,
N
//
2
),
device
=
hidden_states
.
device
,
device
=
hidden_states
.
device
,
dtype
=
hidden_states
.
dtype
)
dtype
=
hidden_states
.
dtype
)
intermediate_cache3
=
torch
.
empty
((
M
,
top_k_num
,
w2
.
shape
[
1
]),
device
=
hidden_states
.
device
,
dtype
=
hidden_states
.
dtype
)
if
hidden_states
.
dtype
==
torch
.
bfloat16
:
if
hidden_states
.
dtype
==
torch
.
bfloat16
:
compute_type
=
tl
.
bfloat16
compute_type
=
tl
.
bfloat16
...
...
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