llmcompressor.modifiers.factory
ModifierFactory
A factory for loading and registering modifiers
Source code in src/llmcompressor/modifiers/factory.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 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 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
create(type_, allow_registered, allow_experimental, **kwargs)
staticmethod
Instantiate a modifier of the given type from registered modifiers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_ | str | The type of modifier to create | required |
framework | The framework the modifier is for | required | |
allow_registered | bool | Whether or not to allow registered modifiers | required |
allow_experimental | bool | Whether or not to allow experimental modifiers | required |
kwargs | Additional keyword arguments to pass to the modifier during instantiation | {} |
Returns:
Type | Description |
---|---|
Modifier | The instantiated modifier |
Raises:
Type | Description |
---|---|
ValueError | If no modifier of the given type is found |
Source code in src/llmcompressor/modifiers/factory.py
load_from_package(package_path)
staticmethod
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package_path | str | The path to the package to load modifiers from | required |
Returns:
Type | Description |
---|---|
Dict[str, Type[Modifier]] | The loaded modifiers, as a mapping of name to class |
Source code in src/llmcompressor/modifiers/factory.py
refresh()
staticmethod
A method to refresh the factory by reloading the modifiers Note: this will clear any previously registered modifiers
Source code in src/llmcompressor/modifiers/factory.py
register(type_, modifier_class)
staticmethod
Register a modifier class to be used by the factory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_ | str | The type of modifier to register | required |
modifier_class | Type[Modifier] | The class of the modifier to register, must subclass the Modifier base class | required |
Raises:
Type | Description |
---|---|
ValueError | If the provided class does not subclass the Modifier base class or is not a type |