fusion-bench 0.2.15__py3-none-any.whl → 0.2.17__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.
Files changed (104) hide show
  1. fusion_bench/method/__init__.py +4 -0
  2. fusion_bench/method/adamerging/flan_t5_layer_wise_adamerging.py +1 -1
  3. fusion_bench/method/adamerging/gpt2_layer_wise_adamerging.py +1 -1
  4. fusion_bench/method/base_algorithm.py +1 -0
  5. fusion_bench/method/dawe/dawe_for_clip.py +1 -1
  6. fusion_bench/method/depth_upscaling/depth_upscaling_for_llama.py +3 -2
  7. fusion_bench/method/fw_merging/__init__.py +2 -0
  8. fusion_bench/method/fw_merging/fw_hard.py +448 -0
  9. fusion_bench/method/fw_merging/fw_soft.py +519 -0
  10. fusion_bench/method/fw_merging/utils.py +331 -0
  11. fusion_bench/method/gossip/flan_t5_layer_wise_gossip.py +1 -1
  12. fusion_bench/method/moe_pruner/__init__.py +7 -0
  13. fusion_bench/method/moe_pruner/hooks/__init__.py +6 -0
  14. fusion_bench/method/moe_pruner/hooks/deepseek_v2.py +85 -0
  15. fusion_bench/method/moe_pruner/hooks/hook.py +23 -0
  16. fusion_bench/method/moe_pruner/hooks/mixtral.py +93 -0
  17. fusion_bench/method/moe_pruner/moe_pruner.py +304 -0
  18. fusion_bench/method/moe_pruner/utils/__init__.py +1 -0
  19. fusion_bench/method/moe_pruner/utils/data.py +154 -0
  20. fusion_bench/method/moe_pruner/utils/layerwrapper.py +61 -0
  21. fusion_bench/method/moe_pruner/utils/prune.py +313 -0
  22. fusion_bench/method/moe_pruner/utils/score.py +41 -0
  23. fusion_bench/method/pruning/__init__.py +1 -0
  24. fusion_bench/method/pruning/llama_sparsegpt_prune.py +223 -0
  25. fusion_bench/method/pruning/sparsegpt_utils/__init__.py +1 -0
  26. fusion_bench/method/pruning/sparsegpt_utils/sparsegpt.py +128 -0
  27. fusion_bench/method/pruning/wanda_utils/data.py +33 -14
  28. fusion_bench/method/pwe_moe/module.py +2 -7
  29. fusion_bench/method/randes/__init__.py +15 -0
  30. fusion_bench/method/randes/base_algorithm.py +1013 -0
  31. fusion_bench/method/randes/modelsoup.py +126 -0
  32. fusion_bench/method/randes/task_arithmetic.py +318 -0
  33. fusion_bench/method/simple_average.py +3 -2
  34. fusion_bench/method/sparselo/sparselo.py +20 -2
  35. fusion_bench/method/tall_mask/__init__.py +1 -0
  36. fusion_bench/method/tall_mask/task_arithmetic.py +133 -0
  37. fusion_bench/method/task_singular_vector/TSVM.py +238 -25
  38. fusion_bench/method/task_singular_vector/utils/TSVM_utils.py +52 -20
  39. fusion_bench/mixins/hydra_config.py +1 -1
  40. fusion_bench/mixins/lightning_fabric.py +25 -1
  41. fusion_bench/mixins/serialization.py +18 -2
  42. fusion_bench/modelpool/base_pool.py +1 -0
  43. fusion_bench/modelpool/clip_vision/modelpool.py +21 -13
  44. fusion_bench/modelpool/lazy_state_dict_pool.py +15 -0
  45. fusion_bench/models/modeling_deepseek_v2/__init__.py +15 -0
  46. fusion_bench/models/modeling_deepseek_v2/configuration_deepseek.py +208 -0
  47. fusion_bench/models/modeling_deepseek_v2/modeling_deepseek.py +1922 -0
  48. fusion_bench/models/modeling_deepseek_v2/tokenization_deepseek_fast.py +38 -0
  49. fusion_bench/models/parameter_dict.py +6 -1
  50. fusion_bench/programs/fabric_fusion_program.py +14 -5
  51. fusion_bench/taskpool/base_pool.py +1 -0
  52. fusion_bench/taskpool/clip_vision/taskpool.py +8 -1
  53. fusion_bench/taskpool/dummy.py +6 -4
  54. fusion_bench/utils/__init__.py +2 -1
  55. fusion_bench/utils/data.py +1 -1
  56. fusion_bench/utils/{instantiate.py → instantiate_utils.py} +3 -0
  57. fusion_bench/utils/lazy_state_dict.py +268 -0
  58. fusion_bench/utils/parameters.py +33 -0
  59. fusion_bench/utils/pylogger.py +28 -0
  60. fusion_bench/utils/state_dict_arithmetic.py +74 -2
  61. fusion_bench/utils/type.py +1 -0
  62. {fusion_bench-0.2.15.dist-info → fusion_bench-0.2.17.dist-info}/METADATA +8 -2
  63. {fusion_bench-0.2.15.dist-info → fusion_bench-0.2.17.dist-info}/RECORD +104 -44
  64. {fusion_bench-0.2.15.dist-info → fusion_bench-0.2.17.dist-info}/WHEEL +1 -1
  65. fusion_bench_config/dataset/image_classification/test/TALL10.yaml +28 -0
  66. fusion_bench_config/dataset/image_classification/test/TALL12.yaml +28 -0
  67. fusion_bench_config/dataset/image_classification/test/TALL16.yaml +28 -0
  68. fusion_bench_config/dataset/image_classification/test/TALL18.yaml +28 -0
  69. fusion_bench_config/dataset/image_classification/train/TALL10.yaml +28 -0
  70. fusion_bench_config/dataset/image_classification/train/TALL12.yaml +28 -0
  71. fusion_bench_config/dataset/image_classification/train/TALL16.yaml +28 -0
  72. fusion_bench_config/dataset/image_classification/train/TALL18.yaml +28 -0
  73. fusion_bench_config/fabric_model_fusion.yaml +2 -2
  74. fusion_bench_config/method/fw_merging/fw_hard.yaml +11 -0
  75. fusion_bench_config/method/fw_merging/fw_soft.yaml +12 -0
  76. fusion_bench_config/method/moe_pruner/moe_pruner.yaml +15 -0
  77. fusion_bench_config/method/pruning/llama_sparsegpt_pruning.yaml +16 -0
  78. fusion_bench_config/method/randes/superposed_model_soup.yaml +18 -0
  79. fusion_bench_config/method/randes/superposed_task_arithmetic.yaml +20 -0
  80. fusion_bench_config/method/randes/superposed_task_arithmetic_lora.yaml +20 -0
  81. fusion_bench_config/method/sparselo_pruning/llama_iterative_sparselo.yaml +2 -1
  82. fusion_bench_config/method/sparselo_pruning/llama_pcp_sparselo.yaml +1 -1
  83. fusion_bench_config/method/sparselo_pruning/llama_sparselo.yaml +1 -1
  84. fusion_bench_config/method/tall_mask/task_arithmetic.yaml +4 -0
  85. fusion_bench_config/method/task_singular_vector/TaskSingularVectorMerging.yaml +2 -1
  86. fusion_bench_config/model/clip-vit/clip-vit-base-patch32_TALL10.yaml +29 -0
  87. fusion_bench_config/model/clip-vit/clip-vit-base-patch32_TALL12.yaml +29 -0
  88. fusion_bench_config/model/clip-vit/clip-vit-base-patch32_TALL16.yaml +29 -0
  89. fusion_bench_config/model/clip-vit/clip-vit-base-patch32_TALL18.yaml +29 -0
  90. fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_TALL10.yaml +8 -0
  91. fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_TALL12.yaml +8 -0
  92. fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_TALL16.yaml +8 -0
  93. fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_TALL18.yaml +8 -0
  94. fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_cars_and_dtd.yaml +16 -0
  95. fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_sun397_and_cars.yaml +16 -0
  96. fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_sun397_and_dtd.yaml +16 -0
  97. fusion_bench_config/modelpool/CLIPVisionModelPool/clip-vit-base-patch32_sun397_cars_and_dtd.yaml +19 -0
  98. fusion_bench_config/modelpool/CausalLMPool/deepseek-v2-lite.yaml +15 -0
  99. fusion_bench_config/modelpool/CausalLMPool/mixtral-8x7b.yaml +14 -0
  100. fusion_bench_config/modelpool/SeqenceClassificationModelPool/roberta-base_glue.yaml +69 -0
  101. fusion_bench_config/taskpool/LMEvalHarnessTaskPool/lm_eval.yaml +0 -1
  102. {fusion_bench-0.2.15.dist-info → fusion_bench-0.2.17.dist-info}/entry_points.txt +0 -0
  103. {fusion_bench-0.2.15.dist-info → fusion_bench-0.2.17.dist-info}/licenses/LICENSE +0 -0
  104. {fusion_bench-0.2.15.dist-info → fusion_bench-0.2.17.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,208 @@
1
+ from transformers.configuration_utils import PretrainedConfig
2
+ from transformers.utils import logging
3
+
4
+ logger = logging.get_logger(__name__)
5
+
6
+ DEEPSEEK_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
7
+
8
+
9
+ class DeepseekV2Config(PretrainedConfig):
10
+ r"""
11
+ This is the configuration class to store the configuration of a [`DeepseekV2Model`]. It is used to instantiate an DeepSeek
12
+ model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
13
+ defaults will yield a similar configuration to that of the DeepSeek-V2.
14
+
15
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
16
+ documentation from [`PretrainedConfig`] for more information.
17
+
18
+
19
+ Args:
20
+ vocab_size (`int`, *optional*, defaults to 102400):
21
+ Vocabulary size of the Deep model. Defines the number of different tokens that can be represented by the
22
+ `inputs_ids` passed when calling [`DeepseekV2Model`]
23
+ hidden_size (`int`, *optional*, defaults to 4096):
24
+ Dimension of the hidden representations.
25
+ intermediate_size (`int`, *optional*, defaults to 11008):
26
+ Dimension of the MLP representations.
27
+ moe_intermediate_size (`int`, *optional*, defaults to 1407):
28
+ Dimension of the MoE representations.
29
+ num_hidden_layers (`int`, *optional*, defaults to 32):
30
+ Number of hidden layers in the Transformer decoder.
31
+ num_attention_heads (`int`, *optional*, defaults to 32):
32
+ Number of attention heads for each attention layer in the Transformer decoder.
33
+ n_shared_experts (`int`, *optional*, defaults to None):
34
+ Number of shared experts, None means dense model.
35
+ n_routed_experts (`int`, *optional*, defaults to None):
36
+ Number of routed experts, None means dense model.
37
+ routed_scaling_factor (`float`, *optional*, defaults to 1.0):
38
+ Scaling factor or routed experts.
39
+ topk_method (`str`, *optional*, defaults to `gready`):
40
+ Topk method used in routed gate.
41
+ n_group (`int`, *optional*, defaults to None):
42
+ Number of groups for routed experts.
43
+ topk_group (`int`, *optional*, defaults to None):
44
+ Number of selected groups for each token(for each token, ensuring the selected experts is only within `topk_group` groups).
45
+ num_experts_per_tok (`int`, *optional*, defaults to None):
46
+ Number of selected experts, None means dense model.
47
+ moe_layer_freq (`int`, *optional*, defaults to 1):
48
+ The frequency of the MoE layer: one expert layer for every `moe_layer_freq - 1` dense layers.
49
+ first_k_dense_replace (`int`, *optional*, defaults to 0):
50
+ Number of dense layers in shallow layers(embed->dense->dense->...->dense->moe->moe...->lm_head).
51
+ \--k dense layers--/
52
+ norm_topk_prob (`bool`, *optional*, defaults to False):
53
+ Whether to normalize the weights of the routed experts.
54
+ scoring_func (`str`, *optional*, defaults to 'softmax'):
55
+ Method of computing expert weights.
56
+ aux_loss_alpha (`float`, *optional*, defaults to 0.001):
57
+ Auxiliary loss weight coefficient.
58
+ seq_aux = (`bool`, *optional*, defaults to True):
59
+ Whether to compute the auxiliary loss for each individual sample.
60
+ num_key_value_heads (`int`, *optional*):
61
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
62
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
63
+ `num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
64
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
65
+ by meanpooling all the original heads within that group. For more details checkout [this
66
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
67
+ `num_attention_heads`.
68
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
69
+ The non-linear activation function (function or string) in the decoder.
70
+ max_position_embeddings (`int`, *optional*, defaults to 2048):
71
+ The maximum sequence length that this model might ever be used with.
72
+ initializer_range (`float`, *optional*, defaults to 0.02):
73
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
74
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
75
+ The epsilon used by the rms normalization layers.
76
+ use_cache (`bool`, *optional*, defaults to `True`):
77
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
78
+ relevant if `config.is_decoder=True`.
79
+ pad_token_id (`int`, *optional*):
80
+ Padding token id.
81
+ bos_token_id (`int`, *optional*, defaults to 1):
82
+ Beginning of stream token id.
83
+ eos_token_id (`int`, *optional*, defaults to 2):
84
+ End of stream token id.
85
+ pretraining_tp (`int`, *optional*, defaults to 1):
86
+ Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
87
+ document](https://huggingface.co/docs/transformers/parallelism) to understand more about it. This value is
88
+ necessary to ensure exact reproducibility of the pretraining results. Please refer to [this
89
+ issue](https://github.com/pytorch/pytorch/issues/76232).
90
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
91
+ Whether to tie weight embeddings
92
+ rope_theta (`float`, *optional*, defaults to 10000.0):
93
+ The base period of the RoPE embeddings.
94
+ rope_scaling (`Dict`, *optional*):
95
+ Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
96
+ strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
97
+ `{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
98
+ `max_position_embeddings` to the expected new maximum.
99
+ attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
100
+ Whether to use a bias in the query, key, value and output projection layers during self-attention.
101
+ attention_dropout (`float`, *optional*, defaults to 0.0):
102
+ The dropout ratio for the attention probabilities.
103
+
104
+ ```python
105
+ >>> from transformers import DeepseekV2Model, DeepseekV2Config
106
+
107
+ >>> # Initializing a Deepseek-V2 style configuration
108
+ >>> configuration = DeepseekV2Config()
109
+
110
+ >>> # Accessing the model configuration
111
+ >>> configuration = model.config
112
+ ```"""
113
+
114
+ model_type = "deepseek_v2"
115
+ keys_to_ignore_at_inference = ["past_key_values"]
116
+
117
+ def __init__(
118
+ self,
119
+ vocab_size=102400,
120
+ hidden_size=4096,
121
+ intermediate_size=11008,
122
+ moe_intermediate_size=1407,
123
+ num_hidden_layers=30,
124
+ num_attention_heads=32,
125
+ num_key_value_heads=32,
126
+ n_shared_experts=None,
127
+ n_routed_experts=None,
128
+ ep_size=1,
129
+ routed_scaling_factor=1.0,
130
+ kv_lora_rank=512,
131
+ q_lora_rank=1536,
132
+ qk_rope_head_dim=64,
133
+ v_head_dim=128,
134
+ qk_nope_head_dim=128,
135
+ topk_method="gready",
136
+ n_group=None,
137
+ topk_group=None,
138
+ num_experts_per_tok=None,
139
+ moe_layer_freq=1,
140
+ first_k_dense_replace=0,
141
+ norm_topk_prob=False,
142
+ scoring_func="softmax",
143
+ aux_loss_alpha=0.001,
144
+ seq_aux=True,
145
+ hidden_act="silu",
146
+ max_position_embeddings=2048,
147
+ initializer_range=0.02,
148
+ rms_norm_eps=1e-6,
149
+ use_cache=True,
150
+ pad_token_id=None,
151
+ bos_token_id=100000,
152
+ eos_token_id=100001,
153
+ pretraining_tp=1,
154
+ tie_word_embeddings=False,
155
+ rope_theta=10000.0,
156
+ rope_scaling=None,
157
+ attention_bias=False,
158
+ attention_dropout=0.0,
159
+ **kwargs,
160
+ ):
161
+ self.vocab_size = vocab_size
162
+ self.max_position_embeddings = max_position_embeddings
163
+ self.hidden_size = hidden_size
164
+ self.intermediate_size = intermediate_size
165
+ self.moe_intermediate_size = moe_intermediate_size
166
+ self.num_hidden_layers = num_hidden_layers
167
+ self.num_attention_heads = num_attention_heads
168
+ self.n_shared_experts = n_shared_experts
169
+ self.n_routed_experts = n_routed_experts
170
+ self.ep_size = ep_size
171
+ self.routed_scaling_factor = routed_scaling_factor
172
+ self.kv_lora_rank = kv_lora_rank
173
+ self.q_lora_rank = q_lora_rank
174
+ self.qk_rope_head_dim = qk_rope_head_dim
175
+ self.v_head_dim = v_head_dim
176
+ self.qk_nope_head_dim = qk_nope_head_dim
177
+ self.topk_method = topk_method
178
+ self.n_group = n_group
179
+ self.topk_group = topk_group
180
+ self.num_experts_per_tok = num_experts_per_tok
181
+ self.moe_layer_freq = moe_layer_freq
182
+ self.first_k_dense_replace = first_k_dense_replace
183
+ self.norm_topk_prob = norm_topk_prob
184
+ self.scoring_func = scoring_func
185
+ self.aux_loss_alpha = aux_loss_alpha
186
+ self.seq_aux = seq_aux
187
+ # for backward compatibility
188
+ if num_key_value_heads is None:
189
+ num_key_value_heads = num_attention_heads
190
+
191
+ self.num_key_value_heads = num_key_value_heads
192
+ self.hidden_act = hidden_act
193
+ self.initializer_range = initializer_range
194
+ self.rms_norm_eps = rms_norm_eps
195
+ self.pretraining_tp = pretraining_tp
196
+ self.use_cache = use_cache
197
+ self.rope_theta = rope_theta
198
+ self.rope_scaling = rope_scaling
199
+ self.attention_bias = attention_bias
200
+ self.attention_dropout = attention_dropout
201
+
202
+ super().__init__(
203
+ pad_token_id=pad_token_id,
204
+ bos_token_id=bos_token_id,
205
+ eos_token_id=eos_token_id,
206
+ tie_word_embeddings=tie_word_embeddings,
207
+ **kwargs,
208
+ )