fusion_bench.taskpool¶
Base Class¶
BaseTaskPool
¶
Bases: BaseYAMLSerializable
Abstract base class for task pools in the FusionBench framework.
A task pool represents a collection of evaluation tasks that can be used to assess model performance across multiple benchmarks or datasets. This base class defines the common interface that all task pool implementations must follow, ensuring consistency across different task types and evaluation scenarios.
Task pools are designed to be configurable through YAML files and can be used in various model fusion and evaluation workflows. They provide a standardized way to evaluate models on multiple tasks and aggregate results.
The class inherits from BaseYAMLSerializable to support configuration management and serialization capabilities.
Attributes:
-
_program
–Optional program reference for execution context.
-
_config_key
–Configuration key used for YAML configuration ("taskpool").
Abstract Methods
evaluate: Must be implemented by subclasses to define task-specific evaluation logic.
Example
Implementing a custom task pool:
Source code in fusion_bench/taskpool/base_pool.py
7 8 9 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 |
|
evaluate(model, *args, **kwargs)
abstractmethod
¶
Evaluate a model on all tasks in the task pool and return aggregated results.
This abstract method defines the core evaluation interface that all task pool implementations must provide. It should evaluate the given model on all tasks managed by the pool and return a structured report of the results.
The evaluation process typically involves: 1. Iterating through all tasks in the pool 2. Running model inference on each task's dataset 3. Computing task-specific metrics 4. Aggregating results into a standardized report format
Parameters:
-
model
(Any
) –The model to evaluate. Can be any model type (PyTorch model, Hugging Face model, etc.) that is compatible with the specific task pool implementation.
-
*args
(Any
, default:()
) –Additional positional arguments that may be needed for task-specific evaluation procedures.
-
**kwargs
(Any
, default:{}
) –Additional keyword arguments for evaluation configuration, such as batch_size, device, evaluation metrics, etc.
Returns:
-
Dict[str, Any]
–
Example
For an image classification task pool:
Raises:
-
NotImplementedError
–This method must be implemented by subclasses.
Note
Implementations should ensure that the returned dictionary structure is consistent and that metric names are standardized across similar task types to enable meaningful comparison and aggregation.
Source code in fusion_bench/taskpool/base_pool.py
Vision Task Pool¶
NYUv2 Tasks¶
NYUv2TaskPool
¶
Bases: TaskPool
Task pool for multi-task learning evaluation on the NYUv2 dataset.
This task pool provides evaluation capabilities for multi-task learning models on the NYU Depth V2 (NYUv2) dataset, which is a popular benchmark for indoor scene understanding. The dataset supports multiple computer vision tasks including semantic segmentation, depth estimation, and surface normal prediction.
The task pool is designed to work with encoder-decoder architectures where a shared encoder processes input images and task-specific decoders generate predictions for different tasks. It integrates with PyTorch Lightning for streamlined training and evaluation workflows.
Supported Tasks
- Semantic segmentation
- Depth estimation
- Surface normal prediction
Source code in fusion_bench/taskpool/nyuv2_taskpool.py
__init__(taskpool_config)
¶
Initialize the NYUv2 task pool with configuration settings.
Parameters:
-
taskpool_config
(DictConfig
) –Configuration object containing all necessary parameters for the task pool, including: - data_dir: Path to the directory containing NYUv2 dataset - tasks: List of tasks to evaluate (e.g., ["semantic", "depth"]) - batch_size: Batch size for evaluation data loader - num_workers: Number of worker processes for data loading
Source code in fusion_bench/taskpool/nyuv2_taskpool.py
CLIP Task Pool¶
CLIPVisionModelTaskPool
¶
Bases: HydraConfigMixin
, LightningFabricMixin
, BaseTaskPool
This class is used to define the image classification task for CLIP models.
Attributes:
-
test_datasets
(Union[DictConfig, Dict[str, Dataset]]
) –The test datasets to evaluate the model on.
-
processor
(Union[DictConfig, CLIPProcessor]
) –The processor used for preprocessing the input data.
-
data_processor
(Union[DictConfig, CLIPProcessor]
) –The data processor used for processing the input data.
-
clip_model
(Union[DictConfig, CLIPModel]
) –The CLIP model used for evaluation.
-
dataloader_kwargs
(DictConfig
) –Keyword arguments for the data loader.
-
layer_wise_feature_save_path
(Optional[str]
) –Path to save the layer-wise features.
-
layer_wise_feature_first_token_only
(bool
) –Boolean indicating whether to save only the first token of the features.
-
layer_wise_feature_max_num
(Optional[int]
) –Maximum number of features to save.
-
fast_dev_run
(bool
) –Boolean indicating whether to run in fast development mode.
Source code in fusion_bench/taskpool/clip_vision/taskpool.py
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 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
|
__init__(test_datasets, *, processor, clip_model, data_processor=None, dataloader_kwargs=None, layer_wise_feature_save_path=None, layer_wise_feature_first_token_only=True, layer_wise_feature_max_num=None, fast_dev_run=None, move_to_device=True, **kwargs)
¶
Initialize the CLIPVisionModelTaskPool.
Source code in fusion_bench/taskpool/clip_vision/taskpool.py
evaluate(model, name=None, **kwargs)
¶
Evaluate the model on the image classification task.
Parameters:
-
model
(Union[CLIPVisionModel, CLIPVisionTransformer]
) –The model to evaluate.
-
name
(Optional[str]
, default:None
) –The name of the model. This will be logged into the report if not None.
Returns:
-
–
Dict[str, Any]: A dictionary containing the evaluation results for each task.
Source code in fusion_bench/taskpool/clip_vision/taskpool.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
|
on_task_evaluation_begin(classifier, task_name)
¶
Called at the beginning of task evaluation to set up hooks for saving layer-wise features.
Parameters:
-
classifier
(HFCLIPClassifier
) –The classifier being evaluated.
-
task_name
(str
) –The name of the task being evaluated.
Source code in fusion_bench/taskpool/clip_vision/taskpool.py
on_task_evaluation_end()
¶
Called at the end of task evaluation to save features and remove hooks.
Source code in fusion_bench/taskpool/clip_vision/taskpool.py
setup()
¶
Set up the processor, data processor, CLIP model, test datasets, and data loaders.
Source code in fusion_bench/taskpool/clip_vision/taskpool.py
SparseWEMoECLIPVisionModelTaskPool
¶
Bases: CLIPVisionModelTaskPool
Source code in fusion_bench/taskpool/clip_vision/clip_sparse_wemoe_taskpool.py
RankoneMoECLIPVisionModelTaskPool
¶
Bases: CLIPVisionModelTaskPool
Source code in fusion_bench/taskpool/clip_vision/clip_rankone_moe_taskpool.py
Natural Language Processing (NLP) Tasks¶
GPT-2¶
GPT2TextClassificationTaskPool
¶
Bases: BaseTaskPool
, LightningFabricMixin
A task pool for GPT2 text classification tasks. This class manages the tasks and provides methods for loading test dataset and evaluation.
Source code in fusion_bench/taskpool/gpt2_text_classification.py
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 |
|
evaluate(model, name=None)
¶
Evaluate the model on the test datasets.
Parameters:
-
model
(GPT2Model
) –The model to evaluate.
-
name
(str
, default:None
) –The name of the model. Defaults to None. This is used to identify the model in the report.
Returns:
-
dict
–A dictionary containing the evaluation results for each task.
Source code in fusion_bench/taskpool/gpt2_text_classification.py
Flan-T5¶
fusion_bench.compat.taskpool.flan_t5_glue_text_generation.FlanT5GLUETextGenerationTask
¶
Bases: BaseTask
Source code in fusion_bench/compat/taskpool/flan_t5_glue_text_generation.py
LM-Eval-Harness Integration (LLM)¶
LMEvalHarnessTaskPool
¶
Bases: BaseTaskPool
, LightningFabricMixin
A task pool implementation that interfaces with the LM Evaluation Harness framework.
This class provides a wrapper around the LM Evaluation Harness (lm-eval) library, enabling evaluation of language models on various standardized benchmarks and tasks. It inherits from BaseTaskPool and LightningFabricMixin to provide distributed computing capabilities through PyTorch Lightning Fabric.
The task pool supports evaluation on multiple tasks simultaneously and provides flexible configuration options for batch processing, output formatting, and logging. It automatically handles model setup and wrapping for distributed evaluation when using Lightning Fabric.
Parameters:
-
tasks
(Union[str, List[str]]
) –A single task name or list of task names to evaluate on. Examples: "hellaswag", ["arc_easy", "arc_challenge", "hellaswag"]
-
apply_chat_template
(bool
, default:False
) –Whether to apply chat template formatting to inputs. Useful for instruction-tuned or chat models.
-
include_path
(Optional[str]
, default:None
) –Path to additional task definitions or custom tasks.
-
batch_size
(int
, default:1
) –Number of samples to process in each batch. Larger values may improve throughput but require more memory.
-
metadata
(Optional[DictConfig]
, default:None
) –Additional metadata to include in evaluation results.
-
verbosity
(Optional[Literal['CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG']]
, default:None
) –Logging verbosity level for the evaluation process.
-
output_path
(Optional[str]
, default:None
) –Custom path for saving evaluation results. If None, results are saved to the default log directory.
-
log_samples
(bool
, default:False
) –Whether to log individual sample predictions and targets. Useful for debugging but increases output size significantly.
-
_usage_
(Optional[str]
, default:None
) –Internal usage tracking string.
-
_version_
(Optional[str]
, default:None
) –Internal version tracking string.
-
**kwargs
–Additional arguments passed to the LM Evaluation Harness.
Example
Source code in fusion_bench/taskpool/lm_eval_harness/taskpool.py
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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
evaluate(model, *command_line_args, **kwargs)
¶
Evaluate a language model on the configured tasks using LM Evaluation Harness.
This method wraps the model with the LM Evaluation Harness framework and executes evaluation on all configured tasks. It automatically handles command-line argument construction, model wrapping with Lightning Fabric for distributed evaluation, and result logging.
The evaluation process includes: 1. Building command-line arguments from instance configuration 2. Setting up the LM Evaluation Harness argument parser 3. Wrapping the model with Lightning Fabric if not already wrapped 4. Creating an HFLM (Hugging Face Language Model) wrapper 5. Executing the evaluation through the LM-Eval CLI interface
Parameters:
-
model
–The language model to evaluate. Can be a Hugging Face model, PyTorch model, or any model compatible with the LM Evaluation Harness. The model will be automatically wrapped with Lightning Fabric for distributed evaluation if not already wrapped.
-
*command_line_args
–Additional positional command-line arguments (currently unused but preserved for interface compatibility).
-
**kwargs
–Additional keyword arguments that will be converted to command-line flags and passed to the LM Evaluation Harness. Keys will be prefixed with '--' and values converted to strings.
Returns:
-
None
–Results are written to the configured output path and logged.
Example
Note
The method leverages the LM Evaluation Harness's command-line interface internally, which provides standardized evaluation procedures and ensures compatibility with the broader evaluation ecosystem.
Source code in fusion_bench/taskpool/lm_eval_harness/taskpool.py
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 |
|
Task Agnostic¶
Utility Classes¶
DummyTaskPool
¶
Bases: BaseTaskPool
A lightweight task pool implementation for debugging and development workflows.
This dummy task pool provides a minimal evaluation interface that focuses on model introspection rather than task-specific performance evaluation. It's designed for development scenarios where you need to test model fusion pipelines, validate architectures, or debug workflows without the overhead of running actual evaluation tasks.
The task pool is particularly useful when
- You want to verify model fusion works correctly
- You need to check parameter counts after fusion
- You're developing new fusion algorithms
- You want to test infrastructure without expensive evaluations
Example
Source code in fusion_bench/taskpool/dummy.py
__init__(model_save_path=None, **kwargs)
¶
Initialize the dummy task pool with optional model saving capability.
Parameters:
-
model_save_path
(Optional[str]
, default:None
) –Optional path where the evaluated model should be saved. If provided, the model will be serialized and saved to this location after evaluation using the separate_save utility. If None, no model saving will be performed.
Example
Source code in fusion_bench/taskpool/dummy.py
evaluate(model)
¶
Perform lightweight evaluation and analysis of the given model.
This method provides a minimal evaluation that focuses on model introspection rather than task-specific performance metrics. It performs parameter analysis, optionally saves the model, and returns a summary report.
The evaluation process includes: 1. Printing human-readable parameter information (rank-zero only) 2. Optionally saving the model if a save path was configured 3. Generating and returning a model summary report
Parameters:
-
model
–The model to evaluate. Can be any PyTorch nn.Module including fusion models, pre-trained models, or custom architectures.
Returns:
-
dict
–A model summary report containing parameter statistics and architecture information. See get_model_summary() for detailed format specification.