2025-12-10 20:15:03 +08:00
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
|
|
|
|
|
|
2026-02-24 11:13:52 +08:00
|
|
|
|
import os
|
2025-12-10 20:15:03 +08:00
|
|
|
|
from collections.abc import Callable
|
|
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
|
|
|
|
from .utils.logging import get_connector_logger
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
from .connectors.base import OmniConnectorBase
|
|
|
|
|
|
from .utils.config import ConnectorSpec
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
# Fallback for direct execution
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
|
|
from omni_connectors.connectors.base import OmniConnectorBase
|
|
|
|
|
|
from omni_connectors.utils.config import ConnectorSpec
|
|
|
|
|
|
|
|
|
|
|
|
logger = get_connector_logger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class OmniConnectorFactory:
|
|
|
|
|
|
"""Factory for creating OmniConnectors."""
|
|
|
|
|
|
|
|
|
|
|
|
_registry: dict[str, Callable[[dict[str, Any]], OmniConnectorBase]] = {}
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def register_connector(cls, name: str, constructor: Callable[[dict[str, Any]], OmniConnectorBase]) -> None:
|
|
|
|
|
|
"""Register a connector constructor."""
|
|
|
|
|
|
if name in cls._registry:
|
|
|
|
|
|
raise ValueError(f"Connector '{name}' is already registered.")
|
|
|
|
|
|
cls._registry[name] = constructor
|
|
|
|
|
|
logger.debug(f"Registered connector: {name}")
|
|
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def create_connector(cls, spec: ConnectorSpec) -> OmniConnectorBase:
|
|
|
|
|
|
"""Create a connector from specification."""
|
|
|
|
|
|
if spec.name not in cls._registry:
|
|
|
|
|
|
raise ValueError(f"Unknown connector: {spec.name}. Available: {list(cls._registry.keys())}")
|
|
|
|
|
|
|
|
|
|
|
|
constructor = cls._registry[spec.name]
|
|
|
|
|
|
try:
|
|
|
|
|
|
connector = constructor(spec.extra)
|
|
|
|
|
|
logger.info(f"Created connector: {spec.name}")
|
|
|
|
|
|
return connector
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logger.error(f"Failed to create connector {spec.name}: {e}")
|
2026-01-22 18:09:55 +08:00
|
|
|
|
raise ValueError(f"Failed to create connector {spec.name}: {e}")
|
2025-12-10 20:15:03 +08:00
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
|
def list_registered_connectors(cls) -> list[str]:
|
|
|
|
|
|
"""List all registered connector names."""
|
|
|
|
|
|
return list(cls._registry.keys())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Register built-in connectors with lazy imports
|
2026-02-24 11:13:52 +08:00
|
|
|
|
def _create_mooncake_store_connector(config: dict[str, Any]) -> OmniConnectorBase:
|
2025-12-10 20:15:03 +08:00
|
|
|
|
try:
|
2026-02-24 11:13:52 +08:00
|
|
|
|
from .connectors.mooncake_store_connector import MooncakeStoreConnector
|
2025-12-10 20:15:03 +08:00
|
|
|
|
except ImportError:
|
|
|
|
|
|
# Fallback import
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
2026-02-24 11:13:52 +08:00
|
|
|
|
from omni_connectors.connectors.mooncake_store_connector import MooncakeStoreConnector
|
|
|
|
|
|
return MooncakeStoreConnector(config)
|
2025-12-10 20:15:03 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _create_shm_connector(config: dict[str, Any]) -> OmniConnectorBase:
|
|
|
|
|
|
try:
|
|
|
|
|
|
from .connectors.shm_connector import SharedMemoryConnector
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
# Fallback import
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
|
|
from omni_connectors.connectors.shm_connector import SharedMemoryConnector
|
|
|
|
|
|
return SharedMemoryConnector(config)
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-01-27 20:17:02 +08:00
|
|
|
|
def _create_yuanrong_connector(config: dict[str, Any]) -> OmniConnectorBase:
|
|
|
|
|
|
try:
|
|
|
|
|
|
from .connectors.yuanrong_connector import YuanrongConnector
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
|
|
from omni_connectors.connectors.yuanrong_connector import YuanrongConnector
|
|
|
|
|
|
return YuanrongConnector(config)
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-05-20 14:51:33 +08:00
|
|
|
|
def _create_yuanrong_transfer_engine_connector(config: dict[str, Any]) -> OmniConnectorBase:
|
|
|
|
|
|
try:
|
|
|
|
|
|
from vllm_omni.platforms.npu.omni_connectors import YuanrongTransferEngineConnector
|
|
|
|
|
|
except ImportError as exc:
|
|
|
|
|
|
raise ImportError(
|
|
|
|
|
|
"YuanrongTransferEngineConnector is only available in the NPU platform "
|
|
|
|
|
|
"environment. Install the Ascend/Yuanrong runtime dependencies before "
|
|
|
|
|
|
"using this connector."
|
|
|
|
|
|
) from exc
|
|
|
|
|
|
return YuanrongTransferEngineConnector(config)
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-02-24 11:13:52 +08:00
|
|
|
|
def _create_mooncake_transfer_engine_connector(config: dict[str, Any]) -> OmniConnectorBase:
|
|
|
|
|
|
try:
|
|
|
|
|
|
from .connectors.mooncake_transfer_engine_connector import MooncakeTransferEngineConnector
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
|
|
from omni_connectors.connectors.mooncake_transfer_engine_connector import MooncakeTransferEngineConnector
|
|
|
|
|
|
return MooncakeTransferEngineConnector(config)
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-06-10 08:37:33 +08:00
|
|
|
|
def _create_mori_transfer_engine_connector(config: dict[str, Any]) -> OmniConnectorBase:
|
|
|
|
|
|
try:
|
|
|
|
|
|
from .connectors.mori_transfer_engine_connector import MoriTransferEngineConnector
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
|
|
|
|
|
from omni_connectors.connectors.mori_transfer_engine_connector import MoriTransferEngineConnector
|
|
|
|
|
|
return MoriTransferEngineConnector(config)
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-12-10 20:15:03 +08:00
|
|
|
|
# Register connectors
|
2026-02-24 11:13:52 +08:00
|
|
|
|
OmniConnectorFactory.register_connector("MooncakeStoreConnector", _create_mooncake_store_connector)
|
|
|
|
|
|
OmniConnectorFactory.register_connector("MooncakeTransferEngineConnector", _create_mooncake_transfer_engine_connector)
|
2025-12-10 20:15:03 +08:00
|
|
|
|
OmniConnectorFactory.register_connector("SharedMemoryConnector", _create_shm_connector)
|
2026-01-27 20:17:02 +08:00
|
|
|
|
OmniConnectorFactory.register_connector("YuanrongConnector", _create_yuanrong_connector)
|
2026-05-20 14:51:33 +08:00
|
|
|
|
OmniConnectorFactory.register_connector("YuanrongTransferEngineConnector", _create_yuanrong_transfer_engine_connector)
|
2026-06-10 08:37:33 +08:00
|
|
|
|
OmniConnectorFactory.register_connector("MoriTransferEngineConnector", _create_mori_transfer_engine_connector)
|
2026-02-24 11:13:52 +08:00
|
|
|
|
# Backward-compatible aliases – will be removed in the future
|
|
|
|
|
|
OmniConnectorFactory.register_connector("MooncakeConnector", _create_mooncake_store_connector)
|