"""tile_kernels: TileLang kernels for DeepSeek inference, plus pure-torch references. Import is lazy on purpose. `tile_kernels.torch` is a pure-torch reference implementation of every kernel here, and it has no TileLang dependency of its own -- but the eager `from . import (config, quant, ...)` below used to pull the whole compiled stack in, so on a host without TileLang even `import tile_kernels.torch` failed. Making the submodules lazy means the reference path is usable wherever torch is, which is what a bring-up on a new accelerator needs before any kernel has been ported. Everything the eager form exported is still available; it is just resolved on first access. `import tile_kernels; tile_kernels.quant.per_token_cast(...)` and `from tile_kernels.quant import per_token_cast` both behave as before. """ import importlib # Submodules that were imported eagerly before. Resolving one of these imports it. _SUBMODULES = frozenset( { "config", "utils", "engram", "mhc", "modeling", "moe", "quant", "rand", "transform", "torch", "testing", } ) # Names re-exported from .config by the eager form. _CONFIG_EXPORTS = frozenset( { "get_amax_clamp_for_quant", "get_deterministic_algorithms", "get_device_num_sms", "get_num_ai_cores", "get_num_cube_cores", "get_num_sms", "get_num_vec_cores", "get_pdl", "get_token_alignment", "get_max_smem_per_sm", "get_max_ub_per_vector_core", "set_amax_clamp_for_quant", "set_num_sms", "set_pdl", "set_token_alignment", "use_deterministic_algorithms", } ) def __getattr__(name: str): if name in _SUBMODULES: module = importlib.import_module(f".{name}", __name__) globals()[name] = module return module if name in _CONFIG_EXPORTS: value = getattr(importlib.import_module(".config", __name__), name) globals()[name] = value return value if name.startswith("__") and name.endswith("__"): raise AttributeError(name) try: version = importlib.import_module("._version", __name__) except ImportError: raise AttributeError(f"module {__name__!r} has no attribute {name!r}") from None if hasattr(version, name): value = getattr(version, name) globals()[name] = value return value raise AttributeError(f"module {__name__!r} has no attribute {name!r}") def __dir__() -> list[str]: return sorted(set(globals()) | _SUBMODULES | _CONFIG_EXPORTS)