Discover and autoload all available backends installed as separate packages. Packages with an entrypoint for "bitsandbytes.backends" will be loaded. Inspired by PyTorch implementation: https://pytorch.org/tutorials/prototype/python_extension_autoload.html
()
| 50 | |
| 51 | |
| 52 | def _import_backends(): |
| 53 | """ |
| 54 | Discover and autoload all available backends installed as separate packages. |
| 55 | Packages with an entrypoint for "bitsandbytes.backends" will be loaded. |
| 56 | Inspired by PyTorch implementation: https://pytorch.org/tutorials/prototype/python_extension_autoload.html |
| 57 | """ |
| 58 | from importlib.metadata import entry_points |
| 59 | |
| 60 | extensions = entry_points(group="bitsandbytes.backends") |
| 61 | |
| 62 | for ext in extensions: |
| 63 | try: |
| 64 | entry = ext.load() |
| 65 | entry() |
| 66 | except Exception as e: |
| 67 | raise RuntimeError(f"bitsandbytes: failed to load backend {ext.name}: {e}") from e |
| 68 | |
| 69 | |
| 70 | _import_backends() |