( repo_id: str revision: str | None = None version: int | None = None backend: str | None = None user_agent: str | dict | None = None trust_remote_code: bool | list[str] = False ) → ModuleType
Parameters
False,
only kernels from trusted organisations are allowed. When True, all
repositories are allowed. A list of strings will be used to verify signing
identities in a future release; for now it emits a warning and falls
back to the default trust check. Returns
ModuleType
The imported kernel module.
Load a kernel from the kernel hub.
This function downloads a kernel to the local Hugging Face Hub cache directory (if it was not downloaded before) and then loads the kernel.
( repo_path: Path backend: str | None = None ) → ModuleType
Import a kernel from a local kernel repository path.
( repo_id: str revision: str | None = None version: int | None = None backend: str | None = None ) → bool
Parameters
str) —
The Hub repository containing the kernel. str, optional) —
The specific revision (branch, tag, or commit) to download. Cannot be used together with version. int, optional) —
The kernel version to download. Cannot be used together with revision.
Either version or revision must be specified. str, optional) —
The backend to load the kernel for. Can only be cpu or the backend that Torch is compiled for.
The backend will be detected automatically if not provided. Returns
bool
True if a kernel is available for the current environment.
Check whether a kernel build exists for the current environment (Torch version and compute framework).
( repo_id: str revision: str | None = None version: int | None = None backend: str | None = None ) → list[Decision]
Parameters
str) —
The Hub repository containing the kernel. str, optional) —
The specific revision (branch, tag, or commit) to inspect. Cannot be used together with version. int, optional) —
The kernel version to inspect. Cannot be used together with revision.
Either version or revision must be specified. str, optional) —
The backend to resolve variants for. Can only be cpu or the backend that Torch is compiled for.
The backend will be detected automatically if not provided. Returns
list[Decision]
One VariantAccepted or VariantRejected per build variant
in the repository, compatible variants first.
Resolve all build variants of a kernel against the current environment.
The decisions are sorted with compatible variants first, the most preferred variant leading.
( ) → list[LoadedKernel]
Returns
list[LoadedKernel]
One LoadedKernel per distinct kernel variant path loaded in this process.
Return a snapshot of every kernel that has been loaded into the current process.
The returned list is a new list; mutating it does not affect the registry.
( repo_id: str lockfile: pathlib.Path | None backend: str | None = None revision: str | None = None ) → ModuleType
Parameters
str) —
The Hub repository containing the kernel. Path, optional) —
Path to the lockfile. If not provided, the lockfile will be loaded from the caller’s package metadata. str, optional) —
The backend to load the kernel for. Can only be cpu or the backend that Torch is compiled for.
The backend will be detected automatically if not provided. str, optional) —
The specific revision (branch, tag, or commit) to download. Cannot be used together with version. Returns
ModuleType
The imported kernel module.
Get a pre-downloaded, locked kernel.
If lockfile is not specified, the lockfile will be loaded from the caller’s package metadata.
( repo_id: str local_files_only: bool = False ) → ModuleType
Get a kernel using a lock file.
( metadata: Metadata module: module repo_info: kernels.utils.RepoInfo | None )
This dataclass provides information about a loaded kernel:
metadata (Metadata): kernel metadata.module (ModuleType): the imported kernel module.repo_info (kernels.utils.RepoInfo | None): populated only for
kernels loaded via get_kernel. Loaders that work from a local path
(get_local_kernel) or a lockfile (get_locked_kernel, load_kernel)
leave this as None.The metadata includes the following properties that describe a kernel:
id (str): kernel identifier that is unique to the kernel version + backend.name (str): the name of the kernel.version (int): the version of the kernel.license (str): the license of the kernel.upstream (str | None): the upstream repository of the kernel.python_depends (list[str]): required Python dependencies.backend: information about the kernel’s backend.This dataclass stores the origin of the kernel.
The following fields are available:
repo_id (str): the Hub repository containing the kernel.revision (str): the specific revision of the kernel.