# Backends A backend bundles the pattern lists that drive each pipeline stage. When `transform()` is called without an explicit `patterns` argument, the active backend supplies the conversion and fusion patterns automatically. The quantization pipeline similarly reads the backend's `quantized_patterns` and `smooth_patterns`. ## Built-in backends | Backend | Package | Patterns | |---------|---------|----------| | `"tensorrt"` | `embedl_deploy._internal.tensorrt` | Full set: conversions, fusions, smooth, quantized. Ships as `embedl-deploy-tensorrt`. | | `"lattice"` | `embedl_deploy._internal.lattice` | Conversions (fusions, smooth, quantized TBA). Ships as `embedl-deploy-lattice`. | ## Selecting a backend ```python from embedl_deploy.backend import set_backend set_backend("tensorrt") ``` After this call, `transform(model, (example_input,))` uses the TensorRT conversion and fusion patterns — equivalent to passing `patterns=TENSORRT_PATTERNS` explicitly. If only one backend is installed, `get_backend()` auto-selects it. With multiple backends installed you must call `set_backend()` before any pipeline function that relies on implicit pattern selection. ## API reference ```python from embedl_deploy.backend import ( Backend, discover_backends, get_backend, reset_backends, set_backend, ) ``` ### set_backend(name) Select the active backend by name. Raises `ValueError` if the name does not match any discovered backend. ### get_backend() Return the active `Backend`. If none has been set, auto-discovers backends and selects the only one found. Raises `RuntimeError` when zero or multiple backends are installed without an explicit `set_backend()` call. ### discover_backends() Scan for installed backend packages and return a list of `Backend` instances. Results are cached after the first call. ### reset_backends() Clear the cached discovery results and deselect the active backend. Useful in test suites to isolate backend state between tests. ### Backend ```python @dataclass(frozen=True) class Backend: name: str conversion_patterns: Sequence[type[Pattern]] = () fusion_patterns: Sequence[type[Pattern]] = () smooth_patterns: Sequence[type[Pattern]] = () quantized_patterns: Sequence[type[Pattern]] = () ``` Each field holds pattern classes for the corresponding pipeline stage. Validation in `__post_init__` ensures every pattern's `phase` matches the field it is assigned to.