lucweber commited on
Commit
d4c0208
·
verified ·
1 Parent(s): e11fe9e

Upload difficulty scorer model

Browse files
README.md ADDED
File without changes
__init.py__ ADDED
@@ -0,0 +1 @@
 
 
1
+ from .model import CausalLMForRegression
config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen3ForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 151643,
8
+ "eos_token_id": 151645,
9
+ "head_dim": 128,
10
+ "hidden_act": "silu",
11
+ "hidden_size": 4096,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 12288,
14
+ "max_position_embeddings": 40960,
15
+ "max_window_layers": 36,
16
+ "model_type": "qwen3",
17
+ "num_attention_heads": 32,
18
+ "num_hidden_layers": 36,
19
+ "num_key_value_heads": 8,
20
+ "output_hidden_states": true,
21
+ "rms_norm_eps": 1e-06,
22
+ "rope_scaling": null,
23
+ "rope_theta": 1000000,
24
+ "sliding_window": null,
25
+ "tie_word_embeddings": false,
26
+ "torch_dtype": "bfloat16",
27
+ "transformers_version": "4.51.3",
28
+ "use_cache": true,
29
+ "use_sliding_window": false,
30
+ "vocab_size": 151936
31
+ }
generation_config.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "temperature": 0.6,
10
+ "top_k": 20,
11
+ "top_p": 0.95,
12
+ "transformers_version": "4.51.3"
13
+ }
latest ADDED
@@ -0,0 +1 @@
 
 
1
+ global_step2538
model.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from typing import Optional
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+ import torch
5
+ import torch.nn as nn
6
+
7
+
8
+ # Define a custom model that wraps a causal LM and adds a regression head
9
+ class CausalLMForRegression(nn.Module):
10
+ def __init__(self, model_name):
11
+ super().__init__()
12
+ # Load the causal LM with hidden states enabled
13
+ self.model = AutoModelForCausalLM.from_pretrained(
14
+ model_name,
15
+ output_hidden_states=True
16
+ )
17
+ self.base_model = "Qwen/Qwen3-8B" # WARNING: USED FOR GETTING TOKENIZER. THIS IS HARDCODED FOR NOW!!
18
+ # Using pooled hidden state to a single scalar
19
+ self.regression_head = nn.Linear(self.model.config.hidden_size, 1)
20
+ try:
21
+ regression_head_path = os.path.join(model_name, "regression_head.bin")
22
+ state = torch.load(regression_head_path, map_location="cpu")
23
+ self.regression_head.load_state_dict(state)
24
+ except FileNotFoundError:
25
+ print(f"No regression head found. Initializing with random weights!")
26
+ self._keys_to_ignore_on_save = []
27
+
28
+ def forward(self, input_ids, attention_mask=None, labels=None):
29
+ # Flatten extra dimensions if present
30
+ if input_ids.dim() == 3:
31
+ # e.g. from (accum_steps, batch_size, seq_length) to (accum_steps * batch_size, seq_length)
32
+ input_ids = input_ids.view(-1, input_ids.size(-1))
33
+ if attention_mask is not None and attention_mask.dim() == 3:
34
+ attention_mask = attention_mask.view(-1, attention_mask.size(-1))
35
+
36
+ outputs = self.model(input_ids, attention_mask=attention_mask)
37
+ hidden_states = outputs.hidden_states[-1] # Now should have shape: (batch, seq_length, hidden_size)
38
+
39
+ # Mean-pooling over non-padding tokens
40
+ if attention_mask is not None:
41
+ mask = attention_mask.unsqueeze(-1).expand_as(hidden_states).to(hidden_states.dtype)
42
+ hidden_sum = torch.sum(hidden_states * mask, dim=1)
43
+ lengths = mask.sum(dim=1)
44
+ pooled = hidden_sum / lengths
45
+ else:
46
+ pooled = hidden_states.mean(dim=1)
47
+
48
+ logits = self.regression_head(pooled).squeeze(-1)
49
+
50
+ loss = None
51
+ if labels is not None:
52
+ loss_fn = nn.HuberLoss() #nn.MSELoss()
53
+ loss = loss_fn(logits, labels)
54
+
55
+ return {"loss": loss, "logits": logits}
56
+
57
+ def get_input_embeddings(self):
58
+ # Delegate to the underlying causal LM's get_input_embeddings method.
59
+ return self.model.get_input_embeddings()
60
+
61
+ def save_pretrained(self, output_dir, safe_serialization=False):
62
+ os.makedirs(output_dir, exist_ok=True)
63
+
64
+ # Ensure we are saving the entire model properly
65
+ model_state_dict = self.model.state_dict()
66
+ for key, value in model_state_dict.items():
67
+ if value.shape[0] == 0:
68
+ print(f"Warning: Tensor {key} has shape {value.shape}, which may be problematic.")
69
+
70
+ # Save model with proper weight tie handling
71
+ self.model.save_pretrained(output_dir, safe_serialization=False)
72
+ torch.save(self.regression_head.state_dict(), os.path.join(output_dir, "regression_head.bin"))
73
+
74
+
75
+ def get_tokenizer(self):
76
+ try:
77
+ tokenizer = AutoTokenizer.from_pretrained(self.model.name_or_path)
78
+ print(f"Loaded tokenizer from {self.model.name_or_path}")
79
+ except:
80
+ tokenizer = AutoTokenizer.from_pretrained(self.base_model)
81
+ print(f"Loaded tokenizer from {self.base_model}")
82
+ return tokenizer
83
+
84
+ @classmethod
85
+ def from_pretrained(cls, output_dir):
86
+ from_local = os.path.exists(output_dir)
87
+ loading_kwargs = {"use_safetensors": False} if from_local else {}
88
+
89
+ model = AutoModelForCausalLM.from_pretrained(output_dir, **loading_kwargs)
90
+
91
+ # Explicitly enable `output_hidden_states` after loading
92
+ model.config.output_hidden_states = True
93
+
94
+ # Create an uninitialized instance of CausalLMForRegression
95
+ instance = cls.__new__(cls)
96
+ nn.Module.__init__(instance)
97
+ instance._keys_to_ignore_on_save = []
98
+ instance.model = model
99
+
100
+ # Load the regression head separately
101
+ instance.regression_head = nn.Linear(model.config.hidden_size, 1)
102
+ try:
103
+ regression_head_path = os.path.join(output_dir, "regression_head.bin")
104
+ state = torch.load(regression_head_path, map_location="cpu")
105
+ instance.regression_head.load_state_dict(state)
106
+ except FileNotFoundError:
107
+ print(f"No regression head found. Initializing with random weights!")
108
+ return instance
modelcard.json ADDED
File without changes
pytorch_model-00001-of-00002.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e97747b78d7635f05b471e0a518f8f8b5add4fbdca1e38b14ca69b81795f5db5
3
+ size 16380934585
pytorch_model-00002-of-00002.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0dbe39d5f09210d37da3795026145a1666b6b401aede8ac7a3cf0da3de9bfefd
3
+ size 600005
pytorch_model.bin.index.json ADDED
@@ -0,0 +1,406 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 16381478928
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "pytorch_model-00001-of-00002.bin",
7
+ "model.embed_tokens.weight": "pytorch_model-00001-of-00002.bin",
8
+ "model.layers.0.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
9
+ "model.layers.0.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
10
+ "model.layers.0.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
11
+ "model.layers.0.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
12
+ "model.layers.0.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
13
+ "model.layers.0.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
14
+ "model.layers.0.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
15
+ "model.layers.0.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
16
+ "model.layers.0.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
17
+ "model.layers.0.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
18
+ "model.layers.0.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
19
+ "model.layers.1.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
20
+ "model.layers.1.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
21
+ "model.layers.1.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
22
+ "model.layers.1.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
23
+ "model.layers.1.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
24
+ "model.layers.1.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
25
+ "model.layers.1.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
26
+ "model.layers.1.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
27
+ "model.layers.1.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
28
+ "model.layers.1.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
29
+ "model.layers.1.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
30
+ "model.layers.10.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
31
+ "model.layers.10.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
32
+ "model.layers.10.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
33
+ "model.layers.10.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
34
+ "model.layers.10.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
35
+ "model.layers.10.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
36
+ "model.layers.10.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
37
+ "model.layers.10.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
38
+ "model.layers.10.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
39
+ "model.layers.10.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
40
+ "model.layers.10.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
41
+ "model.layers.11.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
42
+ "model.layers.11.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
43
+ "model.layers.11.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
44
+ "model.layers.11.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
45
+ "model.layers.11.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
46
+ "model.layers.11.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
47
+ "model.layers.11.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
48
+ "model.layers.11.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
49
+ "model.layers.11.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
50
+ "model.layers.11.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
51
+ "model.layers.11.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
52
+ "model.layers.12.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
53
+ "model.layers.12.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
54
+ "model.layers.12.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
55
+ "model.layers.12.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
56
+ "model.layers.12.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
57
+ "model.layers.12.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
58
+ "model.layers.12.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
59
+ "model.layers.12.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
60
+ "model.layers.12.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
61
+ "model.layers.12.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
62
+ "model.layers.12.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
63
+ "model.layers.13.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
64
+ "model.layers.13.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
65
+ "model.layers.13.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
66
+ "model.layers.13.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
67
+ "model.layers.13.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
68
+ "model.layers.13.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
69
+ "model.layers.13.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
70
+ "model.layers.13.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
71
+ "model.layers.13.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
72
+ "model.layers.13.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
73
+ "model.layers.13.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
74
+ "model.layers.14.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
75
+ "model.layers.14.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
76
+ "model.layers.14.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
77
+ "model.layers.14.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
78
+ "model.layers.14.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
79
+ "model.layers.14.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
80
+ "model.layers.14.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
81
+ "model.layers.14.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
82
+ "model.layers.14.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
83
+ "model.layers.14.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
84
+ "model.layers.14.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
85
+ "model.layers.15.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
86
+ "model.layers.15.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
87
+ "model.layers.15.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
88
+ "model.layers.15.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
89
+ "model.layers.15.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
90
+ "model.layers.15.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
91
+ "model.layers.15.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
92
+ "model.layers.15.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
93
+ "model.layers.15.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
94
+ "model.layers.15.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
95
+ "model.layers.15.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
96
+ "model.layers.16.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
97
+ "model.layers.16.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
98
+ "model.layers.16.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
99
+ "model.layers.16.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
100
+ "model.layers.16.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
101
+ "model.layers.16.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
102
+ "model.layers.16.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
103
+ "model.layers.16.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
104
+ "model.layers.16.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
105
+ "model.layers.16.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
106
+ "model.layers.16.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
107
+ "model.layers.17.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
108
+ "model.layers.17.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
109
+ "model.layers.17.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
110
+ "model.layers.17.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
111
+ "model.layers.17.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
112
+ "model.layers.17.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
113
+ "model.layers.17.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
114
+ "model.layers.17.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
115
+ "model.layers.17.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
116
+ "model.layers.17.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
117
+ "model.layers.17.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
118
+ "model.layers.18.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
119
+ "model.layers.18.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
120
+ "model.layers.18.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
121
+ "model.layers.18.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
122
+ "model.layers.18.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
123
+ "model.layers.18.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
124
+ "model.layers.18.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
125
+ "model.layers.18.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
126
+ "model.layers.18.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
127
+ "model.layers.18.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
128
+ "model.layers.18.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
129
+ "model.layers.19.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
130
+ "model.layers.19.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
131
+ "model.layers.19.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
132
+ "model.layers.19.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
133
+ "model.layers.19.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
134
+ "model.layers.19.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
135
+ "model.layers.19.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
136
+ "model.layers.19.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
137
+ "model.layers.19.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
138
+ "model.layers.19.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
139
+ "model.layers.19.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
140
+ "model.layers.2.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
141
+ "model.layers.2.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
142
+ "model.layers.2.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
143
+ "model.layers.2.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
144
+ "model.layers.2.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
145
+ "model.layers.2.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
146
+ "model.layers.2.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
147
+ "model.layers.2.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
148
+ "model.layers.2.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
149
+ "model.layers.2.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
150
+ "model.layers.2.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
151
+ "model.layers.20.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
152
+ "model.layers.20.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
153
+ "model.layers.20.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
154
+ "model.layers.20.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
155
+ "model.layers.20.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
156
+ "model.layers.20.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
157
+ "model.layers.20.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
158
+ "model.layers.20.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
159
+ "model.layers.20.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
160
+ "model.layers.20.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
161
+ "model.layers.20.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
162
+ "model.layers.21.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
163
+ "model.layers.21.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
164
+ "model.layers.21.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
165
+ "model.layers.21.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
166
+ "model.layers.21.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
167
+ "model.layers.21.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
168
+ "model.layers.21.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
169
+ "model.layers.21.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
170
+ "model.layers.21.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
171
+ "model.layers.21.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
172
+ "model.layers.21.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
173
+ "model.layers.22.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
174
+ "model.layers.22.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
175
+ "model.layers.22.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
176
+ "model.layers.22.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
177
+ "model.layers.22.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
178
+ "model.layers.22.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
179
+ "model.layers.22.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
180
+ "model.layers.22.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
181
+ "model.layers.22.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
182
+ "model.layers.22.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
183
+ "model.layers.22.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
184
+ "model.layers.23.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
185
+ "model.layers.23.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
186
+ "model.layers.23.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
187
+ "model.layers.23.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
188
+ "model.layers.23.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
189
+ "model.layers.23.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
190
+ "model.layers.23.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
191
+ "model.layers.23.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
192
+ "model.layers.23.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
193
+ "model.layers.23.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
194
+ "model.layers.23.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
195
+ "model.layers.24.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
196
+ "model.layers.24.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
197
+ "model.layers.24.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
198
+ "model.layers.24.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
199
+ "model.layers.24.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
200
+ "model.layers.24.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
201
+ "model.layers.24.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
202
+ "model.layers.24.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
203
+ "model.layers.24.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
204
+ "model.layers.24.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
205
+ "model.layers.24.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
206
+ "model.layers.25.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
207
+ "model.layers.25.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
208
+ "model.layers.25.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
209
+ "model.layers.25.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
210
+ "model.layers.25.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
211
+ "model.layers.25.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
212
+ "model.layers.25.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
213
+ "model.layers.25.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
214
+ "model.layers.25.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
215
+ "model.layers.25.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
216
+ "model.layers.25.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
217
+ "model.layers.26.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
218
+ "model.layers.26.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
219
+ "model.layers.26.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
220
+ "model.layers.26.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
221
+ "model.layers.26.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
222
+ "model.layers.26.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
223
+ "model.layers.26.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
224
+ "model.layers.26.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
225
+ "model.layers.26.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
226
+ "model.layers.26.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
227
+ "model.layers.26.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
228
+ "model.layers.27.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
229
+ "model.layers.27.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
230
+ "model.layers.27.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
231
+ "model.layers.27.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
232
+ "model.layers.27.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
233
+ "model.layers.27.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
234
+ "model.layers.27.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
235
+ "model.layers.27.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
236
+ "model.layers.27.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
237
+ "model.layers.27.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
238
+ "model.layers.27.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
239
+ "model.layers.28.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
240
+ "model.layers.28.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
241
+ "model.layers.28.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
242
+ "model.layers.28.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
243
+ "model.layers.28.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
244
+ "model.layers.28.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
245
+ "model.layers.28.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
246
+ "model.layers.28.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
247
+ "model.layers.28.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
248
+ "model.layers.28.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
249
+ "model.layers.28.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
250
+ "model.layers.29.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
251
+ "model.layers.29.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
252
+ "model.layers.29.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
253
+ "model.layers.29.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
254
+ "model.layers.29.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
255
+ "model.layers.29.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
256
+ "model.layers.29.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
257
+ "model.layers.29.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
258
+ "model.layers.29.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
259
+ "model.layers.29.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
260
+ "model.layers.29.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
261
+ "model.layers.3.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
262
+ "model.layers.3.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
263
+ "model.layers.3.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
264
+ "model.layers.3.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
265
+ "model.layers.3.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
266
+ "model.layers.3.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
267
+ "model.layers.3.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
268
+ "model.layers.3.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
269
+ "model.layers.3.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
270
+ "model.layers.3.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
271
+ "model.layers.3.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
272
+ "model.layers.30.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
273
+ "model.layers.30.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
274
+ "model.layers.30.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
275
+ "model.layers.30.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
276
+ "model.layers.30.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
277
+ "model.layers.30.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
278
+ "model.layers.30.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
279
+ "model.layers.30.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
280
+ "model.layers.30.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
281
+ "model.layers.30.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
282
+ "model.layers.30.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
283
+ "model.layers.31.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
284
+ "model.layers.31.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
285
+ "model.layers.31.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
286
+ "model.layers.31.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
287
+ "model.layers.31.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
288
+ "model.layers.31.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
289
+ "model.layers.31.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
290
+ "model.layers.31.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
291
+ "model.layers.31.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
292
+ "model.layers.31.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
293
+ "model.layers.31.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
294
+ "model.layers.32.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
295
+ "model.layers.32.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
296
+ "model.layers.32.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
297
+ "model.layers.32.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
298
+ "model.layers.32.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
299
+ "model.layers.32.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
300
+ "model.layers.32.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
301
+ "model.layers.32.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
302
+ "model.layers.32.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
303
+ "model.layers.32.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
304
+ "model.layers.32.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
305
+ "model.layers.33.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
306
+ "model.layers.33.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
307
+ "model.layers.33.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
308
+ "model.layers.33.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
309
+ "model.layers.33.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
310
+ "model.layers.33.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
311
+ "model.layers.33.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
312
+ "model.layers.33.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
313
+ "model.layers.33.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
314
+ "model.layers.33.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
315
+ "model.layers.33.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
316
+ "model.layers.34.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
317
+ "model.layers.34.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
318
+ "model.layers.34.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
319
+ "model.layers.34.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
320
+ "model.layers.34.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
321
+ "model.layers.34.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
322
+ "model.layers.34.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
323
+ "model.layers.34.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
324
+ "model.layers.34.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
325
+ "model.layers.34.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
326
+ "model.layers.34.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
327
+ "model.layers.35.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
328
+ "model.layers.35.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
329
+ "model.layers.35.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
330
+ "model.layers.35.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
331
+ "model.layers.35.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
332
+ "model.layers.35.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
333
+ "model.layers.35.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
334
+ "model.layers.35.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
335
+ "model.layers.35.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
336
+ "model.layers.35.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
337
+ "model.layers.35.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
338
+ "model.layers.4.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
339
+ "model.layers.4.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
340
+ "model.layers.4.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
341
+ "model.layers.4.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
342
+ "model.layers.4.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
343
+ "model.layers.4.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
344
+ "model.layers.4.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
345
+ "model.layers.4.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
346
+ "model.layers.4.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
347
+ "model.layers.4.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
348
+ "model.layers.4.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
349
+ "model.layers.5.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
350
+ "model.layers.5.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
351
+ "model.layers.5.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
352
+ "model.layers.5.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
353
+ "model.layers.5.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
354
+ "model.layers.5.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
355
+ "model.layers.5.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
356
+ "model.layers.5.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
357
+ "model.layers.5.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
358
+ "model.layers.5.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
359
+ "model.layers.5.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
360
+ "model.layers.6.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
361
+ "model.layers.6.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
362
+ "model.layers.6.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
363
+ "model.layers.6.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
364
+ "model.layers.6.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
365
+ "model.layers.6.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
366
+ "model.layers.6.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
367
+ "model.layers.6.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
368
+ "model.layers.6.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
369
+ "model.layers.6.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
370
+ "model.layers.6.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
371
+ "model.layers.7.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
372
+ "model.layers.7.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
373
+ "model.layers.7.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
374
+ "model.layers.7.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
375
+ "model.layers.7.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
376
+ "model.layers.7.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
377
+ "model.layers.7.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
378
+ "model.layers.7.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
379
+ "model.layers.7.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
380
+ "model.layers.7.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
381
+ "model.layers.7.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
382
+ "model.layers.8.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
383
+ "model.layers.8.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
384
+ "model.layers.8.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
385
+ "model.layers.8.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
386
+ "model.layers.8.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
387
+ "model.layers.8.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
388
+ "model.layers.8.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
389
+ "model.layers.8.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
390
+ "model.layers.8.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
391
+ "model.layers.8.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
392
+ "model.layers.8.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
393
+ "model.layers.9.input_layernorm.weight": "pytorch_model-00002-of-00002.bin",
394
+ "model.layers.9.mlp.down_proj.weight": "pytorch_model-00001-of-00002.bin",
395
+ "model.layers.9.mlp.gate_proj.weight": "pytorch_model-00001-of-00002.bin",
396
+ "model.layers.9.mlp.up_proj.weight": "pytorch_model-00001-of-00002.bin",
397
+ "model.layers.9.post_attention_layernorm.weight": "pytorch_model-00002-of-00002.bin",
398
+ "model.layers.9.self_attn.k_norm.weight": "pytorch_model-00001-of-00002.bin",
399
+ "model.layers.9.self_attn.k_proj.weight": "pytorch_model-00001-of-00002.bin",
400
+ "model.layers.9.self_attn.o_proj.weight": "pytorch_model-00001-of-00002.bin",
401
+ "model.layers.9.self_attn.q_norm.weight": "pytorch_model-00001-of-00002.bin",
402
+ "model.layers.9.self_attn.q_proj.weight": "pytorch_model-00001-of-00002.bin",
403
+ "model.layers.9.self_attn.v_proj.weight": "pytorch_model-00001-of-00002.bin",
404
+ "model.norm.weight": "pytorch_model-00001-of-00002.bin"
405
+ }
406
+ }
regression_head.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bfab33e6e3e4560d39f766bcde7843cbbc3a0f61175e99922eed5dae050e39da
3
+ size 16381480584
rng_state_0.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2658016c0b7dd2e81bdc3fd1a7c273d1a3e71d5bbc85e15564086266c450fb06
3
+ size 14960
rng_state_1.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3d06145b81b5ded05d055df7243b4b2581bb23f0bb853a0534d6e4a62cb6d210
3
+ size 14960
rng_state_2.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ed43f565759da9b9bb7102cd17708bd0bcc140f30d1d2b843fb63571e7eed2a8
3
+ size 14960
rng_state_3.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f418ab8bae8f48f01ab52c6d5fc505596f51a69b886850493bbc0092968d129d
3
+ size 14960
scheduler.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c510c43d10855e06cc544329b7ff4b0d2b08a8116db99cde31586911f6d4a39c
3
+ size 1064
trainer_state.json ADDED
@@ -0,0 +1,484 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "best_global_step": 1500,
3
+ "best_metric": 0.6232942938804626,
4
+ "best_model_checkpoint": "/data/horse/ws/luwe911g-nemotron_ws/synthetic-instruction-data-generation/analysis/train_difficulty_scorer/checkpoints/checkpoint-1500",
5
+ "epoch": 7.9774111176586135,
6
+ "eval_steps": 100,
7
+ "global_step": 2544,
8
+ "is_hyper_param_search": false,
9
+ "is_local_process_zero": true,
10
+ "is_world_process_zero": true,
11
+ "log_history": [
12
+ {
13
+ "epoch": 0.3142801021410332,
14
+ "grad_norm": 2.72916316986084,
15
+ "learning_rate": 9.9e-06,
16
+ "loss": 0.062,
17
+ "step": 100
18
+ },
19
+ {
20
+ "epoch": 0.3142801021410332,
21
+ "eval_loss": 0.01668722555041313,
22
+ "eval_mse": 0.03342443332076073,
23
+ "eval_pearson_r": 0.2520392835140228,
24
+ "eval_r2": -0.12196338176727295,
25
+ "eval_runtime": 0.9873,
26
+ "eval_samples_per_second": 104.321,
27
+ "eval_steps_per_second": 26.334,
28
+ "step": 100
29
+ },
30
+ {
31
+ "epoch": 0.6285602042820664,
32
+ "grad_norm": 7.041975021362305,
33
+ "learning_rate": 9.594926350245501e-06,
34
+ "loss": 0.0183,
35
+ "step": 200
36
+ },
37
+ {
38
+ "epoch": 0.6285602042820664,
39
+ "eval_loss": 0.013392927125096321,
40
+ "eval_mse": 0.026777038350701332,
41
+ "eval_pearson_r": 0.35883840918540955,
42
+ "eval_r2": 0.10117077827453613,
43
+ "eval_runtime": 0.9862,
44
+ "eval_samples_per_second": 104.441,
45
+ "eval_steps_per_second": 26.364,
46
+ "step": 200
47
+ },
48
+ {
49
+ "epoch": 0.9428403064230996,
50
+ "grad_norm": 6.196834087371826,
51
+ "learning_rate": 9.185761047463177e-06,
52
+ "loss": 0.017,
53
+ "step": 300
54
+ },
55
+ {
56
+ "epoch": 0.9428403064230996,
57
+ "eval_loss": 0.014142508618533611,
58
+ "eval_mse": 0.028310200199484825,
59
+ "eval_pearson_r": 0.34453094005584717,
60
+ "eval_r2": 0.04970693588256836,
61
+ "eval_runtime": 0.9869,
62
+ "eval_samples_per_second": 104.363,
63
+ "eval_steps_per_second": 26.344,
64
+ "step": 300
65
+ },
66
+ {
67
+ "epoch": 1.2545668827342369,
68
+ "grad_norm": 3.1854069232940674,
69
+ "learning_rate": 8.776595744680852e-06,
70
+ "loss": 0.013,
71
+ "step": 400
72
+ },
73
+ {
74
+ "epoch": 1.2545668827342369,
75
+ "eval_loss": 0.013145764358341694,
76
+ "eval_mse": 0.02628500573337078,
77
+ "eval_pearson_r": 0.3917391896247864,
78
+ "eval_r2": 0.11768698692321777,
79
+ "eval_runtime": 0.9902,
80
+ "eval_samples_per_second": 104.021,
81
+ "eval_steps_per_second": 26.258,
82
+ "step": 400
83
+ },
84
+ {
85
+ "epoch": 1.56884698487527,
86
+ "grad_norm": 2.2994000911712646,
87
+ "learning_rate": 8.367430441898528e-06,
88
+ "loss": 0.0135,
89
+ "step": 500
90
+ },
91
+ {
92
+ "epoch": 1.56884698487527,
93
+ "eval_loss": 0.011843894608318806,
94
+ "eval_mse": 0.023691682144999504,
95
+ "eval_pearson_r": 0.4777704179286957,
96
+ "eval_r2": 0.20473748445510864,
97
+ "eval_runtime": 0.9867,
98
+ "eval_samples_per_second": 104.389,
99
+ "eval_steps_per_second": 26.351,
100
+ "step": 500
101
+ },
102
+ {
103
+ "epoch": 1.8831270870163033,
104
+ "grad_norm": 1.4870805740356445,
105
+ "learning_rate": 7.958265139116204e-06,
106
+ "loss": 0.0115,
107
+ "step": 600
108
+ },
109
+ {
110
+ "epoch": 1.8831270870163033,
111
+ "eval_loss": 0.013224405236542225,
112
+ "eval_mse": 0.026459576562047005,
113
+ "eval_pearson_r": 0.4158453345298767,
114
+ "eval_r2": 0.11182713508605957,
115
+ "eval_runtime": 1.0077,
116
+ "eval_samples_per_second": 102.216,
117
+ "eval_steps_per_second": 25.802,
118
+ "step": 600
119
+ },
120
+ {
121
+ "epoch": 2.1948536633274407,
122
+ "grad_norm": 4.134687900543213,
123
+ "learning_rate": 7.549099836333879e-06,
124
+ "loss": 0.0088,
125
+ "step": 700
126
+ },
127
+ {
128
+ "epoch": 2.1948536633274407,
129
+ "eval_loss": 0.013537898659706116,
130
+ "eval_mse": 0.027076171711087227,
131
+ "eval_pearson_r": 0.4764866530895233,
132
+ "eval_r2": 0.09112972021102905,
133
+ "eval_runtime": 0.9823,
134
+ "eval_samples_per_second": 104.858,
135
+ "eval_steps_per_second": 26.469,
136
+ "step": 700
137
+ },
138
+ {
139
+ "epoch": 2.5091337654684738,
140
+ "grad_norm": 0.8281658291816711,
141
+ "learning_rate": 7.1399345335515555e-06,
142
+ "loss": 0.0064,
143
+ "step": 800
144
+ },
145
+ {
146
+ "epoch": 2.5091337654684738,
147
+ "eval_loss": 0.010303011164069176,
148
+ "eval_mse": 0.020632537081837654,
149
+ "eval_pearson_r": 0.5958652496337891,
150
+ "eval_r2": 0.30742424726486206,
151
+ "eval_runtime": 0.9884,
152
+ "eval_samples_per_second": 104.209,
153
+ "eval_steps_per_second": 26.305,
154
+ "step": 800
155
+ },
156
+ {
157
+ "epoch": 2.823413867609507,
158
+ "grad_norm": 4.725385665893555,
159
+ "learning_rate": 6.730769230769232e-06,
160
+ "loss": 0.0068,
161
+ "step": 900
162
+ },
163
+ {
164
+ "epoch": 2.823413867609507,
165
+ "eval_loss": 0.012674727477133274,
166
+ "eval_mse": 0.025358131155371666,
167
+ "eval_pearson_r": 0.5820975303649902,
168
+ "eval_r2": 0.14879947900772095,
169
+ "eval_runtime": 0.9974,
170
+ "eval_samples_per_second": 103.266,
171
+ "eval_steps_per_second": 26.067,
172
+ "step": 900
173
+ },
174
+ {
175
+ "epoch": 3.135140443920644,
176
+ "grad_norm": 0.9976857900619507,
177
+ "learning_rate": 6.321603927986907e-06,
178
+ "loss": 0.0051,
179
+ "step": 1000
180
+ },
181
+ {
182
+ "epoch": 3.135140443920644,
183
+ "eval_loss": 0.009650396183133125,
184
+ "eval_mse": 0.019312988966703415,
185
+ "eval_pearson_r": 0.6038205623626709,
186
+ "eval_r2": 0.3517177700996399,
187
+ "eval_runtime": 0.9924,
188
+ "eval_samples_per_second": 103.788,
189
+ "eval_steps_per_second": 26.199,
190
+ "step": 1000
191
+ },
192
+ {
193
+ "epoch": 3.4494205460616776,
194
+ "grad_norm": 1.735731840133667,
195
+ "learning_rate": 5.912438625204583e-06,
196
+ "loss": 0.0034,
197
+ "step": 1100
198
+ },
199
+ {
200
+ "epoch": 3.4494205460616776,
201
+ "eval_loss": 0.011387597769498825,
202
+ "eval_mse": 0.022768154740333557,
203
+ "eval_pearson_r": 0.5331981778144836,
204
+ "eval_r2": 0.2357376217842102,
205
+ "eval_runtime": 1.0408,
206
+ "eval_samples_per_second": 98.965,
207
+ "eval_steps_per_second": 24.981,
208
+ "step": 1100
209
+ },
210
+ {
211
+ "epoch": 3.7637006482027107,
212
+ "grad_norm": 0.24521802365779877,
213
+ "learning_rate": 5.503273322422259e-06,
214
+ "loss": 0.0032,
215
+ "step": 1200
216
+ },
217
+ {
218
+ "epoch": 3.7637006482027107,
219
+ "eval_loss": 0.010628500953316689,
220
+ "eval_mse": 0.02123476378619671,
221
+ "eval_pearson_r": 0.5781332850456238,
222
+ "eval_r2": 0.2872092127799988,
223
+ "eval_runtime": 0.9896,
224
+ "eval_samples_per_second": 104.08,
225
+ "eval_steps_per_second": 26.273,
226
+ "step": 1200
227
+ },
228
+ {
229
+ "epoch": 4.075427224513848,
230
+ "grad_norm": 1.210878610610962,
231
+ "learning_rate": 5.094108019639935e-06,
232
+ "loss": 0.0025,
233
+ "step": 1300
234
+ },
235
+ {
236
+ "epoch": 4.075427224513848,
237
+ "eval_loss": 0.010471797548234463,
238
+ "eval_mse": 0.020952731370925903,
239
+ "eval_pearson_r": 0.5631570219993591,
240
+ "eval_r2": 0.2966762185096741,
241
+ "eval_runtime": 0.9887,
242
+ "eval_samples_per_second": 104.175,
243
+ "eval_steps_per_second": 26.297,
244
+ "step": 1300
245
+ },
246
+ {
247
+ "epoch": 4.389707326654881,
248
+ "grad_norm": 0.7935001254081726,
249
+ "learning_rate": 4.684942716857611e-06,
250
+ "loss": 0.0016,
251
+ "step": 1400
252
+ },
253
+ {
254
+ "epoch": 4.389707326654881,
255
+ "eval_loss": 0.01045281533151865,
256
+ "eval_mse": 0.020906325429677963,
257
+ "eval_pearson_r": 0.5742180347442627,
258
+ "eval_r2": 0.2982339859008789,
259
+ "eval_runtime": 0.9895,
260
+ "eval_samples_per_second": 104.088,
261
+ "eval_steps_per_second": 26.275,
262
+ "step": 1400
263
+ },
264
+ {
265
+ "epoch": 4.703987428795914,
266
+ "grad_norm": 0.7895488739013672,
267
+ "learning_rate": 4.275777414075287e-06,
268
+ "loss": 0.0015,
269
+ "step": 1500
270
+ },
271
+ {
272
+ "epoch": 4.703987428795914,
273
+ "eval_loss": 0.009268084540963173,
274
+ "eval_mse": 0.01854919083416462,
275
+ "eval_pearson_r": 0.6232942938804626,
276
+ "eval_r2": 0.3773563504219055,
277
+ "eval_runtime": 0.9876,
278
+ "eval_samples_per_second": 104.292,
279
+ "eval_steps_per_second": 26.326,
280
+ "step": 1500
281
+ },
282
+ {
283
+ "epoch": 5.015714005107052,
284
+ "grad_norm": 0.3999693691730499,
285
+ "learning_rate": 3.866612111292962e-06,
286
+ "loss": 0.0014,
287
+ "step": 1600
288
+ },
289
+ {
290
+ "epoch": 5.015714005107052,
291
+ "eval_loss": 0.009675208479166031,
292
+ "eval_mse": 0.01935533992946148,
293
+ "eval_pearson_r": 0.5987623333930969,
294
+ "eval_r2": 0.35029613971710205,
295
+ "eval_runtime": 1.0789,
296
+ "eval_samples_per_second": 95.47,
297
+ "eval_steps_per_second": 24.099,
298
+ "step": 1600
299
+ },
300
+ {
301
+ "epoch": 5.329994107248085,
302
+ "grad_norm": 0.2833040952682495,
303
+ "learning_rate": 3.457446808510639e-06,
304
+ "loss": 0.0006,
305
+ "step": 1700
306
+ },
307
+ {
308
+ "epoch": 5.329994107248085,
309
+ "eval_loss": 0.00994726363569498,
310
+ "eval_mse": 0.019889621064066887,
311
+ "eval_pearson_r": 0.5999482870101929,
312
+ "eval_r2": 0.3323618769645691,
313
+ "eval_runtime": 0.9912,
314
+ "eval_samples_per_second": 103.917,
315
+ "eval_steps_per_second": 26.231,
316
+ "step": 1700
317
+ },
318
+ {
319
+ "epoch": 5.644274209389118,
320
+ "grad_norm": 0.1224384605884552,
321
+ "learning_rate": 3.0482815057283143e-06,
322
+ "loss": 0.0006,
323
+ "step": 1800
324
+ },
325
+ {
326
+ "epoch": 5.644274209389118,
327
+ "eval_loss": 0.009732786566019058,
328
+ "eval_mse": 0.01945064589381218,
329
+ "eval_pearson_r": 0.6066421866416931,
330
+ "eval_r2": 0.3470969796180725,
331
+ "eval_runtime": 0.9881,
332
+ "eval_samples_per_second": 104.236,
333
+ "eval_steps_per_second": 26.312,
334
+ "step": 1800
335
+ },
336
+ {
337
+ "epoch": 5.958554311530151,
338
+ "grad_norm": 0.03875954821705818,
339
+ "learning_rate": 2.6391162029459905e-06,
340
+ "loss": 0.0007,
341
+ "step": 1900
342
+ },
343
+ {
344
+ "epoch": 5.958554311530151,
345
+ "eval_loss": 0.009639283642172813,
346
+ "eval_mse": 0.019304735586047173,
347
+ "eval_pearson_r": 0.6057748198509216,
348
+ "eval_r2": 0.35199475288391113,
349
+ "eval_runtime": 1.0009,
350
+ "eval_samples_per_second": 102.908,
351
+ "eval_steps_per_second": 25.977,
352
+ "step": 1900
353
+ },
354
+ {
355
+ "epoch": 6.270280887841288,
356
+ "grad_norm": 0.4777383804321289,
357
+ "learning_rate": 2.2299509001636663e-06,
358
+ "loss": 0.0003,
359
+ "step": 2000
360
+ },
361
+ {
362
+ "epoch": 6.270280887841288,
363
+ "eval_loss": 0.00959899090230465,
364
+ "eval_mse": 0.01921091228723526,
365
+ "eval_pearson_r": 0.6080344915390015,
366
+ "eval_r2": 0.355144202709198,
367
+ "eval_runtime": 0.9877,
368
+ "eval_samples_per_second": 104.285,
369
+ "eval_steps_per_second": 26.324,
370
+ "step": 2000
371
+ },
372
+ {
373
+ "epoch": 6.584560989982322,
374
+ "grad_norm": 0.1112111359834671,
375
+ "learning_rate": 1.820785597381342e-06,
376
+ "loss": 0.0002,
377
+ "step": 2100
378
+ },
379
+ {
380
+ "epoch": 6.584560989982322,
381
+ "eval_loss": 0.009637333452701569,
382
+ "eval_mse": 0.01925988681614399,
383
+ "eval_pearson_r": 0.6114506721496582,
384
+ "eval_r2": 0.35350024700164795,
385
+ "eval_runtime": 1.0749,
386
+ "eval_samples_per_second": 95.819,
387
+ "eval_steps_per_second": 24.187,
388
+ "step": 2100
389
+ },
390
+ {
391
+ "epoch": 6.898841092123355,
392
+ "grad_norm": 0.32920289039611816,
393
+ "learning_rate": 1.4116202945990182e-06,
394
+ "loss": 0.0002,
395
+ "step": 2200
396
+ },
397
+ {
398
+ "epoch": 6.898841092123355,
399
+ "eval_loss": 0.009636594913899899,
400
+ "eval_mse": 0.019291426986455917,
401
+ "eval_pearson_r": 0.6066728830337524,
402
+ "eval_r2": 0.35244154930114746,
403
+ "eval_runtime": 0.9867,
404
+ "eval_samples_per_second": 104.391,
405
+ "eval_steps_per_second": 26.351,
406
+ "step": 2200
407
+ },
408
+ {
409
+ "epoch": 7.210567668434492,
410
+ "grad_norm": 0.1292334944009781,
411
+ "learning_rate": 1.002454991816694e-06,
412
+ "loss": 0.0001,
413
+ "step": 2300
414
+ },
415
+ {
416
+ "epoch": 7.210567668434492,
417
+ "eval_loss": 0.009695847518742085,
418
+ "eval_mse": 0.01940760761499405,
419
+ "eval_pearson_r": 0.6034567952156067,
420
+ "eval_r2": 0.3485416769981384,
421
+ "eval_runtime": 1.0359,
422
+ "eval_samples_per_second": 99.427,
423
+ "eval_steps_per_second": 25.098,
424
+ "step": 2300
425
+ },
426
+ {
427
+ "epoch": 7.5248477705755255,
428
+ "grad_norm": 0.01900539919734001,
429
+ "learning_rate": 5.932896890343699e-07,
430
+ "loss": 0.0001,
431
+ "step": 2400
432
+ },
433
+ {
434
+ "epoch": 7.5248477705755255,
435
+ "eval_loss": 0.0095865149050951,
436
+ "eval_mse": 0.019158780574798584,
437
+ "eval_pearson_r": 0.6077873706817627,
438
+ "eval_r2": 0.3568941354751587,
439
+ "eval_runtime": 0.9886,
440
+ "eval_samples_per_second": 104.191,
441
+ "eval_steps_per_second": 26.301,
442
+ "step": 2400
443
+ },
444
+ {
445
+ "epoch": 7.839127872716559,
446
+ "grad_norm": 0.021035829558968544,
447
+ "learning_rate": 1.8412438625204584e-07,
448
+ "loss": 0.0001,
449
+ "step": 2500
450
+ },
451
+ {
452
+ "epoch": 7.839127872716559,
453
+ "eval_loss": 0.009597421623766422,
454
+ "eval_mse": 0.019200436770915985,
455
+ "eval_pearson_r": 0.6084479093551636,
456
+ "eval_r2": 0.355495810508728,
457
+ "eval_runtime": 0.987,
458
+ "eval_samples_per_second": 104.357,
459
+ "eval_steps_per_second": 26.342,
460
+ "step": 2500
461
+ }
462
+ ],
463
+ "logging_steps": 100,
464
+ "max_steps": 2544,
465
+ "num_input_tokens_seen": 0,
466
+ "num_train_epochs": 8,
467
+ "save_steps": 500,
468
+ "stateful_callbacks": {
469
+ "TrainerControl": {
470
+ "args": {
471
+ "should_epoch_stop": false,
472
+ "should_evaluate": false,
473
+ "should_log": false,
474
+ "should_save": true,
475
+ "should_training_stop": true
476
+ },
477
+ "attributes": {}
478
+ }
479
+ },
480
+ "total_flos": 0.0,
481
+ "train_batch_size": 1,
482
+ "trial_name": null,
483
+ "trial_params": null
484
+ }
zero_to_fp32.py ADDED
@@ -0,0 +1,760 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+
3
+ # Copyright (c) Microsoft Corporation.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ # DeepSpeed Team
7
+
8
+ # This script extracts fp32 consolidated weights from a zero 1, 2 and 3 DeepSpeed checkpoints. It gets
9
+ # copied into the top level checkpoint dir, so the user can easily do the conversion at any point in
10
+ # the future. Once extracted, the weights don't require DeepSpeed and can be used in any
11
+ # application.
12
+ #
13
+ # example:
14
+ # python zero_to_fp32.py . output_dir/
15
+ # or
16
+ # python zero_to_fp32.py . output_dir/ --safe_serialization
17
+
18
+ import argparse
19
+ import torch
20
+ import glob
21
+ import math
22
+ import os
23
+ import re
24
+ import gc
25
+ import json
26
+ import numpy as np
27
+ from tqdm import tqdm
28
+ from collections import OrderedDict
29
+ from dataclasses import dataclass
30
+
31
+ # while this script doesn't use deepspeed to recover data, since the checkpoints are pickled with
32
+ # DeepSpeed data structures it has to be available in the current python environment.
33
+ from deepspeed.utils import logger
34
+ from deepspeed.checkpoint.constants import (DS_VERSION, OPTIMIZER_STATE_DICT, SINGLE_PARTITION_OF_FP32_GROUPS,
35
+ FP32_FLAT_GROUPS, ZERO_STAGE, PARTITION_COUNT, PARAM_SHAPES, BUFFER_NAMES,
36
+ FROZEN_PARAM_SHAPES, FROZEN_PARAM_FRAGMENTS)
37
+
38
+
39
+ @dataclass
40
+ class zero_model_state:
41
+ buffers: dict()
42
+ param_shapes: dict()
43
+ shared_params: list
44
+ ds_version: int
45
+ frozen_param_shapes: dict()
46
+ frozen_param_fragments: dict()
47
+
48
+
49
+ debug = 0
50
+
51
+ # load to cpu
52
+ device = torch.device('cpu')
53
+
54
+
55
+ def atoi(text):
56
+ return int(text) if text.isdigit() else text
57
+
58
+
59
+ def natural_keys(text):
60
+ '''
61
+ alist.sort(key=natural_keys) sorts in human order
62
+ http://nedbatchelder.com/blog/200712/human_sorting.html
63
+ (See Toothy's implementation in the comments)
64
+ '''
65
+ return [atoi(c) for c in re.split(r'(\d+)', text)]
66
+
67
+
68
+ def get_model_state_file(checkpoint_dir, zero_stage):
69
+ if not os.path.isdir(checkpoint_dir):
70
+ raise FileNotFoundError(f"Directory '{checkpoint_dir}' doesn't exist")
71
+
72
+ # there should be only one file
73
+ if zero_stage <= 2:
74
+ file = os.path.join(checkpoint_dir, "mp_rank_00_model_states.pt")
75
+ elif zero_stage == 3:
76
+ file = os.path.join(checkpoint_dir, "zero_pp_rank_0_mp_rank_00_model_states.pt")
77
+
78
+ if not os.path.exists(file):
79
+ raise FileNotFoundError(f"can't find model states file at '{file}'")
80
+
81
+ return file
82
+
83
+
84
+ def get_checkpoint_files(checkpoint_dir, glob_pattern):
85
+ # XXX: need to test that this simple glob rule works for multi-node setup too
86
+ ckpt_files = sorted(glob.glob(os.path.join(checkpoint_dir, glob_pattern)), key=natural_keys)
87
+
88
+ if len(ckpt_files) == 0:
89
+ raise FileNotFoundError(f"can't find {glob_pattern} files in directory '{checkpoint_dir}'")
90
+
91
+ return ckpt_files
92
+
93
+
94
+ def get_optim_files(checkpoint_dir):
95
+ return get_checkpoint_files(checkpoint_dir, "*_optim_states.pt")
96
+
97
+
98
+ def get_model_state_files(checkpoint_dir):
99
+ return get_checkpoint_files(checkpoint_dir, "*_model_states.pt")
100
+
101
+
102
+ def parse_model_states(files):
103
+ zero_model_states = []
104
+ for file in files:
105
+ state_dict = torch.load(file, map_location=device, weights_only=False)
106
+
107
+ if BUFFER_NAMES not in state_dict:
108
+ raise ValueError(f"{file} is not a model state checkpoint")
109
+ buffer_names = state_dict[BUFFER_NAMES]
110
+ if debug:
111
+ print("Found buffers:", buffer_names)
112
+
113
+ # recover just the buffers while restoring them to fp32 if they were saved in fp16
114
+ buffers = {k: v.float() for k, v in state_dict["module"].items() if k in buffer_names}
115
+ param_shapes = state_dict[PARAM_SHAPES]
116
+
117
+ # collect parameters that are included in param_shapes
118
+ param_names = []
119
+ for s in param_shapes:
120
+ for name in s.keys():
121
+ param_names.append(name)
122
+
123
+ # update with frozen parameters
124
+ frozen_param_shapes = state_dict.get(FROZEN_PARAM_SHAPES, None)
125
+ if frozen_param_shapes is not None:
126
+ if debug:
127
+ print(f"Found frozen_param_shapes: {frozen_param_shapes}")
128
+ param_names += list(frozen_param_shapes.keys())
129
+
130
+ # handle shared params
131
+ shared_params = [[k, v] for k, v in state_dict["shared_params"].items()]
132
+
133
+ ds_version = state_dict.get(DS_VERSION, None)
134
+
135
+ frozen_param_fragments = state_dict.get(FROZEN_PARAM_FRAGMENTS, None)
136
+
137
+ z_model_state = zero_model_state(buffers=buffers,
138
+ param_shapes=param_shapes,
139
+ shared_params=shared_params,
140
+ ds_version=ds_version,
141
+ frozen_param_shapes=frozen_param_shapes,
142
+ frozen_param_fragments=frozen_param_fragments)
143
+ zero_model_states.append(z_model_state)
144
+
145
+ return zero_model_states
146
+
147
+
148
+ def parse_optim_states(files, ds_checkpoint_dir):
149
+ total_files = len(files)
150
+ state_dicts = []
151
+ for f in tqdm(files, desc='Loading checkpoint shards'):
152
+ state_dict = torch.load(f, map_location=device, mmap=True, weights_only=False)
153
+ # immediately discard the potentially huge 2 optimizer states as we only care for fp32 master weights
154
+ # and also handle the case where it was already removed by another helper script
155
+ state_dict["optimizer_state_dict"].pop("optimizer_state_dict", None)
156
+ state_dicts.append(state_dict)
157
+
158
+ if not ZERO_STAGE in state_dicts[0][OPTIMIZER_STATE_DICT]:
159
+ raise ValueError(f"{files[0]} is not a zero checkpoint")
160
+ zero_stage = state_dicts[0][OPTIMIZER_STATE_DICT][ZERO_STAGE]
161
+ world_size = state_dicts[0][OPTIMIZER_STATE_DICT][PARTITION_COUNT]
162
+
163
+ # For ZeRO-2 each param group can have different partition_count as data parallelism for expert
164
+ # parameters can be different from data parallelism for non-expert parameters. So we can just
165
+ # use the max of the partition_count to get the dp world_size.
166
+
167
+ if type(world_size) is list:
168
+ world_size = max(world_size)
169
+
170
+ if world_size != total_files:
171
+ raise ValueError(
172
+ f"Expected {world_size} of '*_optim_states.pt' under '{ds_checkpoint_dir}' but found {total_files} files. "
173
+ "Possibly due to an overwrite of an old checkpoint, or a checkpoint didn't get saved by one or more processes."
174
+ )
175
+
176
+ # the groups are named differently in each stage
177
+ if zero_stage <= 2:
178
+ fp32_groups_key = SINGLE_PARTITION_OF_FP32_GROUPS
179
+ elif zero_stage == 3:
180
+ fp32_groups_key = FP32_FLAT_GROUPS
181
+ else:
182
+ raise ValueError(f"unknown zero stage {zero_stage}")
183
+
184
+ fp32_flat_groups = [state_dicts[i][OPTIMIZER_STATE_DICT][fp32_groups_key] for i in range(len(state_dicts))]
185
+ return zero_stage, world_size, fp32_flat_groups
186
+
187
+
188
+ def _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters):
189
+ """
190
+ Returns fp32 state_dict reconstructed from ds checkpoint
191
+
192
+ Args:
193
+ - ``ds_checkpoint_dir``: path to the deepspeed checkpoint folder (where the optimizer files are)
194
+
195
+ """
196
+ print(f"Processing zero checkpoint '{ds_checkpoint_dir}'")
197
+
198
+ optim_files = get_optim_files(ds_checkpoint_dir)
199
+ zero_stage, world_size, fp32_flat_groups = parse_optim_states(optim_files, ds_checkpoint_dir)
200
+ print(f"Detected checkpoint of type zero stage {zero_stage}, world_size: {world_size}")
201
+
202
+ model_files = get_model_state_files(ds_checkpoint_dir)
203
+
204
+ zero_model_states = parse_model_states(model_files)
205
+ print(f'Parsing checkpoint created by deepspeed=={zero_model_states[0].ds_version}')
206
+
207
+ if zero_stage <= 2:
208
+ return _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
209
+ exclude_frozen_parameters)
210
+ elif zero_stage == 3:
211
+ return _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
212
+ exclude_frozen_parameters)
213
+
214
+
215
+ def _zero2_merge_frozen_params(state_dict, zero_model_states):
216
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
217
+ return
218
+
219
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
220
+ frozen_param_fragments = zero_model_states[0].frozen_param_fragments
221
+
222
+ if debug:
223
+ num_elem = sum(s.numel() for s in frozen_param_shapes.values())
224
+ print(f'rank 0: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
225
+
226
+ wanted_params = len(frozen_param_shapes)
227
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
228
+ avail_numel = sum([p.numel() for p in frozen_param_fragments.values()])
229
+ print(f'Frozen params: Have {avail_numel} numels to process.')
230
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
231
+
232
+ total_params = 0
233
+ total_numel = 0
234
+ for name, shape in frozen_param_shapes.items():
235
+ total_params += 1
236
+ unpartitioned_numel = shape.numel()
237
+ total_numel += unpartitioned_numel
238
+
239
+ state_dict[name] = frozen_param_fragments[name]
240
+
241
+ if debug:
242
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
243
+
244
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
245
+
246
+
247
+ def _has_callable(obj, fn):
248
+ attr = getattr(obj, fn, None)
249
+ return callable(attr)
250
+
251
+
252
+ def _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
253
+ param_shapes = zero_model_states[0].param_shapes
254
+
255
+ # Reconstruction protocol:
256
+ #
257
+ # XXX: document this
258
+
259
+ if debug:
260
+ for i in range(world_size):
261
+ for j in range(len(fp32_flat_groups[0])):
262
+ print(f"{FP32_FLAT_GROUPS}[{i}][{j}].shape={fp32_flat_groups[i][j].shape}")
263
+
264
+ # XXX: memory usage doubles here (zero2)
265
+ num_param_groups = len(fp32_flat_groups[0])
266
+ merged_single_partition_of_fp32_groups = []
267
+ for i in range(num_param_groups):
268
+ merged_partitions = [sd[i] for sd in fp32_flat_groups]
269
+ full_single_fp32_vector = torch.cat(merged_partitions, 0)
270
+ merged_single_partition_of_fp32_groups.append(full_single_fp32_vector)
271
+ avail_numel = sum(
272
+ [full_single_fp32_vector.numel() for full_single_fp32_vector in merged_single_partition_of_fp32_groups])
273
+
274
+ if debug:
275
+ wanted_params = sum([len(shapes) for shapes in param_shapes])
276
+ wanted_numel = sum([sum(shape.numel() for shape in shapes.values()) for shapes in param_shapes])
277
+ # not asserting if there is a mismatch due to possible padding
278
+ print(f"Have {avail_numel} numels to process.")
279
+ print(f"Need {wanted_numel} numels in {wanted_params} params.")
280
+
281
+ # params
282
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
283
+ # out-of-core computing solution
284
+ total_numel = 0
285
+ total_params = 0
286
+ for shapes, full_single_fp32_vector in zip(param_shapes, merged_single_partition_of_fp32_groups):
287
+ offset = 0
288
+ avail_numel = full_single_fp32_vector.numel()
289
+ for name, shape in shapes.items():
290
+
291
+ unpartitioned_numel = shape.numel() if _has_callable(shape, 'numel') else math.prod(shape)
292
+ total_numel += unpartitioned_numel
293
+ total_params += 1
294
+
295
+ if debug:
296
+ print(f"{name} full shape: {shape} unpartitioned numel {unpartitioned_numel} ")
297
+ state_dict[name] = full_single_fp32_vector.narrow(0, offset, unpartitioned_numel).view(shape)
298
+ offset += unpartitioned_numel
299
+
300
+ # Z2 started to align to 2*world_size to improve nccl performance. Therefore both offset and
301
+ # avail_numel can differ by anywhere between 0..2*world_size. Due to two unrelated complex
302
+ # paddings performed in the code it's almost impossible to predict the exact numbers w/o the
303
+ # live optimizer object, so we are checking that the numbers are within the right range
304
+ align_to = 2 * world_size
305
+
306
+ def zero2_align(x):
307
+ return align_to * math.ceil(x / align_to)
308
+
309
+ if debug:
310
+ print(f"original offset={offset}, avail_numel={avail_numel}")
311
+
312
+ offset = zero2_align(offset)
313
+ avail_numel = zero2_align(avail_numel)
314
+
315
+ if debug:
316
+ print(f"aligned offset={offset}, avail_numel={avail_numel}")
317
+
318
+ # Sanity check
319
+ if offset != avail_numel:
320
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
321
+
322
+ print(f"Reconstructed fp32 state dict with {total_params} params {total_numel} elements")
323
+
324
+
325
+ def _get_fp32_state_dict_from_zero2_checkpoint(world_size, fp32_flat_groups, zero_model_states,
326
+ exclude_frozen_parameters):
327
+ state_dict = OrderedDict()
328
+
329
+ # buffers
330
+ buffers = zero_model_states[0].buffers
331
+ state_dict.update(buffers)
332
+ if debug:
333
+ print(f"added {len(buffers)} buffers")
334
+
335
+ if not exclude_frozen_parameters:
336
+ _zero2_merge_frozen_params(state_dict, zero_model_states)
337
+
338
+ _zero2_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
339
+
340
+ # recover shared parameters
341
+ for pair in zero_model_states[0].shared_params:
342
+ if pair[1] in state_dict:
343
+ state_dict[pair[0]] = state_dict[pair[1]]
344
+
345
+ return state_dict
346
+
347
+
348
+ def zero3_partitioned_param_info(unpartitioned_numel, world_size):
349
+ remainder = unpartitioned_numel % world_size
350
+ padding_numel = (world_size - remainder) if remainder else 0
351
+ partitioned_numel = math.ceil(unpartitioned_numel / world_size)
352
+ return partitioned_numel, padding_numel
353
+
354
+
355
+ def _zero3_merge_frozen_params(state_dict, world_size, zero_model_states):
356
+ if zero_model_states[0].frozen_param_shapes is None or len(zero_model_states[0].frozen_param_shapes) == 0:
357
+ return
358
+
359
+ if debug:
360
+ for i in range(world_size):
361
+ num_elem = sum(s.numel() for s in zero_model_states[i].frozen_param_fragments.values())
362
+ print(f'rank {i}: {FROZEN_PARAM_SHAPES}.numel = {num_elem}')
363
+
364
+ frozen_param_shapes = zero_model_states[0].frozen_param_shapes
365
+ wanted_params = len(frozen_param_shapes)
366
+ wanted_numel = sum(s.numel() for s in frozen_param_shapes.values())
367
+ avail_numel = sum([p.numel() for p in zero_model_states[0].frozen_param_fragments.values()]) * world_size
368
+ print(f'Frozen params: Have {avail_numel} numels to process.')
369
+ print(f'Frozen params: Need {wanted_numel} numels in {wanted_params} params')
370
+
371
+ total_params = 0
372
+ total_numel = 0
373
+ for name, shape in zero_model_states[0].frozen_param_shapes.items():
374
+ total_params += 1
375
+ unpartitioned_numel = shape.numel()
376
+ total_numel += unpartitioned_numel
377
+
378
+ param_frags = tuple(model_state.frozen_param_fragments[name] for model_state in zero_model_states)
379
+ state_dict[name] = torch.cat(param_frags, 0).narrow(0, 0, unpartitioned_numel).view(shape)
380
+
381
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
382
+
383
+ if debug:
384
+ print(
385
+ f"Frozen params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
386
+ )
387
+
388
+ print(f"Reconstructed Frozen fp32 state dict with {total_params} params {total_numel} elements")
389
+
390
+
391
+ class GatheredTensor:
392
+ """
393
+ A pseudo tensor that collects partitioned weights.
394
+ It is more memory efficient when there are multiple groups.
395
+ """
396
+
397
+ def __init__(self, flat_groups, flat_groups_offset, offset, partitioned_numel, shape):
398
+ self.flat_groups = flat_groups
399
+ self.flat_groups_offset = flat_groups_offset
400
+ self.offset = offset
401
+ self.partitioned_numel = partitioned_numel
402
+ self.shape = shape
403
+ self.dtype = self.flat_groups[0][0].dtype
404
+
405
+ def contiguous(self):
406
+ """
407
+ Merge partitioned weights from flat_groups into a single tensor.
408
+ """
409
+ end_idx = self.offset + self.partitioned_numel
410
+ world_size = len(self.flat_groups)
411
+ pad_flat_param_chunks = []
412
+
413
+ for rank_i in range(world_size):
414
+ # for each rank, we need to collect weights from related group/groups
415
+ flat_groups_at_rank_i = self.flat_groups[rank_i]
416
+ start_group_id = None
417
+ end_group_id = None
418
+ for group_id in range(len(self.flat_groups_offset)):
419
+ if self.flat_groups_offset[group_id] <= self.offset < self.flat_groups_offset[group_id + 1]:
420
+ start_group_id = group_id
421
+ if self.flat_groups_offset[group_id] < end_idx <= self.flat_groups_offset[group_id + 1]:
422
+ end_group_id = group_id
423
+ break
424
+ # collect weights from related group/groups
425
+ for group_id in range(start_group_id, end_group_id + 1):
426
+ flat_tensor = flat_groups_at_rank_i[group_id]
427
+ start_offset = self.offset - self.flat_groups_offset[group_id]
428
+ end_offset = min(end_idx, self.flat_groups_offset[group_id + 1]) - self.flat_groups_offset[group_id]
429
+ pad_flat_param_chunks.append(flat_tensor[start_offset:end_offset])
430
+
431
+ # collect weights from all ranks
432
+ pad_flat_param = torch.cat(pad_flat_param_chunks, dim=0)
433
+ param = pad_flat_param[:self.shape.numel()].view(self.shape).contiguous()
434
+ return param
435
+
436
+
437
+ def _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states):
438
+ param_shapes = zero_model_states[0].param_shapes
439
+ avail_numel = sum([flat_group.numel() for flat_group in fp32_flat_groups[0]]) * world_size
440
+
441
+ # Reconstruction protocol: For zero3 we need to zip the partitions together at boundary of each
442
+ # param, re-consolidating each param, while dealing with padding if any
443
+
444
+ # merge list of dicts, preserving order
445
+ param_shapes = {k: v for d in param_shapes for k, v in d.items()}
446
+
447
+ if debug:
448
+ for i in range(world_size):
449
+ print(f"{FP32_FLAT_GROUPS}[{i}].shape={fp32_flat_groups[i].shape}")
450
+
451
+ wanted_params = len(param_shapes)
452
+ wanted_numel = sum(shape.numel() for shape in param_shapes.values())
453
+ # not asserting if there is a mismatch due to possible padding
454
+ avail_numel = fp32_flat_groups[0].numel() * world_size
455
+ print(f"Trainable params: Have {avail_numel} numels to process.")
456
+ print(f"Trainable params: Need {wanted_numel} numels in {wanted_params} params.")
457
+
458
+ # params
459
+ # XXX: for huge models that can't fit into the host's RAM we will have to recode this to support
460
+ # out-of-core computing solution
461
+ offset = 0
462
+ total_numel = 0
463
+ total_params = 0
464
+ flat_groups_offset = [0] + list(np.cumsum([flat_tensor.numel() for flat_tensor in fp32_flat_groups[0]]))
465
+ for name, shape in tqdm(param_shapes.items(), desc='Gathering sharded weights'):
466
+ unpartitioned_numel = shape.numel()
467
+ total_numel += unpartitioned_numel
468
+ total_params += 1
469
+ partitioned_numel, partitioned_padding_numel = zero3_partitioned_param_info(unpartitioned_numel, world_size)
470
+
471
+ if debug:
472
+ print(
473
+ f"Trainable params: {total_params} {name} full shape: {shape} partition0 numel={partitioned_numel} partitioned_padding_numel={partitioned_padding_numel}"
474
+ )
475
+
476
+ # memory efficient tensor
477
+ tensor = GatheredTensor(fp32_flat_groups, flat_groups_offset, offset, partitioned_numel, shape)
478
+ state_dict[name] = tensor
479
+ offset += partitioned_numel
480
+
481
+ offset *= world_size
482
+
483
+ # Sanity check
484
+ if offset != avail_numel:
485
+ raise ValueError(f"consumed {offset} numels out of {avail_numel} - something is wrong")
486
+
487
+ print(f"Reconstructed Trainable fp32 state dict with {total_params} params {total_numel} elements")
488
+
489
+
490
+ def _get_fp32_state_dict_from_zero3_checkpoint(world_size, fp32_flat_groups, zero_model_states,
491
+ exclude_frozen_parameters):
492
+ state_dict = OrderedDict()
493
+
494
+ # buffers
495
+ buffers = zero_model_states[0].buffers
496
+ state_dict.update(buffers)
497
+ if debug:
498
+ print(f"added {len(buffers)} buffers")
499
+
500
+ if not exclude_frozen_parameters:
501
+ _zero3_merge_frozen_params(state_dict, world_size, zero_model_states)
502
+
503
+ _zero3_merge_trainable_params(state_dict, world_size, fp32_flat_groups, zero_model_states)
504
+
505
+ # recover shared parameters
506
+ for pair in zero_model_states[0].shared_params:
507
+ if pair[1] in state_dict:
508
+ state_dict[pair[0]] = state_dict[pair[1]]
509
+
510
+ return state_dict
511
+
512
+
513
+ def to_torch_tensor(state_dict, return_empty_tensor=False):
514
+ """
515
+ Convert state_dict of GatheredTensor to torch tensor
516
+ """
517
+ torch_state_dict = {}
518
+ converted_tensors = {}
519
+ for name, tensor in state_dict.items():
520
+ tensor_id = id(tensor)
521
+ if tensor_id in converted_tensors: # shared tensors
522
+ shared_tensor = torch_state_dict[converted_tensors[tensor_id]]
523
+ torch_state_dict[name] = shared_tensor
524
+ else:
525
+ converted_tensors[tensor_id] = name
526
+ if return_empty_tensor:
527
+ torch_state_dict[name] = torch.empty(tensor.shape, dtype=tensor.dtype)
528
+ else:
529
+ torch_state_dict[name] = tensor.contiguous()
530
+ return torch_state_dict
531
+
532
+
533
+ def get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir,
534
+ tag=None,
535
+ exclude_frozen_parameters=False,
536
+ lazy_mode=False):
537
+ """
538
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated state_dict that can be loaded with
539
+ ``load_state_dict()`` and used for training without DeepSpeed or shared with others, for example
540
+ via a model hub.
541
+
542
+ Args:
543
+ - ``checkpoint_dir``: path to the desired checkpoint folder
544
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in 'latest' file. e.g., ``global_step14``
545
+ - ``exclude_frozen_parameters``: exclude frozen parameters
546
+ - ``lazy_mode``: get state_dict in lazy mode. It returns a dict of pesduo tensor instead of torch tensor, which is more memory efficient.
547
+ Convert the pesduo tensor to torch tensor by ``.contiguous()``
548
+
549
+ Returns:
550
+ - pytorch ``state_dict``
551
+
552
+ A typical usage might be ::
553
+
554
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
555
+ # do the training and checkpoint saving
556
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir) # already on cpu
557
+ model = model.cpu() # move to cpu
558
+ model.load_state_dict(state_dict)
559
+ # submit to model hub or save the model to share with others
560
+
561
+ In this example the ``model`` will no longer be usable in the deepspeed context of the same
562
+ application. i.e. you will need to re-initialize the deepspeed engine, since
563
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
564
+
565
+ If you want it all done for you, use ``load_state_dict_from_zero_checkpoint`` instead.
566
+
567
+ Note: the above usage may not work if your application doesn't have sufficient free CPU memory.
568
+ You may need to use the offline approach using the ``zero_to_fp32.py`` script that is saved with
569
+ the checkpoint. Or you can load state_dict in lazy mode ::
570
+
571
+ from deepspeed.utils.zero_to_fp32 import get_fp32_state_dict_from_zero_checkpoint
572
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, lazy_mode=True) # not on cpu
573
+ for name, lazy_tensor in state_dict.item():
574
+ tensor = lazy_tensor.contiguous() # to cpu
575
+ print(name, tensor)
576
+ # del tensor to release memory if it no longer in use
577
+ """
578
+ if tag is None:
579
+ latest_path = os.path.join(checkpoint_dir, 'latest')
580
+ if os.path.isfile(latest_path):
581
+ with open(latest_path, 'r') as fd:
582
+ tag = fd.read().strip()
583
+ else:
584
+ raise ValueError(f"Unable to find 'latest' file at {latest_path}")
585
+
586
+ ds_checkpoint_dir = os.path.join(checkpoint_dir, tag)
587
+
588
+ if not os.path.isdir(ds_checkpoint_dir):
589
+ raise FileNotFoundError(f"Directory '{ds_checkpoint_dir}' doesn't exist")
590
+
591
+ state_dict = _get_fp32_state_dict_from_zero_checkpoint(ds_checkpoint_dir, exclude_frozen_parameters)
592
+ if lazy_mode:
593
+ return state_dict
594
+ else:
595
+ return to_torch_tensor(state_dict)
596
+
597
+
598
+ def convert_zero_checkpoint_to_fp32_state_dict(checkpoint_dir,
599
+ output_dir,
600
+ max_shard_size="5GB",
601
+ safe_serialization=False,
602
+ tag=None,
603
+ exclude_frozen_parameters=False):
604
+ """
605
+ Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict`` file that can be
606
+ loaded with ``torch.load(file)`` + ``load_state_dict()`` and used for training without DeepSpeed.
607
+
608
+ Args:
609
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
610
+ - ``output_dir``: directory to the pytorch fp32 state_dict output files
611
+ - ``max_shard_size``: the maximum size for a checkpoint before being sharded, default value is 5GB
612
+ - ``safe_serialization``: whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).
613
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
614
+ - ``exclude_frozen_parameters``: exclude frozen parameters
615
+ """
616
+
617
+ # Dependency pre-check
618
+ if safe_serialization:
619
+ try:
620
+ from safetensors.torch import save_file
621
+ except ImportError:
622
+ print('If you want to use `safe_serialization`, please `pip install safetensors`')
623
+ raise
624
+ if max_shard_size is not None:
625
+ try:
626
+ from huggingface_hub import split_torch_state_dict_into_shards
627
+ except ImportError:
628
+ print('If you want to use `max_shard_size`, please `pip install huggingface_hub`')
629
+ raise
630
+
631
+ # Convert zero checkpoint to state_dict
632
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir,
633
+ tag,
634
+ exclude_frozen_parameters,
635
+ lazy_mode=True)
636
+
637
+ # Shard the model if it is too big.
638
+ weights_name = "model.safetensors" if safe_serialization else "pytorch_model.bin"
639
+ if max_shard_size is not None:
640
+ filename_pattern = weights_name.replace(".bin", "{suffix}.bin").replace(".safetensors", "{suffix}.safetensors")
641
+ # an memory-efficient approach for sharding
642
+ empty_state_dict = to_torch_tensor(state_dict, return_empty_tensor=True)
643
+ state_dict_split = split_torch_state_dict_into_shards(empty_state_dict,
644
+ filename_pattern=filename_pattern,
645
+ max_shard_size=max_shard_size)
646
+ else:
647
+ from collections import namedtuple
648
+ StateDictSplit = namedtuple("StateDictSplit", ["is_sharded", "filename_to_tensors"])
649
+ state_dict_split = StateDictSplit(is_sharded=False,
650
+ filename_to_tensors={weights_name: list(state_dict.keys())})
651
+
652
+ # Save the model by shard
653
+ os.makedirs(output_dir, exist_ok=True)
654
+ filename_to_tensors = state_dict_split.filename_to_tensors.items()
655
+ for shard_file, tensors in tqdm(filename_to_tensors, desc="Saving checkpoint shards"):
656
+ shard_state_dict = {tensor_name: state_dict[tensor_name] for tensor_name in tensors}
657
+ shard_state_dict = to_torch_tensor(shard_state_dict)
658
+ output_path = os.path.join(output_dir, shard_file)
659
+ if safe_serialization:
660
+ save_file(shard_state_dict, output_path, metadata={"format": "pt"})
661
+ else:
662
+ torch.save(shard_state_dict, output_path)
663
+ # release the memory of current shard
664
+ for tensor_name in list(shard_state_dict.keys()):
665
+ del state_dict[tensor_name]
666
+ del shard_state_dict[tensor_name]
667
+ del shard_state_dict
668
+ gc.collect()
669
+
670
+ # Save index if sharded
671
+ if state_dict_split.is_sharded:
672
+ index = {
673
+ "metadata": state_dict_split.metadata,
674
+ "weight_map": state_dict_split.tensor_to_filename,
675
+ }
676
+ save_index_file = "model.safetensors.index.json" if safe_serialization else "pytorch_model.bin.index.json"
677
+ save_index_file = os.path.join(output_dir, save_index_file)
678
+ with open(save_index_file, "w", encoding="utf-8") as f:
679
+ content = json.dumps(index, indent=2, sort_keys=True) + "\n"
680
+ f.write(content)
681
+
682
+
683
+ def load_state_dict_from_zero_checkpoint(model, checkpoint_dir, tag=None):
684
+ """
685
+ 1. Put the provided model to cpu
686
+ 2. Convert ZeRO 2 or 3 checkpoint into a single fp32 consolidated ``state_dict``
687
+ 3. Load it into the provided model
688
+
689
+ Args:
690
+ - ``model``: the model object to update
691
+ - ``checkpoint_dir``: path to the desired checkpoint folder. (one that contains the tag-folder, like ``global_step14``)
692
+ - ``tag``: checkpoint tag used as a unique identifier for checkpoint. If not provided will attempt to load tag in the file named ``latest`` in the checkpoint folder, e.g., ``global_step14``
693
+
694
+ Returns:
695
+ - ``model`: modified model
696
+
697
+ Make sure you have plenty of CPU memory available before you call this function. If you don't
698
+ have enough use the ``zero_to_fp32.py`` utility to do the conversion. You will find it
699
+ conveniently placed for you in the checkpoint folder.
700
+
701
+ A typical usage might be ::
702
+
703
+ from deepspeed.utils.zero_to_fp32 import load_state_dict_from_zero_checkpoint
704
+ model = load_state_dict_from_zero_checkpoint(trainer.model, checkpoint_dir)
705
+ # submit to model hub or save the model to share with others
706
+
707
+ Note, that once this was run, the ``model`` will no longer be usable in the deepspeed context
708
+ of the same application. i.e. you will need to re-initialize the deepspeed engine, since
709
+ ``model.load_state_dict(state_dict)`` will remove all the deepspeed magic from it.
710
+
711
+ """
712
+ logger.info(f"Extracting fp32 weights")
713
+ state_dict = get_fp32_state_dict_from_zero_checkpoint(checkpoint_dir, tag)
714
+
715
+ logger.info(f"Overwriting model with fp32 weights")
716
+ model = model.cpu()
717
+ model.load_state_dict(state_dict, strict=False)
718
+
719
+ return model
720
+
721
+
722
+ if __name__ == "__main__":
723
+ parser = argparse.ArgumentParser()
724
+ parser.add_argument("checkpoint_dir",
725
+ type=str,
726
+ help="path to the desired checkpoint folder, e.g., path/checkpoint-12")
727
+ parser.add_argument("output_dir",
728
+ type=str,
729
+ help="directory to the pytorch fp32 state_dict output files"
730
+ "(e.g. path/checkpoint-12-output/)")
731
+ parser.add_argument(
732
+ "--max_shard_size",
733
+ type=str,
734
+ default="5GB",
735
+ help="The maximum size for a checkpoint before being sharded. Checkpoints shard will then be each of size"
736
+ "lower than this size. If expressed as a string, needs to be digits followed by a unit (like `5MB`"
737
+ "We default it to 5GB in order for models to be able to run easily on free-tier google colab instances"
738
+ "without CPU OOM issues.")
739
+ parser.add_argument(
740
+ "--safe_serialization",
741
+ default=False,
742
+ action='store_true',
743
+ help="Whether to save the model using `safetensors` or the traditional PyTorch way (that uses `pickle`).")
744
+ parser.add_argument("-t",
745
+ "--tag",
746
+ type=str,
747
+ default=None,
748
+ help="checkpoint tag used as a unique identifier for checkpoint. e.g., global_step1")
749
+ parser.add_argument("--exclude_frozen_parameters", action='store_true', help="exclude frozen parameters")
750
+ parser.add_argument("-d", "--debug", action='store_true', help="enable debug")
751
+ args = parser.parse_args()
752
+
753
+ debug = args.debug
754
+
755
+ convert_zero_checkpoint_to_fp32_state_dict(args.checkpoint_dir,
756
+ args.output_dir,
757
+ max_shard_size=args.max_shard_size,
758
+ safe_serialization=args.safe_serialization,
759
+ tag=args.tag,
760
+ exclude_frozen_parameters=args.exclude_frozen_parameters)