npu fused op (#7386)
Co-authored-by: Li Junwen <lijunwen13@hisilicon.com>
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
from torch import nn
|
||||
|
||||
from sglang.srt.utils import cpu_has_amx_support, is_cpu, is_cuda, is_hip
|
||||
from sglang.srt.utils import cpu_has_amx_support, is_cpu, is_cuda, is_hip, is_npu
|
||||
|
||||
_is_cuda = is_cuda()
|
||||
_is_hip = is_hip()
|
||||
_is_cpu = is_cpu()
|
||||
_is_cpu_amx_available = cpu_has_amx_support()
|
||||
_is_npu = is_npu()
|
||||
|
||||
|
||||
class CustomOp(nn.Module):
|
||||
@@ -60,6 +61,9 @@ class CustomOp(nn.Module):
|
||||
def forward_cuda(self, *args, **kwargs):
|
||||
raise NotImplementedError
|
||||
|
||||
def forward_npu(self, *args, **kwargs):
|
||||
raise NotImplementedError
|
||||
|
||||
def forward_hip(self, *args, **kwargs):
|
||||
return self.forward_cuda(*args, **kwargs)
|
||||
|
||||
@@ -79,5 +83,7 @@ class CustomOp(nn.Module):
|
||||
return self.forward_hip
|
||||
elif _is_cpu and _is_cpu_amx_available:
|
||||
return self.forward_cpu
|
||||
elif _is_npu:
|
||||
return self.forward_npu
|
||||
else:
|
||||
return self.forward_native
|
||||
|
||||
Reference in New Issue
Block a user