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
c3e9d506
Unverified
Commit
c3e9d506
authored
May 07, 2025
by
Isotr0py
Committed by
GitHub
May 07, 2025
Browse files
[Misc] Use `apply_rotary_emb` from vllm_flash_attn for Qwen2-VL vision RoPE (#17726)
Signed-off-by:
Isotr0py
<
2037008807@qq.com
>
parent
822de7fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
12 deletions
+6
-12
vllm/model_executor/models/qwen2_5_vl.py
vllm/model_executor/models/qwen2_5_vl.py
+2
-7
vllm/model_executor/models/qwen2_vl.py
vllm/model_executor/models/qwen2_vl.py
+4
-5
No files found.
vllm/model_executor/models/qwen2_5_vl.py
View file @
c3e9d506
...
@@ -297,13 +297,8 @@ class Qwen2_5_VisionAttention(nn.Module):
...
@@ -297,13 +297,8 @@ class Qwen2_5_VisionAttention(nn.Module):
q
,
k
,
v
=
(
rearrange
(
x
,
"s b ... -> b s ..."
).
contiguous
()
q
,
k
,
v
=
(
rearrange
(
x
,
"s b ... -> b s ..."
).
contiguous
()
for
x
in
(
q
,
k
,
v
))
for
x
in
(
q
,
k
,
v
))
if
rotary_pos_emb
is
not
None
:
if
rotary_pos_emb
is
not
None
:
use_flash_attn
=
self
.
attn_backend
==
_Backend
.
FLASH_ATTN
q
=
apply_rotary_pos_emb_vision
(
q
,
rotary_pos_emb
)
q
=
apply_rotary_pos_emb_vision
(
q
,
k
=
apply_rotary_pos_emb_vision
(
k
,
rotary_pos_emb
)
rotary_pos_emb
,
use_flash_attn
=
use_flash_attn
)
k
=
apply_rotary_pos_emb_vision
(
k
,
rotary_pos_emb
,
use_flash_attn
=
use_flash_attn
)
if
self
.
attn_backend
==
_Backend
.
FLASH_ATTN
:
if
self
.
attn_backend
==
_Backend
.
FLASH_ATTN
:
# from vllm_flash_attn.flash_attn_interface import (
# from vllm_flash_attn.flash_attn_interface import (
...
...
vllm/model_executor/models/qwen2_vl.py
View file @
c3e9d506
...
@@ -64,7 +64,7 @@ from vllm.multimodal.processing import (BaseMultiModalProcessor,
...
@@ -64,7 +64,7 @@ from vllm.multimodal.processing import (BaseMultiModalProcessor,
BaseProcessingInfo
,
PromptReplacement
,
BaseProcessingInfo
,
PromptReplacement
,
PromptUpdate
)
PromptUpdate
)
from
vllm.multimodal.profiling
import
BaseDummyInputsBuilder
from
vllm.multimodal.profiling
import
BaseDummyInputsBuilder
from
vllm.platforms
import
_Backend
from
vllm.platforms
import
_Backend
,
current_platform
from
vllm.sequence
import
IntermediateTensors
from
vllm.sequence
import
IntermediateTensors
from
vllm.transformers_utils.config
import
uses_mrope
from
vllm.transformers_utils.config
import
uses_mrope
from
vllm.transformers_utils.processor
import
(
from
vllm.transformers_utils.processor
import
(
...
@@ -230,14 +230,13 @@ def apply_rotary_emb_torch(x: torch.Tensor,
...
@@ -230,14 +230,13 @@ def apply_rotary_emb_torch(x: torch.Tensor,
def
apply_rotary_pos_emb_vision
(
t
:
torch
.
Tensor
,
def
apply_rotary_pos_emb_vision
(
t
:
torch
.
Tensor
,
freqs
:
torch
.
Tensor
,
freqs
:
torch
.
Tensor
)
->
torch
.
Tensor
:
use_flash_attn
=
False
)
->
torch
.
Tensor
:
t_
=
t
.
float
()
t_
=
t
.
float
()
cos
=
freqs
.
cos
()
cos
=
freqs
.
cos
()
sin
=
freqs
.
sin
()
sin
=
freqs
.
sin
()
apply_rotary_emb
=
apply_rotary_emb_torch
apply_rotary_emb
=
apply_rotary_emb_torch
if
use_flash_attn
:
if
current_platform
.
is_cuda
()
:
from
flash_attn.layers.rotary
import
apply_rotary_emb
from
vllm.vllm_
flash_attn.layers.rotary
import
apply_rotary_emb
output
=
apply_rotary_emb
(
t_
,
cos
,
sin
).
type_as
(
t
)
output
=
apply_rotary_emb
(
t_
,
cos
,
sin
).
type_as
(
t
)
return
output
return
output
...
...
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