Package Management¶
fusion_bench.utils.packages
¶
compare_versions(v1, v2)
¶
Compare two version strings. Returns -1 if v1 < v2, 0 if v1 == v2, 1 if v1 > v2
Source code in fusion_bench/utils/packages.py
import_object(abs_obj_name)
¶
Imports a class from a module given the absolute class name.
Parameters:
-
abs_obj_name
(str
) βThe absolute name of the object to import.
Returns:
-
Any
βThe imported class.
Source code in fusion_bench/utils/packages.py
fusion_bench.utils.lazy_imports
¶
Lazy-Imports module.
This is code taken from the HuggingFace team <https://huggingface.co/>
.
Many thanks to HuggingFace for
your consent <https://github.com/huggingface/transformers/issues/12861#issuecomment-886712209>
to publish it as a standalone package.
LazyImporter
¶
Bases: ModuleType
Lazy importer for modules and their components.
This class allows for lazy importing of modules, meaning modules are only imported when they are actually accessed. This can help reduce startup time and memory usage for large packages with many optional dependencies.
Attributes:
-
_modules
(Set[str]
) βSet of module names available for import.
-
_class_to_module
(Dict[str, str]
) βMapping from class/function names to their module names.
-
_objects
(Dict[str, Any]
) βDictionary of extra objects to include in the module.
-
_name
βName of the module.
-
_import_structure
βDictionary mapping module names to lists of their exports.
Source code in fusion_bench/utils/lazy_imports.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
__dir__()
¶
Return list of available attributes for autocompletion.
Returns:
-
List[str]
βList of all available attribute names.
__getattr__(name)
¶
Get attribute lazily, importing the module if necessary.
Parameters:
-
name
(str
) βThe name of the attribute to retrieve.
Returns:
-
Any
βThe requested attribute.
Raises:
-
AttributeError
βIf the attribute is not found in any module.
Source code in fusion_bench/utils/lazy_imports.py
__init__(name, module_file, import_structure, extra_objects=None)
¶
Initialize the LazyImporter.
Parameters:
-
name
(str
) βThe name of the module.
-
module_file
(str
) βPath to the module file.
-
import_structure
(Dict[str, List[str]]
) βDictionary mapping module names to lists of their exports.
-
extra_objects
(Optional[Dict[str, Any]]
, default:None
) βOptional dictionary of extra objects to include.
Source code in fusion_bench/utils/lazy_imports.py
__reduce__()
¶
Support for pickling the LazyImporter.
Returns:
-
tuple
βTuple containing the class and arguments needed to reconstruct the object.
Source code in fusion_bench/utils/lazy_imports.py
LazyPyModule
¶
Bases: ModuleType
Module wrapper for lazy import.
Adapted from Optuna: https://github.com/optuna/optuna/blob/1f92d496b0c4656645384e31539e4ee74992ff55/optuna/init.py
This class wraps specified module and lazily import it when they are actually accessed. This can help reduce startup time and memory usage by deferring module imports until they are needed.
Parameters:
-
name
(str
) βName of module to apply lazy import.
Attributes:
-
_name
(str
) βThe name of the module to be lazily imported.
Source code in fusion_bench/utils/lazy_imports.py
__getattr__(item)
¶
Get attribute from the lazily loaded module.
Parameters:
-
item
(str
) βThe name of the attribute to retrieve.
Returns:
-
Any
βThe requested attribute from the loaded module.
Source code in fusion_bench/utils/lazy_imports.py
__init__(name)
¶
Initialize the LazyPyModule.
Parameters:
-
name
(str
) βThe name of the module to be lazily imported.