[Perf] torch compile for dit and rope kernel (#317)

Signed-off-by: zjy0516 <riverclouds.zhu@qq.com>
This commit is contained in:
Jiangyun Zhu authored and GitHub committed 2025-12-19 03:16:20 +00:00
1 parent d6310e2ea9
commit 5216cf4ae6
5 files changed
+164 -76

No files matched your search

+38
View File
@@ -0,0 +1,38 @@
from collections.abc import Callable
from typing import Any
import torch.nn as nn
from vllm_omni.utils.platform_utils import detect_device_type
class CustomOp(nn.Module):
"""
Base class for custom ops.
Dispatches the forward method to the appropriate backend.
"""
def __init__(self) -> None:
super().__init__()
self.is_cuda = detect_device_type() == "cuda"
self._forward_method = self.dispatch_forward()
def dispatch_forward(self) -> Callable:
if self.is_cuda:
return self.forward_cuda
else:
return self.forward_native
def forward(self, *args, **kwargs) -> Any:
return self._forward_method(*args, **kwargs)
def forward_native(self, *args, **kwargs):
"""PyTorch-native implementation of the forward method.
This method is optional. If implemented, it can be used with compilers
such as torch.compile or PyTorch XLA. Also, it can be used for testing
purposes.
"""
raise NotImplementedError
def forward_cuda(self, *args, **kwargs):
raise NotImplementedError