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#
Whether |
|
The installed version of |
|
Whether |
|
Import |
Data#
API#
- core.ops._backends.logger#
‘getLogger(…)’
- core.ops._backends.is_available(module: str) bool#
Whether
modulehas 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_specmay 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,
The installed version of
module, orNonewhen it cannot be determined.Prefers
module.__version__so source checkouts without distribution metadata still report a version, then falls back toimportlib.metadataunderdist(defaults to the top-level module name). EveryNoneis 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,
Whether
moduleis installed atmin_versionor 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,
Import
moduleand check it providessymbols(dotted names allowed).symbolsis 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. ARuntimeErrororOSErrorraised 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.