[Kernel][Helion] Helion kernel lazy registration (#48264)
Signed-off-by: Sean Chen <seachen@redhat.com>
This commit is contained in:
@@ -37,6 +37,7 @@ try:
|
||||
get_kernel_by_name,
|
||||
get_registered_kernels,
|
||||
)
|
||||
from vllm.kernels.helion.ops import import_all_kernels
|
||||
from vllm.kernels.helion.utils import get_canonical_gpu_name
|
||||
from vllm.logger import init_logger
|
||||
from vllm.utils.import_utils import has_helion
|
||||
@@ -382,6 +383,9 @@ def main():
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# import all helion kernels
|
||||
import_all_kernels()
|
||||
|
||||
import logging
|
||||
|
||||
if args.verbose:
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Helion integration for vLLM."""
|
||||
|
||||
import vllm.kernels.helion.ops # noqa: F401 Auto-register all Helion ops
|
||||
from vllm.kernels.helion.case_key import CaseKey
|
||||
from vllm.kernels.helion.config_manager import (
|
||||
ConfigManager,
|
||||
|
||||
@@ -1,11 +1,33 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Auto-import all Helion op modules to trigger kernel registration."""
|
||||
"""Helion kernel implementation.
|
||||
|
||||
Importing this package does NOT register any kernels. Runtime code imports the
|
||||
specific op module it needs, e.g.::
|
||||
|
||||
from vllm.kernels.helion.ops import scaled_mm # noqa: F401
|
||||
|
||||
which triggers that op's ``@register_kernel`` as an import side effect.
|
||||
|
||||
Tools that need the full registry (e.g. scripts/autotune_helion_kernels.py)
|
||||
call ``import_all_ops()`` to force every op module to register.
|
||||
"""
|
||||
|
||||
import importlib
|
||||
import pkgutil
|
||||
|
||||
# Automatically import all submodules so that @register_kernel
|
||||
# decorators execute and register ops with torch.ops.vllm_helion.
|
||||
for _module_info in pkgutil.iter_modules(__path__):
|
||||
importlib.import_module(f"{__name__}.{_module_info.name}")
|
||||
|
||||
def import_all_kernels() -> list[str]:
|
||||
"""Import every kernel submodule so all ``@register_kernel`` decorators run.
|
||||
|
||||
Returns:
|
||||
The fully-qualified module names that were imported.
|
||||
"""
|
||||
imported: list[str] = []
|
||||
for module_info in pkgutil.iter_modules(__path__):
|
||||
if module_info.ispkg:
|
||||
continue
|
||||
module_name = f"{__name__}.{module_info.name}"
|
||||
importlib.import_module(module_name)
|
||||
imported.append(module_name)
|
||||
return imported
|
||||
|
||||
Reference in New Issue
Block a user