core.ops._backends#

Construction-time checks for the optional libraries an operation family binds.

require imports a module, verifies that the exports the caller is about to use exist and are not None, optionally checks a minimum version, and hands the module back. It is called from __init__ (or from a family selector that __init__ calls), never from forward: an operation binds its kernels once and then calls them directly.

This module keeps no state. There is no registry, inventory or cached availability table; each family’s backends.py says, in code next to the import, exactly what it needs.

Module Contents#

Functions#

is_available

Whether module has an import spec.

installed_version

The installed version of module, or None when it cannot be determined.

has_min_version

Whether module is installed at min_version or newer. Unknown versions are False.

require

Import module and check it provides symbols (dotted names allowed).

Data#

API#

core.ops._backends.logger#

‘getLogger(…)’

core.ops._backends.is_available(module: str) → bool#

Whether module has an import spec.

Use this to record a capability once at construction (self._packed_cp = ...) when the input that needs it – packed sequences, say – is only known at execution. For a dotted name, find_spec may import its parent package. Probe a top-level package when parent-import side effects must be avoided.

core.ops._backends.installed_version(
module: str,
dist: str | None = None,
) → packaging.version.Version | None#

The installed version of module, or None when it cannot be determined.

Prefers module.__version__ so source checkouts without distribution metadata still report a version, then falls back to importlib.metadata under dist (defaults to the top-level module name). Every None is logged with its reason: callers treat an unknown version as “requirement not met”, which is safe but should not be silent.

core.ops._backends.has_min_version(
module: str,
min_version: str,
dist: str | None = None,
) → bool#

Whether module is installed at min_version or newer. Unknown versions are False.

core.ops._backends.require(
module: str,
*symbols: str,
min_version: str | None = None,
dist: str | None = None,
needed_by: str,
) → types.ModuleType#

Import module and check it provides symbols (dotted names allowed).

symbols is variadic so the common call reads as a sentence, require("fla.ops.foo", "chunk_foo", needed_by="Foo recurrence"), and stays a one-liner when several exports are needed. Everything after it is keyword-only, so a version string or a distribution name can never be mistaken for a symbol.

Raises ImportError – the one exception type every family uses for a missing or broken optional library – with a message that names the operation asking for it. A RuntimeError or OSError raised while the library loads (a native extension built against another CUDA or Torch, for instance) is reported the same way, with the original error chained.