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,274 @@
|
|
|
1
|
+
# NOTE: Working in progress.
|
|
2
|
+
import logging
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any, Literal, Optional, Union # noqa: F401
|
|
5
|
+
|
|
6
|
+
import torch
|
|
7
|
+
from omegaconf import DictConfig
|
|
8
|
+
from PIL.Image import Image
|
|
9
|
+
from torch import nn
|
|
10
|
+
from torch.utils.data import DataLoader
|
|
11
|
+
from tqdm.auto import tqdm
|
|
12
|
+
from transformers import (
|
|
13
|
+
AutoFeatureExtractor,
|
|
14
|
+
CLIPProcessor,
|
|
15
|
+
PreTrainedModel,
|
|
16
|
+
ResNetForImageClassification,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
from fusion_bench.dataset.clip_dataset import CLIPDataset
|
|
20
|
+
from fusion_bench.method import BaseAlgorithm
|
|
21
|
+
from fusion_bench.method.adamerging.entropy_loss import entropy_loss
|
|
22
|
+
from fusion_bench.mixins import CLIPClassificationMixin
|
|
23
|
+
from fusion_bench.modelpool import CLIPVisionModelPool
|
|
24
|
+
from fusion_bench.utils import timeit_context
|
|
25
|
+
from fusion_bench.utils.data import InfiniteDataLoader
|
|
26
|
+
from fusion_bench.utils.instantiate import instantiate
|
|
27
|
+
|
|
28
|
+
from .warppers.dawe_model import DataAdaptiveWeightEnsemblingCLIPVisionModel
|
|
29
|
+
|
|
30
|
+
log = logging.getLogger(__name__)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def convert_to_rgb(image: Image | list[Image]) -> Image | list[Image]:
|
|
34
|
+
if isinstance(image, (list, tuple)):
|
|
35
|
+
return [convert_to_rgb(img) for img in image]
|
|
36
|
+
else:
|
|
37
|
+
return image.convert("RGB")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def load_resnet_processor(pretrained_model_name_or_path: str):
|
|
41
|
+
"""
|
|
42
|
+
Load a ResNet processor for image preprocessing.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
pretrained_model_name_or_path (str): The path or name of the pretrained ResNet model.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
function: A function that processes images using the ResNet processor.
|
|
49
|
+
"""
|
|
50
|
+
processor = AutoFeatureExtractor.from_pretrained(pretrained_model_name_or_path)
|
|
51
|
+
return lambda img: processor(
|
|
52
|
+
images=convert_to_rgb(img), return_tensors="pt", do_rescale=False
|
|
53
|
+
).pixel_values
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class ResNetFeatureExtractor(nn.Module):
|
|
57
|
+
def __init__(self, pretrained_model_name_or_path):
|
|
58
|
+
super().__init__()
|
|
59
|
+
self.model = ResNetForImageClassification.from_pretrained(
|
|
60
|
+
pretrained_model_name_or_path
|
|
61
|
+
)
|
|
62
|
+
self.model.classifier = nn.Flatten(1, -1)
|
|
63
|
+
self.config = self.model.config
|
|
64
|
+
|
|
65
|
+
def forward(self, *args, **kwargs):
|
|
66
|
+
outputs = self.model(*args, **kwargs)
|
|
67
|
+
return outputs.logits
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def load_resnet_feature_extractor(pretrained_model_name_or_path: str):
|
|
71
|
+
model = ResNetFeatureExtractor(pretrained_model_name_or_path)
|
|
72
|
+
return model
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def raw_image_collate_fn(batch):
|
|
76
|
+
images, labels = tuple(zip(*batch))
|
|
77
|
+
labels = torch.as_tensor(labels)
|
|
78
|
+
return images, labels
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class DataAdaptiveWeightEnsemblingForCLIP(
|
|
82
|
+
BaseAlgorithm,
|
|
83
|
+
CLIPClassificationMixin,
|
|
84
|
+
):
|
|
85
|
+
modelpool: CLIPVisionModelPool
|
|
86
|
+
_processor: CLIPProcessor
|
|
87
|
+
|
|
88
|
+
def __init__(
|
|
89
|
+
self,
|
|
90
|
+
# merge options
|
|
91
|
+
merge_mode: Literal["task_wise", "layer_wise"],
|
|
92
|
+
init_lambda: float,
|
|
93
|
+
batch_reduce: bool,
|
|
94
|
+
eval_batch_reduce: bool,
|
|
95
|
+
# model options
|
|
96
|
+
dict_processor: DictConfig,
|
|
97
|
+
dict_feature_extractor: DictConfig,
|
|
98
|
+
hidden_size: Optional[int],
|
|
99
|
+
gate_hidden_layers: int,
|
|
100
|
+
task_vector_dtype: Optional[str | torch.dtype],
|
|
101
|
+
task_vector_sparsity: float,
|
|
102
|
+
# training & logging args
|
|
103
|
+
max_steps: int,
|
|
104
|
+
save_interval: int,
|
|
105
|
+
learning_rate: float = 1e-5,
|
|
106
|
+
skip_training: bool = False,
|
|
107
|
+
resume_checkpoint_path: Optional[str] = None,
|
|
108
|
+
# dataloader args
|
|
109
|
+
batch_size: int = 4,
|
|
110
|
+
num_workers: int = 0,
|
|
111
|
+
pin_memory: bool = True,
|
|
112
|
+
**kwargs,
|
|
113
|
+
):
|
|
114
|
+
# merge options
|
|
115
|
+
self.merge_mode = merge_mode
|
|
116
|
+
self.init_lambda = init_lambda
|
|
117
|
+
self.batch_reduce = batch_reduce
|
|
118
|
+
self.eval_batch_reduce = eval_batch_reduce
|
|
119
|
+
# model options
|
|
120
|
+
self._dict_processor = dict_processor
|
|
121
|
+
self._dict_feature_extractor = dict_feature_extractor
|
|
122
|
+
self.hidden_size = hidden_size
|
|
123
|
+
self.gate_hidden_layers = gate_hidden_layers
|
|
124
|
+
self.task_vector_dtype = task_vector_dtype
|
|
125
|
+
self.task_vector_sparsity = task_vector_sparsity
|
|
126
|
+
# training & logging args
|
|
127
|
+
self.max_steps = max_steps
|
|
128
|
+
self.save_interval = save_interval
|
|
129
|
+
self.learning_rate = learning_rate
|
|
130
|
+
self.skip_training = skip_training
|
|
131
|
+
self.resume_checkpoint_path = resume_checkpoint_path
|
|
132
|
+
# dataloader args
|
|
133
|
+
self.batch_size = batch_size
|
|
134
|
+
self.num_workers = num_workers
|
|
135
|
+
self.pin_memory = pin_memory
|
|
136
|
+
super().__init__(**kwargs)
|
|
137
|
+
|
|
138
|
+
def load_models(self):
|
|
139
|
+
modelpool = self.modelpool
|
|
140
|
+
|
|
141
|
+
dict_processor = instantiate(self._dict_processor)
|
|
142
|
+
clip_processor = modelpool.load_processor()
|
|
143
|
+
|
|
144
|
+
dict_feature_extractor: Union[PreTrainedModel, nn.Module] = instantiate(
|
|
145
|
+
self._dict_feature_extractor
|
|
146
|
+
)
|
|
147
|
+
if self.hidden_size is None:
|
|
148
|
+
# try to infer hidden size from feature extractor model
|
|
149
|
+
self.hidden_size = dict_feature_extractor.config.hidden_sizes[-1]
|
|
150
|
+
|
|
151
|
+
# initialize classification head
|
|
152
|
+
self.setup_zero_shot_classification_head(
|
|
153
|
+
clip_processor=clip_processor,
|
|
154
|
+
task_names=modelpool.model_names,
|
|
155
|
+
)
|
|
156
|
+
model = DataAdaptiveWeightEnsemblingCLIPVisionModel(
|
|
157
|
+
merge_mode=self.merge_mode,
|
|
158
|
+
hidden_size=self.hidden_size,
|
|
159
|
+
dict_processor=dict_processor,
|
|
160
|
+
model_processor=lambda images: clip_processor(
|
|
161
|
+
images=images, return_tensors="pt"
|
|
162
|
+
).pixel_values,
|
|
163
|
+
collate_fn=lambda outputs: torch.cat(
|
|
164
|
+
[out.pooler_output for out in outputs], dim=0
|
|
165
|
+
),
|
|
166
|
+
dict_feature_extractor=dict_feature_extractor,
|
|
167
|
+
base_model=modelpool.load_model("_pretrained_"),
|
|
168
|
+
expert_models=list(modelpool.models()),
|
|
169
|
+
task_vector_dtype=self.task_vector_dtype,
|
|
170
|
+
task_vector_sparsity=self.task_vector_sparsity,
|
|
171
|
+
init_lambda=self.init_lambda,
|
|
172
|
+
gate_hidden_layers=self.gate_hidden_layers,
|
|
173
|
+
batch_reduce=self.batch_reduce,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
if self.resume_checkpoint_path is not None:
|
|
177
|
+
self.fabric.load(self.resume_checkpoint_path, {"model": model})
|
|
178
|
+
return model
|
|
179
|
+
|
|
180
|
+
def load_datasets(self):
|
|
181
|
+
modelpool = self.modelpool
|
|
182
|
+
self.test_datasets = {
|
|
183
|
+
task_name: CLIPDataset(
|
|
184
|
+
modelpool.load_test_dataset(task_name),
|
|
185
|
+
processor=None, # NOTE: processor is not used in CLIPDataset because feature extractor and model may have different processors, so we want to pass the image as is
|
|
186
|
+
)
|
|
187
|
+
for task_name in modelpool.model_names
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
# setup dataloaders for test-time adaptation training
|
|
191
|
+
|
|
192
|
+
dataloader_kwargs = {
|
|
193
|
+
"batch_size": self.batch_size,
|
|
194
|
+
"num_workers": self.num_workers,
|
|
195
|
+
"pin_memory": self.pin_memory,
|
|
196
|
+
}
|
|
197
|
+
self.shuffled_test_loaders = {
|
|
198
|
+
task_name: self.fabric.setup_dataloaders(
|
|
199
|
+
DataLoader(
|
|
200
|
+
test_dataset,
|
|
201
|
+
**dataloader_kwargs,
|
|
202
|
+
collate_fn=raw_image_collate_fn,
|
|
203
|
+
shuffle=True,
|
|
204
|
+
)
|
|
205
|
+
)
|
|
206
|
+
for task_name, test_dataset in self.test_datasets.items()
|
|
207
|
+
}
|
|
208
|
+
self.shuffled_test_loader_iters = {
|
|
209
|
+
task_name: InfiniteDataLoader(loader)
|
|
210
|
+
for task_name, loader in self.shuffled_test_loaders.items()
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
def run(self, modelpool: CLIPVisionModelPool):
|
|
214
|
+
self.modelpool = modelpool
|
|
215
|
+
with timeit_context("Loading models"):
|
|
216
|
+
model = self.load_models()
|
|
217
|
+
with timeit_context("Loading dataloaders"):
|
|
218
|
+
self.load_datasets()
|
|
219
|
+
|
|
220
|
+
# run test-time adaptation
|
|
221
|
+
if not self.skip_training:
|
|
222
|
+
model = self.test_time_adaptation_training(modelpool, model)
|
|
223
|
+
|
|
224
|
+
if self.eval_batch_reduce is not None:
|
|
225
|
+
model.batch_reduce = self.eval_batch_reduce
|
|
226
|
+
return model
|
|
227
|
+
|
|
228
|
+
def test_time_adaptation_training(self, modelpool, model):
|
|
229
|
+
optimizer = torch.optim.Adam(
|
|
230
|
+
[p for p in model.gate.parameters() if p.requires_grad],
|
|
231
|
+
lr=self.learning_rate,
|
|
232
|
+
)
|
|
233
|
+
model, optimizer = self.fabric.setup(model, optimizer)
|
|
234
|
+
model.train()
|
|
235
|
+
for step_idx in tqdm(
|
|
236
|
+
range(self.max_steps),
|
|
237
|
+
desc="TTA Training",
|
|
238
|
+
dynamic_ncols=True,
|
|
239
|
+
):
|
|
240
|
+
log_metrics = {}
|
|
241
|
+
losses = 0
|
|
242
|
+
for task_idx, task_name in enumerate(modelpool.model_names):
|
|
243
|
+
# labels are used for logging acc, not involved in training
|
|
244
|
+
images, labels = next(self.shuffled_test_loader_iters[task_name])
|
|
245
|
+
logits = self.compute_logits(model, images=images, task=task_name)
|
|
246
|
+
loss = entropy_loss(logits)
|
|
247
|
+
losses += loss
|
|
248
|
+
log_metrics[f"train/{task_name}_loss"] = loss.item()
|
|
249
|
+
log_metrics[f"train/{task_name}_accuracy"] = (
|
|
250
|
+
logits.argmax(dim=-1).eq(labels).float().mean().item()
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
optimizer.zero_grad()
|
|
254
|
+
self.fabric.backward(losses)
|
|
255
|
+
optimizer.step()
|
|
256
|
+
|
|
257
|
+
log_metrics["train/loss"] = losses.item()
|
|
258
|
+
self.fabric.log_dict(log_metrics, step=step_idx)
|
|
259
|
+
|
|
260
|
+
if (step_idx + 1) % self.save_interval == 0:
|
|
261
|
+
log.info(f"Saving model at step {step_idx}")
|
|
262
|
+
self.fabric.save(
|
|
263
|
+
Path(self.log_dir) / "checkpoints" / f"model_{step_idx}.pt",
|
|
264
|
+
{"model": model},
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
if (step_idx + 1) % self.save_interval != 0:
|
|
268
|
+
# if the last step was not saved, save it now
|
|
269
|
+
self.fabric.save(
|
|
270
|
+
Path(self.log_dir) / "checkpoints" / f"model_{step_idx}.pt",
|
|
271
|
+
{"model": model},
|
|
272
|
+
)
|
|
273
|
+
|
|
274
|
+
return model
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module provides the `DataAdaptiveWeightEnsemblingModel` class for data-adaptive weight ensembling.
|
|
3
|
+
|
|
4
|
+
The DataAdaptiveWeightEnsemblingModel class is designed to perform data-adaptive weight ensembling
|
|
5
|
+
for model fusion. It supports both task-wise and layer-wise merging modes and allows for the use
|
|
6
|
+
of different feature extractors and processors.
|
|
7
|
+
|
|
8
|
+
Classes:
|
|
9
|
+
DataAdaptiveWeightEnsemblingModel: A class for data-adaptive weight ensembling.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
# flake8: noqa F401
|
|
13
|
+
from .dawe_model import DataAdaptiveWeightEnsemblingModel
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
import logging
|
|
3
|
+
from typing import List, Literal, Optional
|
|
4
|
+
|
|
5
|
+
import torch
|
|
6
|
+
import torch.nn.functional as F
|
|
7
|
+
from torch import Tensor, nn
|
|
8
|
+
from torch.func import functional_call
|
|
9
|
+
from typing_extensions import override
|
|
10
|
+
|
|
11
|
+
from fusion_bench.method.pruning import prune_utils
|
|
12
|
+
from fusion_bench.mixins import SimpleProfilerMixin
|
|
13
|
+
from fusion_bench.models.utils import del_attr, get_attr
|
|
14
|
+
from fusion_bench.utils.devices import get_device
|
|
15
|
+
from fusion_bench.utils.dtype import parse_dtype
|
|
16
|
+
from fusion_bench.utils.state_dict_arithmetic import (
|
|
17
|
+
StateDictType,
|
|
18
|
+
state_dict_weighted_sum,
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
log = logging.getLogger(__name__)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Depth_0_Gate(nn.Module):
|
|
25
|
+
def __init__(self, output_dim: int):
|
|
26
|
+
super().__init__()
|
|
27
|
+
self.weight = nn.Parameter(torch.empty(output_dim), requires_grad=True)
|
|
28
|
+
|
|
29
|
+
def init_weight(self, init_lambda: float):
|
|
30
|
+
nn.init.constant_(self.weight, init_lambda)
|
|
31
|
+
|
|
32
|
+
def forward(self, *args, **kwargs) -> Tensor:
|
|
33
|
+
return self.weight
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class Depth_1_Gate(nn.Module):
|
|
37
|
+
def __init__(self, hidden_size: int, output_dim: int):
|
|
38
|
+
super().__init__()
|
|
39
|
+
self.fc = nn.Linear(hidden_size, output_dim, bias=True)
|
|
40
|
+
|
|
41
|
+
def init_weight(self, init_lambda: float):
|
|
42
|
+
nn.init.normal_(self.fc.weight, std=0.001)
|
|
43
|
+
nn.init.constant_(self.fc.bias, init_lambda)
|
|
44
|
+
|
|
45
|
+
def forward(self, hidden_states: Tensor) -> Tensor:
|
|
46
|
+
return self.fc(hidden_states)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class Depth_2_Gate(nn.Module):
|
|
50
|
+
def __init__(self, hidden_size: int, output_dim: int):
|
|
51
|
+
super().__init__()
|
|
52
|
+
self.fc1 = nn.Linear(hidden_size, hidden_size, bias=True)
|
|
53
|
+
self.fc2 = nn.Linear(hidden_size, output_dim, bias=True)
|
|
54
|
+
|
|
55
|
+
def init_weight(self, init_lambda: float):
|
|
56
|
+
nn.init.normal_(self.fc1.weight, std=0.01)
|
|
57
|
+
nn.init.zeros_(self.fc1.bias)
|
|
58
|
+
nn.init.normal_(self.fc2.weight, std=0.01)
|
|
59
|
+
nn.init.constant_(self.fc2.bias, init_lambda)
|
|
60
|
+
|
|
61
|
+
def forward(self, hidden_states: Tensor) -> Tensor:
|
|
62
|
+
hidden_states = F.relu(self.fc1(hidden_states))
|
|
63
|
+
return self.fc2(hidden_states)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def construct_dawe_gate(
|
|
67
|
+
hidden_size: int,
|
|
68
|
+
coding_size: int,
|
|
69
|
+
init_lambda: float,
|
|
70
|
+
num_hidden_layers: int = 2,
|
|
71
|
+
):
|
|
72
|
+
if num_hidden_layers == 0:
|
|
73
|
+
gate = Depth_0_Gate(coding_size)
|
|
74
|
+
elif num_hidden_layers == 1:
|
|
75
|
+
gate = Depth_1_Gate(hidden_size, coding_size)
|
|
76
|
+
elif num_hidden_layers == 2:
|
|
77
|
+
gate = Depth_2_Gate(hidden_size, coding_size)
|
|
78
|
+
else:
|
|
79
|
+
raise ValueError(f"Unsupported number of hidden layers: {num_hidden_layers}")
|
|
80
|
+
|
|
81
|
+
gate.num_hidden_layers = num_hidden_layers
|
|
82
|
+
gate.init_weight(init_lambda)
|
|
83
|
+
return gate
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class DataAdaptiveWeightEnsemblingModel(nn.Module, SimpleProfilerMixin):
|
|
87
|
+
|
|
88
|
+
def __init__(
|
|
89
|
+
self,
|
|
90
|
+
*,
|
|
91
|
+
merge_mode: Literal["task_wise", "layer_wise"],
|
|
92
|
+
hidden_size: int,
|
|
93
|
+
dict_processor,
|
|
94
|
+
model_processor,
|
|
95
|
+
collate_fn=torch.stack,
|
|
96
|
+
dict_feature_extractor: nn.Module,
|
|
97
|
+
base_model: nn.Module,
|
|
98
|
+
expert_models: List[nn.Module],
|
|
99
|
+
task_vector_dtype: Optional[str | torch.dtype],
|
|
100
|
+
task_vector_sparsity: float,
|
|
101
|
+
init_lambda: float = 0.2,
|
|
102
|
+
gate_hidden_layers: int = 2,
|
|
103
|
+
batch_reduce: bool = False,
|
|
104
|
+
):
|
|
105
|
+
super().__init__()
|
|
106
|
+
self.merge_mode = merge_mode
|
|
107
|
+
self.batch_reduce = batch_reduce
|
|
108
|
+
self.num_experts = len(expert_models)
|
|
109
|
+
|
|
110
|
+
self.collate_fn = collate_fn
|
|
111
|
+
self.dict_processor = dict_processor
|
|
112
|
+
self.model_processor = model_processor
|
|
113
|
+
self.dict_feature_exactor = dict_feature_extractor
|
|
114
|
+
if isinstance(self.dict_feature_exactor, nn.Module):
|
|
115
|
+
self.dict_feature_exactor.requires_grad_(False) # fix the feature extractor
|
|
116
|
+
self.base_model = base_model
|
|
117
|
+
|
|
118
|
+
# compute the task vectors
|
|
119
|
+
for name, param in base_model.named_parameters():
|
|
120
|
+
if not param.requires_grad:
|
|
121
|
+
for m in expert_models:
|
|
122
|
+
del_attr(m, name.split("."))
|
|
123
|
+
else:
|
|
124
|
+
for m in expert_models:
|
|
125
|
+
get_attr(m, name.split(".")).data = (
|
|
126
|
+
get_attr(m, name.split(".")) - param
|
|
127
|
+
)
|
|
128
|
+
# fix base model and expert models
|
|
129
|
+
self.base_model = base_model.requires_grad_(False)
|
|
130
|
+
for m in expert_models:
|
|
131
|
+
m.requires_grad_(False)
|
|
132
|
+
self.task_vectors = nn.ModuleList(expert_models)
|
|
133
|
+
self.num_layers = len(self.task_vectors[0].state_dict())
|
|
134
|
+
if task_vector_dtype is not None:
|
|
135
|
+
log.info(f"Converting task vectors to {task_vector_dtype}")
|
|
136
|
+
self.task_vectors = self.task_vectors.to(parse_dtype(task_vector_dtype))
|
|
137
|
+
if task_vector_sparsity is not None and task_vector_sparsity > 0:
|
|
138
|
+
for module in self.task_vectors.modules():
|
|
139
|
+
if isinstance(module, nn.Linear):
|
|
140
|
+
prune_utils.unstructured_magnitude_prune_(
|
|
141
|
+
module.weight,
|
|
142
|
+
metric_function_or_scores=torch.abs,
|
|
143
|
+
sparsity_ratio=task_vector_sparsity,
|
|
144
|
+
)
|
|
145
|
+
module.weight = nn.Parameter(
|
|
146
|
+
module.weight.to_sparse(),
|
|
147
|
+
requires_grad=module.weight.requires_grad,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
if self.merge_mode == "task_wise":
|
|
151
|
+
self.coding_size = self.num_experts
|
|
152
|
+
elif self.merge_mode == "layer_wise":
|
|
153
|
+
self.coding_size = self.num_experts * self.num_layers
|
|
154
|
+
else:
|
|
155
|
+
raise ValueError(
|
|
156
|
+
"Invalid option of `merge_model`, must be 'task_wise' or 'layer_wise'"
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
self.gate = construct_dawe_gate(
|
|
160
|
+
hidden_size,
|
|
161
|
+
coding_size=self.coding_size,
|
|
162
|
+
init_lambda=init_lambda,
|
|
163
|
+
num_hidden_layers=gate_hidden_layers,
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
def compute_task_vectors(self, coding_weights: Tensor):
|
|
167
|
+
if self.merge_mode == "task_wise":
|
|
168
|
+
state_dict = state_dict_weighted_sum(
|
|
169
|
+
[
|
|
170
|
+
task_vector.state_dict(keep_vars=True)
|
|
171
|
+
for task_vector in self.task_vectors
|
|
172
|
+
],
|
|
173
|
+
coding_weights,
|
|
174
|
+
)
|
|
175
|
+
elif self.merge_mode == "layer_wise":
|
|
176
|
+
coding_weights = coding_weights.view(self.num_experts, -1)
|
|
177
|
+
state_dict = {}
|
|
178
|
+
for weight, task_vector in zip(coding_weights, self.task_vectors):
|
|
179
|
+
for name, param in task_vector.state_dict(keep_vars=True).items():
|
|
180
|
+
state_dict[name] = state_dict.get(name, 0) + weight * param
|
|
181
|
+
else:
|
|
182
|
+
raise ValueError(
|
|
183
|
+
"Invalid option of `merge_model`, must be 'task_wise' or 'layer_wise'"
|
|
184
|
+
)
|
|
185
|
+
return state_dict
|
|
186
|
+
|
|
187
|
+
def merge_weights(self, task_vector: StateDictType):
|
|
188
|
+
state_dict = self.base_model.state_dict(keep_vars=True)
|
|
189
|
+
for name, param in task_vector.items():
|
|
190
|
+
state_dict[name] = state_dict[name] + param
|
|
191
|
+
return state_dict
|
|
192
|
+
|
|
193
|
+
def model_forward_on_single_sample(self, state_dict, sample_idx, *args, **kwargs):
|
|
194
|
+
raise NotImplementedError
|
|
195
|
+
|
|
196
|
+
def model_forward(self, dict_codings, *args, **kwargs):
|
|
197
|
+
if self.batch_reduce:
|
|
198
|
+
with self.profile("merge weights"):
|
|
199
|
+
dict_codings = dict_codings.mean(dim=0)
|
|
200
|
+
task_vector = self.compute_task_vectors(dict_codings)
|
|
201
|
+
state_dict = self.merge_weights(task_vector)
|
|
202
|
+
with self.profile("model forward"):
|
|
203
|
+
return functional_call(
|
|
204
|
+
self.base_model,
|
|
205
|
+
state_dict,
|
|
206
|
+
args=args,
|
|
207
|
+
kwargs=kwargs,
|
|
208
|
+
strict=False, # buffer is not included in the state_dict
|
|
209
|
+
)
|
|
210
|
+
else:
|
|
211
|
+
model_outputs = []
|
|
212
|
+
for sample_idx, dict_coding in enumerate(dict_codings):
|
|
213
|
+
with self.profile("merge weights"):
|
|
214
|
+
task_vector = self.compute_task_vectors(dict_coding)
|
|
215
|
+
state_dict = self.merge_weights(task_vector)
|
|
216
|
+
with self.profile("model forward"):
|
|
217
|
+
model_outputs.append(
|
|
218
|
+
self.model_forward_on_single_sample(
|
|
219
|
+
state_dict,
|
|
220
|
+
sample_idx,
|
|
221
|
+
*args,
|
|
222
|
+
**kwargs,
|
|
223
|
+
)
|
|
224
|
+
)
|
|
225
|
+
model_outputs = self.collate_fn(model_outputs)
|
|
226
|
+
return model_outputs
|
|
227
|
+
|
|
228
|
+
def forward(self, *args, **kwargs):
|
|
229
|
+
# compute dict codings
|
|
230
|
+
if self.dict_processor is not None:
|
|
231
|
+
inputs = self.dict_processor(*args, **kwargs)
|
|
232
|
+
if isinstance(inputs, Tensor):
|
|
233
|
+
inputs = inputs.to(get_device(self.dict_feature_exactor))
|
|
234
|
+
with self.profile("compute sparse codings"):
|
|
235
|
+
dict_features = self.dict_feature_exactor(inputs)
|
|
236
|
+
else:
|
|
237
|
+
with self.profile("compute sparse codings"):
|
|
238
|
+
dict_features = self.dict_feature_exactor(*args, **kwargs)
|
|
239
|
+
dict_codings: Tensor = self.gate(dict_features)
|
|
240
|
+
|
|
241
|
+
if self.model_processor is not None:
|
|
242
|
+
inputs = self.model_processor(*args, **kwargs)
|
|
243
|
+
if isinstance(inputs, Tensor):
|
|
244
|
+
inputs = inputs.to(get_device(self.base_model))
|
|
245
|
+
model_outputs = self.model_forward(dict_codings, inputs)
|
|
246
|
+
else:
|
|
247
|
+
model_outputs = self.model_forward(dict_codings, *args, **kwargs)
|
|
248
|
+
return model_outputs
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
class DataAdaptiveWeightEnsemblingCLIPVisionModel(DataAdaptiveWeightEnsemblingModel):
|
|
252
|
+
@override
|
|
253
|
+
def model_forward_on_single_sample(self, state_dict, sample_idx, images: Tensor):
|
|
254
|
+
return functional_call(
|
|
255
|
+
self.base_model, state_dict, args=images[sample_idx : sample_idx + 1]
|
|
256
|
+
)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from copy import deepcopy
|
|
3
|
+
from typing import List, Mapping, Union # noqa: F401
|
|
4
|
+
|
|
5
|
+
import torch
|
|
6
|
+
from torch import nn
|
|
7
|
+
from tqdm.autonotebook import tqdm
|
|
8
|
+
|
|
9
|
+
from fusion_bench.method import BaseAlgorithm
|
|
10
|
+
from fusion_bench.modelpool import BaseModelPool
|
|
11
|
+
|
|
12
|
+
log = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class DepthUpscalingAlgorithm(BaseAlgorithm):
|
|
16
|
+
R"""
|
|
17
|
+
Implements the Depth Upscaling Algorithm.
|
|
18
|
+
|
|
19
|
+
- Kim et al. SOLAR 10.7B: Scaling Large Language Models with Simple yet Effective Depth Up-Scaling. http://arxiv.org/abs/2312.15166
|
|
20
|
+
|
|
21
|
+
This class extends the `BaseModelFusionAlgorithm` to handle depth upscaling of models.
|
|
22
|
+
It supports upscaling the depth of a model by duplicating specified layers.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
layer_indices (list): List of layer indices to duplicate.
|
|
26
|
+
**kwargs: Additional keyword arguments.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
_config_mapping = BaseAlgorithm._config_mapping | {
|
|
30
|
+
"layer_indices": "layer_indices",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
def __init__(self, layer_indices: Union[str, List[int]], **kwargs):
|
|
34
|
+
self.layer_indices = layer_indices
|
|
35
|
+
super().__init__(**kwargs)
|
|
36
|
+
|
|
37
|
+
@torch.no_grad()
|
|
38
|
+
def run(self, modelpool: nn.ModuleList | BaseModelPool) -> nn.ModuleList:
|
|
39
|
+
"""
|
|
40
|
+
Executes the depth upscaling algorithm on a given model pool.
|
|
41
|
+
|
|
42
|
+
This method checks the type of the model pool, ensures that it contains only one model, and verifies that the model is an instance of `nn.ModuleList`.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
modelpool (nn.ModuleList | ModelPool): The pool of models to upscale. Must contain only one model.
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
nn.ModuleList: The upscaled model.
|
|
49
|
+
|
|
50
|
+
Raises:
|
|
51
|
+
AssertionError: If the model pool contains more than one model or if the model is not an instance of `nn.ModuleList`.
|
|
52
|
+
ValueError: If an invalid layer specification is provided in the configuration.
|
|
53
|
+
"""
|
|
54
|
+
# check the modelpool type
|
|
55
|
+
if isinstance(modelpool, BaseModelPool):
|
|
56
|
+
assert len(modelpool) == 1, "DepthUpscaling only support one model"
|
|
57
|
+
model = modelpool.load_model(modelpool.model_names[0])
|
|
58
|
+
assert isinstance(
|
|
59
|
+
model, nn.ModuleList
|
|
60
|
+
), f"The model should be a `nn.ModuleList`, but got {type(model)}"
|
|
61
|
+
elif isinstance(modelpool, nn.ModuleList):
|
|
62
|
+
model = modelpool
|
|
63
|
+
else:
|
|
64
|
+
raise AssertionError(
|
|
65
|
+
f"Invalid modelpool type: {type(modelpool)}. Expected `ModelPool` or `nn.ModuleList`."
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
# parse the layers
|
|
69
|
+
layer_indices = self.layer_indices
|
|
70
|
+
parsed_layer_indices = []
|
|
71
|
+
for layer in layer_indices:
|
|
72
|
+
if isinstance(layer, int):
|
|
73
|
+
parsed_layer_indices.append(layer)
|
|
74
|
+
elif isinstance(layer, str):
|
|
75
|
+
parsed_layer_indices.extend(eval(layer))
|
|
76
|
+
else:
|
|
77
|
+
raise ValueError("Invalid layer specification: {}".format(layer))
|
|
78
|
+
|
|
79
|
+
# create a new model with the specified layers
|
|
80
|
+
new_model = nn.ModuleList(
|
|
81
|
+
[
|
|
82
|
+
deepcopy(model[i])
|
|
83
|
+
for i in tqdm(
|
|
84
|
+
parsed_layer_indices, desc="constructing depth-upscaled model"
|
|
85
|
+
)
|
|
86
|
+
]
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
return new_model
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from typing_extensions import override
|
|
5
|
+
|
|
6
|
+
from fusion_bench.modelpool.causal_lm.causal_lm import CausalLM, CausalLMPool
|
|
7
|
+
from fusion_bench.utils import timeit_context
|
|
8
|
+
|
|
9
|
+
from .depth_upscaling import DepthUpscalingAlgorithm
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class DepthUpscalingForLlama(DepthUpscalingAlgorithm):
|
|
13
|
+
"""
|
|
14
|
+
Implements depth upscaling for Llama models.
|
|
15
|
+
|
|
16
|
+
This class extends the DepthUpscalingAlgorithm to handle Llama models specifically.
|
|
17
|
+
It supports saving the upscaled model to a specified path.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
layer_indices (list): List of layer indices to upscale.
|
|
21
|
+
model_save_path (Optional[str]): Path to save the upscaled model.
|
|
22
|
+
**kwargs: Additional keyword arguments.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def __init__(self, layer_indices: list, model_save_path: Optional[str], **kwargs):
|
|
26
|
+
if isinstance(model_save_path, str):
|
|
27
|
+
model_save_path = os.path.expanduser(model_save_path)
|
|
28
|
+
self.model_save_path = model_save_path
|
|
29
|
+
super().__init__(layer_indices, **kwargs)
|
|
30
|
+
|
|
31
|
+
@override
|
|
32
|
+
def run(self, modelpool: CausalLMPool):
|
|
33
|
+
"""
|
|
34
|
+
Executes the depth upscaling algorithm on a given model pool.
|
|
35
|
+
|
|
36
|
+
This method loads the pretrained model or the first model in the pool,
|
|
37
|
+
applies the depth upscaling algorithm, and updates the number of hidden layers in the model configuration.
|
|
38
|
+
If a save path is provided, it saves the upscaled model and tokenizer to the specified path.
|
|
39
|
+
|
|
40
|
+
Args:
|
|
41
|
+
modelpool (CausalLMPool): The pool of models to upscale.
|
|
42
|
+
|
|
43
|
+
Returns:
|
|
44
|
+
CausalLM: The upscaled model.
|
|
45
|
+
"""
|
|
46
|
+
if self.model_save_path is not None:
|
|
47
|
+
tokenizer = modelpool.load_tokenizer()
|
|
48
|
+
|
|
49
|
+
model: CausalLM = modelpool.load_pretrained_or_first_model()
|
|
50
|
+
model.model.layers = super().run(model.model.layers)
|
|
51
|
+
model.config.num_hidden_layers = len(model.model.layers)
|
|
52
|
+
|
|
53
|
+
if self.model_save_path is not None:
|
|
54
|
+
with timeit_context(f"Saving the model to {self.model_save_path}"):
|
|
55
|
+
tokenizer.save_pretrained(self.model_save_path)
|
|
56
|
+
model.save_pretrained(self.model_save_path)
|
|
57
|
+
return model
|