File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 44# LICENSE file in the root directory of this source tree.
55
66
7+ import sys
8+
79import torch
810
911from . import _ops , research , utils
3234if torch .cuda .is_available ():
3335 from .backends .cuda import ops as cuda_ops
3436
37+
38+ def _import_backends ():
39+ """
40+ Discover and autoload all available backends installed as separate packages.
41+ Packages with an entrypoint for "bitsandbytes.backends" will be loaded.
42+ Inspired by PyTorch implementation: https://pytorch.org/tutorials/prototype/python_extension_autoload.html
43+ """
44+ from importlib .metadata import entry_points
45+
46+ if sys .version_info < (3 , 10 ):
47+ extensions = entry_points ().get ("bitsandbytes.backends" , [])
48+ else :
49+ extensions = entry_points (group = "bitsandbytes.backends" )
50+
51+ for ext in extensions :
52+ try :
53+ entry = ext .load ()
54+ entry ()
55+ except Exception as e :
56+ raise RuntimeError (f"bitsandbytes: failed to load backend { ext .name } : { e } " ) from e
57+
58+
59+ _import_backends ()
60+
3561__pdoc__ = {
3662 "libbitsandbytes" : False ,
3763 "optim.optimizer.Optimizer8bit" : False ,
You can’t perform that action at this time.
0 commit comments