Utility Classes¶
Debugging Purpose¶
- DummyAlgorithm: A dummy algorithm for testing purposes.
DummyAlgorithm
¶
Bases: BaseAlgorithm
Source code in fusion_bench/method/dummy.py
run(modelpool)
¶
This method returns the pretrained model from the model pool. If the pretrained model is not available, it returns the first model from the model pool.
Parameters:
-
modelpool
(BaseModelPool
) –The pool of models to fuse.
Raises:
-
AssertionError
–If the model is not found in the model pool.
Source code in fusion_bench/method/dummy.py
Analysis Purpose¶
- TaskVectorCosSimilarity: Computes the cosine similarity between task vectors.
- TaskVectorViolinPlot: Generates a violin plot for task vector distributions.
TaskVectorCosSimilarity
¶
Bases: BaseAlgorithm
, LightningFabricMixin
This class is similar to the Dummy algorithm, but it also print (or save) the cosine similarity matrix between the task vectors of the models in the model pool.
Source code in fusion_bench/method/analysis/task_vector_cos_similarity.py
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 167 168 169 170 171 172 |
|
TaskVectorViolinPlot
¶
Bases: BaseAlgorithm
, LightningFabricMixin
, SimpleProfilerMixin
Plot violin plots of task vectors as in: L.Shen, A.Tang, E.Yang et al. Efficient and Effective Weight-Ensembling Mixture of Experts for Multi-Task Model Merging
Source code in fusion_bench/method/analysis/task_vector_violin_plot.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 |
|
__init__(trainable_only, max_points_per_model=1000, fig_kwawrgs=None, output_path=None, **kwargs)
¶
This class creates violin plots to visualize task vectors, which represent the differences between fine-tuned models and their pretrained base model.
Parameters:
-
trainable_only
(bool
) –If True, only consider trainable parameters when computing task vectors. If False, use all parameters.
-
fig_kwargs
(dict
) –Dictionary of keyword arguments to pass to
matplotlib.pyplot.subplots
. Common options include: - figsize: Tuple of (width, height) in inches - dpi: Dots per inch - facecolor: Figure background color Defaults to None. -
output_path
(str
, default:None
) –Path where the violin plot will be saved. If None, uses the fabric logger's log directory. Defaults to None.
-
kwargs
–Additional keyword arguments passed to the parent class(es).
Example:
```python
plotter = TaskVectorViolinPlot(
trainable_only=True,
fig_kwargs={'figsize': (10, 6), 'dpi': 300},
output_path='./plots'
)
plotter.run(modelpool)
```
Source code in fusion_bench/method/analysis/task_vector_violin_plot.py
run(modelpool)
¶
Create violin plots of task vectors comparing different fine-tuned models against a pretrained model.
This method implements the visualization technique from the paper "Efficient and Effective Weight-Ensembling Mixture of Experts for Multi-Task Model Merging". It:
- Loads the pretrained model
- Computes task vectors (differences between fine-tuned and pretrained models)
- Creates violin plots showing the distribution of values in these task vectors
Parameters:
-
modelpool
(BaseModelPool
) –Model pool containing the pretrained model and fine-tuned models
Returns:
-
pretrained_model
(Model
) –The plot is saved to the specified output path.
Source code in fusion_bench/method/analysis/task_vector_violin_plot.py
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 |
|