Introduction to Model Pool Module¶
A modelpool is a collection of models that are utilized in the process of model fusion. In the context of straightforward model fusion techniques, like averaging, only models with the same architecture are used. While for more complex methods, such as AdaMerging 1, each model is paired with a unique set of unlabeled test data. This data is used during the test-time adaptation phase.
Yaml Configuration¶
A modelpool is specified by a yaml
configuration file, which often contains the following fields:
type
: The name of the modelpool.models
: A list of models, each model is dict with the following fields:name
: The name of the model. There are some special names that are reserved for specific purposes, such as_pretrained_
for the pretrained model.path
: The path to the model file.type
: The type of the model. If this field is not specified, the type is inferred from themodel_type
.
For more complex model fusion techniques that requires data, the modelpool configuration file may also contain the following fields:
dataset_type
: The type of the dataset used for training the models in the modelpool.datasets
: A list of datasets, each dataset is dict with the following fields:name
: The name of the dataset, which is used to pair the dataset with the corresponding model. The name of the dataset should match the name of the model.path
: The path to the dataset file.type
: The type of the dataset. If this field is not specified, the type is inferred from thedataset_type
.
We provide a list of modelpools that contain models trained on different datasets and with different architectures. Each modelpool is described in a separate document.
Basic Usage¶
The model is not loaded by default when you initialize a modelpool, you can load a model from a modelpool by calling the load_model
method:
References¶
BaseModelPool
¶
Bases: BaseYAMLSerializableModel
A class for managing and interacting with a pool of models along with their associated datasets or other specifications. For example, a model pool may contain multiple models, each with its own training, validation, and testing datasets. As for the specifications, a vision model pool may contain image preprocessor, and a language model pool may contain a tokenizer.
Attributes:
-
_models
(DictConfig
) –Configuration for all models in the pool.
-
_train_datasets
(Optional[DictConfig]
) –Configuration for training datasets.
-
_val_datasets
(Optional[DictConfig]
) –Configuration for validation datasets.
-
_test_datasets
(Optional[DictConfig]
) –Configuration for testing datasets.
-
_usage_
(Optional[str]
) –Optional usage information.
-
_version_
(Optional[str]
) –Optional version information.
Source code in fusion_bench/modelpool/base_pool.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 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 |
|
all_model_names: List[str]
property
¶
Get the names of all models in the pool, including special models.
Returns:
-
List[str]
–List[str]: A list of all model names.
has_pretrained
property
¶
Check if the model pool contains a pretrained model.
Returns:
-
bool
–True if a pretrained model is available, False otherwise.
model_names: List[str]
property
¶
Get the names of regular models, excluding special models.
Returns:
-
List[str]
–List[str]: A list of regular model names.
test_dataset_names: List[str]
property
¶
Get the names of testing datasets.
Returns:
-
List[str]
–List[str]: A list of testing dataset names.
train_dataset_names: List[str]
property
¶
Get the names of training datasets.
Returns:
-
List[str]
–List[str]: A list of training dataset names.
val_dataset_names: List[str]
property
¶
Get the names of validation datasets.
Returns:
-
List[str]
–List[str]: A list of validation dataset names.
get_model_config(model_name, return_copy=True)
¶
Get the configuration for the specified model.
Parameters:
-
model_name
¶str
) –The name of the model.
Returns:
-
DictConfig
(DictConfig
) –The configuration for the specified model.
Source code in fusion_bench/modelpool/base_pool.py
is_special_model(model_name)
staticmethod
¶
Determine if a model is special based on its name.
Parameters:
-
model_name
¶str
) –The name of the model.
Returns:
-
bool
–True if the model name indicates a special model, False otherwise.
Source code in fusion_bench/modelpool/base_pool.py
load_model(model_name_or_config, *args, **kwargs)
¶
Load a model from the pool based on the provided configuration.
Parameters:
-
model
¶Union[str, DictConfig]
) –The model name or configuration.
Returns:
-
Module
–nn.Module: The instantiated model.
Source code in fusion_bench/modelpool/base_pool.py
load_pretrained_or_first_model(*args, **kwargs)
¶
Load the pretrained model if available, otherwise load the first available model.
Returns:
-
–
nn.Module: The loaded model.
Source code in fusion_bench/modelpool/base_pool.py
load_test_dataset(dataset_name, *args, **kwargs)
¶
Load the testing dataset for the specified model.
Parameters:
-
dataset_name
¶str
) –The name of the model.
Returns:
-
Dataset
(Dataset
) –The instantiated testing dataset.
Source code in fusion_bench/modelpool/base_pool.py
load_train_dataset(dataset_name, *args, **kwargs)
¶
Load the training dataset for the specified model.
Parameters:
-
dataset_name
¶str
) –The name of the model.
Returns:
-
Dataset
(Dataset
) –The instantiated training dataset.
Source code in fusion_bench/modelpool/base_pool.py
load_val_dataset(dataset_name, *args, **kwargs)
¶
Load the validation dataset for the specified model.
Parameters:
-
dataset_name
¶str
) –The name of the model.
Returns:
-
Dataset
(Dataset
) –The instantiated validation dataset.
Source code in fusion_bench/modelpool/base_pool.py
save_model(model, path)
¶
Save the state dictionary of the model to the specified path.
Parameters:
-
model
¶Module
) –The model whose state dictionary is to be saved.
-
path
¶str
) –The path where the state dictionary will be saved.
Source code in fusion_bench/modelpool/base_pool.py
-
AdaMerging: Adaptive Model Merging for Multi-Task Learning. http://arxiv.org/abs/2310.02575 ↩