fusion_bench.program¶
Class Definitions¶
- fusion_bench.programs.BaseHydraProgram: Base class for Hydra-based programs in FusionBench.
- fusion_bench.programs.FabricModelFusionProgram: A program for fusing models using Lightning Fabric.
References¶
BaseHydraProgram
¶
Bases: BaseYAMLSerializableModel
Abstract base class for all FusionBench programs that use Hydra configuration.
This class serves as the foundation for all FusionBench execution programs, providing a standardized interface for configuration-driven model fusion workflows. It combines the serialization capabilities of BaseYAMLSerializableModel with the requirement for a main execution method.
The class is designed to work seamlessly with Hydra's configuration management system, allowing programs to be instantiated and configured through YAML files. This enables flexible, reproducible experiments with different fusion algorithms, model pools, and evaluation tasks.
Key Features:
- Configuration-driven execution through Hydra integration
- YAML serialization support for experiment reproducibility
- Abstract interface ensuring consistent program structure
- Integration with FusionBench's modular architecture
Typical Usage
Subclasses should implement the run()
method to define their specific
fusion workflow. The program can then be executed through the FusionBench
CLI or instantiated directly from configuration files.
Example
class MyFusionProgram(BaseHydraProgram):
def __init__(self, method_config, modelpool_config, taskpool_config):
self.method_config = method_config
self.modelpool_config = modelpool_config
self.taskpool_config = taskpool_config
def run(self):
# Load components
algorithm = load_algorithm(self.method_config)
modelpool = load_modelpool(self.modelpool_config)
taskpool = load_taskpool(self.taskpool_config)
# Execute fusion
merged_model = algorithm.run(modelpool)
# Evaluate results
report = taskpool.evaluate(merged_model)
return report
Note
This is an abstract base class and cannot be instantiated directly.
Subclasses must implement the run()
method to provide concrete
functionality.
See Also:
- FabricModelFusionProgram: Lightning Fabric-based implementation
- BaseYAMLSerializableModel: Parent class providing serialization
- FusionBench CLI documentation for program execution details
Source code in fusion_bench/programs/base_program.py
run()
abstractmethod
¶
Execute the main program workflow.
This abstract method defines the primary entry point for program execution. Subclasses must implement this method to define their specific fusion workflow, including model loading, fusion algorithm execution, and result evaluation.
Source code in fusion_bench/programs/base_program.py
FabricModelFusionProgram
¶
Bases: LightningFabricMixin
, BaseHydraProgram
Source code in fusion_bench/programs/fabric_fusion_program.py
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
evaluate_merged_model(taskpool, merged_model, *args, **kwargs)
¶
Evaluates the merged model using the provided task pool.
Depending on the type of the merged model, this function handles the evaluation differently:
- If the merged model is an instance of nn.Module
, it directly evaluates the model.
- If the merged model is a dictionary, it extracts the model from the dictionary and evaluates it.
The evaluation report is then updated with the remaining dictionary items.
- If the merged model is an iterable, it recursively evaluates each model in the iterable.
- Raises a ValueError
if the merged model is of an invalid type.
Parameters:
-
taskpool
(BaseTaskPool
) –The task pool used for evaluating the merged model.
-
merged_model
(Union[Module, Dict, Iterable]
) –The merged model to be evaluated. It can be an instance of
nn.Module
, a dictionary, or an iterable. -
*args
–Additional positional arguments to be passed to the
evaluate
method of the taskpool. -
**kwargs
–Additional keyword arguments to be passed to the
evaluate
method of the taskpool.
Returns:
-
–
The evaluation report. The type of the report depends on the type of the merged model:
-
–
- If the merged model is an instance of
nn.Module
, the report is a dictionary.
- If the merged model is an instance of
-
–
- If the merged model is a dictionary, the report is a dictionary updated with the remaining dictionary items.
-
–
- If the merged model is an iterable, the report is a list of evaluation reports.
Source code in fusion_bench/programs/fabric_fusion_program.py
run()
¶
Executes the model fusion program.
Source code in fusion_bench/programs/fabric_fusion_program.py
save_merged_model(merged_model)
¶
Saves the merged model to the specified path.