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,573 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
from copy import deepcopy
|
|
4
|
+
from typing import Dict, List, Tuple # noqa: F401
|
|
5
|
+
|
|
6
|
+
import torch
|
|
7
|
+
import torch.nn.functional as F
|
|
8
|
+
from omegaconf import OmegaConf
|
|
9
|
+
from torch import Tensor, nn
|
|
10
|
+
from tqdm.auto import tqdm
|
|
11
|
+
|
|
12
|
+
from fusion_bench.method import BaseAlgorithm
|
|
13
|
+
from fusion_bench.method.simple_average import simple_average
|
|
14
|
+
from fusion_bench.mixins.simple_profiler import SimpleProfilerMixin
|
|
15
|
+
from fusion_bench.modelpool import BaseModelPool
|
|
16
|
+
from fusion_bench.models.utils import get_attr, set_attr
|
|
17
|
+
from fusion_bench.utils.parameters import print_parameters
|
|
18
|
+
|
|
19
|
+
log = logging.getLogger(__name__)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ExpertNotTrainedError(Exception):
|
|
23
|
+
pass
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _is_all_zeros(tensor: Tensor | List[Tensor]) -> bool:
|
|
27
|
+
"""
|
|
28
|
+
Check if a tensor or a list of tensors are all zeros.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
tensor (Tensor | List[Tensor]): A tensor or a list of tensors.
|
|
32
|
+
|
|
33
|
+
Returns:
|
|
34
|
+
bool: True if all elements are zeros, False otherwise.
|
|
35
|
+
"""
|
|
36
|
+
if isinstance(tensor, Tensor):
|
|
37
|
+
return torch.allclose(tensor, torch.zeros_like(tensor))
|
|
38
|
+
else:
|
|
39
|
+
return all(_is_all_zeros(t) for t in tensor)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _svd(w: Tensor, full_matrices=True) -> Tuple[Tensor, Tensor, Tensor]:
|
|
43
|
+
"""
|
|
44
|
+
Perform Singular Value Decomposition (SVD) on a tensor.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
w (Tensor): The input tensor.
|
|
48
|
+
full_matrices (bool): Whether to compute the full-sized U and V matrices.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
Tuple[Tensor, Tensor, Tensor]: The U, S, and V matrices from SVD.
|
|
52
|
+
"""
|
|
53
|
+
u, s, vh = torch.linalg.svd(
|
|
54
|
+
w, full_matrices=full_matrices, driver="gesvd" if w.is_cuda else None
|
|
55
|
+
)
|
|
56
|
+
v = vh.T
|
|
57
|
+
return u, s, v
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def svd(
|
|
61
|
+
w: Tensor, full_matrices=True, accelerator=None
|
|
62
|
+
) -> Tuple[Tensor, Tensor, Tensor]:
|
|
63
|
+
"""
|
|
64
|
+
Perform SVD on a tensor, optionally using a specified accelerator.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
w (Tensor): The input tensor.
|
|
68
|
+
full_matrices (bool): Whether to compute the full-sized U and V matrices.
|
|
69
|
+
accelerator (str): The device to perform the computation on.
|
|
70
|
+
|
|
71
|
+
Returns:
|
|
72
|
+
Tuple[Tensor, Tensor, Tensor]: The U, S, and V matrices from SVD.
|
|
73
|
+
"""
|
|
74
|
+
if accelerator is None:
|
|
75
|
+
return _svd(w, full_matrices=full_matrices)
|
|
76
|
+
original_device = w.device
|
|
77
|
+
w = w.to(accelerator)
|
|
78
|
+
u, s, v = _svd(w)
|
|
79
|
+
return u.to(original_device), s.to(original_device), v.to(original_device)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class SmileGate(nn.Module):
|
|
83
|
+
def __init__(
|
|
84
|
+
self,
|
|
85
|
+
input_features: int,
|
|
86
|
+
w_diff_list: List[Tensor],
|
|
87
|
+
k: int,
|
|
88
|
+
svd_list=None, # cached `svd_list`, pass it to avoid recomputing
|
|
89
|
+
upscaling_accelerator=None,
|
|
90
|
+
):
|
|
91
|
+
"""
|
|
92
|
+
Initialize the SmileGate module.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
input_features (int): The number of input features.
|
|
96
|
+
w_diff_list (List[Tensor]): A list of weight difference tensors.
|
|
97
|
+
k (int): The number of singular values to keep.
|
|
98
|
+
svd_list (List[Tuple[Tensor, Tensor, Tensor]]): Cached SVD results.
|
|
99
|
+
upscaling_accelerator (str): The device to perform the computation on.
|
|
100
|
+
"""
|
|
101
|
+
super().__init__()
|
|
102
|
+
self.input_features = input_features
|
|
103
|
+
self.num_experts = len(w_diff_list)
|
|
104
|
+
weights = []
|
|
105
|
+
for i, w_diff in enumerate(w_diff_list):
|
|
106
|
+
if svd_list is None:
|
|
107
|
+
u, s, v = svd(w_diff, accelerator=upscaling_accelerator)
|
|
108
|
+
else:
|
|
109
|
+
u, s, v = svd_list[i]
|
|
110
|
+
u = u[:, :k]
|
|
111
|
+
s = s[:k]
|
|
112
|
+
v = v[:, :k]
|
|
113
|
+
|
|
114
|
+
# weights.append((s * v).T)
|
|
115
|
+
weights.append(v.T)
|
|
116
|
+
self.k = s.size(0) # k is the actual k after truncation
|
|
117
|
+
|
|
118
|
+
weights = (
|
|
119
|
+
torch.stack(weights, dim=0)
|
|
120
|
+
.reshape(self.num_experts * self.k, -1)
|
|
121
|
+
.contiguous()
|
|
122
|
+
)
|
|
123
|
+
self.weights = nn.Parameter(
|
|
124
|
+
weights
|
|
125
|
+
) # weights should be a tensor of shape (num_experts * k, n)
|
|
126
|
+
|
|
127
|
+
def forward(self, x: Tensor):
|
|
128
|
+
"""
|
|
129
|
+
Forward pass of the SmileGate module.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
x (Tensor): The input tensor.
|
|
133
|
+
|
|
134
|
+
Returns:
|
|
135
|
+
Tensor: The routing weights.
|
|
136
|
+
"""
|
|
137
|
+
batch_size = x.size(0)
|
|
138
|
+
if self.num_experts == 1:
|
|
139
|
+
return torch.ones(batch_size, 1, device=x.device, dtype=x.dtype)
|
|
140
|
+
|
|
141
|
+
routing_weights = F.linear(x, self.weights).view(
|
|
142
|
+
batch_size, self.num_experts, self.k
|
|
143
|
+
)
|
|
144
|
+
routing_weights = routing_weights.norm(p=2, dim=2)
|
|
145
|
+
return routing_weights
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
class SmileCompressedLinear(nn.Module):
|
|
149
|
+
def __init__(self, model: nn.Linear, k: int, svd_cache=None):
|
|
150
|
+
"""
|
|
151
|
+
Initialize the SmileCompressedLinear module.
|
|
152
|
+
|
|
153
|
+
Args:
|
|
154
|
+
model (nn.Linear): The linear model to compress.
|
|
155
|
+
k (int): The number of singular values to keep.
|
|
156
|
+
svd_cache (Tuple[Tensor, Tensor, Tensor]): Cached SVD results.
|
|
157
|
+
"""
|
|
158
|
+
super().__init__()
|
|
159
|
+
if svd_cache is None:
|
|
160
|
+
u, s, v = svd(model.weight)
|
|
161
|
+
else:
|
|
162
|
+
u, s, v = svd_cache
|
|
163
|
+
if k > 0:
|
|
164
|
+
u = u[:, :k]
|
|
165
|
+
s = s[:k]
|
|
166
|
+
v = v[:, :k]
|
|
167
|
+
|
|
168
|
+
self.u = nn.Parameter(u)
|
|
169
|
+
self.svh = nn.Parameter((s * v).T)
|
|
170
|
+
|
|
171
|
+
if model.bias is not None:
|
|
172
|
+
self.bias = nn.Parameter(model.bias.data, requires_grad=True)
|
|
173
|
+
else:
|
|
174
|
+
self.register_parameter("bias", None)
|
|
175
|
+
|
|
176
|
+
def forward(self, x):
|
|
177
|
+
"""
|
|
178
|
+
Forward pass of the SmileCompressedLinear module.
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
x (Tensor): The input tensor.
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
Tensor: The output tensor.
|
|
185
|
+
"""
|
|
186
|
+
x = F.linear(x, self.svh)
|
|
187
|
+
x = F.linear(x, self.u, self.bias)
|
|
188
|
+
return x
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
class SmileMoELinear(nn.Module):
|
|
192
|
+
@torch.no_grad()
|
|
193
|
+
def __init__(
|
|
194
|
+
self,
|
|
195
|
+
pretrained_model: nn.Linear,
|
|
196
|
+
finetuned_models: List[nn.Linear],
|
|
197
|
+
gate_k: int,
|
|
198
|
+
k: int,
|
|
199
|
+
top_k: int = 1,
|
|
200
|
+
full_matrices=True,
|
|
201
|
+
upscaling_accelerator=None,
|
|
202
|
+
routing_use_diff=True,
|
|
203
|
+
):
|
|
204
|
+
"""
|
|
205
|
+
Initialize the SmileMoELinear module.
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
pretrained_model (nn.Linear): The pretrained linear model.
|
|
209
|
+
finetuned_models (List[nn.Linear]): A list of fine-tuned linear models.
|
|
210
|
+
gate_k (int): The number of singular values to keep for the gate.
|
|
211
|
+
k (int): The number of singular values to keep for the experts.
|
|
212
|
+
top_k (int): The number of top experts to select.
|
|
213
|
+
full_matrices (bool): Whether to compute the full-sized U and V matrices.
|
|
214
|
+
upscaling_accelerator (str): The device to perform the computation on.
|
|
215
|
+
routing_use_diff (bool): Whether to use weight differences for routing.
|
|
216
|
+
"""
|
|
217
|
+
super().__init__()
|
|
218
|
+
self.num_experts = len(finetuned_models)
|
|
219
|
+
self.top_k = top_k
|
|
220
|
+
self.k = k
|
|
221
|
+
self.gate_k = gate_k
|
|
222
|
+
self.in_features = pretrained_model.in_features
|
|
223
|
+
self.out_features = pretrained_model.out_features
|
|
224
|
+
|
|
225
|
+
w_diff_list = [m.weight - pretrained_model.weight for m in finetuned_models]
|
|
226
|
+
if _is_all_zeros(w_diff_list):
|
|
227
|
+
# All fine-tuned models are identical to the pretrained model
|
|
228
|
+
raise ExpertNotTrainedError()
|
|
229
|
+
|
|
230
|
+
if routing_use_diff or k > 0:
|
|
231
|
+
svd_cache_list = [
|
|
232
|
+
svd(w, full_matrices=full_matrices, accelerator=upscaling_accelerator)
|
|
233
|
+
for w in w_diff_list
|
|
234
|
+
] # the svd cache list to avoid recomputing
|
|
235
|
+
|
|
236
|
+
# construct the gate network
|
|
237
|
+
if routing_use_diff:
|
|
238
|
+
self.gate = SmileGate(
|
|
239
|
+
input_features=self.in_features,
|
|
240
|
+
w_diff_list=w_diff_list,
|
|
241
|
+
k=gate_k,
|
|
242
|
+
svd_list=svd_cache_list,
|
|
243
|
+
upscaling_accelerator=upscaling_accelerator,
|
|
244
|
+
)
|
|
245
|
+
else:
|
|
246
|
+
self.gate = SmileGate(
|
|
247
|
+
input_features=self.in_features,
|
|
248
|
+
w_diff_list=[m.weight for m in finetuned_models],
|
|
249
|
+
k=gate_k,
|
|
250
|
+
svd_list=None,
|
|
251
|
+
upscaling_accelerator=upscaling_accelerator,
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
# construct experts
|
|
255
|
+
for m, w_diff in zip(finetuned_models, w_diff_list):
|
|
256
|
+
m.weight.data = w_diff
|
|
257
|
+
if k > 0:
|
|
258
|
+
experts = [
|
|
259
|
+
SmileCompressedLinear(m, k, svd_cache=svd_cache)
|
|
260
|
+
for m, svd_cache in zip(finetuned_models, svd_cache_list)
|
|
261
|
+
]
|
|
262
|
+
else:
|
|
263
|
+
# if k is not set (<0), we use the full fine-tuned model
|
|
264
|
+
experts = finetuned_models
|
|
265
|
+
self.experts = nn.ModuleList(experts)
|
|
266
|
+
|
|
267
|
+
if pretrained_model.bias is not None:
|
|
268
|
+
for m in experts:
|
|
269
|
+
m.bias.data = m.bias.data - pretrained_model.bias
|
|
270
|
+
# assign the pretrained model (the shared part)
|
|
271
|
+
self.pretrained_model = pretrained_model
|
|
272
|
+
|
|
273
|
+
def forward(self, hidden_states: Tensor):
|
|
274
|
+
"""
|
|
275
|
+
Forward pass of the SmileMoELinear module.
|
|
276
|
+
|
|
277
|
+
Args:
|
|
278
|
+
hidden_states (Tensor): The input tensor.
|
|
279
|
+
|
|
280
|
+
Returns:
|
|
281
|
+
Tensor: The output tensor.
|
|
282
|
+
"""
|
|
283
|
+
pretrained_out = self.pretrained_model(hidden_states)
|
|
284
|
+
|
|
285
|
+
input_shape = hidden_states.size()
|
|
286
|
+
hidden_states = hidden_states.view(-1, self.in_features)
|
|
287
|
+
|
|
288
|
+
router_logits = self.gate(hidden_states)
|
|
289
|
+
routing_weights = F.softmax(router_logits, dim=1)
|
|
290
|
+
# sample the expert according to the routing weights
|
|
291
|
+
routing_weights, selected_experts = torch.topk(
|
|
292
|
+
routing_weights, self.top_k, dim=-1
|
|
293
|
+
)
|
|
294
|
+
routing_weights /= routing_weights.sum(dim=-1, keepdim=True)
|
|
295
|
+
|
|
296
|
+
final_hidden_states = torch.zeros(
|
|
297
|
+
(hidden_states.size(0), self.out_features),
|
|
298
|
+
dtype=hidden_states.dtype,
|
|
299
|
+
device=hidden_states.device,
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
# One hot encode the selected experts to create an expert mask
|
|
303
|
+
# this will be used to easily index which expert is going to be sollicitated
|
|
304
|
+
expert_mask = torch.nn.functional.one_hot(
|
|
305
|
+
selected_experts, num_classes=self.num_experts
|
|
306
|
+
).permute(2, 1, 0)
|
|
307
|
+
|
|
308
|
+
# Loop over all available experts in the model and perform the computation on each expert
|
|
309
|
+
for expert_idx in range(self.num_experts):
|
|
310
|
+
expert_layer = self.experts[expert_idx]
|
|
311
|
+
idx, top_x = torch.where(expert_mask[expert_idx])
|
|
312
|
+
|
|
313
|
+
# Index the correct hidden states and compute the expert hidden state for
|
|
314
|
+
# the current expert. We need to make sure to multiply the output hidden
|
|
315
|
+
# states by `routing_weights` on the corresponding tokens (top-1 and top-2)
|
|
316
|
+
current_state = hidden_states[None, top_x].reshape(-1, self.in_features)
|
|
317
|
+
if current_state.numel() == 0:
|
|
318
|
+
continue
|
|
319
|
+
current_hidden_states = (
|
|
320
|
+
expert_layer(current_state) * routing_weights[top_x, idx, None]
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
# However `index_add_` only support torch tensors for indexing so we'll use
|
|
324
|
+
# the `top_x` tensor here.
|
|
325
|
+
final_hidden_states.index_add_(
|
|
326
|
+
0, top_x, current_hidden_states.to(hidden_states.dtype)
|
|
327
|
+
)
|
|
328
|
+
final_hidden_states = final_hidden_states.reshape(
|
|
329
|
+
*input_shape[:-1], self.out_features
|
|
330
|
+
)
|
|
331
|
+
final_hidden_states = pretrained_out + final_hidden_states
|
|
332
|
+
return final_hidden_states
|
|
333
|
+
|
|
334
|
+
@property
|
|
335
|
+
def weight(self):
|
|
336
|
+
"""
|
|
337
|
+
Mimic linear layer. Bacause in some cases, user might indicate the device (or dtype of parameters) of the linear layer using `linear_layer.weight.device`
|
|
338
|
+
"""
|
|
339
|
+
return self.pretrained_model.weight
|
|
340
|
+
|
|
341
|
+
@property
|
|
342
|
+
def bias(self):
|
|
343
|
+
return self.pretrained_model.bias
|
|
344
|
+
|
|
345
|
+
def __repr__(self):
|
|
346
|
+
return (
|
|
347
|
+
f"SingularMoELinear("
|
|
348
|
+
f"in_features={self.pretrained_model.in_features}, "
|
|
349
|
+
f"out_features={self.pretrained_model.out_features}, "
|
|
350
|
+
f"num_experts={self.num_experts}, "
|
|
351
|
+
f"top_k={self.top_k}, "
|
|
352
|
+
f"gate_k={self.gate_k}, "
|
|
353
|
+
f"k={self.k}"
|
|
354
|
+
f")"
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
class SmileUpscalingAlgorithm(
|
|
359
|
+
SimpleProfilerMixin,
|
|
360
|
+
BaseAlgorithm,
|
|
361
|
+
):
|
|
362
|
+
_linear_layer_cls = (nn.Linear,)
|
|
363
|
+
_config_mapping = BaseAlgorithm._config_mapping | {
|
|
364
|
+
"device": "device",
|
|
365
|
+
"upscaling_accelerator": "upscaling_accelerator",
|
|
366
|
+
"full_matrices": "full_matrices",
|
|
367
|
+
"gate_k": "gate_k",
|
|
368
|
+
"k": "k",
|
|
369
|
+
"top_k": "top_k",
|
|
370
|
+
"routing_use_diff": "routing_use_diff",
|
|
371
|
+
"average_experts": "average_experts",
|
|
372
|
+
"model_path": "model_path",
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
def __init__(
|
|
376
|
+
self,
|
|
377
|
+
*,
|
|
378
|
+
device: str = "cuda",
|
|
379
|
+
upscaling_accelerator: str = None,
|
|
380
|
+
full_matrices: bool = True,
|
|
381
|
+
gate_k: int = 256,
|
|
382
|
+
k: int = 256,
|
|
383
|
+
top_k: int = 1,
|
|
384
|
+
routing_use_diff: bool = True,
|
|
385
|
+
average_experts: bool = False,
|
|
386
|
+
model_path: str = None,
|
|
387
|
+
**kwargs,
|
|
388
|
+
):
|
|
389
|
+
"""
|
|
390
|
+
Initialize the SmileUpscalingAlgorithm.
|
|
391
|
+
|
|
392
|
+
Args:
|
|
393
|
+
device (str): The device to perform the computation on.
|
|
394
|
+
upscaling_accelerator (str): The device to perform the SVD computation on.
|
|
395
|
+
full_matrices (bool): Whether to compute the full-sized U and V matrices.
|
|
396
|
+
gate_k (int): The number of singular values to keep for the gate.
|
|
397
|
+
k (int): The number of singular values to keep for the experts.
|
|
398
|
+
top_k (int): The number of top experts to select.
|
|
399
|
+
routing_use_diff (bool): Whether to use weight differences for routing.
|
|
400
|
+
average_experts (bool): Whether to average the experts.
|
|
401
|
+
model_path (str): The path to save/load the model.
|
|
402
|
+
**kwargs: Additional arguments.
|
|
403
|
+
"""
|
|
404
|
+
super().__init__()
|
|
405
|
+
self.device = device
|
|
406
|
+
self.upscaling_accelerator = upscaling_accelerator
|
|
407
|
+
self.full_matrices = full_matrices
|
|
408
|
+
self.gate_k = gate_k
|
|
409
|
+
self.k = k
|
|
410
|
+
self.top_k = top_k
|
|
411
|
+
self.routing_use_diff = routing_use_diff
|
|
412
|
+
self.average_experts = average_experts
|
|
413
|
+
self.model_path = model_path
|
|
414
|
+
for key, value in kwargs.items():
|
|
415
|
+
log.warning(f"Unrecognized argument: {key}")
|
|
416
|
+
setattr(self, key, value)
|
|
417
|
+
|
|
418
|
+
# print `self.config` as yaml
|
|
419
|
+
print(f"=== Config for `{type(self).__name__}` ===")
|
|
420
|
+
print(OmegaConf.to_yaml(self.config))
|
|
421
|
+
print(f"=== Config for `{type(self).__name__}` ===")
|
|
422
|
+
|
|
423
|
+
@torch.no_grad()
|
|
424
|
+
def run(self, modelpool: BaseModelPool):
|
|
425
|
+
"""
|
|
426
|
+
Executes the upscaling process.
|
|
427
|
+
|
|
428
|
+
Args:
|
|
429
|
+
modelpool (ModelPool): The pool of models to be used for upscaling.
|
|
430
|
+
|
|
431
|
+
Returns:
|
|
432
|
+
nn.Module: The upscaled model.
|
|
433
|
+
"""
|
|
434
|
+
if not isinstance(modelpool, BaseModelPool):
|
|
435
|
+
modelpool = BaseModelPool(modelpool)
|
|
436
|
+
|
|
437
|
+
if self.config.model_path is not None and os.path.exists(
|
|
438
|
+
self.config.model_path
|
|
439
|
+
):
|
|
440
|
+
log.info(f"Loading model from {self.config.model_path}")
|
|
441
|
+
model = torch.load(self.config.model_path)
|
|
442
|
+
print_parameters(model)
|
|
443
|
+
return model
|
|
444
|
+
|
|
445
|
+
with self.profile("load pretrained model"):
|
|
446
|
+
pretrained_model = modelpool.load_model("_pretrained_")
|
|
447
|
+
with self.profile("load fine-tuned model"):
|
|
448
|
+
finetuned_models = [
|
|
449
|
+
m for m in tqdm(modelpool.models(), total=len(modelpool.model_names))
|
|
450
|
+
]
|
|
451
|
+
|
|
452
|
+
if self.config.device == "cuda" and torch.cuda.is_available():
|
|
453
|
+
pretrained_model = pretrained_model.cuda()
|
|
454
|
+
finetuned_models = [m.cuda() for m in finetuned_models]
|
|
455
|
+
|
|
456
|
+
with self.profile("merge model"):
|
|
457
|
+
model = self.merge(pretrained_model, finetuned_models)
|
|
458
|
+
|
|
459
|
+
self.print_profile_summary()
|
|
460
|
+
if self.config.model_path is not None:
|
|
461
|
+
os.makedirs(os.path.dirname(self.config.model_path), exist_ok=True)
|
|
462
|
+
log.info(f"Saving model to {self.config.model_path}")
|
|
463
|
+
torch.save(model, self.config.model_path)
|
|
464
|
+
print_parameters(model)
|
|
465
|
+
return model
|
|
466
|
+
|
|
467
|
+
def merge(
|
|
468
|
+
self,
|
|
469
|
+
pretrained_model: nn.Module,
|
|
470
|
+
finetuned_models: List[nn.Module],
|
|
471
|
+
in_place: bool = True,
|
|
472
|
+
):
|
|
473
|
+
"""
|
|
474
|
+
Merges the pretrained model with the fine-tuned models to create an upscaled model.
|
|
475
|
+
|
|
476
|
+
Args:
|
|
477
|
+
pretrained_model (nn.Module): The pretrained model.
|
|
478
|
+
finetuned_models (List[nn.Module]): A list of fine-tuned models.
|
|
479
|
+
in_place (bool): If True, modifies the pretrained model in place. Otherwise, creates a copy.
|
|
480
|
+
|
|
481
|
+
Returns:
|
|
482
|
+
nn.Module: The merged model.
|
|
483
|
+
"""
|
|
484
|
+
if in_place:
|
|
485
|
+
model = pretrained_model
|
|
486
|
+
else:
|
|
487
|
+
model = deepcopy(pretrained_model)
|
|
488
|
+
|
|
489
|
+
self._upscale_submodules(model, finetuned_models)
|
|
490
|
+
return model
|
|
491
|
+
|
|
492
|
+
def _upscale_linear_layer(
|
|
493
|
+
self,
|
|
494
|
+
pretrained_model,
|
|
495
|
+
finetuned_models,
|
|
496
|
+
name: str,
|
|
497
|
+
):
|
|
498
|
+
"""
|
|
499
|
+
Upscale a linear layer by merging it with the corresponding layers from the fine-tuned models.
|
|
500
|
+
|
|
501
|
+
Args:
|
|
502
|
+
pretrained_model (nn.Module): The pretrained model.
|
|
503
|
+
finetuned_models (List[nn.Module]): A list of fine-tuned models.
|
|
504
|
+
name (str): The name of the linear layer to upscale.
|
|
505
|
+
"""
|
|
506
|
+
config = self.config
|
|
507
|
+
|
|
508
|
+
name_list = name.split(".")
|
|
509
|
+
module = get_attr(pretrained_model, name_list)
|
|
510
|
+
experts = [get_attr(m, name_list) for m in finetuned_models]
|
|
511
|
+
try:
|
|
512
|
+
moe_linear = SmileMoELinear(
|
|
513
|
+
module,
|
|
514
|
+
experts,
|
|
515
|
+
gate_k=config.gate_k,
|
|
516
|
+
k=config.k,
|
|
517
|
+
top_k=config.top_k,
|
|
518
|
+
routing_use_diff=self.routing_use_diff,
|
|
519
|
+
full_matrices=self.full_matrices,
|
|
520
|
+
upscaling_accelerator=self.upscaling_accelerator,
|
|
521
|
+
)
|
|
522
|
+
except ExpertNotTrainedError:
|
|
523
|
+
print(f"skip {name} because the experts are not trained.")
|
|
524
|
+
return
|
|
525
|
+
set_attr(pretrained_model, name_list, moe_linear)
|
|
526
|
+
# remove the original module from fine-tuned models to save memory
|
|
527
|
+
for m in finetuned_models:
|
|
528
|
+
set_attr(m, name_list, None)
|
|
529
|
+
|
|
530
|
+
def _average_experts(self, pretarined_model, finetuned_models, name: str):
|
|
531
|
+
"""
|
|
532
|
+
Average the experts for a given layer.
|
|
533
|
+
|
|
534
|
+
Args:
|
|
535
|
+
pretarined_model (nn.Module): The pretrained model.
|
|
536
|
+
finetuned_models (List[nn.Module]): A list of fine-tuned models.
|
|
537
|
+
name (str): The name of the layer to average.
|
|
538
|
+
"""
|
|
539
|
+
name_list = name.split(".")
|
|
540
|
+
experts = [get_attr(m, name_list) for m in finetuned_models]
|
|
541
|
+
averaged_module = simple_average(experts)
|
|
542
|
+
set_attr(pretarined_model, name_list, averaged_module)
|
|
543
|
+
|
|
544
|
+
def _upscale_submodules(
|
|
545
|
+
self,
|
|
546
|
+
pretrained_model: nn.Module,
|
|
547
|
+
finetuned_models: List[nn.Module],
|
|
548
|
+
tqdm_desc: str = "Upscaling Linear Modules",
|
|
549
|
+
):
|
|
550
|
+
"""
|
|
551
|
+
Upscales the submodules of the pretrained model by merging them with the corresponding submodules from the fine-tuned models.
|
|
552
|
+
|
|
553
|
+
Args:
|
|
554
|
+
pretrained_model (nn.Module): The pretrained model.
|
|
555
|
+
finetuned_models (List[nn.Module]): A list of fine-tuned models.
|
|
556
|
+
tqdm_desc (str): Description for the tqdm progress bar.
|
|
557
|
+
"""
|
|
558
|
+
config = self.config
|
|
559
|
+
for name, module in tqdm(
|
|
560
|
+
tuple(pretrained_model.named_modules()),
|
|
561
|
+
tqdm_desc,
|
|
562
|
+
leave=False,
|
|
563
|
+
dynamic_ncols=True,
|
|
564
|
+
):
|
|
565
|
+
if isinstance(module, self._linear_layer_cls):
|
|
566
|
+
self._upscale_linear_layer(
|
|
567
|
+
pretrained_model=pretrained_model,
|
|
568
|
+
finetuned_models=finetuned_models,
|
|
569
|
+
name=name,
|
|
570
|
+
)
|
|
571
|
+
elif config.average_experts and len(tuple(module.named_modules())) == 1:
|
|
572
|
+
# if the module is a leaf module, we perform a parameter average
|
|
573
|
+
self._average_experts(pretrained_model, finetuned_models, name)
|