xihc-ucb commited on
Commit
94c4ed7
·
verified ·
1 Parent(s): 7acbbff

Upload FP8Qwen2ForCausalLM

Browse files
README.md ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ tags: []
4
+ ---
5
+
6
+ # Model Card for Model ID
7
+
8
+ <!-- Provide a quick summary of what the model is/does. -->
9
+
10
+
11
+
12
+ ## Model Details
13
+
14
+ ### Model Description
15
+
16
+ <!-- Provide a longer summary of what this model is. -->
17
+
18
+ This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
+
20
+ - **Developed by:** [More Information Needed]
21
+ - **Funded by [optional]:** [More Information Needed]
22
+ - **Shared by [optional]:** [More Information Needed]
23
+ - **Model type:** [More Information Needed]
24
+ - **Language(s) (NLP):** [More Information Needed]
25
+ - **License:** [More Information Needed]
26
+ - **Finetuned from model [optional]:** [More Information Needed]
27
+
28
+ ### Model Sources [optional]
29
+
30
+ <!-- Provide the basic links for the model. -->
31
+
32
+ - **Repository:** [More Information Needed]
33
+ - **Paper [optional]:** [More Information Needed]
34
+ - **Demo [optional]:** [More Information Needed]
35
+
36
+ ## Uses
37
+
38
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
+
40
+ ### Direct Use
41
+
42
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
+
44
+ [More Information Needed]
45
+
46
+ ### Downstream Use [optional]
47
+
48
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
+
50
+ [More Information Needed]
51
+
52
+ ### Out-of-Scope Use
53
+
54
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
+
56
+ [More Information Needed]
57
+
58
+ ## Bias, Risks, and Limitations
59
+
60
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
+
62
+ [More Information Needed]
63
+
64
+ ### Recommendations
65
+
66
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
+
68
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
+
70
+ ## How to Get Started with the Model
71
+
72
+ Use the code below to get started with the model.
73
+
74
+ [More Information Needed]
75
+
76
+ ## Training Details
77
+
78
+ ### Training Data
79
+
80
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
+
82
+ [More Information Needed]
83
+
84
+ ### Training Procedure
85
+
86
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
+
88
+ #### Preprocessing [optional]
89
+
90
+ [More Information Needed]
91
+
92
+
93
+ #### Training Hyperparameters
94
+
95
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
+
97
+ #### Speeds, Sizes, Times [optional]
98
+
99
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
+
101
+ [More Information Needed]
102
+
103
+ ## Evaluation
104
+
105
+ <!-- This section describes the evaluation protocols and provides the results. -->
106
+
107
+ ### Testing Data, Factors & Metrics
108
+
109
+ #### Testing Data
110
+
111
+ <!-- This should link to a Dataset Card if possible. -->
112
+
113
+ [More Information Needed]
114
+
115
+ #### Factors
116
+
117
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
+
119
+ [More Information Needed]
120
+
121
+ #### Metrics
122
+
123
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
+
125
+ [More Information Needed]
126
+
127
+ ### Results
128
+
129
+ [More Information Needed]
130
+
131
+ #### Summary
132
+
133
+
134
+
135
+ ## Model Examination [optional]
136
+
137
+ <!-- Relevant interpretability work for the model goes here -->
138
+
139
+ [More Information Needed]
140
+
141
+ ## Environmental Impact
142
+
143
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
+
145
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
+
147
+ - **Hardware Type:** [More Information Needed]
148
+ - **Hours used:** [More Information Needed]
149
+ - **Cloud Provider:** [More Information Needed]
150
+ - **Compute Region:** [More Information Needed]
151
+ - **Carbon Emitted:** [More Information Needed]
152
+
153
+ ## Technical Specifications [optional]
154
+
155
+ ### Model Architecture and Objective
156
+
157
+ [More Information Needed]
158
+
159
+ ### Compute Infrastructure
160
+
161
+ [More Information Needed]
162
+
163
+ #### Hardware
164
+
165
+ [More Information Needed]
166
+
167
+ #### Software
168
+
169
+ [More Information Needed]
170
+
171
+ ## Citation [optional]
172
+
173
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
+
175
+ **BibTeX:**
176
+
177
+ [More Information Needed]
178
+
179
+ **APA:**
180
+
181
+ [More Information Needed]
182
+
183
+ ## Glossary [optional]
184
+
185
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
+
187
+ [More Information Needed]
188
+
189
+ ## More Information [optional]
190
+
191
+ [More Information Needed]
192
+
193
+ ## Model Card Authors [optional]
194
+
195
+ [More Information Needed]
196
+
197
+ ## Model Card Contact
198
+
199
+ [More Information Needed]
config.json ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "FP8Qwen2ForCausalLM"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "auto_map": {
7
+ "AutoConfig": "configuration_fp8_qwen2.FP8Qwen2Config",
8
+ "AutoModel": "modeling_fp8_qwen2.FP8Qwen2Model",
9
+ "AutoModelForCausalLM": "modeling_fp8_qwen2.FP8Qwen2ForCausalLM",
10
+ "AutoModelForQuestionAnswering": "modeling_fp8_qwen2.FP8Qwen2ForQuestionAnswering",
11
+ "AutoModelForSequenceClassification": "modeling_fp8_qwen2.FP8Qwen2ForSequenceClassification",
12
+ "AutoModelForTokenClassification": "modeling_fp8_qwen2.FP8Qwen2ForTokenClassification"
13
+ },
14
+ "bos_token_id": 151643,
15
+ "dtype": "bfloat16",
16
+ "eos_token_id": 151645,
17
+ "fp8_config": {
18
+ "act_block_size": 16,
19
+ "float8_dtype": "torch.float8_e4m3fn",
20
+ "layer_name": "",
21
+ "mm_block_size": 128,
22
+ "quant_type": "DIV",
23
+ "training_mode": true
24
+ },
25
+ "hidden_act": "silu",
26
+ "hidden_size": 3584,
27
+ "initializer_range": 0.02,
28
+ "intermediate_size": 18944,
29
+ "layer_types": [
30
+ "full_attention",
31
+ "full_attention",
32
+ "full_attention",
33
+ "full_attention",
34
+ "full_attention",
35
+ "full_attention",
36
+ "full_attention",
37
+ "full_attention",
38
+ "full_attention",
39
+ "full_attention",
40
+ "full_attention",
41
+ "full_attention",
42
+ "full_attention",
43
+ "full_attention",
44
+ "full_attention",
45
+ "full_attention",
46
+ "full_attention",
47
+ "full_attention",
48
+ "full_attention",
49
+ "full_attention",
50
+ "full_attention",
51
+ "full_attention",
52
+ "full_attention",
53
+ "full_attention",
54
+ "full_attention",
55
+ "full_attention",
56
+ "full_attention",
57
+ "full_attention"
58
+ ],
59
+ "max_position_embeddings": 32768,
60
+ "max_window_layers": 28,
61
+ "model_name_orig": "Qwen/Qwen2.5-7B-Instruct",
62
+ "model_type": "fp8_qwen2",
63
+ "num_attention_heads": 28,
64
+ "num_hidden_layers": 28,
65
+ "num_key_value_heads": 4,
66
+ "rms_norm_eps": 1e-06,
67
+ "rope_scaling": null,
68
+ "rope_theta": 1000000.0,
69
+ "sliding_window": null,
70
+ "tie_word_embeddings": false,
71
+ "transformers_version": "4.57.0",
72
+ "use_cache": true,
73
+ "use_sliding_window": false,
74
+ "vocab_size": 152064
75
+ }
configuration_fp8_qwen2.py ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Qwen2 model configuration"""
16
+
17
+ import torch
18
+ from dataclasses import dataclass, asdict
19
+ from enum import Enum
20
+
21
+ from transformers.configuration_utils import PretrainedConfig, layer_type_validation
22
+ from transformers.modeling_rope_utils import rope_config_validation
23
+ from transformers.utils import logging
24
+
25
+ from transformers.models.qwen2.configuration_qwen2 import Qwen2Config
26
+
27
+ from quasar.kernel.configs import QuantType
28
+
29
+ logger = logging.get_logger(__name__)
30
+
31
+
32
+ @dataclass
33
+ class FP8Config:
34
+ """
35
+ Configuration for FP8 quantization.
36
+ """
37
+
38
+ float8_dtype: torch.dtype = torch.float8_e4m3fn
39
+ quant_type: QuantType = QuantType.DIV
40
+ layer_name: str = ""
41
+
42
+ act_block_size: int = 16
43
+ mm_block_size: int = 128
44
+
45
+ training_mode: bool = True
46
+ """
47
+ If True, the linear layer will use high-precision weight.
48
+ If False, the linear layer will use per-block quantized weight.
49
+ """
50
+
51
+
52
+ class FP8Qwen2Config(Qwen2Config):
53
+ model_type = "fp8_qwen2"
54
+ fp8_config: FP8Config = FP8Config()
55
+ model_name_orig: str = ""
56
+ """Pass the name of the BF16 model"""
57
+
58
+ def __init__(
59
+ self,
60
+ vocab_size=151936,
61
+ hidden_size=4096,
62
+ intermediate_size=22016,
63
+ num_hidden_layers=32,
64
+ num_attention_heads=32,
65
+ num_key_value_heads=32,
66
+ hidden_act="silu",
67
+ max_position_embeddings=32768,
68
+ initializer_range=0.02,
69
+ rms_norm_eps=1e-6,
70
+ use_cache=True,
71
+ tie_word_embeddings=False,
72
+ rope_theta=10000.0,
73
+ rope_scaling=None,
74
+ use_sliding_window=False,
75
+ sliding_window=4096,
76
+ max_window_layers=28,
77
+ layer_types=None,
78
+ attention_dropout=0.0,
79
+ # Customized configs begins here
80
+ fp8_config=None,
81
+ model_name_orig="",
82
+ **kwargs,
83
+ ):
84
+ super().__init__(
85
+ vocab_size=vocab_size,
86
+ hidden_size=hidden_size,
87
+ intermediate_size=intermediate_size,
88
+ num_hidden_layers=num_hidden_layers,
89
+ num_attention_heads=num_attention_heads,
90
+ num_key_value_heads=num_key_value_heads,
91
+ hidden_act=hidden_act,
92
+ max_position_embeddings=max_position_embeddings,
93
+ initializer_range=initializer_range,
94
+ rms_norm_eps=rms_norm_eps,
95
+ use_cache=use_cache,
96
+ tie_word_embeddings=tie_word_embeddings,
97
+ rope_theta=rope_theta,
98
+ rope_scaling=rope_scaling,
99
+ use_sliding_window=use_sliding_window,
100
+ sliding_window=sliding_window,
101
+ max_window_layers=max_window_layers,
102
+ layer_types=layer_types,
103
+ attention_dropout=attention_dropout,
104
+ **kwargs,
105
+ )
106
+
107
+
108
+ # Convert it from dict to FP8Config (dataclass)
109
+ if fp8_config is not None:
110
+ self.fp8_config = fp8_config if isinstance(fp8_config, FP8Config) else FP8Config(**fp8_config)
111
+ else:
112
+ self.fp8_config = FP8Config()
113
+
114
+ self.model_name_orig = model_name_orig
115
+
116
+
117
+ def to_dict(self):
118
+ output = super().to_dict()
119
+ if hasattr(self.fp8_config, "__dataclass_fields__"):
120
+ cfg_dict = asdict(self.fp8_config)
121
+ for k, v in cfg_dict.items():
122
+ if isinstance(v, torch.dtype): # float8_dtype
123
+ cfg_dict[k] = str(v) # save as 'torch.float8_e4m3fn'
124
+ elif isinstance(v, Enum): # quant_type
125
+ cfg_dict[k] = v.name # save as 'DIV'
126
+ output["fp8_config"] = cfg_dict
127
+ else:
128
+ output["fp8_config"] = self.fp8_config
129
+ return output
130
+
131
+
132
+ @classmethod
133
+ def from_dict(cls, config_dict, **kwargs):
134
+ config = super().from_dict(config_dict, **kwargs)
135
+
136
+ fp8_config = config_dict.get("fp8_config", {})
137
+ for k, v in fp8_config.items():
138
+ if k == "float8_dtype":
139
+ assert v.startswith("torch."), f"Invalid float8_dtype: {v}"
140
+ fp8_config[k] = getattr(torch, v[len("torch."):]) #
141
+ elif k == "quant_type":
142
+ fp8_config[k] = getattr(QuantType, v)
143
+ config.fp8_config = FP8Config(**fp8_config)
144
+ return config
145
+
146
+
147
+ __all__ = ["FP8Qwen2Config"]
148
+
149
+ FP8Qwen2Config.register_for_auto_class()
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 151643,
4
+ "eos_token_id": 151645,
5
+ "transformers_version": "4.57.0"
6
+ }
model-00001-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ff3b270cb6b8ce8a059a43678cebaefb7aa2a3b587aadc5a4e2f6c1e4d13a28
3
+ size 4877660776
model-00002-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:854698ca4d7581b9fd40f5da9176b010422194ec26cab3abd907ff21e477d1ca
3
+ size 4932751008
model-00003-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6295baeb13806b95509f86175dd3a298bf39630071a4dc2b2d31441c9230b011
3
+ size 4330865200
model-00004-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:06006972c3be88e8a44fe21cfe2b0472b130780c781a741f8f90f1fe5ba3aae2
3
+ size 1089994880
model.safetensors.index.json ADDED
@@ -0,0 +1,347 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_parameters": 7615616512,
4
+ "total_size": 15231233024
5
+ },
6
+ "weight_map": {
7
+ "lm_head.weight": "model-00004-of-00004.safetensors",
8
+ "model.embed_tokens.weight": "model-00001-of-00004.safetensors",
9
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00004.safetensors",
10
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
11
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
12
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
13
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
14
+ "model.layers.0.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
15
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
16
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
17
+ "model.layers.0.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
18
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
19
+ "model.layers.0.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
20
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
21
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00004.safetensors",
22
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
23
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
24
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
25
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
26
+ "model.layers.1.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
27
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
28
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
29
+ "model.layers.1.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
30
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
31
+ "model.layers.1.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
32
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
33
+ "model.layers.10.input_layernorm.weight": "model-00002-of-00004.safetensors",
34
+ "model.layers.10.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
35
+ "model.layers.10.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
36
+ "model.layers.10.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
37
+ "model.layers.10.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
38
+ "model.layers.10.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
39
+ "model.layers.10.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
40
+ "model.layers.10.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
41
+ "model.layers.10.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
42
+ "model.layers.10.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
43
+ "model.layers.10.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
44
+ "model.layers.10.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
45
+ "model.layers.11.input_layernorm.weight": "model-00002-of-00004.safetensors",
46
+ "model.layers.11.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
47
+ "model.layers.11.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
48
+ "model.layers.11.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
49
+ "model.layers.11.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
50
+ "model.layers.11.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
51
+ "model.layers.11.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
52
+ "model.layers.11.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
53
+ "model.layers.11.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
54
+ "model.layers.11.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
55
+ "model.layers.11.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
56
+ "model.layers.11.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
57
+ "model.layers.12.input_layernorm.weight": "model-00002-of-00004.safetensors",
58
+ "model.layers.12.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
59
+ "model.layers.12.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
60
+ "model.layers.12.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
61
+ "model.layers.12.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
62
+ "model.layers.12.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
63
+ "model.layers.12.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
64
+ "model.layers.12.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
65
+ "model.layers.12.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
66
+ "model.layers.12.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
67
+ "model.layers.12.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
68
+ "model.layers.12.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
69
+ "model.layers.13.input_layernorm.weight": "model-00002-of-00004.safetensors",
70
+ "model.layers.13.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
71
+ "model.layers.13.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
72
+ "model.layers.13.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
73
+ "model.layers.13.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
74
+ "model.layers.13.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
75
+ "model.layers.13.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
76
+ "model.layers.13.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
77
+ "model.layers.13.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
78
+ "model.layers.13.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
79
+ "model.layers.13.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
80
+ "model.layers.13.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
81
+ "model.layers.14.input_layernorm.weight": "model-00002-of-00004.safetensors",
82
+ "model.layers.14.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
83
+ "model.layers.14.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
84
+ "model.layers.14.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
85
+ "model.layers.14.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
86
+ "model.layers.14.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
87
+ "model.layers.14.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
88
+ "model.layers.14.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
89
+ "model.layers.14.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
90
+ "model.layers.14.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
91
+ "model.layers.14.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
92
+ "model.layers.14.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
93
+ "model.layers.15.input_layernorm.weight": "model-00002-of-00004.safetensors",
94
+ "model.layers.15.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
95
+ "model.layers.15.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
96
+ "model.layers.15.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
97
+ "model.layers.15.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
98
+ "model.layers.15.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
99
+ "model.layers.15.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
100
+ "model.layers.15.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
101
+ "model.layers.15.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
102
+ "model.layers.15.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
103
+ "model.layers.15.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
104
+ "model.layers.15.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
105
+ "model.layers.16.input_layernorm.weight": "model-00002-of-00004.safetensors",
106
+ "model.layers.16.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
107
+ "model.layers.16.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
108
+ "model.layers.16.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
109
+ "model.layers.16.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
110
+ "model.layers.16.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
111
+ "model.layers.16.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
112
+ "model.layers.16.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
113
+ "model.layers.16.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
114
+ "model.layers.16.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
115
+ "model.layers.16.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
116
+ "model.layers.16.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
117
+ "model.layers.17.input_layernorm.weight": "model-00002-of-00004.safetensors",
118
+ "model.layers.17.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
119
+ "model.layers.17.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
120
+ "model.layers.17.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
121
+ "model.layers.17.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
122
+ "model.layers.17.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
123
+ "model.layers.17.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
124
+ "model.layers.17.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
125
+ "model.layers.17.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
126
+ "model.layers.17.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
127
+ "model.layers.17.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
128
+ "model.layers.17.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
129
+ "model.layers.18.input_layernorm.weight": "model-00003-of-00004.safetensors",
130
+ "model.layers.18.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
131
+ "model.layers.18.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
132
+ "model.layers.18.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
133
+ "model.layers.18.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
134
+ "model.layers.18.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
135
+ "model.layers.18.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
136
+ "model.layers.18.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
137
+ "model.layers.18.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
138
+ "model.layers.18.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
139
+ "model.layers.18.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
140
+ "model.layers.18.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
141
+ "model.layers.19.input_layernorm.weight": "model-00003-of-00004.safetensors",
142
+ "model.layers.19.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
143
+ "model.layers.19.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
144
+ "model.layers.19.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
145
+ "model.layers.19.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
146
+ "model.layers.19.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
147
+ "model.layers.19.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
148
+ "model.layers.19.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
149
+ "model.layers.19.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
150
+ "model.layers.19.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
151
+ "model.layers.19.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
152
+ "model.layers.19.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
153
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00004.safetensors",
154
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
155
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
156
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
157
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
158
+ "model.layers.2.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
159
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
160
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
161
+ "model.layers.2.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
162
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
163
+ "model.layers.2.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
164
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
165
+ "model.layers.20.input_layernorm.weight": "model-00003-of-00004.safetensors",
166
+ "model.layers.20.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
167
+ "model.layers.20.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
168
+ "model.layers.20.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
169
+ "model.layers.20.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
170
+ "model.layers.20.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
171
+ "model.layers.20.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
172
+ "model.layers.20.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
173
+ "model.layers.20.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
174
+ "model.layers.20.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
175
+ "model.layers.20.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
176
+ "model.layers.20.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
177
+ "model.layers.21.input_layernorm.weight": "model-00003-of-00004.safetensors",
178
+ "model.layers.21.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
179
+ "model.layers.21.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
180
+ "model.layers.21.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
181
+ "model.layers.21.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
182
+ "model.layers.21.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
183
+ "model.layers.21.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
184
+ "model.layers.21.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
185
+ "model.layers.21.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
186
+ "model.layers.21.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
187
+ "model.layers.21.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
188
+ "model.layers.21.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
189
+ "model.layers.22.input_layernorm.weight": "model-00003-of-00004.safetensors",
190
+ "model.layers.22.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
191
+ "model.layers.22.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
192
+ "model.layers.22.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
193
+ "model.layers.22.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
194
+ "model.layers.22.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
195
+ "model.layers.22.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
196
+ "model.layers.22.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
197
+ "model.layers.22.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
198
+ "model.layers.22.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
199
+ "model.layers.22.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
200
+ "model.layers.22.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
201
+ "model.layers.23.input_layernorm.weight": "model-00003-of-00004.safetensors",
202
+ "model.layers.23.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
203
+ "model.layers.23.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
204
+ "model.layers.23.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
205
+ "model.layers.23.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
206
+ "model.layers.23.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
207
+ "model.layers.23.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
208
+ "model.layers.23.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
209
+ "model.layers.23.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
210
+ "model.layers.23.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
211
+ "model.layers.23.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
212
+ "model.layers.23.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
213
+ "model.layers.24.input_layernorm.weight": "model-00003-of-00004.safetensors",
214
+ "model.layers.24.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
215
+ "model.layers.24.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
216
+ "model.layers.24.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
217
+ "model.layers.24.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
218
+ "model.layers.24.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
219
+ "model.layers.24.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
220
+ "model.layers.24.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
221
+ "model.layers.24.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
222
+ "model.layers.24.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
223
+ "model.layers.24.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
224
+ "model.layers.24.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
225
+ "model.layers.25.input_layernorm.weight": "model-00003-of-00004.safetensors",
226
+ "model.layers.25.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
227
+ "model.layers.25.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
228
+ "model.layers.25.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
229
+ "model.layers.25.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
230
+ "model.layers.25.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
231
+ "model.layers.25.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
232
+ "model.layers.25.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
233
+ "model.layers.25.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
234
+ "model.layers.25.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
235
+ "model.layers.25.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
236
+ "model.layers.25.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
237
+ "model.layers.26.input_layernorm.weight": "model-00003-of-00004.safetensors",
238
+ "model.layers.26.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
239
+ "model.layers.26.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
240
+ "model.layers.26.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
241
+ "model.layers.26.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
242
+ "model.layers.26.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
243
+ "model.layers.26.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
244
+ "model.layers.26.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
245
+ "model.layers.26.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
246
+ "model.layers.26.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
247
+ "model.layers.26.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
248
+ "model.layers.26.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
249
+ "model.layers.27.input_layernorm.weight": "model-00003-of-00004.safetensors",
250
+ "model.layers.27.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
251
+ "model.layers.27.mlp.gate_proj.weight": "model-00003-of-00004.safetensors",
252
+ "model.layers.27.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
253
+ "model.layers.27.post_attention_layernorm.weight": "model-00003-of-00004.safetensors",
254
+ "model.layers.27.self_attn.k_proj.bias": "model-00003-of-00004.safetensors",
255
+ "model.layers.27.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
256
+ "model.layers.27.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
257
+ "model.layers.27.self_attn.q_proj.bias": "model-00003-of-00004.safetensors",
258
+ "model.layers.27.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
259
+ "model.layers.27.self_attn.v_proj.bias": "model-00003-of-00004.safetensors",
260
+ "model.layers.27.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
261
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00004.safetensors",
262
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
263
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
264
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
265
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
266
+ "model.layers.3.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
267
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
268
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
269
+ "model.layers.3.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
270
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
271
+ "model.layers.3.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
272
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
273
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00004.safetensors",
274
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
275
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
276
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
277
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
278
+ "model.layers.4.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
279
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
280
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
281
+ "model.layers.4.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
282
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
283
+ "model.layers.4.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
284
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
285
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00004.safetensors",
286
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
287
+ "model.layers.5.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
288
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
289
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
290
+ "model.layers.5.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
291
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
292
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
293
+ "model.layers.5.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
294
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
295
+ "model.layers.5.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
296
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
297
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00004.safetensors",
298
+ "model.layers.6.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
299
+ "model.layers.6.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
300
+ "model.layers.6.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
301
+ "model.layers.6.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
302
+ "model.layers.6.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
303
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
304
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
305
+ "model.layers.6.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
306
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
307
+ "model.layers.6.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
308
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
309
+ "model.layers.7.input_layernorm.weight": "model-00001-of-00004.safetensors",
310
+ "model.layers.7.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
311
+ "model.layers.7.mlp.gate_proj.weight": "model-00001-of-00004.safetensors",
312
+ "model.layers.7.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
313
+ "model.layers.7.post_attention_layernorm.weight": "model-00001-of-00004.safetensors",
314
+ "model.layers.7.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
315
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
316
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
317
+ "model.layers.7.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
318
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
319
+ "model.layers.7.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
320
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
321
+ "model.layers.8.input_layernorm.weight": "model-00002-of-00004.safetensors",
322
+ "model.layers.8.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
323
+ "model.layers.8.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
324
+ "model.layers.8.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
325
+ "model.layers.8.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
326
+ "model.layers.8.self_attn.k_proj.bias": "model-00001-of-00004.safetensors",
327
+ "model.layers.8.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
328
+ "model.layers.8.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
329
+ "model.layers.8.self_attn.q_proj.bias": "model-00001-of-00004.safetensors",
330
+ "model.layers.8.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
331
+ "model.layers.8.self_attn.v_proj.bias": "model-00001-of-00004.safetensors",
332
+ "model.layers.8.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
333
+ "model.layers.9.input_layernorm.weight": "model-00002-of-00004.safetensors",
334
+ "model.layers.9.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
335
+ "model.layers.9.mlp.gate_proj.weight": "model-00002-of-00004.safetensors",
336
+ "model.layers.9.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
337
+ "model.layers.9.post_attention_layernorm.weight": "model-00002-of-00004.safetensors",
338
+ "model.layers.9.self_attn.k_proj.bias": "model-00002-of-00004.safetensors",
339
+ "model.layers.9.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
340
+ "model.layers.9.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
341
+ "model.layers.9.self_attn.q_proj.bias": "model-00002-of-00004.safetensors",
342
+ "model.layers.9.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
343
+ "model.layers.9.self_attn.v_proj.bias": "model-00002-of-00004.safetensors",
344
+ "model.layers.9.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
345
+ "model.norm.weight": "model-00003-of-00004.safetensors"
346
+ }
347
+ }
modeling_fp8_qwen2.py ADDED
@@ -0,0 +1,427 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Callable, Optional, Union
2
+
3
+ import torch
4
+ from torch import nn
5
+
6
+ from transformers.activations import ACT2FN
7
+ from transformers.cache_utils import Cache, DynamicCache
8
+ from transformers.generation import GenerationMixin
9
+ from transformers.integrations import use_kernel_forward_from_hub
10
+ from transformers.masking_utils import create_causal_mask, create_sliding_window_causal_mask
11
+ from transformers.modeling_flash_attention_utils import FlashAttentionKwargs
12
+ from transformers.modeling_layers import (
13
+ GenericForQuestionAnswering,
14
+ GenericForSequenceClassification,
15
+ GenericForTokenClassification,
16
+ GradientCheckpointingLayer,
17
+ )
18
+ from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
19
+ from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
20
+ from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
21
+ from transformers.processing_utils import Unpack
22
+ from transformers.utils import TransformersKwargs, auto_docstring, can_return_tuple, logging
23
+ from transformers.utils.deprecation import deprecate_kwarg
24
+ from transformers.utils.generic import check_model_inputs
25
+ from transformers.models.qwen2.configuration_qwen2 import Qwen2Config
26
+
27
+ from transformers.models.qwen2.modeling_qwen2 import (
28
+ Qwen2MLP,
29
+ Qwen2Attention,
30
+ apply_rotary_pos_emb,
31
+ eager_attention_forward,
32
+ Qwen2RMSNorm,
33
+ Qwen2RotaryEmbedding,
34
+ Qwen2Model,
35
+ Qwen2ForCausalLM,
36
+ )
37
+
38
+ from transformers.modeling_layers import (
39
+ GenericForQuestionAnswering,
40
+ GenericForSequenceClassification,
41
+ GenericForTokenClassification,
42
+ GradientCheckpointingLayer,
43
+ )
44
+
45
+ from .configuration_fp8_qwen2 import FP8Qwen2Config
46
+
47
+ from torchao.float8.float8_training_tensor import Float8TrainingTensor
48
+
49
+ from quasar.module import (
50
+ FP8RMSNorm,
51
+ FP8DSLinearWithCoat,
52
+ FP8DSLinearWithCoatWeightBlock,
53
+ FP8FusedSiLUMul,
54
+ FP8Identity,
55
+ )
56
+
57
+ from quasar.kernel.configs import FP8RMSNormConfig, QuantType, FP8MulConfig, FP8DSLinearWithCoatConfig, FP8QuantConfig
58
+ from quasar.kernel.quant.quantize_hp2pb import fp8_quantize_hp2pb
59
+ from quasar.kernel.quant.dequantize_pb2hp import fp8_dequantize_pb2hp
60
+
61
+ logger = logging.get_logger(__name__)
62
+
63
+
64
+ class FP8Qwen2MLP(Qwen2MLP):
65
+ def __init__(self, config: FP8Qwen2Config):
66
+ super().__init__(config)
67
+ linear_module = FP8DSLinearWithCoat if config.fp8_config.training_mode else FP8DSLinearWithCoatWeightBlock
68
+ self.gate_proj = linear_module(self.hidden_size, self.intermediate_size, bias=False, dsgemm_config=FP8DSLinearWithCoatConfig(layer_name=f"gate_proj"))
69
+ self.up_proj = linear_module(self.hidden_size, self.intermediate_size, bias=False, dsgemm_config=FP8DSLinearWithCoatConfig(layer_name=f"up_proj"))
70
+ self.down_proj = linear_module(self.intermediate_size, self.hidden_size, bias=False, dsgemm_config=FP8DSLinearWithCoatConfig(layer_name=f"down_proj"))
71
+
72
+ if config.hidden_act == "silu":
73
+ mul_config = FP8MulConfig(
74
+ quant_type=QuantType.MUL,
75
+ )
76
+ self.act_fn = FP8FusedSiLUMul(mul_config)
77
+ else:
78
+ raise ValueError(f"Unsupported activation function: {config.hidden_act}")
79
+
80
+ def forward(self, x):
81
+ gate_x = self.gate_proj(x)
82
+ up_x = self.up_proj(x)
83
+
84
+ mul_x = self.act_fn(gate_x, up_x)
85
+ down_proj = self.down_proj(mul_x)
86
+
87
+ return down_proj
88
+
89
+
90
+ class FP8Qwen2Attention(Qwen2Attention):
91
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
92
+
93
+ def __init__(self, config: FP8Qwen2Config, layer_idx: int):
94
+ super().__init__(config, layer_idx)
95
+ linear_module = FP8DSLinearWithCoat if config.fp8_config.training_mode else FP8DSLinearWithCoatWeightBlock
96
+ self.q_proj = linear_module(config.hidden_size, config.num_attention_heads * self.head_dim, bias=True, dsgemm_config=FP8DSLinearWithCoatConfig(layer_name=f"q_proj"))
97
+ self.k_proj = linear_module(config.hidden_size, config.num_key_value_heads * self.head_dim, bias=True, dsgemm_config=FP8DSLinearWithCoatConfig(layer_name=f"k_proj"))
98
+ self.v_proj = linear_module(config.hidden_size, config.num_key_value_heads * self.head_dim, bias=True, dsgemm_config=FP8DSLinearWithCoatConfig(layer_name=f"v_proj"))
99
+
100
+ if not config.fp8_config.training_mode:
101
+ # Only when doing inference, we quantize the output of the attention layer.
102
+ self.o_proj = linear_module(
103
+ config.num_attention_heads * self.head_dim, config.hidden_size, bias=False,
104
+ dsgemm_config=FP8DSLinearWithCoatConfig(
105
+ fwd_input_quant_type=QuantType.DIV,
106
+ layer_name=f"o_proj",
107
+ scale_dtype=torch.float32,
108
+ )
109
+ )
110
+
111
+
112
+ @deprecate_kwarg("past_key_value", new_name="past_key_values", version="4.58")
113
+ def forward(
114
+ self,
115
+ hidden_states: torch.Tensor,
116
+ position_embeddings: tuple[torch.Tensor, torch.Tensor],
117
+ attention_mask: Optional[torch.Tensor],
118
+ past_key_values: Optional[Cache] = None,
119
+ cache_position: Optional[torch.LongTensor] = None,
120
+ **kwargs: Unpack[FlashAttentionKwargs],
121
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
122
+ if isinstance(hidden_states, Float8TrainingTensor):
123
+ # Float8Tensor's last dim is quantize group size, not hidden size.
124
+ input_shape = hidden_states.shape[:-2]
125
+ else:
126
+ input_shape = hidden_states.shape[:-1]
127
+ hidden_shape = (*input_shape, -1, self.head_dim)
128
+
129
+ query_states = self.q_proj(hidden_states).view(hidden_shape).transpose(1, 2)
130
+ key_states = self.k_proj(hidden_states).view(hidden_shape).transpose(1, 2)
131
+ value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2)
132
+
133
+ cos, sin = position_embeddings
134
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
135
+
136
+ # TODO: Add quantization
137
+
138
+ if past_key_values is not None:
139
+ # sin and cos are specific to RoPE models; cache_position needed for the static cache
140
+ cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
141
+ key_states, value_states = past_key_values.update(key_states, value_states, self.layer_idx, cache_kwargs)
142
+
143
+ attention_interface: Callable = eager_attention_forward
144
+ if self.config._attn_implementation != "eager":
145
+ attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
146
+
147
+ attn_output, attn_weights = attention_interface(
148
+ self,
149
+ query_states,
150
+ key_states,
151
+ value_states,
152
+ attention_mask,
153
+ dropout=0.0 if not self.training else self.attention_dropout,
154
+ scaling=self.scaling,
155
+ sliding_window=self.sliding_window, # main diff with Qwen2
156
+ **kwargs,
157
+ )
158
+
159
+ attn_output = attn_output.reshape(*input_shape, -1).contiguous()
160
+ attn_output = self.o_proj(attn_output)
161
+ return attn_output, attn_weights
162
+
163
+
164
+ class FP8Qwen2DecoderLayer(GradientCheckpointingLayer):
165
+ def __init__(self, config: FP8Qwen2Config, layer_idx: int):
166
+ super().__init__()
167
+ self.hidden_size = config.hidden_size
168
+
169
+ self.self_attn = FP8Qwen2Attention(config=config, layer_idx=layer_idx)
170
+
171
+ self.mlp = FP8Qwen2MLP(config)
172
+ self.input_layernorm = FP8RMSNorm(config.hidden_size, eps=config.rms_norm_eps, norm_config=FP8RMSNormConfig(mm_block_size=config.fp8_config.mm_block_size, quant_type=QuantType.MUL, save_fp8_input=True))
173
+ self.post_attention_layernorm = FP8RMSNorm(config.hidden_size, eps=config.rms_norm_eps, norm_config=FP8RMSNormConfig(mm_block_size=config.fp8_config.mm_block_size, quant_type=QuantType.MUL, save_fp8_input=True))
174
+ self.attention_type = config.layer_types[layer_idx]
175
+
176
+ @deprecate_kwarg("past_key_value", new_name="past_key_values", version="4.58")
177
+ def forward(
178
+ self,
179
+ hidden_states: torch.Tensor,
180
+ attention_mask: Optional[torch.Tensor] = None,
181
+ position_ids: Optional[torch.LongTensor] = None,
182
+ past_key_values: Optional[Cache] = None,
183
+ use_cache: Optional[bool] = False,
184
+ cache_position: Optional[torch.LongTensor] = None,
185
+ position_embeddings: Optional[tuple[torch.Tensor, torch.Tensor]] = None, # necessary, but kept here for BC
186
+ **kwargs: Unpack[TransformersKwargs],
187
+ ) -> torch.Tensor:
188
+ residual = hidden_states
189
+ hidden_states = self.input_layernorm(hidden_states)
190
+ # Self Attention
191
+ hidden_states, _ = self.self_attn(
192
+ hidden_states=hidden_states,
193
+ attention_mask=attention_mask,
194
+ position_ids=position_ids,
195
+ past_key_values=past_key_values,
196
+ use_cache=use_cache,
197
+ cache_position=cache_position,
198
+ position_embeddings=position_embeddings,
199
+ **kwargs,
200
+ )
201
+ hidden_states = residual + hidden_states
202
+
203
+ # Fully Connected
204
+ residual = hidden_states
205
+ hidden_states = self.post_attention_layernorm(hidden_states)
206
+ hidden_states = self.mlp(hidden_states)
207
+ hidden_states = residual + hidden_states
208
+ return hidden_states
209
+
210
+
211
+ @auto_docstring
212
+ class FP8Qwen2PreTrainedModel(PreTrainedModel):
213
+ config_class = FP8Qwen2Config
214
+ config: FP8Qwen2Config
215
+ base_model_prefix = "model"
216
+ supports_gradient_checkpointing = True
217
+ _no_split_modules = ["FP8Qwen2DecoderLayer"]
218
+ _skip_keys_device_placement = ["past_key_values"]
219
+ _supports_flash_attn = True
220
+ _supports_sdpa = True
221
+ _supports_flex_attn = True
222
+
223
+ _can_compile_fullgraph = True
224
+ _supports_attention_backend = True
225
+ _can_record_outputs = {
226
+ "hidden_states": FP8Qwen2DecoderLayer,
227
+ "attentions": FP8Qwen2Attention,
228
+ }
229
+
230
+
231
+ @auto_docstring
232
+ class FP8Qwen2Model(FP8Qwen2PreTrainedModel):
233
+ def __init__(self, config: FP8Qwen2Config):
234
+ super().__init__(config)
235
+ self.padding_idx = config.pad_token_id
236
+ self.vocab_size = config.vocab_size
237
+
238
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
239
+ self.layers = nn.ModuleList(
240
+ [FP8Qwen2DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
241
+ )
242
+ self.norm = Qwen2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
243
+ self.rotary_emb = Qwen2RotaryEmbedding(config=config)
244
+ self.gradient_checkpointing = False
245
+ self.has_sliding_layers = "sliding_attention" in self.config.layer_types
246
+
247
+ # Initialize weights and apply final processing
248
+ self.post_init()
249
+
250
+ forward = Qwen2Model.forward
251
+
252
+
253
+ @auto_docstring
254
+ class FP8Qwen2ForCausalLM(FP8Qwen2PreTrainedModel, GenerationMixin):
255
+ config_class = FP8Qwen2Config
256
+ _tied_weights_keys = ["lm_head.weight"]
257
+ _tp_plan = {"lm_head": "colwise_rep"}
258
+ _pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
259
+
260
+ def __init__(self, config):
261
+ super().__init__(config)
262
+ self.model = FP8Qwen2Model(config)
263
+ self.vocab_size = config.vocab_size
264
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
265
+
266
+ # Initialize weights and apply final processing
267
+ self.post_init()
268
+
269
+ @can_return_tuple
270
+ @auto_docstring
271
+ def forward(
272
+ self,
273
+ input_ids: Optional[torch.LongTensor] = None,
274
+ attention_mask: Optional[torch.Tensor] = None,
275
+ position_ids: Optional[torch.LongTensor] = None,
276
+ past_key_values: Optional[Cache] = None,
277
+ inputs_embeds: Optional[torch.FloatTensor] = None,
278
+ labels: Optional[torch.LongTensor] = None,
279
+ use_cache: Optional[bool] = None,
280
+ cache_position: Optional[torch.LongTensor] = None,
281
+ logits_to_keep: Union[int, torch.Tensor] = 0,
282
+ **kwargs: Unpack[TransformersKwargs],
283
+ ) -> CausalLMOutputWithPast:
284
+ r"""
285
+ Example:
286
+
287
+ ```python
288
+ >>> from transformers import AutoTokenizer, Qwen2ForCausalLM
289
+
290
+ >>> model = Qwen2ForCausalLM.from_pretrained("meta-qwen2/Qwen2-2-7b-hf")
291
+ >>> tokenizer = AutoTokenizer.from_pretrained("meta-qwen2/Qwen2-2-7b-hf")
292
+
293
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
294
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
295
+
296
+ >>> # Generate
297
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
298
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
299
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
300
+ ```"""
301
+ outputs: BaseModelOutputWithPast = self.model(
302
+ input_ids=input_ids,
303
+ attention_mask=attention_mask,
304
+ position_ids=position_ids,
305
+ past_key_values=past_key_values,
306
+ inputs_embeds=inputs_embeds,
307
+ use_cache=use_cache,
308
+ cache_position=cache_position,
309
+ **kwargs,
310
+ )
311
+
312
+ hidden_states = outputs.last_hidden_state
313
+ # Only compute necessary logits, and do not upcast them to float if we are not computing the loss
314
+ slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
315
+ logits = self.lm_head(hidden_states[:, slice_indices, :])
316
+
317
+ loss = None
318
+ if labels is not None:
319
+ loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.vocab_size, **kwargs)
320
+
321
+ return CausalLMOutputWithPast(
322
+ loss=loss,
323
+ logits=logits,
324
+ past_key_values=outputs.past_key_values,
325
+ hidden_states=outputs.hidden_states,
326
+ attentions=outputs.attentions,
327
+ )
328
+
329
+
330
+ class FP8Qwen2ForSequenceClassification(GenericForSequenceClassification, FP8Qwen2PreTrainedModel):
331
+ pass
332
+
333
+
334
+ class FP8Qwen2ForTokenClassification(GenericForTokenClassification, FP8Qwen2PreTrainedModel):
335
+ pass
336
+
337
+
338
+ class FP8Qwen2ForQuestionAnswering(GenericForQuestionAnswering, FP8Qwen2PreTrainedModel):
339
+ base_model_prefix = "transformer" # For BC, where `transformer` was used instead of `model`
340
+
341
+
342
+ __all__ = [
343
+ "FP8Qwen2PreTrainedModel",
344
+ "FP8Qwen2Model",
345
+ "FP8Qwen2ForCausalLM",
346
+ "FP8Qwen2ForSequenceClassification",
347
+ "FP8Qwen2ForTokenClassification",
348
+ "FP8Qwen2ForQuestionAnswering",
349
+ ]
350
+
351
+
352
+ FP8Qwen2Model.register_for_auto_class("AutoModel")
353
+ FP8Qwen2ForCausalLM.register_for_auto_class("AutoModelForCausalLM")
354
+
355
+
356
+ def make_state_dict_compatible_with_hf(
357
+ state_dict: dict[str, torch.Tensor],
358
+ linear_keys: list[str],
359
+ undesired_linear_keys: list[str],
360
+ config: FP8Qwen2Config = FP8Qwen2Config(),
361
+ already_fp8: bool = False,
362
+ ) -> dict[str, torch.Tensor]:
363
+ """
364
+ Make the state dict compatible with HuggingFace.
365
+ """
366
+ # Assert linear keys and undesired linear keys are non-overlapping
367
+ assert set(linear_keys).isdisjoint(set(undesired_linear_keys))
368
+
369
+ compatible_state_dict = {}
370
+
371
+ for key in state_dict.keys():
372
+ if any(k in key for k in linear_keys):
373
+ weight = state_dict[key]
374
+
375
+ if already_fp8:
376
+ # The name (either weight or weight_scale_inv) is the same as the original key.
377
+ compatible_state_dict[key] = weight
378
+ else:
379
+ # We need to use float32 for the scale, since we are using DeepGEMM.
380
+ tmp_quant_cfg = FP8QuantConfig(
381
+ float8_dtype=config.fp8_config.float8_dtype,
382
+ quant_type=config.fp8_config.quant_type,
383
+ fwd_block_size=config.fp8_config.mm_block_size,
384
+ scale_dtype=torch.float32,
385
+ )
386
+ quant_weight, scale_weight = fp8_quantize_hp2pb(
387
+ weight, tmp_quant_cfg, block_size=config.fp8_config.mm_block_size
388
+ )
389
+
390
+ name_quant = key.replace("weight", "weight")
391
+ name_scale = key.replace("weight", "weight_scale_inv")
392
+ compatible_state_dict[name_quant] = quant_weight
393
+ compatible_state_dict[name_scale] = scale_weight
394
+
395
+ elif any(k in key for k in undesired_linear_keys):
396
+ # Dequantize the weight
397
+ if already_fp8:
398
+ # We only do the dequantization once. When encountering the weight, we skip it.
399
+ if "weight_scale_inv" in key:
400
+ name_quant = key.replace("weight_scale_inv", "weight")
401
+ quant_weight = state_dict[name_quant]
402
+ scale_weight = state_dict[key]
403
+ weight = fp8_dequantize_pb2hp(quant_weight, scale_weight, config.fp8_config, block_size=config.fp8_config.mm_block_size)
404
+ compatible_state_dict[name_quant] = weight
405
+ else:
406
+ # Do not quantize the weight.
407
+ compatible_state_dict[key] = state_dict[key]
408
+
409
+ else:
410
+ compatible_state_dict[key] = state_dict[key]
411
+ return compatible_state_dict
412
+
413
+
414
+ def set_named_weight_to_fp8(
415
+ model: FP8Qwen2ForCausalLM,
416
+ linear_keys: list[str] = ["q_proj", "k_proj", "v_proj", "gate_proj", "up_proj", "down_proj"],
417
+ ):
418
+ """
419
+ Set the dtype of the weight of the linear layers to FP8.
420
+ Also set layer name for debugging.
421
+ """
422
+ for name, module in model.named_modules():
423
+ if any(k in name for k in linear_keys):
424
+ module.weight.data = module.weight.data.to(torch.float8_e4m3fn)
425
+ module.layer_name = name
426
+
427
+ return model