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,99 @@
|
|
|
1
|
+
from typing import Literal
|
|
2
|
+
|
|
3
|
+
import torch.nn as nn
|
|
4
|
+
|
|
5
|
+
from . import resnet
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ResnetDilated(nn.Module):
|
|
9
|
+
def __init__(self, orig_resnet, dilate_scale=8):
|
|
10
|
+
super(ResnetDilated, self).__init__()
|
|
11
|
+
from functools import partial
|
|
12
|
+
|
|
13
|
+
if dilate_scale == 8:
|
|
14
|
+
orig_resnet.layer3.apply(partial(self._nostride_dilate, dilate=2))
|
|
15
|
+
orig_resnet.layer4.apply(partial(self._nostride_dilate, dilate=4))
|
|
16
|
+
elif dilate_scale == 16:
|
|
17
|
+
orig_resnet.layer4.apply(partial(self._nostride_dilate, dilate=2))
|
|
18
|
+
|
|
19
|
+
# take pre-defined ResNet, except AvgPool and FC
|
|
20
|
+
self.conv1 = orig_resnet.conv1
|
|
21
|
+
self.bn1 = orig_resnet.bn1
|
|
22
|
+
self.relu = orig_resnet.relu
|
|
23
|
+
|
|
24
|
+
self.maxpool = orig_resnet.maxpool
|
|
25
|
+
self.layer1 = orig_resnet.layer1
|
|
26
|
+
self.layer2 = orig_resnet.layer2
|
|
27
|
+
self.layer3 = orig_resnet.layer3
|
|
28
|
+
self.layer4 = orig_resnet.layer4
|
|
29
|
+
|
|
30
|
+
self.feature_dim = orig_resnet.feature_dim
|
|
31
|
+
|
|
32
|
+
def _nostride_dilate(self, m, dilate):
|
|
33
|
+
classname = m.__class__.__name__
|
|
34
|
+
if classname.find("Conv") != -1:
|
|
35
|
+
# the convolution with stride
|
|
36
|
+
if m.stride == (2, 2):
|
|
37
|
+
m.stride = (1, 1)
|
|
38
|
+
if m.kernel_size == (3, 3):
|
|
39
|
+
m.dilation = (dilate // 2, dilate // 2)
|
|
40
|
+
m.padding = (dilate // 2, dilate // 2)
|
|
41
|
+
# other convoluions
|
|
42
|
+
else:
|
|
43
|
+
if m.kernel_size == (3, 3):
|
|
44
|
+
m.dilation = (dilate, dilate)
|
|
45
|
+
m.padding = (dilate, dilate)
|
|
46
|
+
|
|
47
|
+
def forward(self, x):
|
|
48
|
+
x = self.relu(self.bn1(self.conv1(x)))
|
|
49
|
+
x = self.maxpool(x)
|
|
50
|
+
|
|
51
|
+
x = self.layer1(x)
|
|
52
|
+
x = self.layer2(x)
|
|
53
|
+
x = self.layer3(x)
|
|
54
|
+
x = self.layer4(x)
|
|
55
|
+
return x
|
|
56
|
+
|
|
57
|
+
def forward_stage(self, x, stage):
|
|
58
|
+
assert stage in [
|
|
59
|
+
"conv",
|
|
60
|
+
"layer1",
|
|
61
|
+
"layer2",
|
|
62
|
+
"layer3",
|
|
63
|
+
"layer4",
|
|
64
|
+
"layer1_without_conv",
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
if stage == "conv":
|
|
68
|
+
x = self.relu(self.bn1(self.conv1(x)))
|
|
69
|
+
x = self.maxpool(x)
|
|
70
|
+
return x
|
|
71
|
+
|
|
72
|
+
elif stage == "layer1":
|
|
73
|
+
x = self.relu(self.bn1(self.conv1(x)))
|
|
74
|
+
x = self.maxpool(x)
|
|
75
|
+
x = self.layer1(x)
|
|
76
|
+
return x
|
|
77
|
+
|
|
78
|
+
elif stage == "layer1_without_conv":
|
|
79
|
+
x = self.layer1(x)
|
|
80
|
+
return x
|
|
81
|
+
|
|
82
|
+
else: # Stage 2, 3 or 4
|
|
83
|
+
layer = getattr(self, stage)
|
|
84
|
+
return layer(x)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def resnet_dilated(
|
|
88
|
+
basenet: str, pretrained: bool = True, dilate_scale: Literal[8, 16] = 8
|
|
89
|
+
):
|
|
90
|
+
r"""Dilated Residual Network models from `"Dilated Residual Networks" <https://openaccess.thecvf.com/content_cvpr_2017/papers/Yu_Dilated_Residual_Networks_CVPR_2017_paper.pdf>`_
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
basenet (str): The type of ResNet.
|
|
94
|
+
pretrained (bool): If True, returns a model pre-trained on ImageNet.
|
|
95
|
+
dilate_scale ({8, 16}, default=8): The type of dilating process.
|
|
96
|
+
"""
|
|
97
|
+
return ResnetDilated(
|
|
98
|
+
resnet.__dict__[basenet](pretrained=pretrained), dilate_scale=dilate_scale
|
|
99
|
+
)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
from typing import List, Mapping
|
|
2
|
+
|
|
3
|
+
import torch
|
|
4
|
+
from torch import nn
|
|
5
|
+
|
|
6
|
+
__all__ = "ParamterDictModel"
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def set_attr(obj, names: List[str], val, check_parent: bool = False):
|
|
10
|
+
"""
|
|
11
|
+
Sets an attribute of an object recursively.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
obj (object): Object to set attribute of.
|
|
15
|
+
names (list): List of attribute names to set recursively.
|
|
16
|
+
val (object): Value to set the attribute to.
|
|
17
|
+
check_parent (bool): If True, checks if the parent attribute exists; otherwise, creates it if it does not exist.
|
|
18
|
+
"""
|
|
19
|
+
if len(names) == 1:
|
|
20
|
+
setattr(obj, names[0], val)
|
|
21
|
+
else:
|
|
22
|
+
if check_parent and not hasattr(obj, names[0]):
|
|
23
|
+
setattr(obj, names[0], nn.Module())
|
|
24
|
+
set_attr(getattr(obj, names[0]), names[1:], val, check_parent=check_parent)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def has_attr(obj, names: List[str]):
|
|
28
|
+
"""
|
|
29
|
+
Checks if an attribute exists in an object recursively.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
obj (object): Object to check attribute of.
|
|
33
|
+
names (list): List of attribute names to check recursively.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
bool: True if the attribute exists; otherwise, False.
|
|
37
|
+
"""
|
|
38
|
+
if len(names) == 1:
|
|
39
|
+
return hasattr(obj, names[0])
|
|
40
|
+
else:
|
|
41
|
+
return has_attr(getattr(obj, names[0]), names[1:])
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class ParameterDictModel(nn.Module):
|
|
45
|
+
"""
|
|
46
|
+
This model is used to create a model with parameters from a dictionary.
|
|
47
|
+
It behaves like a normal `nn.ParameterDict`, but support keys with dots.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
def __init__(
|
|
51
|
+
self,
|
|
52
|
+
parameters: Mapping[str, nn.Parameter],
|
|
53
|
+
):
|
|
54
|
+
super().__init__()
|
|
55
|
+
for name, param in parameters.items():
|
|
56
|
+
assert isinstance(param, nn.Parameter), f"{name} is not a nn.Parameter"
|
|
57
|
+
set_attr(
|
|
58
|
+
self,
|
|
59
|
+
name.split("."),
|
|
60
|
+
param,
|
|
61
|
+
check_parent=True,
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
def __repr__(self):
|
|
65
|
+
"""
|
|
66
|
+
Generate a string representation of the model's parameters.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
str: A string representation of the model's parameters.
|
|
70
|
+
"""
|
|
71
|
+
param_reprs = []
|
|
72
|
+
for name, param in self.named_parameters():
|
|
73
|
+
param_repr = f"{name}: {param.size()}"
|
|
74
|
+
param_reprs.append(param_repr)
|
|
75
|
+
return f"{self.__class__.__name__}({', '.join(param_reprs)})"
|
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
import logging
|
|
3
|
+
from typing import Dict, List, Tuple # noqa: F401
|
|
4
|
+
|
|
5
|
+
import torch
|
|
6
|
+
import torch.func
|
|
7
|
+
from torch import Tensor, nn
|
|
8
|
+
from torch.func import functional_call
|
|
9
|
+
from torch.nn import functional as F
|
|
10
|
+
|
|
11
|
+
from fusion_bench.utils.type import StateDictType
|
|
12
|
+
|
|
13
|
+
log = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def join_list(list_of_list: List[List]):
|
|
17
|
+
ans = []
|
|
18
|
+
for l in list_of_list:
|
|
19
|
+
ans.extend(l)
|
|
20
|
+
return ans
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def del_attr(obj, names: List[str]):
|
|
24
|
+
"""
|
|
25
|
+
Deletes an attribute from an object recursively.
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
obj (object): Object to delete attribute from.
|
|
29
|
+
names (list): List of attribute names to delete recursively.
|
|
30
|
+
"""
|
|
31
|
+
if len(names) == 1:
|
|
32
|
+
delattr(obj, names[0])
|
|
33
|
+
else:
|
|
34
|
+
del_attr(getattr(obj, names[0]), names[1:])
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def set_attr(obj, names: List[str], val):
|
|
38
|
+
"""
|
|
39
|
+
Sets an attribute of an object recursively.
|
|
40
|
+
|
|
41
|
+
Args:
|
|
42
|
+
obj (object): Object to set attribute of.
|
|
43
|
+
names (list): List of attribute names to set recursively.
|
|
44
|
+
val (object): Value to set the attribute to.
|
|
45
|
+
"""
|
|
46
|
+
if len(names) == 1:
|
|
47
|
+
setattr(obj, names[0], val)
|
|
48
|
+
else:
|
|
49
|
+
set_attr(getattr(obj, names[0]), names[1:], val)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def get_attr(obj, names: List[str]):
|
|
53
|
+
"""
|
|
54
|
+
Gets an attribute of an object recursively.
|
|
55
|
+
|
|
56
|
+
Args:
|
|
57
|
+
obj (object): Object to get attribute of.
|
|
58
|
+
names (list): List of attribute names to get recursively.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
object: The attribute of the object.
|
|
62
|
+
"""
|
|
63
|
+
if len(names) == 1:
|
|
64
|
+
return getattr(obj, names[0])
|
|
65
|
+
else:
|
|
66
|
+
return get_attr(getattr(obj, names[0]), names[1:])
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class Depth_0_Gate(nn.Module):
|
|
70
|
+
def __init__(self, num_experts: int):
|
|
71
|
+
super().__init__()
|
|
72
|
+
self.weight = nn.Parameter(torch.empty(num_experts), requires_grad=True)
|
|
73
|
+
|
|
74
|
+
def init_weight(self, init_lambda: float):
|
|
75
|
+
nn.init.constant_(self.weight, init_lambda)
|
|
76
|
+
|
|
77
|
+
def forward(self, *args, **kwargs) -> Tensor:
|
|
78
|
+
return self.weight
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class Depth_1_Gate(nn.Module):
|
|
82
|
+
def __init__(self, hidden_size: int, num_experts: int):
|
|
83
|
+
super().__init__()
|
|
84
|
+
self.fc = nn.Linear(hidden_size, num_experts, bias=True)
|
|
85
|
+
|
|
86
|
+
def init_weight(self, init_lambda: float):
|
|
87
|
+
nn.init.normal_(self.fc.weight, std=0.01)
|
|
88
|
+
nn.init.constant_(self.fc.bias, init_lambda)
|
|
89
|
+
|
|
90
|
+
def forward(self, hidden_states: Tensor) -> Tensor:
|
|
91
|
+
return self.fc(hidden_states)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class Depth_2_Gate(nn.Module):
|
|
95
|
+
def __init__(self, hidden_size: int, num_experts: int):
|
|
96
|
+
super().__init__()
|
|
97
|
+
self.fc1 = nn.Linear(hidden_size, num_experts * 2, bias=True)
|
|
98
|
+
self.fc2 = nn.Linear(num_experts * 2, num_experts, bias=True)
|
|
99
|
+
|
|
100
|
+
def init_weight(self, init_lambda: float):
|
|
101
|
+
nn.init.normal_(self.fc1.weight, std=0.01)
|
|
102
|
+
nn.init.zeros_(self.fc1.bias)
|
|
103
|
+
nn.init.normal_(self.fc2.weight, std=0.01)
|
|
104
|
+
nn.init.constant_(self.fc2.bias, init_lambda)
|
|
105
|
+
|
|
106
|
+
def forward(self, hidden_states: Tensor) -> Tensor:
|
|
107
|
+
hidden_states = F.relu(self.fc1(hidden_states))
|
|
108
|
+
return self.fc2(hidden_states)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def construct_rankone_moe_gate(
|
|
112
|
+
hidden_size: int,
|
|
113
|
+
num_experts: int,
|
|
114
|
+
init_lambda: float,
|
|
115
|
+
num_hidden_layers: int = 2,
|
|
116
|
+
):
|
|
117
|
+
if num_hidden_layers == 0:
|
|
118
|
+
gate = Depth_0_Gate(num_experts)
|
|
119
|
+
elif num_hidden_layers == 1:
|
|
120
|
+
gate = Depth_1_Gate(hidden_size, num_experts)
|
|
121
|
+
elif num_hidden_layers == 2:
|
|
122
|
+
gate = Depth_2_Gate(hidden_size, num_experts)
|
|
123
|
+
else:
|
|
124
|
+
raise ValueError(f"Unsupported number of hidden layers: {num_hidden_layers}")
|
|
125
|
+
|
|
126
|
+
gate.num_hidden_layers = num_hidden_layers
|
|
127
|
+
gate.init_weight(init_lambda)
|
|
128
|
+
return gate
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class ExpertNotTrainedError(Exception):
|
|
132
|
+
pass
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _is_all_zeros(tensor: Tensor | List[Tensor]) -> bool:
|
|
136
|
+
"""
|
|
137
|
+
Check if a tensor or a list of tensors are all zeros.
|
|
138
|
+
"""
|
|
139
|
+
if isinstance(tensor, Tensor):
|
|
140
|
+
return torch.allclose(tensor, torch.zeros_like(tensor))
|
|
141
|
+
else:
|
|
142
|
+
return all(_is_all_zeros(t) for t in tensor)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _svd(w: Tensor, full_matrices=True) -> Tuple[Tensor, Tensor, Tensor]:
|
|
146
|
+
"""
|
|
147
|
+
Perform Singular Value Decomposition (SVD) on a tensor.
|
|
148
|
+
"""
|
|
149
|
+
u, s, vh = torch.linalg.svd(
|
|
150
|
+
w, full_matrices=full_matrices, driver="gesvd" if w.is_cuda else None
|
|
151
|
+
)
|
|
152
|
+
v = vh.T
|
|
153
|
+
return u, s, v
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def svd(
|
|
157
|
+
w: Tensor, full_matrices=True, accelerator=None
|
|
158
|
+
) -> Tuple[Tensor, Tensor, Tensor]:
|
|
159
|
+
"""
|
|
160
|
+
Perform SVD on a tensor, optionally using a specified accelerator.
|
|
161
|
+
"""
|
|
162
|
+
if accelerator is None:
|
|
163
|
+
return _svd(w, full_matrices=full_matrices)
|
|
164
|
+
original_device = w.device
|
|
165
|
+
w = w.to(accelerator)
|
|
166
|
+
u, s, v = _svd(w)
|
|
167
|
+
return u.to(original_device), s.to(original_device), v.to(original_device)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def fun_joint_svd(
|
|
171
|
+
w_list: List[Tensor], accelerator=None
|
|
172
|
+
) -> Tuple[Tensor, Tensor, Tensor]:
|
|
173
|
+
|
|
174
|
+
w = torch.cat(w_list, dim=1) # stacked_matrix
|
|
175
|
+
original_device = w.device
|
|
176
|
+
if accelerator is not None:
|
|
177
|
+
w = w.to(accelerator)
|
|
178
|
+
u_c, s_c, vh_c = torch.linalg.svd(
|
|
179
|
+
w, full_matrices=False, driver="gesvd" if w.is_cuda else None
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
svd_list = []
|
|
183
|
+
offset = 0
|
|
184
|
+
for matrix in w_list:
|
|
185
|
+
n_cols = matrix.size(1)
|
|
186
|
+
u = u_c
|
|
187
|
+
s = s_c
|
|
188
|
+
vh_ = vh_c[:, offset : offset + n_cols]
|
|
189
|
+
v = vh_.T
|
|
190
|
+
svd_list.append(
|
|
191
|
+
[u.to(original_device), s.to(original_device), v.to(original_device)]
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
offset += n_cols
|
|
195
|
+
return svd_list
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
class RankOneMoE(nn.Module):
|
|
199
|
+
# variable to store the merged state dict temporarily
|
|
200
|
+
_merged_state_dict: StateDictType = None
|
|
201
|
+
|
|
202
|
+
def __init__(
|
|
203
|
+
self,
|
|
204
|
+
hidden_size: int,
|
|
205
|
+
base_model: nn.Module,
|
|
206
|
+
expert_models: List[nn.Module],
|
|
207
|
+
init_lambda: float = 0.2,
|
|
208
|
+
batch_first: bool = False,
|
|
209
|
+
router_hidden_layers: int = 2,
|
|
210
|
+
batch_reduce: bool = False,
|
|
211
|
+
svd_accelerator=False,
|
|
212
|
+
rank_k: int = -1,
|
|
213
|
+
select_k: int = -1,
|
|
214
|
+
):
|
|
215
|
+
"""
|
|
216
|
+
Initializes the RankOneMoE class.
|
|
217
|
+
https://github.com/EnnengYang/RankOne-MoE
|
|
218
|
+
|
|
219
|
+
Args:
|
|
220
|
+
hidden_size (int): The size of the hidden layer in the models.
|
|
221
|
+
base_model (nn.Module): The base model that will be used as a reference for the expert models.
|
|
222
|
+
expert_models (List[nn.Module]): A list of expert models that will be combined.
|
|
223
|
+
init_lambda (float, optional): The initial lambda value for the weight ensembling gate. Defaults to 0.2.
|
|
224
|
+
batch_first (bool, optional): If True, the input tensors are expected to have the batch size as the first dimension. Defaults to False.
|
|
225
|
+
router_hidden_layers (int, optional): The number of hidden layers in the router. Defaults to 2.
|
|
226
|
+
batch_reduce (bool): If True, the batch dimension of routing weights is reduced. Defaults to False.
|
|
227
|
+
"""
|
|
228
|
+
super().__init__()
|
|
229
|
+
self.num_experts = len(expert_models)
|
|
230
|
+
self.hidden_size = hidden_size
|
|
231
|
+
self.batch_first = batch_first
|
|
232
|
+
self.batch_reduce = batch_reduce
|
|
233
|
+
self.svd_accelerator = svd_accelerator
|
|
234
|
+
self.rank_k = rank_k
|
|
235
|
+
self.select_k = select_k
|
|
236
|
+
self.init_lambda = init_lambda
|
|
237
|
+
|
|
238
|
+
self.gate = construct_rankone_moe_gate(
|
|
239
|
+
hidden_size=hidden_size,
|
|
240
|
+
num_experts=int(self.num_experts * self.rank_k),
|
|
241
|
+
init_lambda=init_lambda,
|
|
242
|
+
num_hidden_layers=router_hidden_layers,
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
# compute the task vectors
|
|
246
|
+
for name, param in base_model.named_parameters():
|
|
247
|
+
if not param.requires_grad:
|
|
248
|
+
for m in expert_models:
|
|
249
|
+
del_attr(m, name.split("."))
|
|
250
|
+
else:
|
|
251
|
+
for m in expert_models:
|
|
252
|
+
get_attr(m, name.split(".")).data = (
|
|
253
|
+
get_attr(m, name.split(".")) - param
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
# fix base model and expert models
|
|
257
|
+
self.base_model = base_model.requires_grad_(False)
|
|
258
|
+
for m in expert_models:
|
|
259
|
+
m.requires_grad_(False)
|
|
260
|
+
|
|
261
|
+
# task vecotr (only bias term)
|
|
262
|
+
self.task_vectors_fc1_bias = nn.Parameter(
|
|
263
|
+
torch.stack([e.fc1.bias for e in expert_models], dim=0), requires_grad=False
|
|
264
|
+
)
|
|
265
|
+
self.task_vectors_fc2_bias = nn.Parameter(
|
|
266
|
+
torch.stack([e.fc2.bias for e in expert_models], dim=0), requires_grad=False
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
# SVD representation of task vector (only weight term)
|
|
270
|
+
self.task_vectors_fc1_u = nn.ParameterList()
|
|
271
|
+
self.task_vectors_fc1_svh = nn.ParameterList()
|
|
272
|
+
self.task_vectors_fc2_u = nn.ParameterList()
|
|
273
|
+
self.task_vectors_fc2_svh = nn.ParameterList()
|
|
274
|
+
|
|
275
|
+
for m in expert_models:
|
|
276
|
+
for name, param in m.named_parameters():
|
|
277
|
+
if ".weight" in name:
|
|
278
|
+
|
|
279
|
+
if _is_all_zeros(param):
|
|
280
|
+
# All fine-tuned models are identical to the pretrained model
|
|
281
|
+
raise ExpertNotTrainedError()
|
|
282
|
+
|
|
283
|
+
u, s, v = svd(param, accelerator=self.svd_accelerator)
|
|
284
|
+
u = u[:, : self.rank_k]
|
|
285
|
+
s = s[: self.rank_k]
|
|
286
|
+
v = v[:, : self.rank_k]
|
|
287
|
+
|
|
288
|
+
if "fc1.weight" == name:
|
|
289
|
+
self.task_vectors_fc1_u.append(
|
|
290
|
+
nn.Parameter(u.T, requires_grad=False)
|
|
291
|
+
)
|
|
292
|
+
self.task_vectors_fc1_svh.append(
|
|
293
|
+
nn.Parameter((s * v).T, requires_grad=False)
|
|
294
|
+
)
|
|
295
|
+
elif "fc2.weight" == name:
|
|
296
|
+
self.task_vectors_fc2_u.append(
|
|
297
|
+
nn.Parameter(u.T, requires_grad=False)
|
|
298
|
+
)
|
|
299
|
+
self.task_vectors_fc2_svh.append(
|
|
300
|
+
nn.Parameter((s * v).T, requires_grad=False)
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
# remove the original module from fine-tuned models to save memory
|
|
304
|
+
for name, param in base_model.named_parameters():
|
|
305
|
+
name_list = name.split(".")
|
|
306
|
+
for m in expert_models:
|
|
307
|
+
set_attr(m, name_list, None)
|
|
308
|
+
|
|
309
|
+
@property
|
|
310
|
+
def forward_model(self):
|
|
311
|
+
return functools.partial(
|
|
312
|
+
functional_call,
|
|
313
|
+
self.base_model,
|
|
314
|
+
self._merged_state_dict,
|
|
315
|
+
)
|
|
316
|
+
|
|
317
|
+
def top_k_soft(self, s, k):
|
|
318
|
+
threshold, _ = torch.topk(s, k, largest=True, sorted=False)
|
|
319
|
+
min_threshold = threshold.min()
|
|
320
|
+
# sigmoid -> mask
|
|
321
|
+
mask = torch.sigmoid(100 * (s - min_threshold))
|
|
322
|
+
result = s * mask
|
|
323
|
+
return result
|
|
324
|
+
|
|
325
|
+
def merge_weights(self, expert_weights):
|
|
326
|
+
state_dict = self.base_model.state_dict(keep_vars=True)
|
|
327
|
+
|
|
328
|
+
# Select top-k experts from the expert pool for fusion
|
|
329
|
+
if self.select_k > 0:
|
|
330
|
+
expert_weights = self.top_k_soft(expert_weights, self.select_k)
|
|
331
|
+
|
|
332
|
+
for name in state_dict:
|
|
333
|
+
if name == "fc1.bias":
|
|
334
|
+
for param in self.task_vectors_fc1_bias:
|
|
335
|
+
state_dict[name] = state_dict[name] + self.init_lambda * param
|
|
336
|
+
elif name == "fc2.bias":
|
|
337
|
+
for param in self.task_vectors_fc2_bias:
|
|
338
|
+
state_dict[name] = state_dict[name] + self.init_lambda * param
|
|
339
|
+
|
|
340
|
+
elif name == "fc1.weight":
|
|
341
|
+
w_list = torch.split(
|
|
342
|
+
expert_weights,
|
|
343
|
+
int(expert_weights.size(-1) / self.num_experts),
|
|
344
|
+
dim=-1,
|
|
345
|
+
)
|
|
346
|
+
for weight, u, svh in zip(
|
|
347
|
+
w_list, self.task_vectors_fc1_u, self.task_vectors_fc1_svh
|
|
348
|
+
):
|
|
349
|
+
weight_diag = torch.diag(weight)
|
|
350
|
+
weight_u = torch.mm(weight_diag, u)
|
|
351
|
+
result = torch.matmul(weight_u.T, svh)
|
|
352
|
+
state_dict[name] = state_dict[name] + result
|
|
353
|
+
|
|
354
|
+
elif name == "fc2.weight":
|
|
355
|
+
w_list = torch.split(
|
|
356
|
+
expert_weights,
|
|
357
|
+
int(expert_weights.size(-1) / self.num_experts),
|
|
358
|
+
dim=-1,
|
|
359
|
+
)
|
|
360
|
+
for weight, u, svh in zip(
|
|
361
|
+
w_list, self.task_vectors_fc2_u, self.task_vectors_fc2_svh
|
|
362
|
+
):
|
|
363
|
+
weight_diag = torch.diag(weight)
|
|
364
|
+
weight_u = torch.mm(weight_diag, u)
|
|
365
|
+
result = torch.matmul(weight_u.T, svh)
|
|
366
|
+
state_dict[name] = state_dict[name] + result
|
|
367
|
+
|
|
368
|
+
self._merged_state_dict = state_dict
|
|
369
|
+
return state_dict
|
|
370
|
+
|
|
371
|
+
def forward(self, hidden_states: Tensor):
|
|
372
|
+
if self.gate.num_hidden_layers == 0:
|
|
373
|
+
gate_weights = self.gate()
|
|
374
|
+
else:
|
|
375
|
+
gate_weights = self.gate(hidden_states)
|
|
376
|
+
if self.batch_first:
|
|
377
|
+
# the input is in the shape of (batch_size, seq_len, hidden_size)
|
|
378
|
+
gate_weights = gate_weights.mean(dim=1)
|
|
379
|
+
else:
|
|
380
|
+
# the input is in the shape of (seq_len, batch_size, hidden_size)
|
|
381
|
+
gate_weights = gate_weights.mean(dim=0)
|
|
382
|
+
|
|
383
|
+
if self.gate.num_hidden_layers == 0:
|
|
384
|
+
self.merge_weights(gate_weights)
|
|
385
|
+
output_hidden_states = self.forward_model(hidden_states)
|
|
386
|
+
elif self.batch_reduce:
|
|
387
|
+
gate_weights = gate_weights.mean(dim=0)
|
|
388
|
+
self.merge_weights(gate_weights)
|
|
389
|
+
output_hidden_states = self.forward_model(hidden_states)
|
|
390
|
+
else:
|
|
391
|
+
output_hidden_states = []
|
|
392
|
+
for sample_idx, weights in enumerate(gate_weights):
|
|
393
|
+
self.merge_weights(weights)
|
|
394
|
+
if self.batch_first:
|
|
395
|
+
output_hidden_states.append(
|
|
396
|
+
self.forward_model(hidden_states[sample_idx : sample_idx + 1])
|
|
397
|
+
)
|
|
398
|
+
else:
|
|
399
|
+
output_hidden_states.append(
|
|
400
|
+
self.forward_model(
|
|
401
|
+
hidden_states[:, sample_idx : sample_idx + 1]
|
|
402
|
+
)
|
|
403
|
+
)
|
|
404
|
+
if self.batch_first:
|
|
405
|
+
output_hidden_states = torch.cat(output_hidden_states, dim=0)
|
|
406
|
+
else:
|
|
407
|
+
output_hidden_states = torch.cat(output_hidden_states, dim=1)
|
|
408
|
+
|
|
409
|
+
self._merged_state_dict = None
|
|
410
|
+
return output_hidden_states
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from copy import deepcopy
|
|
3
|
+
|
|
4
|
+
import torch
|
|
5
|
+
from safetensors import safe_open
|
|
6
|
+
from safetensors.torch import save_file
|
|
7
|
+
from torch import nn
|
|
8
|
+
|
|
9
|
+
from fusion_bench.utils.dtype import parse_dtype
|
|
10
|
+
|
|
11
|
+
__all__ = ["separate_save", "separate_load"]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def dir_is_empty(path: str) -> bool:
|
|
15
|
+
return not os.path.exists(path) or len(os.listdir(path)) == 0
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def separate_save(
|
|
19
|
+
model: nn.Module,
|
|
20
|
+
save_dir: str,
|
|
21
|
+
dtype=None,
|
|
22
|
+
in_place: bool = True,
|
|
23
|
+
model_file="functional.bin",
|
|
24
|
+
state_dict_file="state_dict.bin",
|
|
25
|
+
use_safe_tensors: bool = True,
|
|
26
|
+
):
|
|
27
|
+
"""
|
|
28
|
+
Save the model's architecture and state dictionary separately.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
model (nn.Module): The PyTorch model to save.
|
|
32
|
+
save_dir (str): The directory where the model and state dictionary will be saved.
|
|
33
|
+
in_place (bool, optional): If True, the original model is modified. If False, a deepcopy of the model is used. Default is True.
|
|
34
|
+
model_file (str, optional): The name of the file to save the model's architecture. Default is "functional.bin".
|
|
35
|
+
state_dict_file (str, optional): The name of the file to save the model's state dictionary. Default is "state_dict.bin".
|
|
36
|
+
"""
|
|
37
|
+
if os.path.exists(save_dir) and not dir_is_empty(save_dir):
|
|
38
|
+
raise FileExistsError(f"Directory exists and is not empty. {save_dir}")
|
|
39
|
+
|
|
40
|
+
if not in_place:
|
|
41
|
+
model = deepcopy(model)
|
|
42
|
+
state_dict = {}
|
|
43
|
+
for name, param in model.state_dict().items():
|
|
44
|
+
state_dict[name] = param.clone().detach().to(dtype=dtype).cpu()
|
|
45
|
+
|
|
46
|
+
model = model.to_empty(device="meta")
|
|
47
|
+
|
|
48
|
+
if not os.path.exists(save_dir):
|
|
49
|
+
os.makedirs(save_dir)
|
|
50
|
+
torch.save(model, os.path.join(save_dir, model_file))
|
|
51
|
+
if not use_safe_tensors:
|
|
52
|
+
torch.save(state_dict, os.path.join(save_dir, state_dict_file))
|
|
53
|
+
else:
|
|
54
|
+
save_file(state_dict, os.path.join(save_dir, state_dict_file))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def separate_load(
|
|
58
|
+
load_dir: str,
|
|
59
|
+
strict: bool = True,
|
|
60
|
+
dtype: torch.dtype = None,
|
|
61
|
+
device: torch.device = "cpu",
|
|
62
|
+
model_file="functional.bin",
|
|
63
|
+
state_dict_file="state_dict.bin",
|
|
64
|
+
use_safe_tensors: bool = True,
|
|
65
|
+
):
|
|
66
|
+
"""
|
|
67
|
+
Load the model's architecture and state dictionary separately.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
load_dir (str): The directory from which the model and state dictionary will be loaded.
|
|
71
|
+
strict (bool, optional): Whether to strictly enforce that the keys in state_dict match the keys returned by model's state_dict() function. Default is True.
|
|
72
|
+
model_file (str, optional): The name of the file from which to load the model's architecture. Default is "functional.bin".
|
|
73
|
+
state_dict_file (str, optional): The name of the file from which to load the model's state dictionary. Default is "state_dict.bin".
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
nn.Module: The loaded PyTorch model with the state dictionary applied.
|
|
77
|
+
"""
|
|
78
|
+
if not os.path.exists(load_dir):
|
|
79
|
+
raise FileNotFoundError(f"Directory {load_dir} does not exist.")
|
|
80
|
+
dtype = parse_dtype(dtype)
|
|
81
|
+
|
|
82
|
+
model: nn.Module = (
|
|
83
|
+
torch.load(os.path.join(load_dir, model_file))
|
|
84
|
+
.to(dtype=dtype)
|
|
85
|
+
.to_empty(device=device or "cpu")
|
|
86
|
+
)
|
|
87
|
+
if state_dict_file is not None:
|
|
88
|
+
if not use_safe_tensors:
|
|
89
|
+
state_dict = torch.load(
|
|
90
|
+
os.path.join(load_dir, state_dict_file),
|
|
91
|
+
map_location="cpu",
|
|
92
|
+
)
|
|
93
|
+
else:
|
|
94
|
+
state_dict = {}
|
|
95
|
+
with safe_open(
|
|
96
|
+
os.path.join(load_dir, state_dict_file), framework="pt", device="cpu"
|
|
97
|
+
) as f:
|
|
98
|
+
for k in f.keys():
|
|
99
|
+
state_dict[k] = f.get_tensor(k)
|
|
100
|
+
if dtype is not None:
|
|
101
|
+
for name, param in state_dict.items():
|
|
102
|
+
state_dict[name] = param.to(dtype=dtype, non_blocking=True)
|
|
103
|
+
|
|
104
|
+
model.load_state_dict(state_dict, strict=strict)
|
|
105
|
+
return model
|
|
File without changes
|