fusion-bench 0.2.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fusion_bench/__init__.py +20 -0
- fusion_bench/__main__.py +4 -0
- fusion_bench/compat/__init__.py +0 -0
- fusion_bench/compat/method/__init__.py +109 -0
- fusion_bench/compat/method/base_algorithm.py +58 -0
- fusion_bench/compat/modelpool/AutoModelForSeq2SeqLM.py +34 -0
- fusion_bench/compat/modelpool/__init__.py +116 -0
- fusion_bench/compat/modelpool/base_pool.py +328 -0
- fusion_bench/compat/modelpool/huggingface_clip_vision.py +178 -0
- fusion_bench/compat/taskpool/__init__.py +95 -0
- fusion_bench/compat/taskpool/base_pool.py +111 -0
- fusion_bench/compat/taskpool/clip_image_classification.py +210 -0
- fusion_bench/compat/taskpool/flan_t5_glue_text_generation.py +175 -0
- fusion_bench/constants/__init__.py +2 -0
- fusion_bench/constants/paths.py +18 -0
- fusion_bench/dataset/__init__.py +29 -0
- fusion_bench/dataset/arc_agi/__init__.py +6 -0
- fusion_bench/dataset/arc_agi/arc.py +308 -0
- fusion_bench/dataset/arc_agi/arc_agi.py +365 -0
- fusion_bench/dataset/arc_agi/augmenters.py +1036 -0
- fusion_bench/dataset/arc_agi/messagers.py +1355 -0
- fusion_bench/dataset/arc_agi/np_cache.py +168 -0
- fusion_bench/dataset/arc_agi/preprocess.py +298 -0
- fusion_bench/dataset/arc_agi/representers.py +1019 -0
- fusion_bench/dataset/clip_dataset.py +71 -0
- fusion_bench/dataset/fer2013.py +12 -0
- fusion_bench/dataset/gpt2_glue.py +300 -0
- fusion_bench/dataset/gsm8k.py +60 -0
- fusion_bench/dataset/image_dataset.py +55 -0
- fusion_bench/dataset/imdb.py +11 -0
- fusion_bench/dataset/llama/__init__.py +1 -0
- fusion_bench/dataset/llama/alpaca.py +232 -0
- fusion_bench/dataset/llama/collate.py +120 -0
- fusion_bench/dataset/llama/metamathqa.py +50 -0
- fusion_bench/dataset/llama/openai.py +160 -0
- fusion_bench/dataset/llama/preference_700k.py +70 -0
- fusion_bench/dataset/llama/sharegpt.py +141 -0
- fusion_bench/dataset/llama/squad.py +125 -0
- fusion_bench/dataset/llama/stanford_shp.py +90 -0
- fusion_bench/dataset/llama/ultrachat.py +58 -0
- fusion_bench/dataset/llama/utils/__init__.py +0 -0
- fusion_bench/dataset/llama/wikitext.py +89 -0
- fusion_bench/dataset/nyuv2.py +119 -0
- fusion_bench/method/__init__.py +177 -0
- fusion_bench/method/ada_svd/__init__.py +2 -0
- fusion_bench/method/ada_svd/clip_vision.py +319 -0
- fusion_bench/method/adamerging/__init__.py +6 -0
- fusion_bench/method/adamerging/clip_layer_wise_adamerging.py +46 -0
- fusion_bench/method/adamerging/clip_task_wise_adamerging.py +187 -0
- fusion_bench/method/adamerging/entropy_loss.py +25 -0
- fusion_bench/method/adamerging/flan_t5_layer_wise_adamerging.py +332 -0
- fusion_bench/method/adamerging/gpt2_layer_wise_adamerging.py +351 -0
- fusion_bench/method/adamerging/layer_wise_adamerging.py +252 -0
- fusion_bench/method/adamerging/llama_adamerging.py +335 -0
- fusion_bench/method/adamerging/min_norm_solvers.py +227 -0
- fusion_bench/method/adamerging/task_wise_adamerging.py +174 -0
- fusion_bench/method/adamerging/utils.py +15 -0
- fusion_bench/method/analysis/__init__.py +2 -0
- fusion_bench/method/analysis/task_vector_cos_similarity.py +172 -0
- fusion_bench/method/analysis/task_vector_violin_plot.py +205 -0
- fusion_bench/method/base_algorithm.py +44 -0
- fusion_bench/method/classification/__init__.py +3 -0
- fusion_bench/method/classification/clip_finetune.py +444 -0
- fusion_bench/method/classification/continual_clip_finetune.py +297 -0
- fusion_bench/method/concrete_subspace/__init__.py +6 -0
- fusion_bench/method/concrete_subspace/clip_concrete_adamerging.py +595 -0
- fusion_bench/method/concrete_subspace/clip_concrete_task_arithmetic.py +263 -0
- fusion_bench/method/dare/__init__.py +4 -0
- fusion_bench/method/dare/simple_average.py +31 -0
- fusion_bench/method/dare/task_arithmetic.py +82 -0
- fusion_bench/method/dare/ties_merging.py +100 -0
- fusion_bench/method/dare/utils.py +87 -0
- fusion_bench/method/dawe/__init__.py +2 -0
- fusion_bench/method/dawe/dawe_for_clip.py +274 -0
- fusion_bench/method/dawe/warppers/__init__.py +13 -0
- fusion_bench/method/dawe/warppers/dawe_model.py +256 -0
- fusion_bench/method/depth_upscaling/__init__.py +3 -0
- fusion_bench/method/depth_upscaling/depth_upscaling.py +89 -0
- fusion_bench/method/depth_upscaling/depth_upscaling_for_llama.py +57 -0
- fusion_bench/method/dummy.py +35 -0
- fusion_bench/method/ensemble.py +98 -0
- fusion_bench/method/fisher_merging/__init__.py +4 -0
- fusion_bench/method/fisher_merging/clip_fisher_merging.py +191 -0
- fusion_bench/method/fisher_merging/fisher_merging.py +484 -0
- fusion_bench/method/fisher_merging/gpt2_fisher_merging.py +193 -0
- fusion_bench/method/linear/__init__.py +6 -0
- fusion_bench/method/linear/expo.py +118 -0
- fusion_bench/method/linear/linear_interpolation.py +60 -0
- fusion_bench/method/linear/llama_expo.py +229 -0
- fusion_bench/method/linear/simple_average_for_llama.py +54 -0
- fusion_bench/method/linear/task_arithmetic_for_llama.py +57 -0
- fusion_bench/method/lm_finetune/__init__.py +3 -0
- fusion_bench/method/lm_finetune/bradley_terry_rm.py +432 -0
- fusion_bench/method/lm_finetune/causal_lm_pretrain.py +7 -0
- fusion_bench/method/lm_finetune/fullfinetune_sft.py +375 -0
- fusion_bench/method/lm_finetune/peftfinetune_sft.py +370 -0
- fusion_bench/method/mixture_of_experts/__init__.py +7 -0
- fusion_bench/method/mixture_of_experts/mixtral_merging.py +112 -0
- fusion_bench/method/mixture_of_experts/mixtral_upcycling.py +329 -0
- fusion_bench/method/model_recombination.py +121 -0
- fusion_bench/method/opcm/__init__.py +4 -0
- fusion_bench/method/opcm/opcm.py +277 -0
- fusion_bench/method/opcm/task_arithmetic.py +115 -0
- fusion_bench/method/opcm/ties_merging.py +156 -0
- fusion_bench/method/opcm/utils.py +73 -0
- fusion_bench/method/opcm/weight_average.py +120 -0
- fusion_bench/method/pruning/__init__.py +5 -0
- fusion_bench/method/pruning/llama_magnitude_prune.py +202 -0
- fusion_bench/method/pruning/llama_random_prune.py +143 -0
- fusion_bench/method/pruning/llama_wanda_prune.py +359 -0
- fusion_bench/method/pruning/magnitude_diff_pruning.py +180 -0
- fusion_bench/method/pruning/prune_utils.py +165 -0
- fusion_bench/method/pruning/wanda_utils/__init__.py +7 -0
- fusion_bench/method/pruning/wanda_utils/ablate.py +188 -0
- fusion_bench/method/pruning/wanda_utils/data.py +135 -0
- fusion_bench/method/pruning/wanda_utils/eval.py +245 -0
- fusion_bench/method/pruning/wanda_utils/layerwrapper.py +61 -0
- fusion_bench/method/pruning/wanda_utils/prune.py +581 -0
- fusion_bench/method/pruning/wanda_utils/prune_opt.py +539 -0
- fusion_bench/method/pruning/wanda_utils/sparsegpt.py +165 -0
- fusion_bench/method/pwe_moe/__init__.py +5 -0
- fusion_bench/method/pwe_moe/clip_pwe_moe.py +315 -0
- fusion_bench/method/pwe_moe/module.py +316 -0
- fusion_bench/method/pwe_moe/phn/__init__.py +2 -0
- fusion_bench/method/pwe_moe/phn/solvers.py +195 -0
- fusion_bench/method/pwe_moe/utils.py +43 -0
- fusion_bench/method/rankone_moe/__init__.py +3 -0
- fusion_bench/method/rankone_moe/clip_rankone_moe.py +160 -0
- fusion_bench/method/rankone_moe/rankone_moe.py +249 -0
- fusion_bench/method/regmean/__init__.py +4 -0
- fusion_bench/method/regmean/clip_regmean.py +131 -0
- fusion_bench/method/regmean/gpt2_regmean.py +147 -0
- fusion_bench/method/regmean/regmean.py +375 -0
- fusion_bench/method/simple_average.py +112 -0
- fusion_bench/method/slerp/__init__.py +2 -0
- fusion_bench/method/slerp/slerp.py +101 -0
- fusion_bench/method/slerp/slerp_utils.py +107 -0
- fusion_bench/method/smile_upscaling/__init__.py +3 -0
- fusion_bench/method/smile_upscaling/singular_projection_merging.py +198 -0
- fusion_bench/method/smile_upscaling/smile_mistral_upscaling.py +331 -0
- fusion_bench/method/smile_upscaling/smile_upscaling.py +573 -0
- fusion_bench/method/sparse_we_moe/__init__.py +2 -0
- fusion_bench/method/sparse_we_moe/sparse_clip_we_moe.py +248 -0
- fusion_bench/method/sparse_we_moe/sparse_we_moe.py +301 -0
- fusion_bench/method/sparselo/__init__.py +2 -0
- fusion_bench/method/sparselo/sparselo.py +955 -0
- fusion_bench/method/surgery/__init__.py +1 -0
- fusion_bench/method/surgery/clip_layer_wise_adamerging_surgery.py +157 -0
- fusion_bench/method/tall_mask/__init__.py +0 -0
- fusion_bench/method/tall_mask/utils.py +234 -0
- fusion_bench/method/task_arithmetic/__init__.py +2 -0
- fusion_bench/method/task_arithmetic/task_arithmetic.py +151 -0
- fusion_bench/method/task_singular_vector/TSVC.py +16 -0
- fusion_bench/method/task_singular_vector/TSVM.py +63 -0
- fusion_bench/method/task_singular_vector/__init__.py +9 -0
- fusion_bench/method/task_singular_vector/utils/TSVC_utils.py +50 -0
- fusion_bench/method/task_singular_vector/utils/TSVM_utils.py +640 -0
- fusion_bench/method/task_singular_vector/utils/__init__.py +7 -0
- fusion_bench/method/ties_merging/__init__.py +2 -0
- fusion_bench/method/ties_merging/ties_merging.py +117 -0
- fusion_bench/method/ties_merging/ties_merging_utils.py +331 -0
- fusion_bench/method/trust_region/__init__.py +2 -0
- fusion_bench/method/trust_region/clip_task_arithmetic.py +205 -0
- fusion_bench/method/trust_region/utils.py +58 -0
- fusion_bench/method/we_moe/__init__.py +2 -0
- fusion_bench/method/we_moe/clip_we_moe.py +161 -0
- fusion_bench/method/we_moe/we_moe.py +247 -0
- fusion_bench/method/weighted_average/__init__.py +3 -0
- fusion_bench/method/weighted_average/llama.py +113 -0
- fusion_bench/method/weighted_average/weighted_average.py +102 -0
- fusion_bench/metrics/__init__.py +0 -0
- fusion_bench/metrics/continual_learning/backward_transfer.py +22 -0
- fusion_bench/metrics/nyuv2/__init__.py +11 -0
- fusion_bench/metrics/nyuv2/depth.py +45 -0
- fusion_bench/metrics/nyuv2/loss.py +31 -0
- fusion_bench/metrics/nyuv2/noise.py +16 -0
- fusion_bench/metrics/nyuv2/normal.py +48 -0
- fusion_bench/metrics/nyuv2/segmentation.py +43 -0
- fusion_bench/metrics/text_to_image_generation/__init__.py +9 -0
- fusion_bench/metrics/text_to_image_generation/aesthetic_scorer.py +123 -0
- fusion_bench/metrics/text_to_image_generation/compressibility.py +49 -0
- fusion_bench/metrics/text_to_image_generation/pickscore_scorer.py +95 -0
- fusion_bench/mixins/__init__.py +28 -0
- fusion_bench/mixins/clip_classification.py +252 -0
- fusion_bench/mixins/fabric_training.py +320 -0
- fusion_bench/mixins/lightning_fabric.py +174 -0
- fusion_bench/mixins/optim/__init__.py +0 -0
- fusion_bench/mixins/optim/adamw_with_warmup.py +42 -0
- fusion_bench/mixins/rich_live.py +21 -0
- fusion_bench/mixins/serialization.py +132 -0
- fusion_bench/mixins/simple_profiler.py +79 -0
- fusion_bench/modelpool/PeftModelForSeq2SeqLM.py +49 -0
- fusion_bench/modelpool/__init__.py +42 -0
- fusion_bench/modelpool/base_pool.py +268 -0
- fusion_bench/modelpool/causal_lm/__init__.py +2 -0
- fusion_bench/modelpool/causal_lm/causal_lm.py +139 -0
- fusion_bench/modelpool/clip_vision/__init__.py +1 -0
- fusion_bench/modelpool/clip_vision/modelpool.py +145 -0
- fusion_bench/modelpool/huggingface_automodel.py +20 -0
- fusion_bench/modelpool/huggingface_gpt2_classification.py +63 -0
- fusion_bench/modelpool/nyuv2_modelpool.py +40 -0
- fusion_bench/modelpool/seq2seq_lm/__init__.py +2 -0
- fusion_bench/modelpool/seq2seq_lm/modelpool.py +65 -0
- fusion_bench/modelpool/seq_classification_lm/__init__.py +2 -0
- fusion_bench/modelpool/seq_classification_lm/reward_model.py +15 -0
- fusion_bench/modelpool/seq_classification_lm/seq_classification_lm.py +98 -0
- fusion_bench/models/__init__.py +3 -0
- fusion_bench/models/chat_templates/__init__.py +1 -0
- fusion_bench/models/chat_templates/llama_3_Instruct.py +1 -0
- fusion_bench/models/chat_templates/load_tokenizer.py +43 -0
- fusion_bench/models/hf_clip.py +199 -0
- fusion_bench/models/linearized/__init__.py +0 -0
- fusion_bench/models/linearized/linearized_model_utils.py +91 -0
- fusion_bench/models/linearized/vision_model.py +122 -0
- fusion_bench/models/llama/__init__.py +16 -0
- fusion_bench/models/llama/model_utils/__init__.py +0 -0
- fusion_bench/models/llama/model_utils/embedding.py +87 -0
- fusion_bench/models/llama/model_utils/liger_kernel.py +86 -0
- fusion_bench/models/llama/model_utils/misc.py +112 -0
- fusion_bench/models/llama/model_utils/mod.py +52 -0
- fusion_bench/models/llama/model_utils/visual.py +241 -0
- fusion_bench/models/llama/patcher.py +78 -0
- fusion_bench/models/llama/tokenizer_loader.py +153 -0
- fusion_bench/models/masks/__init__.py +2 -0
- fusion_bench/models/masks/mask_model.py +160 -0
- fusion_bench/models/modeling_losparse_llama/__init__.py +4 -0
- fusion_bench/models/modeling_losparse_llama/configuration_losparse_llama.py +205 -0
- fusion_bench/models/modeling_losparse_llama/losparse_linear.py +67 -0
- fusion_bench/models/modeling_losparse_llama/modeling_losparse_llama.py +1825 -0
- fusion_bench/models/modeling_losparse_llama/register.py +8 -0
- fusion_bench/models/modeling_losparse_llama/utils.py +60 -0
- fusion_bench/models/modeling_smile_mistral/__init__.py +48 -0
- fusion_bench/models/modeling_smile_mistral/configuration_smile_mistral.py +21 -0
- fusion_bench/models/modeling_smile_mistral/modeling_smile_mistral.py +1034 -0
- fusion_bench/models/modeling_smile_mistral/register.py +8 -0
- fusion_bench/models/nyuv2/__init__.py +0 -0
- fusion_bench/models/nyuv2/aspp.py +82 -0
- fusion_bench/models/nyuv2/lightning_module.py +176 -0
- fusion_bench/models/nyuv2/resnet.py +405 -0
- fusion_bench/models/nyuv2/resnet_dilated.py +99 -0
- fusion_bench/models/parameter_dict.py +75 -0
- fusion_bench/models/rankone_moe.py +410 -0
- fusion_bench/models/separate_io.py +105 -0
- fusion_bench/models/smile_moe/__init__.py +0 -0
- fusion_bench/models/smile_moe/linear.py +256 -0
- fusion_bench/models/sparse_we_moe.py +459 -0
- fusion_bench/models/surgery/__init__.py +1 -0
- fusion_bench/models/surgery/surgerymodelwrapper.py +158 -0
- fusion_bench/models/utils.py +80 -0
- fusion_bench/models/we_moe.py +247 -0
- fusion_bench/models/wrappers/__init__.py +0 -0
- fusion_bench/models/wrappers/ensemble.py +183 -0
- fusion_bench/models/wrappers/layer_wise_fusion.py +336 -0
- fusion_bench/models/wrappers/task_wise_fusion.py +249 -0
- fusion_bench/optim/__init__.py +2 -0
- fusion_bench/optim/exception.py +47 -0
- fusion_bench/optim/lr_scheduler/__init__.py +1 -0
- fusion_bench/optim/lr_scheduler/linear_warmup.py +222 -0
- fusion_bench/optim/lr_scheduler/utils/__init__.py +1 -0
- fusion_bench/optim/lr_scheduler/utils/visualization.py +119 -0
- fusion_bench/optim/mezo.py +118 -0
- fusion_bench/programs/__init__.py +20 -0
- fusion_bench/programs/base_program.py +9 -0
- fusion_bench/programs/fabric_fusion_program.py +299 -0
- fusion_bench/scripts/__init__.py +0 -0
- fusion_bench/scripts/cli.py +43 -0
- fusion_bench/scripts/clip/__init__.py +0 -0
- fusion_bench/scripts/clip/convert_checkpoint.py +39 -0
- fusion_bench/scripts/imgui.py +218 -0
- fusion_bench/scripts/nyuv2_mtl_train.py +137 -0
- fusion_bench/scripts/webui.py +405 -0
- fusion_bench/taskpool/__init__.py +39 -0
- fusion_bench/taskpool/base_pool.py +35 -0
- fusion_bench/taskpool/clip_vision/__init__.py +4 -0
- fusion_bench/taskpool/clip_vision/clip_rankone_moe_taskpool.py +112 -0
- fusion_bench/taskpool/clip_vision/clip_sparse_wemoe_taskpool.py +120 -0
- fusion_bench/taskpool/clip_vision/taskpool.py +392 -0
- fusion_bench/taskpool/dummy.py +58 -0
- fusion_bench/taskpool/gpt2_text_classification.py +149 -0
- fusion_bench/taskpool/llama/__init__.py +1 -0
- fusion_bench/taskpool/llama/reward_model.py +157 -0
- fusion_bench/taskpool/llama/test_generation.py +185 -0
- fusion_bench/taskpool/nyuv2_taskpool.py +65 -0
- fusion_bench/tasks/__init__.py +2 -0
- fusion_bench/tasks/base_task.py +18 -0
- fusion_bench/tasks/classification.py +75 -0
- fusion_bench/tasks/clip_classification/__init__.py +183 -0
- fusion_bench/tasks/clip_classification/cifar10.py +33 -0
- fusion_bench/tasks/clip_classification/cifar100.py +146 -0
- fusion_bench/tasks/clip_classification/clip_dataset.py +1 -0
- fusion_bench/tasks/clip_classification/cub_200_2011.py +208 -0
- fusion_bench/tasks/clip_classification/dtd.py +60 -0
- fusion_bench/tasks/clip_classification/emnist_letters.py +31 -0
- fusion_bench/tasks/clip_classification/emnist_mnist.py +5 -0
- fusion_bench/tasks/clip_classification/eurosat.py +18 -0
- fusion_bench/tasks/clip_classification/fashion_mnist.py +18 -0
- fusion_bench/tasks/clip_classification/fer2013.py +18 -0
- fusion_bench/tasks/clip_classification/flower102.py +106 -0
- fusion_bench/tasks/clip_classification/food101.py +105 -0
- fusion_bench/tasks/clip_classification/gtsrb.py +51 -0
- fusion_bench/tasks/clip_classification/imagenet.py +2103 -0
- fusion_bench/tasks/clip_classification/kmnist.py +17 -0
- fusion_bench/tasks/clip_classification/mnist.py +5 -0
- fusion_bench/tasks/clip_classification/mongo_leaf_disease.py +19 -0
- fusion_bench/tasks/clip_classification/oxford_iiit_pet.py +41 -0
- fusion_bench/tasks/clip_classification/pcam.py +5 -0
- fusion_bench/tasks/clip_classification/rendered_sst2.py +3 -0
- fusion_bench/tasks/clip_classification/resisc45.py +68 -0
- fusion_bench/tasks/clip_classification/stanford_cars.py +209 -0
- fusion_bench/tasks/clip_classification/stl10.py +17 -0
- fusion_bench/tasks/clip_classification/sun397.py +404 -0
- fusion_bench/tasks/clip_classification/svhn.py +5 -0
- fusion_bench/tasks/clip_classification/tiny_imagenet.py +208 -0
- fusion_bench/tasks/flan_t5_text_generation/__init__.py +0 -0
- fusion_bench/tasks/flan_t5_text_generation/datasets_preprocess.py +71 -0
- fusion_bench/tasks/flan_t5_text_generation/glue_evaluation.py +132 -0
- fusion_bench/tasks/flan_t5_text_generation/glue_load_dataset.py +64 -0
- fusion_bench/tasks/flan_t5_text_generation/glue_preprocessors.py +379 -0
- fusion_bench/tasks/flan_t5_text_generation/glue_prompt_templates.py +52 -0
- fusion_bench/utils/__init__.py +14 -0
- fusion_bench/utils/auto.py +31 -0
- fusion_bench/utils/cache_utils.py +58 -0
- fusion_bench/utils/data.py +165 -0
- fusion_bench/utils/devices.py +231 -0
- fusion_bench/utils/dict.py +43 -0
- fusion_bench/utils/dtype.py +146 -0
- fusion_bench/utils/expr.py +90 -0
- fusion_bench/utils/fabric.py +17 -0
- fusion_bench/utils/functools.py +37 -0
- fusion_bench/utils/hydra_utils.py +28 -0
- fusion_bench/utils/instantiate.py +450 -0
- fusion_bench/utils/json.py +93 -0
- fusion_bench/utils/lazy_imports.py +74 -0
- fusion_bench/utils/misc.py +18 -0
- fusion_bench/utils/packages.py +84 -0
- fusion_bench/utils/parameters.py +323 -0
- fusion_bench/utils/path.py +22 -0
- fusion_bench/utils/plot/__init__.py +0 -0
- fusion_bench/utils/plot/color_data.py +1726 -0
- fusion_bench/utils/plot/token.py +52 -0
- fusion_bench/utils/plot/token_notebook.py +127 -0
- fusion_bench/utils/pylogger.py +55 -0
- fusion_bench/utils/rich_utils.py +201 -0
- fusion_bench/utils/set.py +8 -0
- fusion_bench/utils/state_dict_arithmetic.py +297 -0
- fusion_bench/utils/strenum/__init__.py +326 -0
- fusion_bench/utils/strenum/_name_mangler.py +127 -0
- fusion_bench/utils/strenum/_version.py +556 -0
- fusion_bench/utils/tensorboard.py +51 -0
- fusion_bench/utils/timer.py +49 -0
- fusion_bench/utils/type.py +34 -0
- fusion_bench-0.2.9.dist-info/LICENSE +21 -0
- fusion_bench-0.2.9.dist-info/METADATA +258 -0
- fusion_bench-0.2.9.dist-info/RECORD +727 -0
- fusion_bench-0.2.9.dist-info/WHEEL +5 -0
- fusion_bench-0.2.9.dist-info/entry_points.txt +3 -0
- fusion_bench-0.2.9.dist-info/top_level.txt +1 -0
- fusion_bench_config/README.md +12 -0
- fusion_bench_config/clip-vit-base-patch32_robustness_corrupted.yaml +23 -0
- fusion_bench_config/dataset/image_classification/README.md +6 -0
- fusion_bench_config/dataset/image_classification/test/TALL14.yaml +20 -0
- fusion_bench_config/dataset/image_classification/test/TALL20.yaml +28 -0
- fusion_bench_config/dataset/image_classification/test/cifar10.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/cifar100.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/cub-200-2011.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/dtd.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/emnist_letters.yaml +5 -0
- fusion_bench_config/dataset/image_classification/test/emnist_mnist.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/eurosat.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/fashion_mnist.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/fer2013.yaml +3 -0
- fusion_bench_config/dataset/image_classification/test/food101.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/gtsrb.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/kmnist.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/mango-leaf-disease.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/mnist.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/oxford-iiit-pet.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/oxford_flowers102.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/pcam.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/rendered-sst2.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/resisc45.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/stanford-cars.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/stl10.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/sun397.yaml +4 -0
- fusion_bench_config/dataset/image_classification/test/svhn.yaml +6 -0
- fusion_bench_config/dataset/image_classification/test/the_eight_tasks.yaml +9 -0
- fusion_bench_config/dataset/image_classification/test/tiny-imagenet.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/TALL14.yaml +20 -0
- fusion_bench_config/dataset/image_classification/train/TALL20.yaml +28 -0
- fusion_bench_config/dataset/image_classification/train/cifar10.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/cifar100.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/cub-200-2011.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/dtd.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/emnist_letters.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/emnist_mnist.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/eurosat.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/fashion_mnist.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/fer2013.yaml +3 -0
- fusion_bench_config/dataset/image_classification/train/food101.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/gtsrb.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/kmnist.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/mango-leaf-disease.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/mnist.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/oxford-iiit-pet.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/oxford_flowers102.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/pcam.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/rendered-sst2.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/resisc45.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/stanford-cars.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/stl10.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/sun397.yaml +4 -0
- fusion_bench_config/dataset/image_classification/train/svhn.yaml +6 -0
- fusion_bench_config/dataset/image_classification/train/the_eight_tasks.yaml +9 -0
- fusion_bench_config/dataset/image_classification/train/tiny-imagenet.yaml +4 -0
- fusion_bench_config/dataset/image_classification/val/dtd.yaml +10 -0
- fusion_bench_config/dataset/image_classification/val/eurosat.yaml +10 -0
- fusion_bench_config/dataset/image_classification/val/gtsrb.yaml +10 -0
- fusion_bench_config/dataset/image_classification/val/mnist.yaml +10 -0
- fusion_bench_config/dataset/image_classification/val/resisc45.yaml +10 -0
- fusion_bench_config/dataset/image_classification/val/stanford-cars.yaml +10 -0
- fusion_bench_config/dataset/image_classification/val/sun397.yaml +10 -0
- fusion_bench_config/dataset/image_classification/val/svhn.yaml +12 -0
- fusion_bench_config/dataset/image_classification/val/the_eight_tasks.yaml +9 -0
- fusion_bench_config/dataset/llm_sft/alpaca_cleaned.yaml +6 -0
- fusion_bench_config/dataset/llm_sft/ultrachat_200k.yaml +3 -0
- fusion_bench_config/dataset/question_answering/search_qa.yaml +6 -0
- fusion_bench_config/dataset/question_answering/test/search_qa.yaml +7 -0
- fusion_bench_config/dataset/question_answering/train/MetaMathQA.yaml +4 -0
- fusion_bench_config/dataset/question_answering/train/search_qa.yaml +7 -0
- fusion_bench_config/dataset/question_answering/val/search_qa.yaml +7 -0
- fusion_bench_config/dataset/summarization/test/xsum.yaml +4 -0
- fusion_bench_config/dataset/summarization/train/xsum.yaml +4 -0
- fusion_bench_config/dataset/summarization/val/xsum.yaml +4 -0
- fusion_bench_config/dataset/summarization/xsum.yaml +3 -0
- fusion_bench_config/dataset/text_generation/test/gsm-hard.yaml +4 -0
- fusion_bench_config/dataset/text_generation/test/gsm8k.yaml +5 -0
- fusion_bench_config/dataset/text_generation/test/gsm8k_question_label.yaml +3 -0
- fusion_bench_config/dataset/text_generation/train/CodeAlpaca-20k.yaml +4 -0
- fusion_bench_config/dataset/text_generation/train/gsm8k.yaml +5 -0
- fusion_bench_config/dataset/text_generation/train/gsm8k_question_label.yaml +3 -0
- fusion_bench_config/fabric/auto.yaml +16 -0
- fusion_bench_config/fabric/llama_ddp.yaml +18 -0
- fusion_bench_config/fabric/llama_fsdp.yaml +16 -0
- fusion_bench_config/fabric/llama_peft_fsdp.yaml +16 -0
- fusion_bench_config/fabric/loggers/csv_logger.yaml +11 -0
- fusion_bench_config/fabric/loggers/tensorboard_logger.yaml +11 -0
- fusion_bench_config/fabric/loggers/wandb_logger.yaml +2 -0
- fusion_bench_config/fabric/strategy/deepspeed.yaml +10 -0
- fusion_bench_config/fabric/strategy/llama_fsdp.yaml +8 -0
- fusion_bench_config/fabric/strategy/llama_peft_fsdp.yaml +9 -0
- fusion_bench_config/fabric_model_fusion.yaml +20 -0
- fusion_bench_config/hydra/default.yaml +8 -0
- fusion_bench_config/hydra/help/fusion_bench_help.yaml +47 -0
- fusion_bench_config/hydra/job_logging/rich_logging.yaml +20 -0
- fusion_bench_config/llama_full_finetune.yaml +19 -0
- fusion_bench_config/llama_magnitude_pruning.yaml +16 -0
- fusion_bench_config/llama_model_fusion.yaml +17 -0
- fusion_bench_config/method/ada_svd/clip_vision.yaml +9 -0
- fusion_bench_config/method/adamerging/clip.yaml +23 -0
- fusion_bench_config/method/adamerging/layer_wise_flan_t5.yaml +23 -0
- fusion_bench_config/method/adamerging/layer_wise_gpt2.yaml +23 -0
- fusion_bench_config/method/adamerging/llama_sft.yaml +33 -0
- fusion_bench_config/method/adamerging.yaml +23 -0
- fusion_bench_config/method/analysis/task_vector_cos_similarity.yaml +6 -0
- fusion_bench_config/method/analysis/task_vector_violin_plot.yaml +6 -0
- fusion_bench_config/method/classification/clip_continual_finetune.yaml +28 -0
- fusion_bench_config/method/classification/clip_finetune.yaml +26 -0
- fusion_bench_config/method/clip_finetune.yaml +26 -0
- fusion_bench_config/method/concrete_subspace/clip_concrete_layer_wise_adamerging.yaml +27 -0
- fusion_bench_config/method/concrete_subspace/clip_concrete_task_arithmetic.yaml +25 -0
- fusion_bench_config/method/concrete_subspace/clip_concrete_task_wise_adamerging.yaml +27 -0
- fusion_bench_config/method/dare/simple_average.yaml +5 -0
- fusion_bench_config/method/dare/task_arithmetic.yaml +6 -0
- fusion_bench_config/method/dare/ties_merging.yaml +15 -0
- fusion_bench_config/method/dawe/dawe_for_clip.yaml +32 -0
- fusion_bench_config/method/depth_upscaling.yaml +5 -0
- fusion_bench_config/method/dummy.yaml +1 -0
- fusion_bench_config/method/ensemble/max_model_predictor.yaml +1 -0
- fusion_bench_config/method/ensemble/simple_ensemble.yaml +2 -0
- fusion_bench_config/method/ensemble/weighted_ensemble.yaml +6 -0
- fusion_bench_config/method/fisher_merging/clip_fisher_merging.yaml +13 -0
- fusion_bench_config/method/fisher_merging/fisher_merging.yaml +9 -0
- fusion_bench_config/method/fisher_merging/gpt2_fisher_merging.yaml +12 -0
- fusion_bench_config/method/linear/expo.yaml +8 -0
- fusion_bench_config/method/linear/linear_interpolation.yaml +3 -0
- fusion_bench_config/method/linear/llama_expo.yaml +19 -0
- fusion_bench_config/method/linear/llama_expo_with_dare.yaml +19 -0
- fusion_bench_config/method/linear/simple_average_for_llama.yaml +5 -0
- fusion_bench_config/method/linear/task_arithmetic_for_llama.yaml +4 -0
- fusion_bench_config/method/linear/weighted_average.yaml +6 -0
- fusion_bench_config/method/linear/weighted_average_for_llama.yaml +12 -0
- fusion_bench_config/method/lm_finetune/bradley_terry_rm.yaml +47 -0
- fusion_bench_config/method/lm_finetune/fullfinetune_sft.yaml +47 -0
- fusion_bench_config/method/lm_finetune/peftfinetune_sft.yaml +63 -0
- fusion_bench_config/method/mixtral_moe_merging.yaml +4 -0
- fusion_bench_config/method/mixtral_moe_upscaling.yaml +7 -0
- fusion_bench_config/method/model_recombination.yaml +4 -0
- fusion_bench_config/method/opcm/opcm.yaml +12 -0
- fusion_bench_config/method/opcm/task_arithmetic.yaml +12 -0
- fusion_bench_config/method/opcm/ties_merging.yaml +18 -0
- fusion_bench_config/method/opcm/weight_average.yaml +10 -0
- fusion_bench_config/method/pruning/llama_magnitude_pruning.yaml +14 -0
- fusion_bench_config/method/pruning/llama_random_pruning.yaml +9 -0
- fusion_bench_config/method/pruning/llama_wanda_pruning.yaml +16 -0
- fusion_bench_config/method/pruning/magnitude_diff_pruning.yaml +5 -0
- fusion_bench_config/method/pwe_moe_ls_for_clip.yaml +22 -0
- fusion_bench_config/method/rankone_moe/rankone_moe.yaml +26 -0
- fusion_bench_config/method/regmean/clip_regmean.yaml +11 -0
- fusion_bench_config/method/regmean/gpt2_regmean.yaml +12 -0
- fusion_bench_config/method/regmean/regmean.yaml +4 -0
- fusion_bench_config/method/simple_average.yaml +1 -0
- fusion_bench_config/method/slerp/slerp.yaml +6 -0
- fusion_bench_config/method/smile_upscaling/singular_projection_merging.yaml +8 -0
- fusion_bench_config/method/smile_upscaling/smile_mistral_upscaling.yaml +10 -0
- fusion_bench_config/method/smile_upscaling/smile_upscaling.yaml +14 -0
- fusion_bench_config/method/sparselo_pruning/llama_iterative_sparselo.yaml +20 -0
- fusion_bench_config/method/sparselo_pruning/llama_pcp_sparselo.yaml +20 -0
- fusion_bench_config/method/sparselo_pruning/llama_sparselo.yaml +19 -0
- fusion_bench_config/method/surgery/adamerging_surgery.yaml +27 -0
- fusion_bench_config/method/task_arithmetic.yaml +2 -0
- fusion_bench_config/method/task_singular_vector/TaskSingularVectorMerging.yaml +2 -0
- fusion_bench_config/method/ties_merging.yaml +8 -0
- fusion_bench_config/method/trust_region/clip_task_arithmetic.yaml +7 -0
- fusion_bench_config/method/wemoe/sparse_weight_ensembling_moe.yaml +39 -0
- fusion_bench_config/method/wemoe/weight_ensembling_moe.yaml +20 -0
- fusion_bench_config/model/clip-vit/README.md +38 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_TALL14.yaml +22 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_TALL20.yaml +29 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_cifar10.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_cifar100.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_dtd.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_eight_tasks.yaml +10 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_emnist_letters.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_eurosat.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_fashion_mnist.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_fer2013.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_food101.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_gtsrb.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_kmnist.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_mnist.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_oxford-iiit-pet.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_oxford_flowers102.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_pcam.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_rendered-sst2.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_resisc45.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_stanford-cars.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_stl10.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_sun397.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch16_svhn.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_TALL14.yaml +22 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_TALL20.yaml +29 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_cifar10.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_cifar100.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_dtd.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_eight_tasks.yaml +11 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_emnist_letters.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_eurosat.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_fashion_mnist.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_fer2013.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_food101.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_gtsrb.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_kmnist.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_mnist.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_oxford-iiit-pet.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_oxford_flowers102.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_pcam.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_rendered-sst2.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_resisc45.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_stanford-cars.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_stl10.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_sun397.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-base-patch32_svhn.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_TALL14.yaml +22 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_TALL20.yaml +29 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_cifar10.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_cifar100.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_dtd.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_eight_tasks.yaml +10 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_emnist_letters.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_eurosat.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_fashion_mnist.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_fer2013.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_food101.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_gtsrb.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_kmnist.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_mnist.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_oxford-iiit-pet.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_oxford_flowers102.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_pcam.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_rendered-sst2.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_resisc45.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_stanford-cars.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_stl10.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_sun397.yaml +1 -0
- fusion_bench_config/model/clip-vit/clip-vit-large-patch14_svhn.yaml +1 -0
- fusion_bench_config/model/clip-vit/download_TALL20_models.sh +6 -0
- fusion_bench_config/model/clip-vit/generate_vit_model_config.sh +23 -0
- fusion_bench_config/model/flan-t5/flan-t5-base.yaml +3 -0
- fusion_bench_config/model/flan-t5/flan-t5-base_glue-cola.yaml +3 -0
- fusion_bench_config/model/flan-t5/flan-t5-base_glue-cola_lora-16.yaml +4 -0
- fusion_bench_config/model/flan-t5/flan-t5-base_glue-mnli.yaml +3 -0
- fusion_bench_config/model/flan-t5/flan-t5-base_glue-mnli_lora-16.yaml +4 -0
- fusion_bench_config/model/flan-t5/flan-t5-base_glue-mrpc.yaml +3 -0
- fusion_bench_config/model/flan-t5/flan-t5-base_glue-mrpc_lora-16.yaml +4 -0
- fusion_bench_config/model/flan-t5/flan-t5-base_glue-qnli.yaml +3 -0
- fusion_bench_config/model/flan-t5/flan-t5-base_glue-qnli_lora-16.yaml +4 -0
- fusion_bench_config/model/flan-t5/flan-t5-base_glue-qqp.yaml +3 -0
- fusion_bench_config/model/flan-t5/flan-t5-base_glue-qqp_lora-16.yaml +4 -0
- fusion_bench_config/model/flan-t5/flan-t5-base_glue-rte.yaml +3 -0
- fusion_bench_config/model/flan-t5/flan-t5-base_glue-rte_lora-16.yaml +4 -0
- fusion_bench_config/model/flan-t5/flan-t5-base_glue-sst2.yaml +3 -0
- fusion_bench_config/model/flan-t5/flan-t5-base_glue-sst2_lora-16.yaml +4 -0
- fusion_bench_config/model/flan-t5/flan-t5-base_glue-stsb.yaml +3 -0
- fusion_bench_config/model/flan-t5/flan-t5-base_glue-stsb_lora-16.yaml +4 -0
- fusion_bench_config/model/flan-t5/flan-t5-large.yaml +3 -0
- fusion_bench_config/model/flan-t5/flan-t5-large_glue-cola_lora-16.yaml +4 -0
- fusion_bench_config/model/flan-t5/flan-t5-large_glue-mnli_lora-16.yaml +4 -0
- fusion_bench_config/model/flan-t5/flan-t5-large_glue-mrpc_lora-16.yaml +4 -0
- fusion_bench_config/model/flan-t5/flan-t5-large_glue-qnli_lora-16.yaml +4 -0
- fusion_bench_config/model/flan-t5/flan-t5-large_glue-qqp_lora-16.yaml +4 -0
- fusion_bench_config/model/flan-t5/flan-t5-large_glue-rte_lora-16.yaml +4 -0
- fusion_bench_config/model/flan-t5/flan-t5-large_glue-sst2_lora-16.yaml +4 -0
- fusion_bench_config/model/flan-t5/flan-t5-large_glue-stsb_lora-16.yaml +4 -0
- fusion_bench_config/model/flan-t5/generate_flan-t5.sh +38 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/_template.yaml +12 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch16_TA8.yaml +8 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch16_TA8_lora.yaml +53 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch16_TA8_model_only.yaml +6 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch16_TALL14.yaml +11 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch16_TALL14_model_only.yaml +9 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch16_TALL20.yaml +11 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch16_TALL20_model_only.yaml +9 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch16_individual.yaml +19 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch16_individual_lora.yaml +14 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_TA8.yaml +5 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_TA8_control_task.yaml +24 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_TA8_model_only.yaml +3 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_TALL14.yaml +8 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_TALL14_model_only.yaml +6 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_TALL20.yaml +8 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_TALL20_model_only.yaml +6 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_generalization_exp1.yaml +24 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_generalization_exp2.yaml +24 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_individual.yaml +13 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_mtl.yaml +5 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_robustness_clean.yaml +18 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_robustness_corrupted.yaml +29 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_single_finetuned.yaml +5 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_single_task_projection.yaml +15 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_svhn_and_mnist.yaml +6 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_two_tasks_control_task.yaml +18 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-large-patch14_TA8.yaml +8 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-large-patch14_TA8_model_only.yaml +6 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-large-patch14_TALL14.yaml +11 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-large-patch14_TALL14_model_only.yaml +9 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-large-patch14_TALL20.yaml +11 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-large-patch14_TALL20_model_only.yaml +9 -0
- fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-large-patch14_individual.yaml +19 -0
- fusion_bench_config/modelpool/CausalLMPool/llama_alpaca_cleaned.yaml +21 -0
- fusion_bench_config/modelpool/CausalLMPool/llama_codealpaca.yaml +21 -0
- fusion_bench_config/modelpool/CausalLMPool/llama_for_causallm.yaml +20 -0
- fusion_bench_config/modelpool/CausalLMPool/llama_metamathqa.yaml +19 -0
- fusion_bench_config/modelpool/CausalLMPool/llama_ultrachat.yaml +18 -0
- fusion_bench_config/modelpool/CausalLMPool/simle_mixtral_exp_v4.yaml +21 -0
- fusion_bench_config/modelpool/CausalLMPool/single_llama_model.yaml +17 -0
- fusion_bench_config/modelpool/Seq2SeqLMPool/_template.yaml +8 -0
- fusion_bench_config/modelpool/Seq2SeqLMPool/flan-t5-base_glue.yaml +13 -0
- fusion_bench_config/modelpool/Seq2SeqLMPool/flan-t5-base_glue_lora16.yaml +41 -0
- fusion_bench_config/modelpool/Seq2SeqLMPool/flan-t5-base_glue_lora16_tta.yaml +68 -0
- fusion_bench_config/modelpool/Seq2SeqLMPool/flan-t5-base_individual.yaml +7 -0
- fusion_bench_config/modelpool/Seq2SeqLMPool/flan-t5-large_glue_lora16.yaml +45 -0
- fusion_bench_config/modelpool/SeqenceClassificationModelPool/llama_preference700k.yaml +23 -0
- fusion_bench_config/modelpool/SeqenceClassificationModelPool/single_reward_model.yaml +14 -0
- fusion_bench_config/modelpool/automodelpool.yaml +12 -0
- fusion_bench_config/modelpool/gpt-2_glue.yaml +64 -0
- fusion_bench_config/modelpool/mixtral_moe_merging.yaml +14 -0
- fusion_bench_config/modelpool/mixtral_moe_upscaling.yaml +6 -0
- fusion_bench_config/modelpool/nyuv2_modelpool.yaml +26 -0
- fusion_bench_config/modelpool/smile_mistral_exp_v1.yaml +9 -0
- fusion_bench_config/modelpool/smile_mistral_exp_v2.yaml +9 -0
- fusion_bench_config/modelpool/smile_mistral_exp_v3.yaml +9 -0
- fusion_bench_config/modelpool/smile_mistral_exp_v4.yaml +13 -0
- fusion_bench_config/nyuv2_config.yaml +17 -0
- fusion_bench_config/nyuv2_mtl_train.yaml +32 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/_template.yaml +31 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-base-patch32_robustness_corrupted.yaml +27 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-classification_TA8.yaml +11 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-classification_TA8_B16.yaml +31 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-classification_TA8_L14.yaml +12 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-classification_TA8_val.yaml +12 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-classification_TA8_with_control_task.yaml +12 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-classification_TALL14.yaml +19 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-classification_TALL20.yaml +26 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_cifar10.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_cifar100.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_dtd.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_emnist_letters.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_eurosat.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_fashion_mnist.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_fer2013.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_food101.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_gtsrb.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_kmnist.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_mnist.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_oxford-iiit-pet.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_oxford_flowers102.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_oxford_flowers102_val.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_pcam.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_rendered-sst2.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_resisc45.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_stanford-cars.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_stl10.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_sun397.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip-vit-single-task_svhn.yaml +3 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip_rankone_wemoe_clip-vit-classification_TA8.yaml +18 -0
- fusion_bench_config/taskpool/CLIPVisionModelTaskPool/clip_sparse_wemoe_clip-vit-classification_TA8.yaml +18 -0
- fusion_bench_config/taskpool/clip-vit-base-patch32_robustness_clean.yaml +24 -0
- fusion_bench_config/taskpool/clip-vit-base-patch32_robustness_corrupted.yaml +27 -0
- fusion_bench_config/taskpool/clip-vit-base-patch32_svhn_and_mnist.yaml +22 -0
- fusion_bench_config/taskpool/dummy.yaml +2 -0
- fusion_bench_config/taskpool/flan-t5_glue_text_generation.yaml +44 -0
- fusion_bench_config/taskpool/gpt-2_glue.yaml +39 -0
- fusion_bench_config/taskpool/nyuv2_taskpool.yaml +9 -0
- fusion_bench_config/taskpool/reward_model_evaluation.yaml +18 -0
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
import logging
|
|
3
|
+
from copy import deepcopy
|
|
4
|
+
from typing import ( # noqa: F401
|
|
5
|
+
Any,
|
|
6
|
+
Callable,
|
|
7
|
+
Dict,
|
|
8
|
+
Generic,
|
|
9
|
+
Iterator,
|
|
10
|
+
List,
|
|
11
|
+
Optional,
|
|
12
|
+
TypeVar,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
import torch
|
|
16
|
+
from torch import Tensor, nn
|
|
17
|
+
from torch.func import functional_call
|
|
18
|
+
|
|
19
|
+
from fusion_bench.utils.type import StateDictType, TorchModelType
|
|
20
|
+
|
|
21
|
+
__all__ = ["get_layer_wise_weights", "fuse_weights", "LayerWiseMergedModel"]
|
|
22
|
+
|
|
23
|
+
log = logging.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def del_attr(obj, names: List[str]):
|
|
27
|
+
"""
|
|
28
|
+
Deletes an attribute from an object recursively.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
obj (object): Object to delete attribute from.
|
|
32
|
+
names (list): List of attribute names to delete recursively.
|
|
33
|
+
"""
|
|
34
|
+
if len(names) == 1:
|
|
35
|
+
delattr(obj, names[0])
|
|
36
|
+
else:
|
|
37
|
+
del_attr(getattr(obj, names[0]), names[1:])
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def set_attr(obj, names: List[str], val):
|
|
41
|
+
"""
|
|
42
|
+
Sets an attribute of an object recursively.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
obj (object): Object to set attribute of.
|
|
46
|
+
names (list): List of attribute names to set recursively.
|
|
47
|
+
val (object): Value to set the attribute to.
|
|
48
|
+
"""
|
|
49
|
+
if len(names) == 1:
|
|
50
|
+
setattr(obj, names[0], val)
|
|
51
|
+
else:
|
|
52
|
+
set_attr(getattr(obj, names[0]), names[1:], val)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def get_attr(obj, names: List[str]):
|
|
56
|
+
"""
|
|
57
|
+
Gets an attribute of an object recursively.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
obj (object): Object to get attribute of.
|
|
61
|
+
names (list): List of attribute names to get recursively.
|
|
62
|
+
|
|
63
|
+
Returns:
|
|
64
|
+
object: The attribute of the object.
|
|
65
|
+
"""
|
|
66
|
+
if len(names) == 1:
|
|
67
|
+
return getattr(obj, names[0])
|
|
68
|
+
else:
|
|
69
|
+
return get_attr(getattr(obj, names[0]), names[1:])
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def get_layer_wise_weights(
|
|
73
|
+
num_models: int,
|
|
74
|
+
num_layers: int,
|
|
75
|
+
init_values: float = None,
|
|
76
|
+
dtype: torch.dtype = torch.float32,
|
|
77
|
+
):
|
|
78
|
+
"""
|
|
79
|
+
Return a tensor of layer-wise weights for the given number of models and layers.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
num_models (int): The number of models to fuse.
|
|
83
|
+
num_layers (int): The number of layers in each model.
|
|
84
|
+
init_values (float, optional): The initial value for each weight. Defaults to 1.0 / num_models.
|
|
85
|
+
dtype (torch.dtype): dtype of weights. This should be the same with model dtype.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
Tensor: A tensor of shape (num_models, num_layers) containing the layer-wise weights.
|
|
89
|
+
"""
|
|
90
|
+
assert num_models >= 1, f"num_models must be >= 1, got {num_models}"
|
|
91
|
+
assert num_layers >= 1, f"num_layers must be >= 1, got {num_layers}"
|
|
92
|
+
if init_values is None:
|
|
93
|
+
init_values = 1.0 / num_models
|
|
94
|
+
return torch.full((num_models, num_layers), init_values, dtype=dtype)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _fuse_weights(layer_wise_weight: Tensor, tensors: List[Tensor]):
|
|
98
|
+
"""
|
|
99
|
+
Fuse the layer-wise weights with the given state dictionaries.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
layer_wise_weight (Tensor): A tensor of shape (num_models,) containing the layer-wise weights.
|
|
103
|
+
state_dicts (List[Tensor]): A list of state dictionaries, each containing the weights for a single layer.
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
Tensor: A tensor of shape (num_params,) containing the fused weights.
|
|
107
|
+
"""
|
|
108
|
+
assert len(layer_wise_weight) == len(
|
|
109
|
+
tensors
|
|
110
|
+
), f"layer_wise_weight.shape={layer_wise_weight.shape}, len(tensors)={len(tensors)}"
|
|
111
|
+
return sum(
|
|
112
|
+
layer_wise_weight[i] * w.to(layer_wise_weight.device)
|
|
113
|
+
for i, w in enumerate(tensors)
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def fuse_weights(
|
|
118
|
+
layer_wise_weight: Tensor, state_dicts: List[StateDictType]
|
|
119
|
+
) -> StateDictType:
|
|
120
|
+
"""
|
|
121
|
+
Fuse the weights of multiple models using layer-wise fusion.
|
|
122
|
+
|
|
123
|
+
Args:
|
|
124
|
+
layer_wise_weight (Tensor): A tensor of shape (num_models, num_layers) representing the weight of each layer for each model.
|
|
125
|
+
state_dicts (List[StateDict]): A list of state dictionaries, one for each model.
|
|
126
|
+
|
|
127
|
+
Returns:
|
|
128
|
+
A dictionary mapping each weight tensor key to the fused weight tensor.
|
|
129
|
+
"""
|
|
130
|
+
num_models = len(state_dicts)
|
|
131
|
+
num_layers = len(state_dicts[0])
|
|
132
|
+
assert layer_wise_weight.shape == (
|
|
133
|
+
num_models,
|
|
134
|
+
num_layers,
|
|
135
|
+
), f"layer_wise_weight.shape={layer_wise_weight.shape}, expected (num_models, num_layers): ({num_models}, {num_layers})"
|
|
136
|
+
return {
|
|
137
|
+
k: _fuse_weights(
|
|
138
|
+
layer_wise_weight[:, i], [state_dict[k] for state_dict in state_dicts]
|
|
139
|
+
)
|
|
140
|
+
for i, k in enumerate(state_dicts[0].keys())
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class LayerWiseMergedModel(nn.Module, Generic[TorchModelType]):
|
|
145
|
+
_merged_state_dict: StateDictType = None
|
|
146
|
+
|
|
147
|
+
def __init__(
|
|
148
|
+
self,
|
|
149
|
+
layer_wise_weight: Tensor,
|
|
150
|
+
pretrained_model: TorchModelType,
|
|
151
|
+
finetuned_models: List[TorchModelType],
|
|
152
|
+
clamp_weights: bool = True,
|
|
153
|
+
tie_weights: bool = False,
|
|
154
|
+
strict: bool = True,
|
|
155
|
+
sparsity_ratio: Optional[float] = None,
|
|
156
|
+
normalized_merging_weights: bool = False,
|
|
157
|
+
):
|
|
158
|
+
R"""
|
|
159
|
+
This class wraps a pretrained model and a list of finetuned models, and merges the weights of the finetuned models into the pretrained model using layer-wise fusion.
|
|
160
|
+
|
|
161
|
+
Reference:
|
|
162
|
+
|
|
163
|
+
(ICLR 2024) Yang E, Wang Z, Shen L, et al. Adamerging: Adaptive model merging for multi-task learning. https://arxiv.org/pdf/2310.02575
|
|
164
|
+
|
|
165
|
+
Args:
|
|
166
|
+
layer_wise_weight (Tensor): A tensor of shape (num_models, num_layers) representing the weight of each layer for each model.
|
|
167
|
+
pretrained_model (nn.Module): The pretrained model to merge the weights into.
|
|
168
|
+
finetuned_models (List[nn.Module]): A list of finetuned models to merge the weights from. This should have the same architecture as the pretrained model. We use these models to compute the task vectors.
|
|
169
|
+
clamp_weights (bool, optional): If True, the layer-wise weights will be clamped to [0, 1]. Defaults to True.
|
|
170
|
+
tie_weights (bool, optional): This option passes the `tie_weights` argument to the `functional_call` function. Defaults to False.
|
|
171
|
+
strict (bool, optional): This option passes the `strict` argument to the `functional_call` function. Defaults to True.
|
|
172
|
+
sparsity_ratio (float, optional): If `sparsity_ratio` is provided, the task vector will be pruned before merging. A high spasity level can save the memory usage during merging.
|
|
173
|
+
normalized_merging_weights (bool, optional): If True, the layer-wise weights will be normalized for each layer, so that the sum of weights across models for each layer is 1. Defaults to False.
|
|
174
|
+
"""
|
|
175
|
+
super().__init__()
|
|
176
|
+
self.clamp_weights = clamp_weights
|
|
177
|
+
self.tie_weights = tie_weights
|
|
178
|
+
self.strict = strict
|
|
179
|
+
self.sparsity_ratio = sparsity_ratio
|
|
180
|
+
self.nromalized_merging_weights = normalized_merging_weights
|
|
181
|
+
|
|
182
|
+
self.merge_weight = nn.Parameter(layer_wise_weight, requires_grad=True)
|
|
183
|
+
|
|
184
|
+
for name, param in pretrained_model.named_parameters():
|
|
185
|
+
if not param.requires_grad:
|
|
186
|
+
for m in finetuned_models:
|
|
187
|
+
del_attr(m, name.split("."))
|
|
188
|
+
else:
|
|
189
|
+
for m in finetuned_models:
|
|
190
|
+
get_attr(m, name.split(".")).data = (
|
|
191
|
+
get_attr(m, name.split(".")) - param
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
self.pretrained_model = pretrained_model.requires_grad_(False)
|
|
195
|
+
for m in finetuned_models:
|
|
196
|
+
m.requires_grad_(False)
|
|
197
|
+
|
|
198
|
+
self.task_vectors = nn.ModuleList(finetuned_models)
|
|
199
|
+
|
|
200
|
+
# if `sparisty_ratio` is given, pruning the task vectors.
|
|
201
|
+
if sparsity_ratio is not None:
|
|
202
|
+
from fusion_bench.method.pruning.prune_utils import (
|
|
203
|
+
unstructured_magnitude_prune_,
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
for name, param in self.task_vectors.named_parameters():
|
|
207
|
+
if param.dim() != 2:
|
|
208
|
+
continue
|
|
209
|
+
print(f"pruning {name}")
|
|
210
|
+
pruned_param = unstructured_magnitude_prune_(
|
|
211
|
+
param.data.clone(), torch.abs, sparsity_ratio=sparsity_ratio
|
|
212
|
+
)
|
|
213
|
+
set_attr(
|
|
214
|
+
self.task_vectors,
|
|
215
|
+
name.split("."),
|
|
216
|
+
nn.Parameter(pruned_param.to_sparse(), requires_grad=False),
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
@property
|
|
220
|
+
def forward_model(self):
|
|
221
|
+
return functools.partial(
|
|
222
|
+
functional_call,
|
|
223
|
+
self.pretrained_model,
|
|
224
|
+
self._merged_state_dict,
|
|
225
|
+
tie_weights=self.tie_weights,
|
|
226
|
+
strict=self.strict,
|
|
227
|
+
)
|
|
228
|
+
|
|
229
|
+
def merge_and_unload(self, task_vector_mask: Optional[Dict[str, Tensor]] = None):
|
|
230
|
+
self.merge_weights(task_vector_mask=task_vector_mask)
|
|
231
|
+
self.pretrained_model.load_state_dict(self._merged_state_dict)
|
|
232
|
+
return self.pretrained_model
|
|
233
|
+
|
|
234
|
+
def merge_weights(self, task_vector_mask: Optional[Dict[str, Tensor]] = None):
|
|
235
|
+
"""
|
|
236
|
+
Merges the weights of the model.
|
|
237
|
+
Call this after each update step.
|
|
238
|
+
"""
|
|
239
|
+
if self.clamp_weights:
|
|
240
|
+
layer_wise_weight = self.merge_weight.clamp(0, 1)
|
|
241
|
+
else:
|
|
242
|
+
layer_wise_weight = self.merge_weight
|
|
243
|
+
if self.nromalized_merging_weights:
|
|
244
|
+
# normalize the weights for each layer, so that the sum of weights across models for each layer is 1.
|
|
245
|
+
layer_wise_weight = layer_wise_weight.softmax(dim=0)
|
|
246
|
+
|
|
247
|
+
state_dict = self.pretrained_model.state_dict(keep_vars=True)
|
|
248
|
+
# shape of layer_wise_weight: (num_models, num_layers)
|
|
249
|
+
for weight, task_vector in zip(layer_wise_weight, self.task_vectors):
|
|
250
|
+
assert len(list(task_vector.named_parameters())) == weight.size(0)
|
|
251
|
+
if task_vector_mask is not None:
|
|
252
|
+
weight = [
|
|
253
|
+
w * task_vector_mask[name]
|
|
254
|
+
for w, (name, param) in zip(weight, task_vector.named_parameters())
|
|
255
|
+
]
|
|
256
|
+
for w, (name, param) in zip(weight, task_vector.named_parameters()):
|
|
257
|
+
state_dict[name] = state_dict[name] + param * w
|
|
258
|
+
self._merged_state_dict = state_dict
|
|
259
|
+
|
|
260
|
+
return state_dict
|
|
261
|
+
|
|
262
|
+
def forward(self, *args, **kwargs):
|
|
263
|
+
if self._merged_state_dict is None:
|
|
264
|
+
self.merge_weights()
|
|
265
|
+
return self.forward_model(args=args, kwargs=kwargs)
|
|
266
|
+
|
|
267
|
+
# def __getattr__(self, name: str) -> Any:
|
|
268
|
+
# try:
|
|
269
|
+
# return super().__getattr__(name)
|
|
270
|
+
# except AttributeError:
|
|
271
|
+
# attr = getattr(self.model, name)
|
|
272
|
+
# if isinstance(attr, Callable):
|
|
273
|
+
# warnings.warn(
|
|
274
|
+
# f"forwarding `{name}` to the underlying model", UserWarning
|
|
275
|
+
# )
|
|
276
|
+
# return attr
|
|
277
|
+
|
|
278
|
+
# def __setattr__(self, name: str, value: Any) -> None:
|
|
279
|
+
# try:
|
|
280
|
+
# super().__setattr__(name, value)
|
|
281
|
+
# except AttributeError:
|
|
282
|
+
# setattr(self.model, name, value)
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
def merge_weights(module: nn.Module):
|
|
286
|
+
"""
|
|
287
|
+
Merges the weights for all `LayerWiseMergedModel` instances within the given module.
|
|
288
|
+
|
|
289
|
+
Args:
|
|
290
|
+
module (nn.Module): The module to process.
|
|
291
|
+
"""
|
|
292
|
+
if isinstance(module, LayerWiseMergedModel):
|
|
293
|
+
module.merge_weights()
|
|
294
|
+
return
|
|
295
|
+
else:
|
|
296
|
+
for submodule in module.children():
|
|
297
|
+
merge_weights(submodule)
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def merge_and_unload(module: nn.Module):
|
|
301
|
+
"""
|
|
302
|
+
Merges and unloads all `LayerWiseMergedModel` instances within the given module.
|
|
303
|
+
|
|
304
|
+
Args:
|
|
305
|
+
module (nn.Module): The module to process.
|
|
306
|
+
|
|
307
|
+
Returns:
|
|
308
|
+
nn.Module: The updated module with merged weights.
|
|
309
|
+
"""
|
|
310
|
+
if isinstance(module, LayerWiseMergedModel):
|
|
311
|
+
return module.merge_and_unload()
|
|
312
|
+
else:
|
|
313
|
+
for name, submodule in module.named_children():
|
|
314
|
+
need_merge = isinstance(submodule, LayerWiseMergedModel)
|
|
315
|
+
submodule = merge_and_unload(submodule)
|
|
316
|
+
if need_merge:
|
|
317
|
+
setattr(module, name, submodule)
|
|
318
|
+
return module
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def fix_other_parts(module: nn.Module):
|
|
322
|
+
"""
|
|
323
|
+
Sets all parameters in the module to not require gradients, except for the merge weights
|
|
324
|
+
in `LayerWiseMergedModel` instances.
|
|
325
|
+
|
|
326
|
+
Args:
|
|
327
|
+
module (nn.Module): The module to process.
|
|
328
|
+
|
|
329
|
+
Returns:
|
|
330
|
+
nn.Module: The module with updated parameter requirements.
|
|
331
|
+
"""
|
|
332
|
+
module.requires_grad_(False)
|
|
333
|
+
for submodule in module.modules():
|
|
334
|
+
if isinstance(submodule, LayerWiseMergedModel):
|
|
335
|
+
submodule.merge_weight.requires_grad_(True)
|
|
336
|
+
return module
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
R"""
|
|
2
|
+
```python
|
|
3
|
+
# Get the task-wise weights
|
|
4
|
+
task_wise_weights = get_task_wise_weights(num_models)
|
|
5
|
+
|
|
6
|
+
# Define the task vectors (in this case, we'll use the state_dict of the pretrained model)
|
|
7
|
+
task_vectors = ...
|
|
8
|
+
|
|
9
|
+
# Initialize the TaskWiseMergedModel
|
|
10
|
+
merged_model = TaskWiseMergedModel(pretrained_model, task_wise_weights, task_vectors)
|
|
11
|
+
|
|
12
|
+
# Now you can use the merged_model like a regular PyTorch model
|
|
13
|
+
outputs = merged_model(inputs)
|
|
14
|
+
```
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
import functools
|
|
18
|
+
import logging
|
|
19
|
+
from typing import Any, Callable, Dict, Generic, Iterator, List, Optional # noqa: F401
|
|
20
|
+
|
|
21
|
+
import torch
|
|
22
|
+
from torch import Tensor, nn
|
|
23
|
+
from torch.func import functional_call
|
|
24
|
+
|
|
25
|
+
from fusion_bench.utils.type import StateDictType, TorchModelType
|
|
26
|
+
|
|
27
|
+
log = logging.getLogger(__name__)
|
|
28
|
+
|
|
29
|
+
__all__ = ["get_task_wise_weights", "fuse_weights", "TaskWiseMergedModel"]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def del_attr(obj, names: List[str]):
|
|
33
|
+
"""
|
|
34
|
+
Deletes an attribute from an object recursively.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
obj (object): Object to delete attribute from.
|
|
38
|
+
names (list): List of attribute names to delete recursively.
|
|
39
|
+
"""
|
|
40
|
+
if len(names) == 1:
|
|
41
|
+
delattr(obj, names[0])
|
|
42
|
+
else:
|
|
43
|
+
del_attr(getattr(obj, names[0]), names[1:])
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def set_attr(obj, names: List[str], val):
|
|
47
|
+
"""
|
|
48
|
+
Sets an attribute of an object recursively.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
obj (object): Object to set attribute of.
|
|
52
|
+
names (list): List of attribute names to set recursively.
|
|
53
|
+
val (object): Value to set the attribute to.
|
|
54
|
+
"""
|
|
55
|
+
if len(names) == 1:
|
|
56
|
+
setattr(obj, names[0], val)
|
|
57
|
+
else:
|
|
58
|
+
set_attr(getattr(obj, names[0]), names[1:], val)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def get_attr(obj, names: List[str]):
|
|
62
|
+
"""
|
|
63
|
+
Gets an attribute of an object recursively.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
obj (object): Object to get attribute of.
|
|
67
|
+
names (list): List of attribute names to get recursively.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
object: The attribute of the object.
|
|
71
|
+
"""
|
|
72
|
+
if len(names) == 1:
|
|
73
|
+
return getattr(obj, names[0])
|
|
74
|
+
else:
|
|
75
|
+
return get_attr(getattr(obj, names[0]), names[1:])
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def check_parameterNamesMatch(checkpoints: List[StateDictType]) -> None:
|
|
79
|
+
"""
|
|
80
|
+
Checks that the parameter names of the given checkpoints match.
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
checkpoints (List[Dict[str, float]]): A list of checkpoints, where each checkpoint is a dictionary of parameter names and their corresponding values.
|
|
84
|
+
|
|
85
|
+
Raises:
|
|
86
|
+
ValueError: If the number of checkpoints is less than 2 or if the parameter names of any two checkpoints differ.
|
|
87
|
+
|
|
88
|
+
"""
|
|
89
|
+
parameter_names = set(checkpoints[0].keys())
|
|
90
|
+
|
|
91
|
+
if len(checkpoints) >= 2:
|
|
92
|
+
# raise ValueError("Number of models is less than 2.")
|
|
93
|
+
for checkpoint in checkpoints[1:]:
|
|
94
|
+
current_parameterNames = set(checkpoint.keys())
|
|
95
|
+
if current_parameterNames != parameter_names:
|
|
96
|
+
raise ValueError(
|
|
97
|
+
"Differing parameter names in models. "
|
|
98
|
+
f"The different parameters are {parameter_names.symmetric_difference(current_parameterNames)}"
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def get_task_wise_weights(num_models: int, init_values: float = None):
|
|
103
|
+
"""
|
|
104
|
+
This function generates a tensor of weights for each model.
|
|
105
|
+
|
|
106
|
+
Args:
|
|
107
|
+
num_models (int): The number of models.
|
|
108
|
+
init_values (float, optional): The initial value for each weight. Defaults to None.
|
|
109
|
+
|
|
110
|
+
Returns:
|
|
111
|
+
Tensor: A tensor of weights for each model.
|
|
112
|
+
"""
|
|
113
|
+
assert num_models >= 1, f"num_models must be >= 1, got {num_models}"
|
|
114
|
+
if init_values is None:
|
|
115
|
+
init_values = 1.0 / num_models
|
|
116
|
+
return torch.full((num_models,), init_values, dtype=torch.float32)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _fuse_weights(task_wise_weight: Tensor, tensors: List[Tensor]):
|
|
120
|
+
"""
|
|
121
|
+
This function fuses the weights of the models.
|
|
122
|
+
|
|
123
|
+
Args:
|
|
124
|
+
task_wise_weight (Tensor): The weights for each model.
|
|
125
|
+
tensors (List[Tensor]): The list of tensors to be fused.
|
|
126
|
+
|
|
127
|
+
Returns:
|
|
128
|
+
Tensor: The fused weights.
|
|
129
|
+
"""
|
|
130
|
+
device = task_wise_weight.device
|
|
131
|
+
return sum(task_wise_weight[i] * w.to(device) for i, w in enumerate(tensors))
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def fuse_weights(
|
|
135
|
+
task_wise_weight: Tensor, state_dicts: List[StateDictType]
|
|
136
|
+
) -> StateDictType:
|
|
137
|
+
"""
|
|
138
|
+
This function fuses the weights of the models and returns a state dictionary.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
task_wise_weight (Tensor): The weights for each model. on cuda or cpu.
|
|
142
|
+
state_dicts (List[StateDictType]): The list of state dictionaries. on cpu.
|
|
143
|
+
|
|
144
|
+
Returns:
|
|
145
|
+
StateDictType: The fused state dictionary.
|
|
146
|
+
"""
|
|
147
|
+
num_models = len(state_dicts)
|
|
148
|
+
assert (
|
|
149
|
+
task_wise_weight.dim() == 1
|
|
150
|
+
), f"task_wise_weight must be a 1D tensor, got {task_wise_weight.dim()}"
|
|
151
|
+
assert num_models == task_wise_weight.size(
|
|
152
|
+
0
|
|
153
|
+
), f"num_models must be equal to the number of state_dicts, got {num_models} and {task_wise_weight.size(0)}"
|
|
154
|
+
return {
|
|
155
|
+
k: _fuse_weights(task_wise_weight, [sd[k] for sd in state_dicts])
|
|
156
|
+
for k in state_dicts[0].keys()
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class TaskWiseMergedModel(nn.Module, Generic[TorchModelType]):
|
|
161
|
+
_merged_state_dict: StateDictType = None
|
|
162
|
+
|
|
163
|
+
def __init__(
|
|
164
|
+
self,
|
|
165
|
+
task_wise_weight: Tensor,
|
|
166
|
+
pretrained_model: TorchModelType,
|
|
167
|
+
finetuned_models: List[TorchModelType],
|
|
168
|
+
clamp_weights: bool = True,
|
|
169
|
+
tie_weights: bool = False,
|
|
170
|
+
strict: bool = True,
|
|
171
|
+
task_vector_dtype: Optional[torch.dtype] = None,
|
|
172
|
+
):
|
|
173
|
+
super().__init__()
|
|
174
|
+
self.clamp_weights = clamp_weights
|
|
175
|
+
self.tie_weights = tie_weights
|
|
176
|
+
self.strict = strict
|
|
177
|
+
self.task_vector_dtype = task_vector_dtype
|
|
178
|
+
|
|
179
|
+
self.merge_weight = nn.Parameter(task_wise_weight, requires_grad=True)
|
|
180
|
+
|
|
181
|
+
for name, param in pretrained_model.named_parameters():
|
|
182
|
+
if not param.requires_grad:
|
|
183
|
+
for m in finetuned_models:
|
|
184
|
+
del_attr(m, name.split("."))
|
|
185
|
+
else:
|
|
186
|
+
for m in finetuned_models:
|
|
187
|
+
get_attr(m, name.split(".")).data = (
|
|
188
|
+
get_attr(m, name.split(".")) - param
|
|
189
|
+
)
|
|
190
|
+
self.pretrained_model = pretrained_model.requires_grad_(False)
|
|
191
|
+
for m in finetuned_models:
|
|
192
|
+
m.requires_grad_(False)
|
|
193
|
+
self.task_vectors = nn.ModuleList(finetuned_models)
|
|
194
|
+
if self.task_vector_dtype is not None:
|
|
195
|
+
self.task_vectors = self.task_vectors.to(self.task_vector_dtype)
|
|
196
|
+
|
|
197
|
+
@property
|
|
198
|
+
def forward_model(self):
|
|
199
|
+
return functools.partial(
|
|
200
|
+
functional_call,
|
|
201
|
+
self.pretrained_model,
|
|
202
|
+
self._merged_state_dict,
|
|
203
|
+
tie_weights=self.tie_weights,
|
|
204
|
+
strict=self.strict,
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
def merge_weights(self, task_vector_mask: Optional[Dict[str, Tensor]] = None):
|
|
208
|
+
if self.clamp_weights:
|
|
209
|
+
merge_weight = self.merge_weight.clamp(0, 1)
|
|
210
|
+
else:
|
|
211
|
+
merge_weight = self.merge_weight
|
|
212
|
+
|
|
213
|
+
state_dict = self.pretrained_model.state_dict(keep_vars=True)
|
|
214
|
+
for weight, task_vector in zip(merge_weight, self.task_vectors):
|
|
215
|
+
for name, param in task_vector.named_parameters():
|
|
216
|
+
if task_vector_mask is None:
|
|
217
|
+
w = weight
|
|
218
|
+
else:
|
|
219
|
+
w = weight * task_vector_mask[name]
|
|
220
|
+
state_dict[name] = state_dict[name] + param * w
|
|
221
|
+
self._merged_state_dict = state_dict
|
|
222
|
+
return state_dict
|
|
223
|
+
|
|
224
|
+
def merge_and_unload(self, task_vector_mask: Optional[Dict[str, Tensor]] = None):
|
|
225
|
+
self.merge_weights(task_vector_mask=task_vector_mask)
|
|
226
|
+
self.pretrained_model.load_state_dict(self._merged_state_dict)
|
|
227
|
+
return self.pretrained_model
|
|
228
|
+
|
|
229
|
+
def forward(self, *args, **kwargs):
|
|
230
|
+
if self._merged_state_dict is None:
|
|
231
|
+
self.merge_weights()
|
|
232
|
+
return self.forward_model(args=args, kwargs=kwargs)
|
|
233
|
+
|
|
234
|
+
# def __getattr__(self, name: str) -> Any:
|
|
235
|
+
# try:
|
|
236
|
+
# return super().__getattr__(name)
|
|
237
|
+
# except AttributeError:
|
|
238
|
+
# attr = getattr(self.pretrained_model, name)
|
|
239
|
+
# if isinstance(attr, Callable):
|
|
240
|
+
# warnings.warn(
|
|
241
|
+
# f"forwarding `{name}` to the underlying model", UserWarning
|
|
242
|
+
# )
|
|
243
|
+
# return attr
|
|
244
|
+
|
|
245
|
+
# def __setattr__(self, name: str, value: Any) -> None:
|
|
246
|
+
# try:
|
|
247
|
+
# super().__setattr__(name, value)
|
|
248
|
+
# except AttributeError:
|
|
249
|
+
# setattr(self.pretrained_model, name, value)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
class NoSparseGradientError(Exception):
|
|
2
|
+
"""Raised when the gradient is sparse gradient.
|
|
3
|
+
|
|
4
|
+
:param optimizer_name: str. optimizer name.
|
|
5
|
+
:param note: str. special conditions to note (default '').
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
def __init__(self, optimizer_name: str, note: str = ""):
|
|
9
|
+
self.note: str = " " if not note else f" w/ {note} "
|
|
10
|
+
self.message: str = (
|
|
11
|
+
f"[-] {optimizer_name}{self.note}does not support sparse gradient."
|
|
12
|
+
)
|
|
13
|
+
super().__init__(self.message)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ZeroParameterSizeError(Exception):
|
|
17
|
+
"""Raised when the parameter size is 0."""
|
|
18
|
+
|
|
19
|
+
def __init__(self):
|
|
20
|
+
self.message: str = "[-] parameter size is 0"
|
|
21
|
+
super().__init__(self.message)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class NoClosureError(Exception):
|
|
25
|
+
"""Raised when there's no closure function."""
|
|
26
|
+
|
|
27
|
+
def __init__(self, optimizer_name: str, note: str = ""):
|
|
28
|
+
self.message: str = f"[-] {optimizer_name} requires closure.{note}"
|
|
29
|
+
super().__init__(self.message)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class NegativeLRError(Exception):
|
|
33
|
+
"""Raised when learning rate is negative."""
|
|
34
|
+
|
|
35
|
+
def __init__(self, lr: float, lr_type: str = ""):
|
|
36
|
+
self.note: str = lr_type if lr_type else "learning rate"
|
|
37
|
+
self.message: str = f"[-] {self.note} must be positive. ({lr} > 0)"
|
|
38
|
+
super().__init__(self.message)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class NegativeStepError(Exception):
|
|
42
|
+
"""Raised when step is negative."""
|
|
43
|
+
|
|
44
|
+
def __init__(self, num_steps: int, step_type: str = ""):
|
|
45
|
+
self.note: str = step_type if step_type else "step"
|
|
46
|
+
self.message: str = f"[-] {self.note} must be positive. ({num_steps} > 0)"
|
|
47
|
+
super().__init__(self.message)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .linear_warmup import *
|