Text Generation
Transformers
Safetensors
English
gidd
custom_code
dvruette commited on
Commit
2b39035
·
verified ·
1 Parent(s): 3598a4f

Upload folder using huggingface_hub

Browse files
config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "GiddForDiffusionLM"
4
+ ],
5
+ "attention_bias": true,
6
+ "attn_performer": "eager",
7
+ "attn_soft_cap": 30.0,
8
+ "auto_map": {
9
+ "AutoConfig": "configuration_gidd.GiddConfig",
10
+ "AutoModel": "modeling_gidd.GiddModel",
11
+ "AutoModelForCausalLM": "modeling_gidd.GiddForDiffusionLM"
12
+ },
13
+ "bos_token_id": 0,
14
+ "emb_init_scale": 0.1,
15
+ "eos_token_id": 1,
16
+ "head_dim": 128,
17
+ "head_init_scale": 0.0,
18
+ "head_scaling": 0.1111111111111111,
19
+ "hidden_size": 4608,
20
+ "init_scale": 0.005892556509887897,
21
+ "intermediate_size": 18432,
22
+ "is_causal": false,
23
+ "max_log_snr": 9.0,
24
+ "max_position_embeddings": 2048,
25
+ "min_log_snr": -9.0,
26
+ "mlp_bias": true,
27
+ "model_type": "gidd",
28
+ "noise_type": 1000.0,
29
+ "num_attention_heads": 36,
30
+ "num_hidden_layers": 34,
31
+ "resid_scale": 4.0,
32
+ "rms_norm_eps": 1e-06,
33
+ "rope_scaling": null,
34
+ "rope_theta": 10000.0,
35
+ "tie_word_embeddings": false,
36
+ "torch_dtype": "bfloat16",
37
+ "transformers_version": "4.54.0",
38
+ "use_qk_norm": true,
39
+ "vocab_size": 131072,
40
+ "weight_scaling": 1.0
41
+ }
configuration_gidd.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import typing as tp
2
+
3
+ from transformers import PretrainedConfig
4
+
5
+
6
+ class GiddConfig(PretrainedConfig):
7
+ model_type: str = "gidd"
8
+
9
+ def __init__(
10
+ self,
11
+ vocab_size: int = 131072,
12
+ hidden_size: int = 768,
13
+ intermediate_size: int = 3072,
14
+ num_hidden_layers: int = 12,
15
+ num_attention_heads: int = 12,
16
+ head_dim: tp.Optional[int] = None,
17
+ is_causal: bool = False,
18
+ attn_soft_cap: float = 30.0,
19
+ max_position_embeddings: int = 1024,
20
+ resid_scale: float = 4.0,
21
+ rms_norm_eps: float = 1e-6,
22
+ use_qk_norm: bool = True,
23
+ init_scale: float = 0.4,
24
+ emb_init_scale: float = 0.1,
25
+ head_init_scale: float = 0.0,
26
+ weight_scaling: str = "fan_in",
27
+ head_scaling: float = 1.0,
28
+ bos_token_id: int = 0,
29
+ eos_token_id: int = 1,
30
+ rope_theta: float = 10000.0,
31
+ rope_scaling: tp.Dict[str, tp.Union[str, float]] = None,
32
+ attention_bias: bool = False,
33
+ mlp_bias: bool = False,
34
+ tie_word_embeddings: bool = False,
35
+ attn_performer: str = "eager",
36
+ noise_type: float = 0.0,
37
+ min_log_snr: float = -9.0,
38
+ max_log_snr: float = 9.0,
39
+ **kwargs,
40
+ ):
41
+ super().__init__(
42
+ bos_token_id=bos_token_id,
43
+ eos_token_id=eos_token_id,
44
+ **kwargs,
45
+ )
46
+ self.vocab_size = vocab_size
47
+
48
+ self.hidden_size = hidden_size
49
+ self.intermediate_size = intermediate_size
50
+ self.num_hidden_layers = num_hidden_layers
51
+ self.rope_theta = rope_theta
52
+ self.num_attention_heads = num_attention_heads
53
+ self.attn_soft_cap = attn_soft_cap
54
+ self.is_causal = is_causal
55
+ self.max_position_embeddings = max_position_embeddings
56
+ self.resid_scale = resid_scale
57
+ self.init_scale = init_scale
58
+ self.emb_init_scale = emb_init_scale
59
+ self.head_init_scale = head_init_scale
60
+ self.weight_scaling = weight_scaling
61
+ self.head_scaling = head_scaling
62
+ self.rms_norm_eps = rms_norm_eps
63
+ self.use_qk_norm = use_qk_norm
64
+ self.attention_bias = attention_bias
65
+ self.mlp_bias = mlp_bias
66
+ self.rope_scaling = rope_scaling
67
+ self.head_dim = (
68
+ head_dim if head_dim is not None else hidden_size // num_attention_heads
69
+ )
70
+ self.tie_word_embeddings = tie_word_embeddings
71
+ self.attn_performer = attn_performer
72
+ self.noise_type = noise_type
73
+ self.min_log_snr = min_log_snr
74
+ self.max_log_snr = max_log_snr
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 0,
4
+ "eos_token_id": 1,
5
+ "transformers_version": "4.54.0"
6
+ }
model-00001-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0ee10c0dc3b60f8f4ea60be06c590920a7b85078a250511aac0db4c184c4fcf0
3
+ size 4946119120
model-00002-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dd8257df5e1bbcd0dc099389a5f80f58a4c854baa669bac3cd4799f75714253a
3
+ size 4970074808
model-00003-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c50fd4558188506075bb3b1e1732c6c4fbff651d80fa57e853bb1a5ffbf37b98
3
+ size 4885038200
model-00004-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:22ba8c7f034ceece1884afee15a202e03ecbe1194540b72d0cd81fbfb959c2b2
3
+ size 4946128048
model.safetensors.index.json ADDED
@@ -0,0 +1,487 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_parameters": 9873022464,
4
+ "total_size": 19747307520
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.attn_layernorm.weight": "model-00001-of-00004.safetensors",
10
+ "model.layers.0.mlp.down_proj.bias": "model-00001-of-00004.safetensors",
11
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
12
+ "model.layers.0.mlp.up_proj.bias": "model-00001-of-00004.safetensors",
13
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
14
+ "model.layers.0.mlp_layernorm.weight": "model-00001-of-00004.safetensors",
15
+ "model.layers.0.self_attn.k_bias": "model-00001-of-00004.safetensors",
16
+ "model.layers.0.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
17
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
18
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
19
+ "model.layers.0.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
20
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
21
+ "model.layers.0.self_attn.v_bias": "model-00001-of-00004.safetensors",
22
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
23
+ "model.layers.1.attn_layernorm.weight": "model-00001-of-00004.safetensors",
24
+ "model.layers.1.mlp.down_proj.bias": "model-00001-of-00004.safetensors",
25
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
26
+ "model.layers.1.mlp.up_proj.bias": "model-00001-of-00004.safetensors",
27
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
28
+ "model.layers.1.mlp_layernorm.weight": "model-00001-of-00004.safetensors",
29
+ "model.layers.1.self_attn.k_bias": "model-00001-of-00004.safetensors",
30
+ "model.layers.1.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
31
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
32
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
33
+ "model.layers.1.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
34
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
35
+ "model.layers.1.self_attn.v_bias": "model-00001-of-00004.safetensors",
36
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
37
+ "model.layers.10.attn_layernorm.weight": "model-00002-of-00004.safetensors",
38
+ "model.layers.10.mlp.down_proj.bias": "model-00002-of-00004.safetensors",
39
+ "model.layers.10.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
40
+ "model.layers.10.mlp.up_proj.bias": "model-00002-of-00004.safetensors",
41
+ "model.layers.10.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
42
+ "model.layers.10.mlp_layernorm.weight": "model-00002-of-00004.safetensors",
43
+ "model.layers.10.self_attn.k_bias": "model-00002-of-00004.safetensors",
44
+ "model.layers.10.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
45
+ "model.layers.10.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
46
+ "model.layers.10.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
47
+ "model.layers.10.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
48
+ "model.layers.10.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
49
+ "model.layers.10.self_attn.v_bias": "model-00002-of-00004.safetensors",
50
+ "model.layers.10.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
51
+ "model.layers.11.attn_layernorm.weight": "model-00002-of-00004.safetensors",
52
+ "model.layers.11.mlp.down_proj.bias": "model-00002-of-00004.safetensors",
53
+ "model.layers.11.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
54
+ "model.layers.11.mlp.up_proj.bias": "model-00002-of-00004.safetensors",
55
+ "model.layers.11.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
56
+ "model.layers.11.mlp_layernorm.weight": "model-00002-of-00004.safetensors",
57
+ "model.layers.11.self_attn.k_bias": "model-00002-of-00004.safetensors",
58
+ "model.layers.11.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
59
+ "model.layers.11.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
60
+ "model.layers.11.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
61
+ "model.layers.11.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
62
+ "model.layers.11.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
63
+ "model.layers.11.self_attn.v_bias": "model-00002-of-00004.safetensors",
64
+ "model.layers.11.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
65
+ "model.layers.12.attn_layernorm.weight": "model-00002-of-00004.safetensors",
66
+ "model.layers.12.mlp.down_proj.bias": "model-00002-of-00004.safetensors",
67
+ "model.layers.12.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
68
+ "model.layers.12.mlp.up_proj.bias": "model-00002-of-00004.safetensors",
69
+ "model.layers.12.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
70
+ "model.layers.12.mlp_layernorm.weight": "model-00002-of-00004.safetensors",
71
+ "model.layers.12.self_attn.k_bias": "model-00002-of-00004.safetensors",
72
+ "model.layers.12.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
73
+ "model.layers.12.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
74
+ "model.layers.12.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
75
+ "model.layers.12.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
76
+ "model.layers.12.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
77
+ "model.layers.12.self_attn.v_bias": "model-00002-of-00004.safetensors",
78
+ "model.layers.12.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
79
+ "model.layers.13.attn_layernorm.weight": "model-00002-of-00004.safetensors",
80
+ "model.layers.13.mlp.down_proj.bias": "model-00002-of-00004.safetensors",
81
+ "model.layers.13.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
82
+ "model.layers.13.mlp.up_proj.bias": "model-00002-of-00004.safetensors",
83
+ "model.layers.13.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
84
+ "model.layers.13.mlp_layernorm.weight": "model-00002-of-00004.safetensors",
85
+ "model.layers.13.self_attn.k_bias": "model-00002-of-00004.safetensors",
86
+ "model.layers.13.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
87
+ "model.layers.13.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
88
+ "model.layers.13.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
89
+ "model.layers.13.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
90
+ "model.layers.13.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
91
+ "model.layers.13.self_attn.v_bias": "model-00002-of-00004.safetensors",
92
+ "model.layers.13.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
93
+ "model.layers.14.attn_layernorm.weight": "model-00002-of-00004.safetensors",
94
+ "model.layers.14.mlp.down_proj.bias": "model-00002-of-00004.safetensors",
95
+ "model.layers.14.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
96
+ "model.layers.14.mlp.up_proj.bias": "model-00002-of-00004.safetensors",
97
+ "model.layers.14.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
98
+ "model.layers.14.mlp_layernorm.weight": "model-00002-of-00004.safetensors",
99
+ "model.layers.14.self_attn.k_bias": "model-00002-of-00004.safetensors",
100
+ "model.layers.14.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
101
+ "model.layers.14.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
102
+ "model.layers.14.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
103
+ "model.layers.14.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
104
+ "model.layers.14.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
105
+ "model.layers.14.self_attn.v_bias": "model-00002-of-00004.safetensors",
106
+ "model.layers.14.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
107
+ "model.layers.15.attn_layernorm.weight": "model-00002-of-00004.safetensors",
108
+ "model.layers.15.mlp.down_proj.bias": "model-00002-of-00004.safetensors",
109
+ "model.layers.15.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
110
+ "model.layers.15.mlp.up_proj.bias": "model-00002-of-00004.safetensors",
111
+ "model.layers.15.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
112
+ "model.layers.15.mlp_layernorm.weight": "model-00002-of-00004.safetensors",
113
+ "model.layers.15.self_attn.k_bias": "model-00002-of-00004.safetensors",
114
+ "model.layers.15.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
115
+ "model.layers.15.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
116
+ "model.layers.15.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
117
+ "model.layers.15.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
118
+ "model.layers.15.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
119
+ "model.layers.15.self_attn.v_bias": "model-00002-of-00004.safetensors",
120
+ "model.layers.15.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
121
+ "model.layers.16.attn_layernorm.weight": "model-00002-of-00004.safetensors",
122
+ "model.layers.16.mlp.down_proj.bias": "model-00002-of-00004.safetensors",
123
+ "model.layers.16.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
124
+ "model.layers.16.mlp.up_proj.bias": "model-00002-of-00004.safetensors",
125
+ "model.layers.16.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
126
+ "model.layers.16.mlp_layernorm.weight": "model-00002-of-00004.safetensors",
127
+ "model.layers.16.self_attn.k_bias": "model-00002-of-00004.safetensors",
128
+ "model.layers.16.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
129
+ "model.layers.16.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
130
+ "model.layers.16.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
131
+ "model.layers.16.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
132
+ "model.layers.16.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
133
+ "model.layers.16.self_attn.v_bias": "model-00002-of-00004.safetensors",
134
+ "model.layers.16.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
135
+ "model.layers.17.attn_layernorm.weight": "model-00003-of-00004.safetensors",
136
+ "model.layers.17.mlp.down_proj.bias": "model-00003-of-00004.safetensors",
137
+ "model.layers.17.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
138
+ "model.layers.17.mlp.up_proj.bias": "model-00003-of-00004.safetensors",
139
+ "model.layers.17.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
140
+ "model.layers.17.mlp_layernorm.weight": "model-00003-of-00004.safetensors",
141
+ "model.layers.17.self_attn.k_bias": "model-00002-of-00004.safetensors",
142
+ "model.layers.17.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
143
+ "model.layers.17.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
144
+ "model.layers.17.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
145
+ "model.layers.17.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
146
+ "model.layers.17.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
147
+ "model.layers.17.self_attn.v_bias": "model-00002-of-00004.safetensors",
148
+ "model.layers.17.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
149
+ "model.layers.18.attn_layernorm.weight": "model-00003-of-00004.safetensors",
150
+ "model.layers.18.mlp.down_proj.bias": "model-00003-of-00004.safetensors",
151
+ "model.layers.18.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
152
+ "model.layers.18.mlp.up_proj.bias": "model-00003-of-00004.safetensors",
153
+ "model.layers.18.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
154
+ "model.layers.18.mlp_layernorm.weight": "model-00003-of-00004.safetensors",
155
+ "model.layers.18.self_attn.k_bias": "model-00003-of-00004.safetensors",
156
+ "model.layers.18.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
157
+ "model.layers.18.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
158
+ "model.layers.18.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
159
+ "model.layers.18.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
160
+ "model.layers.18.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
161
+ "model.layers.18.self_attn.v_bias": "model-00003-of-00004.safetensors",
162
+ "model.layers.18.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
163
+ "model.layers.19.attn_layernorm.weight": "model-00003-of-00004.safetensors",
164
+ "model.layers.19.mlp.down_proj.bias": "model-00003-of-00004.safetensors",
165
+ "model.layers.19.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
166
+ "model.layers.19.mlp.up_proj.bias": "model-00003-of-00004.safetensors",
167
+ "model.layers.19.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
168
+ "model.layers.19.mlp_layernorm.weight": "model-00003-of-00004.safetensors",
169
+ "model.layers.19.self_attn.k_bias": "model-00003-of-00004.safetensors",
170
+ "model.layers.19.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
171
+ "model.layers.19.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
172
+ "model.layers.19.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
173
+ "model.layers.19.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
174
+ "model.layers.19.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
175
+ "model.layers.19.self_attn.v_bias": "model-00003-of-00004.safetensors",
176
+ "model.layers.19.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
177
+ "model.layers.2.attn_layernorm.weight": "model-00001-of-00004.safetensors",
178
+ "model.layers.2.mlp.down_proj.bias": "model-00001-of-00004.safetensors",
179
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
180
+ "model.layers.2.mlp.up_proj.bias": "model-00001-of-00004.safetensors",
181
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
182
+ "model.layers.2.mlp_layernorm.weight": "model-00001-of-00004.safetensors",
183
+ "model.layers.2.self_attn.k_bias": "model-00001-of-00004.safetensors",
184
+ "model.layers.2.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
185
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
186
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
187
+ "model.layers.2.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
188
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
189
+ "model.layers.2.self_attn.v_bias": "model-00001-of-00004.safetensors",
190
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
191
+ "model.layers.20.attn_layernorm.weight": "model-00003-of-00004.safetensors",
192
+ "model.layers.20.mlp.down_proj.bias": "model-00003-of-00004.safetensors",
193
+ "model.layers.20.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
194
+ "model.layers.20.mlp.up_proj.bias": "model-00003-of-00004.safetensors",
195
+ "model.layers.20.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
196
+ "model.layers.20.mlp_layernorm.weight": "model-00003-of-00004.safetensors",
197
+ "model.layers.20.self_attn.k_bias": "model-00003-of-00004.safetensors",
198
+ "model.layers.20.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
199
+ "model.layers.20.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
200
+ "model.layers.20.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
201
+ "model.layers.20.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
202
+ "model.layers.20.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
203
+ "model.layers.20.self_attn.v_bias": "model-00003-of-00004.safetensors",
204
+ "model.layers.20.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
205
+ "model.layers.21.attn_layernorm.weight": "model-00003-of-00004.safetensors",
206
+ "model.layers.21.mlp.down_proj.bias": "model-00003-of-00004.safetensors",
207
+ "model.layers.21.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
208
+ "model.layers.21.mlp.up_proj.bias": "model-00003-of-00004.safetensors",
209
+ "model.layers.21.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
210
+ "model.layers.21.mlp_layernorm.weight": "model-00003-of-00004.safetensors",
211
+ "model.layers.21.self_attn.k_bias": "model-00003-of-00004.safetensors",
212
+ "model.layers.21.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
213
+ "model.layers.21.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
214
+ "model.layers.21.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
215
+ "model.layers.21.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
216
+ "model.layers.21.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
217
+ "model.layers.21.self_attn.v_bias": "model-00003-of-00004.safetensors",
218
+ "model.layers.21.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
219
+ "model.layers.22.attn_layernorm.weight": "model-00003-of-00004.safetensors",
220
+ "model.layers.22.mlp.down_proj.bias": "model-00003-of-00004.safetensors",
221
+ "model.layers.22.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
222
+ "model.layers.22.mlp.up_proj.bias": "model-00003-of-00004.safetensors",
223
+ "model.layers.22.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
224
+ "model.layers.22.mlp_layernorm.weight": "model-00003-of-00004.safetensors",
225
+ "model.layers.22.self_attn.k_bias": "model-00003-of-00004.safetensors",
226
+ "model.layers.22.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
227
+ "model.layers.22.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
228
+ "model.layers.22.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
229
+ "model.layers.22.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
230
+ "model.layers.22.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
231
+ "model.layers.22.self_attn.v_bias": "model-00003-of-00004.safetensors",
232
+ "model.layers.22.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
233
+ "model.layers.23.attn_layernorm.weight": "model-00003-of-00004.safetensors",
234
+ "model.layers.23.mlp.down_proj.bias": "model-00003-of-00004.safetensors",
235
+ "model.layers.23.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
236
+ "model.layers.23.mlp.up_proj.bias": "model-00003-of-00004.safetensors",
237
+ "model.layers.23.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
238
+ "model.layers.23.mlp_layernorm.weight": "model-00003-of-00004.safetensors",
239
+ "model.layers.23.self_attn.k_bias": "model-00003-of-00004.safetensors",
240
+ "model.layers.23.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
241
+ "model.layers.23.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
242
+ "model.layers.23.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
243
+ "model.layers.23.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
244
+ "model.layers.23.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
245
+ "model.layers.23.self_attn.v_bias": "model-00003-of-00004.safetensors",
246
+ "model.layers.23.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
247
+ "model.layers.24.attn_layernorm.weight": "model-00003-of-00004.safetensors",
248
+ "model.layers.24.mlp.down_proj.bias": "model-00003-of-00004.safetensors",
249
+ "model.layers.24.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
250
+ "model.layers.24.mlp.up_proj.bias": "model-00003-of-00004.safetensors",
251
+ "model.layers.24.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
252
+ "model.layers.24.mlp_layernorm.weight": "model-00003-of-00004.safetensors",
253
+ "model.layers.24.self_attn.k_bias": "model-00003-of-00004.safetensors",
254
+ "model.layers.24.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
255
+ "model.layers.24.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
256
+ "model.layers.24.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
257
+ "model.layers.24.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
258
+ "model.layers.24.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
259
+ "model.layers.24.self_attn.v_bias": "model-00003-of-00004.safetensors",
260
+ "model.layers.24.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
261
+ "model.layers.25.attn_layernorm.weight": "model-00003-of-00004.safetensors",
262
+ "model.layers.25.mlp.down_proj.bias": "model-00003-of-00004.safetensors",
263
+ "model.layers.25.mlp.down_proj.weight": "model-00003-of-00004.safetensors",
264
+ "model.layers.25.mlp.up_proj.bias": "model-00003-of-00004.safetensors",
265
+ "model.layers.25.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
266
+ "model.layers.25.mlp_layernorm.weight": "model-00003-of-00004.safetensors",
267
+ "model.layers.25.self_attn.k_bias": "model-00003-of-00004.safetensors",
268
+ "model.layers.25.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
269
+ "model.layers.25.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
270
+ "model.layers.25.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
271
+ "model.layers.25.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
272
+ "model.layers.25.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
273
+ "model.layers.25.self_attn.v_bias": "model-00003-of-00004.safetensors",
274
+ "model.layers.25.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
275
+ "model.layers.26.attn_layernorm.weight": "model-00004-of-00004.safetensors",
276
+ "model.layers.26.mlp.down_proj.bias": "model-00004-of-00004.safetensors",
277
+ "model.layers.26.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
278
+ "model.layers.26.mlp.up_proj.bias": "model-00003-of-00004.safetensors",
279
+ "model.layers.26.mlp.up_proj.weight": "model-00003-of-00004.safetensors",
280
+ "model.layers.26.mlp_layernorm.weight": "model-00004-of-00004.safetensors",
281
+ "model.layers.26.self_attn.k_bias": "model-00003-of-00004.safetensors",
282
+ "model.layers.26.self_attn.k_norm.weight": "model-00003-of-00004.safetensors",
283
+ "model.layers.26.self_attn.k_proj.weight": "model-00003-of-00004.safetensors",
284
+ "model.layers.26.self_attn.o_proj.weight": "model-00003-of-00004.safetensors",
285
+ "model.layers.26.self_attn.q_norm.weight": "model-00003-of-00004.safetensors",
286
+ "model.layers.26.self_attn.q_proj.weight": "model-00003-of-00004.safetensors",
287
+ "model.layers.26.self_attn.v_bias": "model-00003-of-00004.safetensors",
288
+ "model.layers.26.self_attn.v_proj.weight": "model-00003-of-00004.safetensors",
289
+ "model.layers.27.attn_layernorm.weight": "model-00004-of-00004.safetensors",
290
+ "model.layers.27.mlp.down_proj.bias": "model-00004-of-00004.safetensors",
291
+ "model.layers.27.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
292
+ "model.layers.27.mlp.up_proj.bias": "model-00004-of-00004.safetensors",
293
+ "model.layers.27.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
294
+ "model.layers.27.mlp_layernorm.weight": "model-00004-of-00004.safetensors",
295
+ "model.layers.27.self_attn.k_bias": "model-00004-of-00004.safetensors",
296
+ "model.layers.27.self_attn.k_norm.weight": "model-00004-of-00004.safetensors",
297
+ "model.layers.27.self_attn.k_proj.weight": "model-00004-of-00004.safetensors",
298
+ "model.layers.27.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
299
+ "model.layers.27.self_attn.q_norm.weight": "model-00004-of-00004.safetensors",
300
+ "model.layers.27.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
301
+ "model.layers.27.self_attn.v_bias": "model-00004-of-00004.safetensors",
302
+ "model.layers.27.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
303
+ "model.layers.28.attn_layernorm.weight": "model-00004-of-00004.safetensors",
304
+ "model.layers.28.mlp.down_proj.bias": "model-00004-of-00004.safetensors",
305
+ "model.layers.28.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
306
+ "model.layers.28.mlp.up_proj.bias": "model-00004-of-00004.safetensors",
307
+ "model.layers.28.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
308
+ "model.layers.28.mlp_layernorm.weight": "model-00004-of-00004.safetensors",
309
+ "model.layers.28.self_attn.k_bias": "model-00004-of-00004.safetensors",
310
+ "model.layers.28.self_attn.k_norm.weight": "model-00004-of-00004.safetensors",
311
+ "model.layers.28.self_attn.k_proj.weight": "model-00004-of-00004.safetensors",
312
+ "model.layers.28.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
313
+ "model.layers.28.self_attn.q_norm.weight": "model-00004-of-00004.safetensors",
314
+ "model.layers.28.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
315
+ "model.layers.28.self_attn.v_bias": "model-00004-of-00004.safetensors",
316
+ "model.layers.28.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
317
+ "model.layers.29.attn_layernorm.weight": "model-00004-of-00004.safetensors",
318
+ "model.layers.29.mlp.down_proj.bias": "model-00004-of-00004.safetensors",
319
+ "model.layers.29.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
320
+ "model.layers.29.mlp.up_proj.bias": "model-00004-of-00004.safetensors",
321
+ "model.layers.29.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
322
+ "model.layers.29.mlp_layernorm.weight": "model-00004-of-00004.safetensors",
323
+ "model.layers.29.self_attn.k_bias": "model-00004-of-00004.safetensors",
324
+ "model.layers.29.self_attn.k_norm.weight": "model-00004-of-00004.safetensors",
325
+ "model.layers.29.self_attn.k_proj.weight": "model-00004-of-00004.safetensors",
326
+ "model.layers.29.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
327
+ "model.layers.29.self_attn.q_norm.weight": "model-00004-of-00004.safetensors",
328
+ "model.layers.29.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
329
+ "model.layers.29.self_attn.v_bias": "model-00004-of-00004.safetensors",
330
+ "model.layers.29.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
331
+ "model.layers.3.attn_layernorm.weight": "model-00001-of-00004.safetensors",
332
+ "model.layers.3.mlp.down_proj.bias": "model-00001-of-00004.safetensors",
333
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
334
+ "model.layers.3.mlp.up_proj.bias": "model-00001-of-00004.safetensors",
335
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
336
+ "model.layers.3.mlp_layernorm.weight": "model-00001-of-00004.safetensors",
337
+ "model.layers.3.self_attn.k_bias": "model-00001-of-00004.safetensors",
338
+ "model.layers.3.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
339
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
340
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
341
+ "model.layers.3.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
342
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
343
+ "model.layers.3.self_attn.v_bias": "model-00001-of-00004.safetensors",
344
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
345
+ "model.layers.30.attn_layernorm.weight": "model-00004-of-00004.safetensors",
346
+ "model.layers.30.mlp.down_proj.bias": "model-00004-of-00004.safetensors",
347
+ "model.layers.30.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
348
+ "model.layers.30.mlp.up_proj.bias": "model-00004-of-00004.safetensors",
349
+ "model.layers.30.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
350
+ "model.layers.30.mlp_layernorm.weight": "model-00004-of-00004.safetensors",
351
+ "model.layers.30.self_attn.k_bias": "model-00004-of-00004.safetensors",
352
+ "model.layers.30.self_attn.k_norm.weight": "model-00004-of-00004.safetensors",
353
+ "model.layers.30.self_attn.k_proj.weight": "model-00004-of-00004.safetensors",
354
+ "model.layers.30.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
355
+ "model.layers.30.self_attn.q_norm.weight": "model-00004-of-00004.safetensors",
356
+ "model.layers.30.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
357
+ "model.layers.30.self_attn.v_bias": "model-00004-of-00004.safetensors",
358
+ "model.layers.30.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
359
+ "model.layers.31.attn_layernorm.weight": "model-00004-of-00004.safetensors",
360
+ "model.layers.31.mlp.down_proj.bias": "model-00004-of-00004.safetensors",
361
+ "model.layers.31.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
362
+ "model.layers.31.mlp.up_proj.bias": "model-00004-of-00004.safetensors",
363
+ "model.layers.31.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
364
+ "model.layers.31.mlp_layernorm.weight": "model-00004-of-00004.safetensors",
365
+ "model.layers.31.self_attn.k_bias": "model-00004-of-00004.safetensors",
366
+ "model.layers.31.self_attn.k_norm.weight": "model-00004-of-00004.safetensors",
367
+ "model.layers.31.self_attn.k_proj.weight": "model-00004-of-00004.safetensors",
368
+ "model.layers.31.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
369
+ "model.layers.31.self_attn.q_norm.weight": "model-00004-of-00004.safetensors",
370
+ "model.layers.31.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
371
+ "model.layers.31.self_attn.v_bias": "model-00004-of-00004.safetensors",
372
+ "model.layers.31.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
373
+ "model.layers.32.attn_layernorm.weight": "model-00004-of-00004.safetensors",
374
+ "model.layers.32.mlp.down_proj.bias": "model-00004-of-00004.safetensors",
375
+ "model.layers.32.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
376
+ "model.layers.32.mlp.up_proj.bias": "model-00004-of-00004.safetensors",
377
+ "model.layers.32.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
378
+ "model.layers.32.mlp_layernorm.weight": "model-00004-of-00004.safetensors",
379
+ "model.layers.32.self_attn.k_bias": "model-00004-of-00004.safetensors",
380
+ "model.layers.32.self_attn.k_norm.weight": "model-00004-of-00004.safetensors",
381
+ "model.layers.32.self_attn.k_proj.weight": "model-00004-of-00004.safetensors",
382
+ "model.layers.32.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
383
+ "model.layers.32.self_attn.q_norm.weight": "model-00004-of-00004.safetensors",
384
+ "model.layers.32.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
385
+ "model.layers.32.self_attn.v_bias": "model-00004-of-00004.safetensors",
386
+ "model.layers.32.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
387
+ "model.layers.33.attn_layernorm.weight": "model-00004-of-00004.safetensors",
388
+ "model.layers.33.mlp.down_proj.bias": "model-00004-of-00004.safetensors",
389
+ "model.layers.33.mlp.down_proj.weight": "model-00004-of-00004.safetensors",
390
+ "model.layers.33.mlp.up_proj.bias": "model-00004-of-00004.safetensors",
391
+ "model.layers.33.mlp.up_proj.weight": "model-00004-of-00004.safetensors",
392
+ "model.layers.33.mlp_layernorm.weight": "model-00004-of-00004.safetensors",
393
+ "model.layers.33.self_attn.k_bias": "model-00004-of-00004.safetensors",
394
+ "model.layers.33.self_attn.k_norm.weight": "model-00004-of-00004.safetensors",
395
+ "model.layers.33.self_attn.k_proj.weight": "model-00004-of-00004.safetensors",
396
+ "model.layers.33.self_attn.o_proj.weight": "model-00004-of-00004.safetensors",
397
+ "model.layers.33.self_attn.q_norm.weight": "model-00004-of-00004.safetensors",
398
+ "model.layers.33.self_attn.q_proj.weight": "model-00004-of-00004.safetensors",
399
+ "model.layers.33.self_attn.v_bias": "model-00004-of-00004.safetensors",
400
+ "model.layers.33.self_attn.v_proj.weight": "model-00004-of-00004.safetensors",
401
+ "model.layers.4.attn_layernorm.weight": "model-00001-of-00004.safetensors",
402
+ "model.layers.4.mlp.down_proj.bias": "model-00001-of-00004.safetensors",
403
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
404
+ "model.layers.4.mlp.up_proj.bias": "model-00001-of-00004.safetensors",
405
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
406
+ "model.layers.4.mlp_layernorm.weight": "model-00001-of-00004.safetensors",
407
+ "model.layers.4.self_attn.k_bias": "model-00001-of-00004.safetensors",
408
+ "model.layers.4.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
409
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
410
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
411
+ "model.layers.4.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
412
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
413
+ "model.layers.4.self_attn.v_bias": "model-00001-of-00004.safetensors",
414
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
415
+ "model.layers.5.attn_layernorm.weight": "model-00001-of-00004.safetensors",
416
+ "model.layers.5.mlp.down_proj.bias": "model-00001-of-00004.safetensors",
417
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
418
+ "model.layers.5.mlp.up_proj.bias": "model-00001-of-00004.safetensors",
419
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
420
+ "model.layers.5.mlp_layernorm.weight": "model-00001-of-00004.safetensors",
421
+ "model.layers.5.self_attn.k_bias": "model-00001-of-00004.safetensors",
422
+ "model.layers.5.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
423
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
424
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
425
+ "model.layers.5.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
426
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
427
+ "model.layers.5.self_attn.v_bias": "model-00001-of-00004.safetensors",
428
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
429
+ "model.layers.6.attn_layernorm.weight": "model-00001-of-00004.safetensors",
430
+ "model.layers.6.mlp.down_proj.bias": "model-00001-of-00004.safetensors",
431
+ "model.layers.6.mlp.down_proj.weight": "model-00001-of-00004.safetensors",
432
+ "model.layers.6.mlp.up_proj.bias": "model-00001-of-00004.safetensors",
433
+ "model.layers.6.mlp.up_proj.weight": "model-00001-of-00004.safetensors",
434
+ "model.layers.6.mlp_layernorm.weight": "model-00001-of-00004.safetensors",
435
+ "model.layers.6.self_attn.k_bias": "model-00001-of-00004.safetensors",
436
+ "model.layers.6.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
437
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
438
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
439
+ "model.layers.6.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
440
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
441
+ "model.layers.6.self_attn.v_bias": "model-00001-of-00004.safetensors",
442
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
443
+ "model.layers.7.attn_layernorm.weight": "model-00002-of-00004.safetensors",
444
+ "model.layers.7.mlp.down_proj.bias": "model-00002-of-00004.safetensors",
445
+ "model.layers.7.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
446
+ "model.layers.7.mlp.up_proj.bias": "model-00002-of-00004.safetensors",
447
+ "model.layers.7.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
448
+ "model.layers.7.mlp_layernorm.weight": "model-00002-of-00004.safetensors",
449
+ "model.layers.7.self_attn.k_bias": "model-00001-of-00004.safetensors",
450
+ "model.layers.7.self_attn.k_norm.weight": "model-00001-of-00004.safetensors",
451
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00004.safetensors",
452
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00004.safetensors",
453
+ "model.layers.7.self_attn.q_norm.weight": "model-00001-of-00004.safetensors",
454
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00004.safetensors",
455
+ "model.layers.7.self_attn.v_bias": "model-00001-of-00004.safetensors",
456
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00004.safetensors",
457
+ "model.layers.8.attn_layernorm.weight": "model-00002-of-00004.safetensors",
458
+ "model.layers.8.mlp.down_proj.bias": "model-00002-of-00004.safetensors",
459
+ "model.layers.8.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
460
+ "model.layers.8.mlp.up_proj.bias": "model-00002-of-00004.safetensors",
461
+ "model.layers.8.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
462
+ "model.layers.8.mlp_layernorm.weight": "model-00002-of-00004.safetensors",
463
+ "model.layers.8.self_attn.k_bias": "model-00002-of-00004.safetensors",
464
+ "model.layers.8.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
465
+ "model.layers.8.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
466
+ "model.layers.8.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
467
+ "model.layers.8.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
468
+ "model.layers.8.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
469
+ "model.layers.8.self_attn.v_bias": "model-00002-of-00004.safetensors",
470
+ "model.layers.8.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
471
+ "model.layers.9.attn_layernorm.weight": "model-00002-of-00004.safetensors",
472
+ "model.layers.9.mlp.down_proj.bias": "model-00002-of-00004.safetensors",
473
+ "model.layers.9.mlp.down_proj.weight": "model-00002-of-00004.safetensors",
474
+ "model.layers.9.mlp.up_proj.bias": "model-00002-of-00004.safetensors",
475
+ "model.layers.9.mlp.up_proj.weight": "model-00002-of-00004.safetensors",
476
+ "model.layers.9.mlp_layernorm.weight": "model-00002-of-00004.safetensors",
477
+ "model.layers.9.self_attn.k_bias": "model-00002-of-00004.safetensors",
478
+ "model.layers.9.self_attn.k_norm.weight": "model-00002-of-00004.safetensors",
479
+ "model.layers.9.self_attn.k_proj.weight": "model-00002-of-00004.safetensors",
480
+ "model.layers.9.self_attn.o_proj.weight": "model-00002-of-00004.safetensors",
481
+ "model.layers.9.self_attn.q_norm.weight": "model-00002-of-00004.safetensors",
482
+ "model.layers.9.self_attn.q_proj.weight": "model-00002-of-00004.safetensors",
483
+ "model.layers.9.self_attn.v_bias": "model-00002-of-00004.safetensors",
484
+ "model.layers.9.self_attn.v_proj.weight": "model-00002-of-00004.safetensors",
485
+ "model.norm.weight": "model-00004-of-00004.safetensors"
486
+ }
487
+ }
modeling_gidd.py ADDED
@@ -0,0 +1,1134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import typing as tp
2
+ import warnings
3
+ from functools import partial
4
+ from dataclasses import dataclass
5
+
6
+ import torch
7
+ import torch.nn as nn
8
+ from torch.nn.attention.flex_attention import flex_attention
9
+ from transformers import PreTrainedModel
10
+ from transformers.cache_utils import Cache, DynamicCache
11
+ from transformers.generation.utils import GenerationMixin
12
+ from transformers.pytorch_utils import ALL_LAYERNORM_LAYERS
13
+ from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
14
+
15
+ from .configuration_gidd import GiddConfig
16
+
17
+
18
+ @dataclass
19
+ class AttentionLayerOutput:
20
+ hidden_states: torch.Tensor
21
+ attentions: tp.Optional[torch.Tensor] = None
22
+ past_key_values: tp.Optional[tp.List[tp.Tuple[torch.Tensor, torch.Tensor]]] = None
23
+
24
+ @dataclass
25
+ class DecoderLayerOutput:
26
+ hidden_states: torch.Tensor
27
+ attentions: tp.Optional[torch.Tensor] = None
28
+ past_key_values: tp.Optional[tp.List[tp.Tuple[torch.Tensor, torch.Tensor]]] = None
29
+
30
+
31
+ def promote_dtype(args: tuple, *, dtype: torch.dtype | None = None) -> tuple:
32
+ return tuple(
33
+ torch.as_tensor(x, dtype=dtype) if x is not None else None
34
+ for x in args
35
+ )
36
+
37
+
38
+ class ScaledLinear(nn.Module):
39
+ def __init__(
40
+ self,
41
+ in_features: int,
42
+ out_features: int,
43
+ *,
44
+ scale: float | tp.Literal["fan_in", "fan_out"] = 1.0,
45
+ use_bias: bool = True,
46
+ dtype: torch.dtype | None = None,
47
+ ):
48
+ super().__init__()
49
+
50
+ if scale == "fan_in":
51
+ scale = in_features**-0.5
52
+ elif scale == "fan_out":
53
+ scale = out_features**-0.5
54
+
55
+ if scale != 1.0:
56
+ def _scale_operator(x):
57
+ return x * scale
58
+ else:
59
+ def _scale_operator(x):
60
+ return x
61
+
62
+ self._scale_operator = _scale_operator
63
+ self.in_features = in_features
64
+ self.out_features = out_features
65
+
66
+ self.use_bias = use_bias
67
+
68
+ weight_shape = (out_features, in_features)
69
+ weight = torch.zeros(weight_shape, dtype=dtype)
70
+ self.weight = nn.Parameter(weight)
71
+
72
+ if use_bias:
73
+ bias = torch.zeros((out_features,), dtype=dtype)
74
+ self.bias = nn.Parameter(bias)
75
+ else:
76
+ self.bias = None
77
+
78
+ def forward(
79
+ self,
80
+ inputs: torch.Tensor,
81
+ w: torch.Tensor | None = None,
82
+ ) -> torch.Tensor:
83
+ dtype = inputs.dtype
84
+ weight = self.weight if w is None else w
85
+ bias = self.bias if self.use_bias else None
86
+
87
+ if bias is not None:
88
+ inputs, weight, bias = promote_dtype((inputs, weight, bias), dtype=dtype)
89
+ else:
90
+ inputs, weight = promote_dtype((inputs, weight), dtype=dtype)
91
+
92
+ y = torch.matmul(
93
+ inputs,
94
+ weight.T,
95
+ )
96
+
97
+ y = self._scale_operator(y)
98
+
99
+ if bias is not None:
100
+ y = y + bias.reshape((1,) * (y.ndim - 1) + (-1,))
101
+
102
+ return y
103
+
104
+
105
+ def _apply_rotary_emb(
106
+ x: torch.Tensor,
107
+ cos: torch.Tensor,
108
+ sin: torch.Tensor,
109
+ is_neox_style: bool,
110
+ ) -> torch.Tensor:
111
+ cos = cos.unsqueeze(2).to(dtype=x.dtype)
112
+ sin = sin.unsqueeze(2).to(dtype=x.dtype)
113
+ assert sin.ndim == x.ndim
114
+ if is_neox_style:
115
+ x1, x2 = torch.chunk(x, 2, dim=-1)
116
+ else:
117
+ x1 = x[..., ::2]
118
+ x2 = x[..., 1::2]
119
+
120
+ o1 = x1 * cos - x2 * sin
121
+ o2 = x2 * cos + x1 * sin
122
+
123
+ if is_neox_style:
124
+ return torch.cat((o1, o2), dim=-1)
125
+ else:
126
+ return torch.stack((o1, o2), dim=-1).reshape(x.shape)
127
+
128
+ def apply_basic_rope(
129
+ query: torch.Tensor,
130
+ key: torch.Tensor,
131
+ positions: torch.Tensor,
132
+ frequencies: torch.Tensor,
133
+ rotary_dim: int,
134
+ is_neox_style: bool,
135
+ offsets: torch.Tensor | None = None,
136
+ dtype: torch.dtype = torch.float32,
137
+ ):
138
+ if offsets is not None:
139
+ positions = positions + offsets
140
+ cos, sin = torch.chunk(frequencies[positions], 2, dim=-1)
141
+ if rotary_dim != query.shape[-1]:
142
+ query_rot = _apply_rotary_emb(query[..., :rotary_dim], cos, sin, is_neox_style)
143
+ query = torch.cat((query_rot, query[..., rotary_dim:]), dim=-1)
144
+ key_rot = _apply_rotary_emb(key[..., :rotary_dim], cos, sin, is_neox_style)
145
+ key = torch.cat((key_rot, key[..., rotary_dim:]), dim=-1)
146
+ return query.to(dtype), key.to(dtype), cos, sin
147
+ else:
148
+ query = _apply_rotary_emb(query, cos, sin, is_neox_style)
149
+ key = _apply_rotary_emb(key, cos, sin, is_neox_style)
150
+ return query.to(dtype), key.to(dtype), cos, sin
151
+
152
+ def compute_basic_frequencies(
153
+ base: int,
154
+ rotary_dim: int,
155
+ max_position_embeddings: int,
156
+ ):
157
+ inv = 1.0 / torch.pow(
158
+ base,
159
+ torch.arange(0, rotary_dim, 2, dtype=torch.float32) / rotary_dim,
160
+ )
161
+ freqs = torch.einsum(
162
+ "i,j->ij",
163
+ torch.arange(max_position_embeddings, dtype=torch.float32),
164
+ inv,
165
+ )
166
+ freqs = torch.cat([freqs.cos(), freqs.sin()], dim=-1)
167
+ return freqs
168
+
169
+ class RotaryEmbedding(nn.Module):
170
+ def __init__(
171
+ self,
172
+ head_size: int,
173
+ rotary_dim: int,
174
+ max_position_embeddings: int,
175
+ base: int,
176
+ is_neox_style: bool,
177
+ dtype: torch.dtype,
178
+ ):
179
+ super().__init__()
180
+ self.head_size = head_size
181
+ self.rotary_dim = rotary_dim
182
+ self.max_position_embeddings = max_position_embeddings
183
+ self.base = base
184
+ self.is_neox_style = is_neox_style
185
+ self.dtype = dtype
186
+
187
+ def forward(
188
+ self,
189
+ positions: torch.Tensor,
190
+ query: torch.Tensor,
191
+ key: torch.Tensor,
192
+ offsets: torch.Tensor | None = None,
193
+ frequencies: torch.Tensor | None = None,
194
+ ) -> tuple[torch.Tensor, torch.Tensor]:
195
+ if frequencies is None:
196
+ frequencies = compute_basic_frequencies(
197
+ base=self.base,
198
+ rotary_dim=self.rotary_dim,
199
+ max_position_embeddings=self.max_position_embeddings,
200
+ )
201
+ if hasattr(frequencies, "value"):
202
+ frequencies = frequencies.value
203
+ return apply_basic_rope(
204
+ query=query,
205
+ key=key,
206
+ positions=positions,
207
+ frequencies=frequencies,
208
+ rotary_dim=self.rotary_dim,
209
+ is_neox_style=self.is_neox_style,
210
+ offsets=offsets,
211
+ dtype=self.dtype,
212
+ )
213
+
214
+
215
+ class GiddRMSNorm(nn.Module):
216
+ def __init__(
217
+ self,
218
+ config: GiddConfig,
219
+ dtype=torch.float32,
220
+ ):
221
+ super().__init__()
222
+ self.config = config
223
+ self.epsilon = self.config.rms_norm_eps
224
+ self.weight = nn.Parameter(torch.zeros(self.config.hidden_size, dtype=dtype))
225
+ # self.bias = nn.Parameter(torch.zeros(self.config.hidden_size, dtype=dtype))
226
+
227
+ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
228
+ dtype = hidden_states.dtype
229
+ variance = hidden_states.to(torch.float32)
230
+ variance = variance.pow(2.0)
231
+ variance = variance.mean(-1, keepdim=True)
232
+ hidden_states = hidden_states * torch.rsqrt(variance + self.epsilon)
233
+
234
+ hidden_states = ((1 + self.weight) * hidden_states)
235
+ return hidden_states.to(dtype)
236
+
237
+ ALL_LAYERNORM_LAYERS.append(GiddRMSNorm)
238
+
239
+
240
+ class GiddMLP(nn.Module):
241
+ def __init__(
242
+ self,
243
+ config: GiddConfig,
244
+ dtype=torch.float32,
245
+ ):
246
+ super().__init__()
247
+ self.config = config
248
+ self.dtype = dtype
249
+
250
+ linear_class = partial(
251
+ ScaledLinear,
252
+ scale=config.weight_scaling,
253
+ dtype=dtype,
254
+ use_bias=self.config.mlp_bias,
255
+ )
256
+ self.up_proj = linear_class(config.hidden_size, config.intermediate_size)
257
+ self.down_proj = linear_class(config.intermediate_size, config.hidden_size)
258
+
259
+ def forward(self, h: torch.Tensor) -> torch.Tensor:
260
+ h = self.up_proj(h)
261
+ h = torch.relu(h) ** 2
262
+ h = self.down_proj(h)
263
+ return h
264
+
265
+
266
+ class FlexSoftcapAttention(nn.Module):
267
+ def __init__(self, head_dim, n_heads, softmax_scale, soft_cap):
268
+ super().__init__()
269
+ self.d_model = head_dim * n_heads
270
+ self.n_heads = n_heads
271
+ self.head_dim = head_dim
272
+ self.scale = float(softmax_scale)
273
+ self.soft_cap = float(soft_cap)
274
+
275
+ def forward(
276
+ self,
277
+ q: torch.Tensor,
278
+ k: torch.Tensor,
279
+ v: torch.Tensor,
280
+ attention_mask: torch.Tensor | None = None,
281
+ ):
282
+ B, _, L = q.shape[:3]
283
+
284
+ def score_mod(score, b, h, q_idx, kv_idx):
285
+ soft_cap = self.soft_cap
286
+ score = soft_cap * torch.tanh(score / soft_cap)
287
+ keep = attention_mask[b, q_idx, kv_idx]
288
+ return torch.where(keep, score, torch.finfo(score.dtype).min)
289
+
290
+ out = flex_attention(
291
+ q,
292
+ k,
293
+ v,
294
+ score_mod=score_mod,
295
+ scale=self.scale,
296
+ )
297
+ out = out.transpose(1, 2).contiguous().view(B, L, self.d_model)
298
+ return out, None
299
+
300
+
301
+ class VanillaSoftcapAttention(nn.Module):
302
+ def __init__(self, head_dim, n_heads, softmax_scale, soft_cap):
303
+ super().__init__()
304
+ self.d_model = head_dim * n_heads
305
+ self.n_heads = n_heads
306
+ self.head_dim = head_dim
307
+ self.scale = float(softmax_scale)
308
+ self.soft_cap = float(soft_cap)
309
+
310
+ def forward(
311
+ self,
312
+ q: torch.Tensor,
313
+ k: torch.Tensor,
314
+ v: torch.Tensor,
315
+ attention_mask: torch.Tensor | None = None,
316
+ ):
317
+ B, _, L = q.shape[:3]
318
+ scores = torch.einsum(
319
+ "bhqd,bhkd->bhqk",
320
+ q * self.scale,
321
+ k,
322
+ )
323
+ scores = self.soft_cap * torch.tanh(scores / self.soft_cap)
324
+ if attention_mask is not None:
325
+ scores = scores.masked_fill(~attention_mask.unsqueeze(1), torch.finfo(scores.dtype).min)
326
+ probs = torch.softmax(scores.to(torch.float32), dim=-1).to(scores.dtype)
327
+ out = torch.einsum(
328
+ "bhqk,bhkd->bhqd",
329
+ probs,
330
+ v,
331
+ )
332
+ out = out.transpose(1, 2).contiguous().view(B, L, self.d_model)
333
+ return out, probs
334
+
335
+
336
+ class GiddAttention(nn.Module):
337
+ def __init__(
338
+ self,
339
+ config: GiddConfig,
340
+ layer_idx: int,
341
+ dtype=torch.float32,
342
+ ):
343
+ super().__init__()
344
+
345
+ self.hidden_size = config.hidden_size
346
+ head_dim = config.hidden_size // config.num_attention_heads
347
+ self.head_dim = getattr(config, "head_dim", head_dim)
348
+ self.num_attention_heads = self.hidden_size // self.head_dim
349
+ self.is_causal = config.is_causal
350
+ self.layer_idx = layer_idx
351
+
352
+ self.use_qk_norm = config.use_qk_norm
353
+ if self.use_qk_norm:
354
+ self.q_norm = GiddRMSNorm(config, dtype=torch.float32)
355
+ self.k_norm = GiddRMSNorm(config, dtype=torch.float32)
356
+ else:
357
+ self.q_norm = None
358
+ self.k_norm = None
359
+
360
+ self.attention_bias = config.attention_bias
361
+ if self.attention_bias:
362
+ self.k_bias = nn.Parameter(
363
+ torch.zeros((self.num_attention_heads, self.head_dim), dtype=dtype),
364
+ )
365
+ self.v_bias = nn.Parameter(
366
+ torch.zeros((self.num_attention_heads, self.head_dim), dtype=dtype),
367
+ )
368
+ else:
369
+ self.k_bias = None
370
+ self.v_bias = None
371
+
372
+ linear_class = partial(
373
+ ScaledLinear,
374
+ scale=config.weight_scaling,
375
+ dtype=dtype,
376
+ use_bias=False,
377
+ )
378
+ self.q_proj = linear_class(
379
+ self.hidden_size,
380
+ self.num_attention_heads * self.head_dim,
381
+ )
382
+ self.k_proj = linear_class(
383
+ self.hidden_size,
384
+ self.num_attention_heads * self.head_dim,
385
+ )
386
+ self.v_proj = linear_class(
387
+ self.hidden_size,
388
+ self.num_attention_heads * self.head_dim,
389
+ )
390
+ self.o_proj = linear_class(
391
+ self.num_attention_heads * self.head_dim,
392
+ self.hidden_size,
393
+ )
394
+
395
+ self.rotary = RotaryEmbedding(
396
+ head_size=self.head_dim,
397
+ rotary_dim=self.head_dim,
398
+ max_position_embeddings=config.max_position_embeddings,
399
+ base=config.rope_theta,
400
+ is_neox_style=True,
401
+ dtype=dtype,
402
+ )
403
+
404
+ if config.attn_performer == "flex":
405
+ self.attention_performer = FlexSoftcapAttention(
406
+ head_dim=self.head_dim,
407
+ n_heads=self.num_attention_heads,
408
+ softmax_scale=self.head_dim**-0.5,
409
+ soft_cap=config.attn_soft_cap,
410
+ )
411
+ elif config.attn_performer == "eager":
412
+ self.attention_performer = VanillaSoftcapAttention(
413
+ head_dim=self.head_dim,
414
+ n_heads=self.num_attention_heads,
415
+ softmax_scale=self.head_dim**-0.5,
416
+ soft_cap=config.attn_soft_cap,
417
+ )
418
+ else:
419
+ raise ValueError(f"Unknown attn_performer: {config.attn_performer}")
420
+
421
+ def concatenate(
422
+ self,
423
+ *,
424
+ query: torch.Tensor,
425
+ key: torch.Tensor,
426
+ value: torch.Tensor,
427
+ attention_mask: torch.Tensor,
428
+ past_key_values: tp.Optional[tuple[torch.Tensor, torch.Tensor]] = None,
429
+ ):
430
+ assert query.shape[1] == key.shape[1], "Query and Key lengths must match for GIDD attention."
431
+ if attention_mask is not None:
432
+ if attention_mask.dtype != torch.bool:
433
+ warnings.warn("attention_mask should be a boolean array", stacklevel=1)
434
+ attention_mask = (attention_mask == 1)
435
+
436
+ batch_size = query.shape[0]
437
+
438
+ # shape of attention_mask: (batch_size, seq_len)
439
+ # or (batch_size, query_len, kv_len)
440
+
441
+ if attention_mask.ndim == 2:
442
+ attention_mask = attention_mask.unsqueeze(1)
443
+ attention_mask = attention_mask.expand(-1, query.shape[1], -1)
444
+ elif attention_mask.ndim == 3:
445
+ # already in correct shape
446
+ pass
447
+
448
+ if self.attention_bias:
449
+ ones = torch.ones(
450
+ attention_mask.shape[:2] + (1,),
451
+ dtype=attention_mask.dtype,
452
+ device=attention_mask.device,
453
+ )
454
+ attention_mask = torch.cat(
455
+ [
456
+ ones,
457
+ attention_mask,
458
+ ],
459
+ dim=-1,
460
+ )
461
+
462
+ if past_key_values is not None:
463
+ past_keys, past_values = past_key_values
464
+ key = torch.cat([past_keys, key], dim=1)
465
+ value = torch.cat([past_values, value], dim=1)
466
+ elif self.attention_bias:
467
+ n_heads = self.num_attention_heads
468
+ bias_shape = (batch_size, 1, n_heads, self.head_dim)
469
+ k_bias = self.k_bias.view(1, 1, n_heads, self.head_dim).expand(bias_shape)
470
+ v_bias = self.v_bias.view(1, 1, n_heads, self.head_dim).expand(bias_shape)
471
+ key = torch.cat([k_bias, key], dim=1)
472
+ value = torch.cat([v_bias, value], dim=1)
473
+
474
+ # shape of attention_mask: (batch_size, 1, query_len, kv_len + 1)
475
+ return query, key, value, attention_mask, (key, value)
476
+
477
+ def forward(
478
+ self,
479
+ hidden_states: torch.Tensor,
480
+ attention_mask: torch.Tensor,
481
+ position_ids: torch.Tensor,
482
+ past_key_values: tp.Optional[tuple[torch.Tensor, torch.Tensor]] = None,
483
+ frequencies: tp.Optional[torch.Tensor] = None,
484
+ output_attentions: bool = False,
485
+ ) -> AttentionLayerOutput:
486
+ batch_size, sequence_length = hidden_states.shape[:2]
487
+ query_states = self.q_proj(hidden_states)
488
+ key_states = self.k_proj(hidden_states)
489
+ value_states = self.v_proj(hidden_states)
490
+
491
+ if self.use_qk_norm:
492
+ query_states = self.q_norm(query_states)
493
+ key_states = self.k_norm(key_states)
494
+
495
+ qshape = (
496
+ batch_size,
497
+ sequence_length,
498
+ self.num_attention_heads,
499
+ self.head_dim,
500
+ )
501
+ kv_shape = (
502
+ batch_size,
503
+ sequence_length,
504
+ self.num_attention_heads,
505
+ self.head_dim,
506
+ )
507
+ query_states = query_states.view(qshape)
508
+ key_states = key_states.view(kv_shape)
509
+ value_states = value_states.view(kv_shape)
510
+
511
+ query_states, key_states, cos, sin = self.rotary(
512
+ positions=position_ids,
513
+ query=query_states,
514
+ key=key_states,
515
+ frequencies=frequencies,
516
+ )
517
+
518
+ (
519
+ query_states,
520
+ key_states,
521
+ value_states,
522
+ attention_mask,
523
+ past_key_values,
524
+ ) = self.concatenate(
525
+ query=query_states,
526
+ key=key_states,
527
+ value=value_states,
528
+ attention_mask=attention_mask,
529
+ past_key_values=past_key_values,
530
+ )
531
+
532
+ attention_out, attentions = self.attention_performer.forward(
533
+ q=query_states.transpose(1, 2),
534
+ k=key_states.transpose(1, 2),
535
+ v=value_states.transpose(1, 2),
536
+ attention_mask=attention_mask,
537
+ )
538
+
539
+ attn_output = self.o_proj(attention_out)
540
+
541
+ return AttentionLayerOutput(
542
+ hidden_states=attn_output,
543
+ attentions=attentions if output_attentions else None,
544
+ past_key_values=past_key_values,
545
+ )
546
+
547
+
548
+ class GiddLayer(nn.Module):
549
+ def __init__(
550
+ self,
551
+ config: GiddConfig,
552
+ layer_idx: int,
553
+ dtype=torch.float32,
554
+ resid_scale: float = 1.0,
555
+ ):
556
+ super().__init__()
557
+ self.config = config
558
+ self.resid_scale = resid_scale
559
+ self.layer_idx = layer_idx
560
+
561
+ self.self_attn = GiddAttention(
562
+ layer_idx=layer_idx,
563
+ config=config,
564
+ dtype=dtype,
565
+ )
566
+
567
+ self.mlp = GiddMLP(
568
+ config=config,
569
+ dtype=dtype,
570
+ )
571
+ self.attn_layernorm = GiddRMSNorm(
572
+ config=config,
573
+ dtype=torch.float32,
574
+ )
575
+ self.mlp_layernorm = GiddRMSNorm(
576
+ config=config,
577
+ dtype=torch.float32,
578
+ )
579
+
580
+ def forward(
581
+ self,
582
+ hidden_states: torch.Tensor,
583
+ attention_mask: torch.Tensor,
584
+ position_ids: torch.Tensor,
585
+ past_key_values: tp.Optional[tuple[torch.Tensor, torch.Tensor]] = None,
586
+ frequencies: tp.Optional[torch.Tensor] = None,
587
+ output_attentions: bool = False,
588
+ ) -> DecoderLayerOutput:
589
+ attn_inputs = self.attn_layernorm(hidden_states)
590
+ attn_outputs = self.self_attn(
591
+ attn_inputs,
592
+ attention_mask=attention_mask,
593
+ position_ids=position_ids,
594
+ past_key_values=past_key_values,
595
+ frequencies=frequencies,
596
+ output_attentions=output_attentions,
597
+ )
598
+ hidden_states = hidden_states + self.resid_scale * attn_outputs.hidden_states
599
+
600
+ mlp_inputs = self.mlp_layernorm(hidden_states)
601
+ mlp_output = self.mlp(mlp_inputs)
602
+ hidden_states = hidden_states + self.resid_scale * mlp_output
603
+
604
+ return DecoderLayerOutput(
605
+ hidden_states=hidden_states,
606
+ attentions=attn_outputs.attentions,
607
+ past_key_values=attn_outputs.past_key_values,
608
+ )
609
+
610
+
611
+ class GiddPreTrainedModel(PreTrainedModel):
612
+ config_class = GiddConfig
613
+ base_model_prefix = "model"
614
+ supports_gradient_checkpointing = False
615
+ _no_split_modules = ["GiddLayer"]
616
+ _skip_keys_device_placement = ["past_key_values"]
617
+ _supports_flash_attn = False
618
+ _supports_sdpa = False
619
+ _supports_flex_attn = False
620
+ _can_compile_fullgraph = False
621
+ _supports_attention_backend = False
622
+ _can_record_outputs = {
623
+ "hidden_states": GiddLayer,
624
+ "attentions": GiddAttention,
625
+ }
626
+
627
+ def _init_weights(self, module):
628
+ super()._init_weights(module)
629
+ nn.init.normal_(module.weight, mean=0.0, std=self.config.initializer_range)
630
+
631
+
632
+ class GiddModel(GiddPreTrainedModel):
633
+ def __init__(
634
+ self,
635
+ config: GiddConfig,
636
+ ):
637
+ super().__init__(config=config)
638
+
639
+ self.resid_scale = config.resid_scale / config.num_hidden_layers
640
+ dtype = config.torch_dtype
641
+
642
+ self.embed_tokens = nn.Embedding(
643
+ num_embeddings=self.config.vocab_size,
644
+ embedding_dim=self.config.hidden_size,
645
+ )
646
+ self.embed_tokens.weight.data = self.embed_tokens.weight.data.to(dtype)
647
+ nn.init.normal_(self.embed_tokens.weight, mean=0.0, std=self.config.emb_init_scale)
648
+
649
+ freqs = compute_basic_frequencies(
650
+ base=config.rope_theta,
651
+ rotary_dim=config.hidden_size // config.num_attention_heads,
652
+ max_position_embeddings=config.max_position_embeddings,
653
+ )
654
+ self.frequencies = nn.Buffer(freqs, persistent=False)
655
+
656
+ self.layers = nn.ModuleList(
657
+ [
658
+ GiddLayer(
659
+ config=config,
660
+ layer_idx=i,
661
+ resid_scale=self.resid_scale,
662
+ dtype=dtype,
663
+ )
664
+ for i in range(self.config.num_hidden_layers)
665
+ ]
666
+ )
667
+ self.norm = GiddRMSNorm(
668
+ config=config,
669
+ dtype=torch.float32,
670
+ )
671
+
672
+ def forward(
673
+ self,
674
+ input_ids: tp.Optional[torch.Tensor] = None,
675
+ inputs_embeds: tp.Optional[torch.Tensor] = None,
676
+ attention_mask: tp.Optional[torch.Tensor] = None,
677
+ position_ids: tp.Optional[torch.Tensor] = None,
678
+ past_key_values: tp.Optional[list[tuple[torch.Tensor, torch.Tensor]]] = None,
679
+ use_cache: bool = False,
680
+ cache_position: tp.Optional[torch.LongTensor] = None,
681
+ output_attentions: tp.Optional[bool] = None,
682
+ output_hidden_states: tp.Optional[bool] = None,
683
+ ) -> BaseModelOutputWithPast:
684
+ if (input_ids is None) ^ (inputs_embeds is not None):
685
+ raise ValueError(
686
+ "You cannot specify both input_ids and inputs_embeds at the same time, and must specify either one"
687
+ )
688
+ if inputs_embeds is None:
689
+ inputs_embeds = self.embed_tokens(input_ids.to(torch.long))
690
+
691
+ if use_cache and past_key_values is None:
692
+ past_key_values = [None] * self.config.num_hidden_layers
693
+ elif past_key_values is not None:
694
+ past_key_values = list(past_key_values)
695
+
696
+ if position_ids is None:
697
+ past_seen_tokens = 0
698
+ if past_key_values is not None and any(past_key_values):
699
+ past_seen_tokens = [kv[0].shape[1] for kv in past_key_values if kv is not None][0]
700
+ cache_position = torch.arange(inputs_embeds.shape[1], device=inputs_embeds.device) + past_seen_tokens
701
+ position_ids = cache_position.unsqueeze(0)
702
+
703
+ batch_size, sequence_length, _ = inputs_embeds.shape
704
+
705
+ assert sequence_length <= self.config.max_position_embeddings, (
706
+ f"Maximum Position Embedding Reached ! (expected <= {self.config.max_position_embeddings} got {sequence_length})"
707
+ )
708
+ if attention_mask is None:
709
+ attention_mask = torch.ones(
710
+ (batch_size, sequence_length),
711
+ dtype=torch.bool,
712
+ device=inputs_embeds.device,
713
+ )
714
+ else:
715
+ if attention_mask.dtype != torch.bool:
716
+ attention_mask = (attention_mask == 1)
717
+
718
+ if position_ids is None:
719
+ position_ids = torch.arange(
720
+ inputs_embeds.shape[-2],
721
+ dtype=torch.int32,
722
+ device=inputs_embeds.device,
723
+ )
724
+ position_ids = position_ids.unsqueeze(0).expand(inputs_embeds.shape[:-1])
725
+
726
+ hidden_states = inputs_embeds
727
+
728
+ all_attentions = () if output_attentions else None
729
+ all_hidden_states = () if output_hidden_states else None
730
+ for idx, block in enumerate(self.layers):
731
+ if output_hidden_states:
732
+ all_hidden_states += (hidden_states,)
733
+
734
+ layer_outputs = block(
735
+ hidden_states=hidden_states,
736
+ attention_mask=attention_mask,
737
+ position_ids=position_ids,
738
+ output_attentions=output_attentions,
739
+ frequencies=self.frequencies,
740
+ past_key_values=past_key_values[idx] if past_key_values is not None else None,
741
+ )
742
+ hidden_states = layer_outputs.hidden_states
743
+
744
+ if output_attentions:
745
+ all_attentions += (layer_outputs.attentions,)
746
+
747
+ if use_cache:
748
+ past_key_values[idx] = layer_outputs.past_key_values
749
+
750
+ hidden_states = self.norm(hidden_states)
751
+
752
+ if output_hidden_states:
753
+ all_hidden_states += (hidden_states,)
754
+
755
+ return BaseModelOutputWithPast(
756
+ last_hidden_state=hidden_states,
757
+ hidden_states=all_hidden_states,
758
+ attentions=all_attentions,
759
+ past_key_values=past_key_values,
760
+ )
761
+
762
+
763
+ class GiddForDiffusionLM(GiddPreTrainedModel, GenerationMixin):
764
+ def __init__(
765
+ self,
766
+ config: GiddConfig,
767
+ ):
768
+ super().__init__(config=config)
769
+
770
+ self.model = GiddModel(config=config)
771
+
772
+ self.lm_head = ScaledLinear(
773
+ config.hidden_size,
774
+ config.vocab_size,
775
+ scale=config.head_scaling,
776
+ dtype=config.torch_dtype,
777
+ use_bias=False,
778
+ )
779
+
780
+ def forward(
781
+ self,
782
+ input_ids: tp.Optional[torch.Tensor] = None,
783
+ inputs_embeds: tp.Optional[torch.Tensor] = None,
784
+ attention_mask: tp.Optional[torch.Tensor] = None,
785
+ position_ids: tp.Optional[torch.Tensor] = None,
786
+ past_key_values: tp.Optional[list[tuple[torch.Tensor, torch.Tensor]]] = None,
787
+ use_cache: bool = False,
788
+ output_attentions: tp.Optional[bool] = None,
789
+ output_hidden_states: tp.Optional[bool] = None,
790
+ ) -> CausalLMOutputWithPast:
791
+ outputs = self.model(
792
+ input_ids=input_ids,
793
+ inputs_embeds=inputs_embeds,
794
+ attention_mask=attention_mask,
795
+ position_ids=position_ids,
796
+ past_key_values=past_key_values,
797
+ output_attentions=output_attentions,
798
+ output_hidden_states=output_hidden_states,
799
+ use_cache=use_cache,
800
+ )
801
+
802
+ hidden_states = outputs.last_hidden_state
803
+
804
+ if self.config.tie_word_embeddings:
805
+ logits = hidden_states @ self.model.embed_tokens.weight.t()
806
+ else:
807
+ logits = self.lm_head(hidden_states)
808
+
809
+ return CausalLMOutputWithPast(
810
+ loss=None,
811
+ logits=logits,
812
+ hidden_states=outputs.hidden_states,
813
+ attentions=outputs.attentions,
814
+ past_key_values=outputs.past_key_values,
815
+ )
816
+
817
+ def _sample_prior(self, shape: tuple[int, ...], device: torch.device, mask_token_id: int = 3) -> torch.Tensor:
818
+ p_unif = torch.sigmoid(
819
+ torch.ones(shape, device=device) * self.config.min_log_snr + self.config.noise_type
820
+ )
821
+ r = torch.rand(shape, device=device)
822
+ unif = torch.randint(0, self.config.vocab_size, shape, device=device)
823
+ samples = torch.where(r < p_unif, unif, mask_token_id)
824
+ return samples
825
+
826
+ def _probs_with_topk_topp(self, logits, temperature: float, top_p: float | None, top_k: int | None):
827
+ if temperature == 0.0:
828
+ probs = torch.zeros_like(logits)
829
+ indices = torch.argmax(logits, dim=-1, keepdim=True)
830
+ probs.scatter_(-1, indices, 1.0)
831
+ return probs
832
+
833
+ x = logits / temperature
834
+
835
+ if top_k is not None and 0 < top_k < x.size(-1):
836
+ kth = torch.topk(x, top_k, dim=-1).values[..., -1, None]
837
+ x = torch.where(x < kth, torch.full_like(x, float("-inf")), x)
838
+
839
+ if top_p is not None and 0.0 < top_p < 1.0:
840
+ sorted_logits, sorted_idx = torch.sort(x, descending=True, dim=-1)
841
+ sorted_probs = torch.softmax(sorted_logits, dim=-1)
842
+ cumprobs = sorted_probs.cumsum(dim=-1)
843
+
844
+ remove = cumprobs > top_p
845
+ remove[..., 1:] = remove[..., :-1].clone()
846
+ remove[..., 0] = False
847
+
848
+ sorted_logits = sorted_logits.masked_fill(remove, float("-inf"))
849
+ x = x.scatter(-1, sorted_idx, sorted_logits)
850
+
851
+ probs = torch.softmax(x, dim=-1)
852
+
853
+ return probs
854
+
855
+ def _pi_lambda(self, log_snr, mask_token_id=3):
856
+ unif_vec = torch.ones((self.config.vocab_size,), device=log_snr.device) / (self.config.vocab_size - 1)
857
+ unif_vec[mask_token_id] = 0.0
858
+ alpha = torch.sigmoid(log_snr + self.config.noise_type)
859
+ pi = alpha * unif_vec
860
+ pi[..., mask_token_id] = 1.0 - alpha
861
+ return pi
862
+
863
+ def _sample_ancestral(
864
+ self,
865
+ z: torch.Tensor,
866
+ x_hat: torch.Tensor,
867
+ log_snr_t: torch.Tensor,
868
+ log_snr_s: torch.Tensor,
869
+ mask_token_id: int = 3,
870
+ ):
871
+ alpha_s = log_snr_s.sigmoid()
872
+ alpha_t = log_snr_t.sigmoid()
873
+ beta_s, beta_t = 1.0 - alpha_s, 1.0 - alpha_t
874
+ alpha_t_s = alpha_t / alpha_s
875
+
876
+ pi_s = self._pi_lambda(log_snr_s, mask_token_id=mask_token_id)
877
+ pi_t = self._pi_lambda(log_snr_t, mask_token_id=mask_token_id)
878
+ beta_pi_t_s = beta_t * pi_t - alpha_t_s * beta_s * pi_s
879
+ # beta_pi_t_s_at_z = beta_pi_t_s[z]
880
+
881
+ q_t = alpha_t * x_hat + beta_t * pi_t[None, None, :]
882
+ q_s = alpha_s * x_hat + beta_s * pi_s[None, None, :]
883
+ q_t_at_z = q_t.gather(-1, z.unsqueeze(-1)).squeeze(-1)
884
+
885
+ z_vec = torch.nn.functional.one_hot(z, num_classes=self.config.vocab_size).to(q_t.dtype)
886
+ q_t_s_at_z = alpha_t_s * z_vec + beta_pi_t_s[z, None]
887
+
888
+ p_s_t = q_s * q_t_s_at_z / q_t_at_z[..., None]
889
+
890
+ z_next = torch.multinomial(p_s_t.flatten(0, 1), num_samples=1).view_as(z)
891
+ return z_next
892
+
893
+ def _sample_adaptive(
894
+ self,
895
+ z: torch.Tensor,
896
+ logits: torch.Tensor,
897
+ log_snr: torch.Tensor,
898
+ n_tokens: int = 1,
899
+ mask_token_id: int = 3,
900
+ temperature: float = 0.0,
901
+ top_p: float | None = None,
902
+ top_k: int | None = None,
903
+ ):
904
+ pi_vec = self._pi_lambda(log_snr, mask_token_id=mask_token_id)
905
+ p_noise = pi_vec[z]
906
+ p_noise = p_noise / p_noise.sum(dim=-1, keepdim=True)
907
+
908
+ x_hat = logits.softmax(dim=-1)
909
+ p_max = x_hat.max(dim=-1).values
910
+ p_curr = x_hat.gather(-1, z.unsqueeze(-1)).squeeze(-1)
911
+ p_delta = (p_max - p_curr) * p_noise
912
+
913
+ next_poss = torch.topk(p_delta, n_tokens, dim=-1).indices
914
+ probs = self._probs_with_topk_topp(
915
+ logits=logits,
916
+ temperature=temperature,
917
+ top_p=top_p,
918
+ top_k=top_k,
919
+ )
920
+ next_tokens = torch.multinomial(probs.flatten(0, 1), num_samples=1).view_as(z)
921
+
922
+ z_next = z.clone()
923
+ batch_indices = torch.arange(z.shape[0], device=z.device).unsqueeze(-1)
924
+ z_next[batch_indices, next_poss] = next_tokens[batch_indices, next_poss]
925
+ return z_next
926
+
927
+ @torch.no_grad()
928
+ def generate(
929
+ self,
930
+ inputs: tp.Optional[torch.Tensor] = None,
931
+ max_length: int = 2048,
932
+ min_length: int = 0,
933
+ temperature: float = 1.0,
934
+ block_length: int = 128,
935
+ steps: int = 128,
936
+ top_p: tp.Optional[float] = None,
937
+ top_k: tp.Optional[int] = None,
938
+ bos_token_id: int = 0,
939
+ eos_token_id: int = 1,
940
+ pad_token_id: int = 2,
941
+ mask_token_id: int = 3,
942
+ sampling_method: tp.Literal["ancestral", "adaptive"] = "ancestral",
943
+ noise_schedule: tp.Literal["linear", "cosine"] | tp.Callable[[torch.Tensor], torch.Tensor] = "cosine",
944
+ tokens_per_step: int = 1,
945
+ show_progress: bool = False,
946
+ ):
947
+ r"""
948
+ Generates tokens with block-wise denoising diffusion.
949
+
950
+ Parameters:
951
+ inputs (`torch.Tensor`):
952
+ The token sequence used as a prompt for the generation.
953
+ temperature (`float`, *optional*, defaults to 0.0):
954
+ The value used to module the next token probabilities. A value of 0.0 corresponds to greedy decoding.
955
+ block_length (`int`, *optional*, defaults to 32):
956
+ The size of each generation block. The model generates text in parallel within these blocks. This is a
957
+ key parameter for controlling the granularity of the generation process.
958
+ steps (`int`, *optional*, defaults to 32):
959
+ The number of denoising steps to perform for each block.
960
+ max_length (`int`, *optional*, defaults to 2048):
961
+ The maximum length of the sequence to be generated.
962
+ min_length (`int`, *optional*, defaults to 0):
963
+ The minimum length of the sequence to be generated.
964
+ top_p (`float`, *optional*):
965
+ If set to a float value between 0 and 1, only the most probable tokens with probabilities that add up to
966
+ `top_p` or higher are kept for generation (nucleus sampling).
967
+ top_k (`int`, *optional*):
968
+ The number of highest probability vocabulary tokens to keep for top-k-filtering.
969
+ bos_token_id (`int`, *optional*, defaults to 0):
970
+ The token ID for the beginning-of-sequence token.
971
+ eos_token_id (`int`, *optional*, defaults to 1):
972
+ The token ID for the end-of-sequence token.
973
+ pad_token_id (`int`, *optional*, defaults to 2):
974
+ The token ID for the padding token.
975
+ mask_token_id (`int`, *optional*, defaults to 3):
976
+ The token ID used as a placeholder for tokens that are yet to be generated.
977
+ Return:
978
+ `torch.Tensor`: A string containing the generated token IDs, starting
979
+ after the prompt and stopping at the first `eos_id` or `gen_length`.
980
+ """
981
+ if sampling_method not in ["ancestral", "adaptive"]:
982
+ raise ValueError(f"Unsupported sampling method: {sampling_method}")
983
+ if noise_schedule not in ["linear", "cosine"] and not callable(noise_schedule):
984
+ raise ValueError("noise_schedule must be 'linear', 'cosine', or a callable function.")
985
+
986
+ if inputs is None:
987
+ inputs = torch.tensor([[bos_token_id]], device=self.device, dtype=torch.long)
988
+ batch_size = 1
989
+ prompt_length = 0
990
+ else:
991
+ batch_size = inputs.shape[0]
992
+ prompt_length = inputs.shape[1]
993
+ if eos_token_id in inputs:
994
+ warnings.warn("Input prompt contains eos_token_id. Generation may stop earlier than expected.", stacklevel=1)
995
+ input_ids = inputs.to(self.device)
996
+
997
+ total_length = self.config.max_position_embeddings
998
+
999
+ if noise_schedule == "linear":
1000
+ noise_schedule_fn = lambda t: 1.0 - t
1001
+ elif noise_schedule == "cosine":
1002
+ noise_schedule_fn = lambda t: 0.5 + 0.5 * torch.cos(t * torch.pi)
1003
+ else:
1004
+ noise_schedule_fn = noise_schedule
1005
+
1006
+ x_prior = self._sample_prior(
1007
+ shape=(batch_size, total_length),
1008
+ device=self.device,
1009
+ mask_token_id=mask_token_id,
1010
+ )
1011
+ x = x_prior.clone()
1012
+ if prompt_length > 0:
1013
+ x[:, :prompt_length] = input_ids.clone()
1014
+
1015
+ position_ids = torch.arange(total_length, device=self.device)
1016
+ position_ids = position_ids.unsqueeze(0).expand(batch_size, -1)
1017
+
1018
+ noise_mask = torch.ones_like(x, dtype=torch.bool)
1019
+ noise_mask[:, :prompt_length] = False
1020
+
1021
+ min_log_snr = torch.tensor(self.config.min_log_snr, device=self.device)
1022
+ max_log_snr = torch.tensor(self.config.max_log_snr, device=self.device)
1023
+ alpha_min = torch.sigmoid(min_log_snr)
1024
+ alpha_max = torch.sigmoid(max_log_snr)
1025
+ ts = torch.linspace(0.0, 1.0, steps=steps + 1, device=self.device)
1026
+ alpha_t = (alpha_max - alpha_min) * noise_schedule_fn(ts) + alpha_min
1027
+ log_snrs = torch.log(alpha_t / (1.0 - alpha_t)).clip(min_log_snr, max_log_snr)
1028
+
1029
+ if show_progress:
1030
+ import tqdm.auto as tqdm
1031
+ est_num_blocks = (max_length + block_length - 1) // block_length
1032
+ est_num_steps = est_num_blocks * steps
1033
+ pbar = tqdm.tqdm(total=est_num_steps)
1034
+ update_pbar = lambda n: pbar.update(n)
1035
+ def stop_pbar():
1036
+ pbar.total = pbar.n
1037
+ pbar.refresh()
1038
+ close_pbar = lambda: pbar.close()
1039
+ else:
1040
+ update_pbar = lambda n: None
1041
+ stop_pbar = lambda: None
1042
+ close_pbar = lambda: None
1043
+
1044
+ try:
1045
+ num_blocks = 0
1046
+ while True:
1047
+ current_window_start = prompt_length + num_blocks * block_length
1048
+ current_window_end = current_window_start + block_length
1049
+ attn_mask = (noise_mask[..., :, None] >= noise_mask[..., None, :])
1050
+
1051
+ keep_logits = False
1052
+ past_key_values = None
1053
+ for step in range(steps, 0, -1):
1054
+ if past_key_values is None:
1055
+ output = self.forward(
1056
+ input_ids=x[:, :current_window_start],
1057
+ attention_mask=attn_mask[:, :current_window_start, :current_window_start],
1058
+ position_ids=position_ids[:, :current_window_start],
1059
+ use_cache=True,
1060
+ )
1061
+ past_key_values = output.past_key_values
1062
+
1063
+ if not keep_logits:
1064
+ logits = self.forward(
1065
+ input_ids=x[:, current_window_start:],
1066
+ attention_mask=attn_mask[:, current_window_start:],
1067
+ position_ids=position_ids[:, current_window_start:],
1068
+ past_key_values=past_key_values,
1069
+ ).logits
1070
+ active_logits = logits[:, :block_length, :]
1071
+ # logits = self.forward(
1072
+ # input_ids=x,
1073
+ # attention_mask=attn_mask,
1074
+ # position_ids=position_ids,
1075
+ # past_key_values=None
1076
+ # ).logits
1077
+ # active_logits = logits[:, current_window_start:current_window_end, :]
1078
+
1079
+ active_logits[..., mask_token_id] = float("-inf")
1080
+ min_eos_idx = max(0, min_length + prompt_length - current_window_start)
1081
+ active_logits[:, :min_eos_idx, eos_token_id] = float("-inf")
1082
+
1083
+ z_t = x[:, current_window_start:current_window_end]
1084
+ if sampling_method == "ancestral":
1085
+ x_hat = self._probs_with_topk_topp(
1086
+ active_logits.to(torch.float32),
1087
+ temperature=temperature,
1088
+ top_k=top_k,
1089
+ top_p=top_p,
1090
+ )
1091
+
1092
+ z_s = self._sample_ancestral(
1093
+ z=z_t,
1094
+ x_hat=x_hat,
1095
+ log_snr_t=log_snrs[step],
1096
+ log_snr_s=log_snrs[step - 1],
1097
+ mask_token_id=mask_token_id,
1098
+ )
1099
+ elif sampling_method == "adaptive":
1100
+ z_s = self._sample_adaptive(
1101
+ z=z_t,
1102
+ logits=active_logits.to(torch.float32),
1103
+ log_snr=log_snrs[step],
1104
+ n_tokens=tokens_per_step,
1105
+ mask_token_id=mask_token_id,
1106
+ temperature=temperature,
1107
+ top_p=top_p,
1108
+ top_k=top_k,
1109
+ )
1110
+ keep_logits = (z_s == z_t).all().item()
1111
+
1112
+ x[:, current_window_start:current_window_end] = z_s.clone()
1113
+
1114
+ update_pbar(1)
1115
+
1116
+ num_blocks += 1
1117
+ noise_mask[:, :current_window_end] = False
1118
+
1119
+ has_eos = (x == eos_token_id).any(-1).all().item()
1120
+ all_done = current_window_end >= max_length + prompt_length or has_eos
1121
+ if all_done:
1122
+ stop_pbar()
1123
+ break
1124
+ finally:
1125
+ close_pbar()
1126
+
1127
+ generated_answer = x[:, :max_length + prompt_length]
1128
+
1129
+ eos_idx = (generated_answer == eos_token_id).int().argmax(dim=-1)
1130
+ for i, idx in enumerate(eos_idx):
1131
+ if idx > 0:
1132
+ generated_answer[i, idx:] = pad_token_id
1133
+
1134
+ return generated_answer
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<|begin_of_text|>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<|end_of_text|>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "mask_token": {
17
+ "content": "<|mask|>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "pad_token": {
24
+ "content": "<|padding|>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<|begin_of_text|>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<|end_of_text|>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "<|padding|>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "<|mask|>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "4": {
36
+ "content": " ",
37
+ "lstrip": false,
38
+ "normalized": true,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": false
42
+ },
43
+ "5": {
44
+ "content": " ",
45
+ "lstrip": false,
46
+ "normalized": true,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": false
50
+ },
51
+ "6": {
52
+ "content": " ",
53
+ "lstrip": false,
54
+ "normalized": true,
55
+ "rstrip": false,
56
+ "single_word": false,
57
+ "special": false
58
+ },
59
+ "7": {
60
+ "content": " ",
61
+ "lstrip": false,
62
+ "normalized": true,
63
+ "rstrip": false,
64
+ "single_word": false,
65
+ "special": false
66
+ },
67
+ "8": {
68
+ "content": " ",
69
+ "lstrip": false,
70
+ "normalized": true,
71
+ "rstrip": false,
72
+ "single_word": false,
73
+ "special": false
74
+ },
75
+ "9": {
76
+ "content": " ",
77
+ "lstrip": false,
78
+ "normalized": true,
79
+ "rstrip": false,
80
+ "single_word": false,
81
+ "special": false
82
+ },
83
+ "10": {
84
+ "content": " ",
85
+ "lstrip": false,
86
+ "normalized": true,
87
+ "rstrip": false,
88
+ "single_word": false,
89
+ "special": false
90
+ },
91
+ "11": {
92
+ "content": " ",
93
+ "lstrip": false,
94
+ "normalized": true,
95
+ "rstrip": false,
96
+ "single_word": false,
97
+ "special": false
98
+ },
99
+ "12": {
100
+ "content": " ",
101
+ "lstrip": false,
102
+ "normalized": true,
103
+ "rstrip": false,
104
+ "single_word": false,
105
+ "special": false
106
+ },
107
+ "13": {
108
+ "content": " ",
109
+ "lstrip": false,
110
+ "normalized": true,
111
+ "rstrip": false,
112
+ "single_word": false,
113
+ "special": false
114
+ },
115
+ "14": {
116
+ "content": " ",
117
+ "lstrip": false,
118
+ "normalized": true,
119
+ "rstrip": false,
120
+ "single_word": false,
121
+ "special": false
122
+ },
123
+ "15": {
124
+ "content": " ",
125
+ "lstrip": false,
126
+ "normalized": true,
127
+ "rstrip": false,
128
+ "single_word": false,
129
+ "special": false
130
+ }
131
+ },
132
+ "bos_token": "<|begin_of_text|>",
133
+ "clean_up_tokenization_spaces": false,
134
+ "eos_token": "<|end_of_text|>",
135
+ "extra_special_tokens": {},
136
+ "mask_token": "<|mask|>",
137
+ "model_max_length": 1000000000000000019884624838656,
138
+ "pad_token": "<|padding|>",
139
+ "tokenizer_class": "PreTrainedTokenizerFast"
140
+ }