[ROCm] [CI] Add ROCm Dockerfile and AMD CI (vllm v0.12.0) (#280)
Signed-off-by: tjtanaa <tunjian.tan@embeddedllm.com> Co-authored-by: Hongxia Yang <hongxia.yang@amd.com>
This commit is contained in:
1 parent
85bc8bfa6a
commit
13584fd98e
19 files changed
+948
-14
No files matched your search
@@ -3,7 +3,7 @@ from typing import Any
|
||||
|
||||
import torch.nn as nn
|
||||
|
||||
from vllm_omni.utils.platform_utils import detect_device_type
|
||||
from vllm_omni.utils.platform_utils import detect_device_type, is_rocm
|
||||
|
||||
|
||||
class CustomOp(nn.Module):
|
||||
@@ -18,7 +18,9 @@ class CustomOp(nn.Module):
|
||||
self._forward_method = self.dispatch_forward()
|
||||
|
||||
def dispatch_forward(self) -> Callable:
|
||||
if self.is_cuda:
|
||||
if is_rocm():
|
||||
return self.forward_hip
|
||||
elif self.is_cuda:
|
||||
return self.forward_cuda
|
||||
else:
|
||||
return self.forward_native
|
||||
@@ -36,3 +38,7 @@ class CustomOp(nn.Module):
|
||||
|
||||
def forward_cuda(self, *args, **kwargs):
|
||||
raise NotImplementedError
|
||||
|
||||
def forward_hip(self, *args, **kwargs):
|
||||
# By default, we assume that HIP ops are compatible with CUDA ops.
|
||||
return self.forward_cuda(*args, **kwargs)
|
||||
@@ -1,8 +1,13 @@
|
||||
from importlib.util import find_spec
|
||||
|
||||
import torch
|
||||
from einops import rearrange, repeat
|
||||
from vllm.logger import init_logger
|
||||
|
||||
from vllm_omni.diffusion.layers.custom_op import CustomOp
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
def rotate_half(x, interleaved=False):
|
||||
if not interleaved:
|
||||
@@ -45,6 +50,11 @@ class RotaryEmbedding(CustomOp):
|
||||
super().__init__()
|
||||
self.is_neox_style = is_neox_style
|
||||
self.interleaved = not is_neox_style
|
||||
self.apply_rotary_emb_flash_attn = None
|
||||
if find_spec("flash_attn") is not None:
|
||||
from flash_attn.ops.triton.rotary import apply_rotary
|
||||
|
||||
self.apply_rotary_emb_flash_attn = apply_rotary
|
||||
|
||||
def forward_cuda(
|
||||
self,
|
||||
@@ -66,6 +76,27 @@ class RotaryEmbedding(CustomOp):
|
||||
interleaved=self.interleaved,
|
||||
)
|
||||
|
||||
def forward_hip(
|
||||
self,
|
||||
x: torch.Tensor,
|
||||
cos: torch.Tensor,
|
||||
sin: torch.Tensor,
|
||||
) -> torch.Tensor:
|
||||
if self.apply_rotary_emb_flash_attn is None:
|
||||
return self.forward_cuda(x, cos, sin)
|
||||
|
||||
if cos.dim() == 3:
|
||||
# (B, S, D/2) -> (S, D/2)
|
||||
cos = cos[0]
|
||||
sin = sin[0]
|
||||
|
||||
return self.apply_rotary_emb_flash_attn(
|
||||
x,
|
||||
cos,
|
||||
sin,
|
||||
interleaved=self.interleaved,
|
||||
)
|
||||
|
||||
def forward_native(
|
||||
self,
|
||||
x: torch.Tensor,
|
||||
|
||||
Reference in new issue
Block a user