YifeiZuo commited on
Commit
2643e15
·
verified ·
1 Parent(s): dcc7159

Upload cleaned Parallax model (config + modeling + weights + tokenizer)

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
__pycache__/configuration_parallax.cpython-312.pyc ADDED
Binary file (2.12 kB). View file
 
__pycache__/modeling_parallax.cpython-312.pyc ADDED
Binary file (12.5 kB). View file
 
config.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "parallax",
3
+ "architectures": [
4
+ "ParallaxForCausalLM"
5
+ ],
6
+ "auto_map": {
7
+ "AutoConfig": "configuration_parallax.ParallaxConfig",
8
+ "AutoModelForCausalLM": "modeling_parallax.ParallaxForCausalLM"
9
+ },
10
+ "vocab_size": 151936,
11
+ "hidden_size": 2048,
12
+ "intermediate_size": 6144,
13
+ "num_hidden_layers": 28,
14
+ "num_attention_heads": 16,
15
+ "num_key_value_heads": 8,
16
+ "head_dim": 128,
17
+ "hidden_act": "silu",
18
+ "max_position_embeddings": 4096,
19
+ "initializer_range": 0.02,
20
+ "rms_norm_eps": 1e-06,
21
+ "use_cache": true,
22
+ "tie_word_embeddings": true,
23
+ "rope_parameters": {
24
+ "rope_type": "default",
25
+ "rope_theta": 1000000
26
+ },
27
+ "attention_bias": false,
28
+ "use_sliding_window": false,
29
+ "sliding_window": null,
30
+ "max_window_layers": 28,
31
+ "attention_dropout": 0.0,
32
+ "attn_type": "parallax",
33
+ "torch_dtype": "bfloat16",
34
+ "bos_token_id": 151643,
35
+ "eos_token_id": 151645
36
+ }
configuration_parallax.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Parallax HF config (inherits Qwen3Config).
2
+
3
+ Parallax (Parameterized Local Linear Attention) reuses the Qwen3 architecture
4
+ and swaps softmax self-attention for the parallax op. This config inherits from
5
+ ``transformers.models.qwen3.configuration_qwen3.Qwen3Config`` so it picks up all
6
+ of Qwen3's conventions for free (strict dataclass, ``rope_parameters``,
7
+ ``layer_types``, tp/pp plans, etc.).
8
+
9
+ The only Parallax-specific addition is the ``attn_type`` field, which selects the
10
+ attention implementation. When ``attn_type == "sdpa"`` this config describes a
11
+ plain Qwen3-equivalent model.
12
+
13
+ Reference: https://arxiv.org/abs/2605.29157
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ from transformers.models.qwen3.configuration_qwen3 import Qwen3Config
19
+
20
+
21
+ class ParallaxConfig(Qwen3Config):
22
+ r"""Config for the Parallax model (Qwen3-derived).
23
+
24
+ Args:
25
+ attn_type (`str`, *optional*, defaults to `"parallax"`):
26
+ Attention implementation. Must be one of ``"sdpa"`` or
27
+ ``"parallax"``. ``"sdpa"`` uses the plain Qwen3 causal attention
28
+ path (softmax attention). ``"parallax"`` uses the parallax op and
29
+ requires the extra ``r_proj`` / ``r_norm`` per-layer weights.
30
+ """
31
+
32
+ model_type = "parallax"
33
+
34
+ # ---- Parallax-specific extra ----
35
+ # "sdpa" : plain causal self-attention (identical to Qwen3).
36
+ # "parallax": the parallax op (adds r_proj + r_norm and replaces softmax
37
+ # self-attention).
38
+ attn_type: str = "parallax"
39
+
40
+ def __post_init__(self, **kwargs):
41
+ if self.attn_type not in ("sdpa", "parallax"):
42
+ raise ValueError(
43
+ f"attn_type must be 'sdpa' or 'parallax', got {self.attn_type!r}"
44
+ )
45
+ super().__post_init__(**kwargs)
46
+
47
+
48
+ __all__ = ["ParallaxConfig"]
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model-00001-of-00001.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ebbb9d2e2d800b4d3dac6e3c851542f6ab81636861283b449670d9e9d36b53e
3
+ size 3676083323
model.safetensors.index.json ADDED
@@ -0,0 +1,373 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 3676038144
4
+ },
5
+ "weight_map": {
6
+ "model.embed_tokens.weight": "model-00001-of-00001.safetensors",
7
+ "model.layers.0.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
8
+ "model.layers.0.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
9
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
10
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
11
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
12
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
13
+ "model.layers.0.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
14
+ "model.layers.0.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
15
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
16
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
17
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
18
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00001.safetensors",
19
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
20
+ "model.layers.1.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
21
+ "model.layers.1.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
22
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
23
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
24
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
25
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
26
+ "model.layers.1.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
27
+ "model.layers.1.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
28
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
29
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
30
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
31
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00001.safetensors",
32
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
33
+ "model.layers.2.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
34
+ "model.layers.2.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
35
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
36
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
37
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
38
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
39
+ "model.layers.2.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
40
+ "model.layers.2.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
41
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
42
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
43
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
44
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00001.safetensors",
45
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
46
+ "model.layers.3.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
47
+ "model.layers.3.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
48
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
49
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
50
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
51
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
52
+ "model.layers.3.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
53
+ "model.layers.3.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
54
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
55
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
56
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
57
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00001.safetensors",
58
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
59
+ "model.layers.4.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
60
+ "model.layers.4.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
61
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
62
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
63
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
64
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
65
+ "model.layers.4.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
66
+ "model.layers.4.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
67
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
68
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
69
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
70
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00001.safetensors",
71
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
72
+ "model.layers.5.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
73
+ "model.layers.5.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
74
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
75
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
76
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
77
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
78
+ "model.layers.5.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
79
+ "model.layers.5.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
80
+ "model.layers.5.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
81
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
82
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
83
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00001.safetensors",
84
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
85
+ "model.layers.6.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
86
+ "model.layers.6.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
87
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
88
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
89
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
90
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
91
+ "model.layers.6.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
92
+ "model.layers.6.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
93
+ "model.layers.6.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
94
+ "model.layers.6.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
95
+ "model.layers.6.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
96
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00001.safetensors",
97
+ "model.layers.6.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
98
+ "model.layers.7.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
99
+ "model.layers.7.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
100
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
101
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
102
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
103
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
104
+ "model.layers.7.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
105
+ "model.layers.7.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
106
+ "model.layers.7.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
107
+ "model.layers.7.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
108
+ "model.layers.7.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
109
+ "model.layers.7.input_layernorm.weight": "model-00001-of-00001.safetensors",
110
+ "model.layers.7.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
111
+ "model.layers.8.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
112
+ "model.layers.8.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
113
+ "model.layers.8.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
114
+ "model.layers.8.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
115
+ "model.layers.8.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
116
+ "model.layers.8.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
117
+ "model.layers.8.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
118
+ "model.layers.8.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
119
+ "model.layers.8.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
120
+ "model.layers.8.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
121
+ "model.layers.8.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
122
+ "model.layers.8.input_layernorm.weight": "model-00001-of-00001.safetensors",
123
+ "model.layers.8.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
124
+ "model.layers.9.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
125
+ "model.layers.9.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
126
+ "model.layers.9.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
127
+ "model.layers.9.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
128
+ "model.layers.9.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
129
+ "model.layers.9.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
130
+ "model.layers.9.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
131
+ "model.layers.9.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
132
+ "model.layers.9.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
133
+ "model.layers.9.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
134
+ "model.layers.9.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
135
+ "model.layers.9.input_layernorm.weight": "model-00001-of-00001.safetensors",
136
+ "model.layers.9.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
137
+ "model.layers.10.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
138
+ "model.layers.10.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
139
+ "model.layers.10.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
140
+ "model.layers.10.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
141
+ "model.layers.10.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
142
+ "model.layers.10.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
143
+ "model.layers.10.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
144
+ "model.layers.10.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
145
+ "model.layers.10.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
146
+ "model.layers.10.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
147
+ "model.layers.10.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
148
+ "model.layers.10.input_layernorm.weight": "model-00001-of-00001.safetensors",
149
+ "model.layers.10.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
150
+ "model.layers.11.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
151
+ "model.layers.11.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
152
+ "model.layers.11.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
153
+ "model.layers.11.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
154
+ "model.layers.11.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
155
+ "model.layers.11.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
156
+ "model.layers.11.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
157
+ "model.layers.11.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
158
+ "model.layers.11.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
159
+ "model.layers.11.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
160
+ "model.layers.11.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
161
+ "model.layers.11.input_layernorm.weight": "model-00001-of-00001.safetensors",
162
+ "model.layers.11.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
163
+ "model.layers.12.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
164
+ "model.layers.12.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
165
+ "model.layers.12.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
166
+ "model.layers.12.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
167
+ "model.layers.12.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
168
+ "model.layers.12.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
169
+ "model.layers.12.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
170
+ "model.layers.12.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
171
+ "model.layers.12.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
172
+ "model.layers.12.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
173
+ "model.layers.12.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
174
+ "model.layers.12.input_layernorm.weight": "model-00001-of-00001.safetensors",
175
+ "model.layers.12.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
176
+ "model.layers.13.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
177
+ "model.layers.13.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
178
+ "model.layers.13.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
179
+ "model.layers.13.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
180
+ "model.layers.13.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
181
+ "model.layers.13.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
182
+ "model.layers.13.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
183
+ "model.layers.13.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
184
+ "model.layers.13.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
185
+ "model.layers.13.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
186
+ "model.layers.13.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
187
+ "model.layers.13.input_layernorm.weight": "model-00001-of-00001.safetensors",
188
+ "model.layers.13.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
189
+ "model.layers.14.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
190
+ "model.layers.14.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
191
+ "model.layers.14.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
192
+ "model.layers.14.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
193
+ "model.layers.14.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
194
+ "model.layers.14.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
195
+ "model.layers.14.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
196
+ "model.layers.14.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
197
+ "model.layers.14.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
198
+ "model.layers.14.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
199
+ "model.layers.14.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
200
+ "model.layers.14.input_layernorm.weight": "model-00001-of-00001.safetensors",
201
+ "model.layers.14.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
202
+ "model.layers.15.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
203
+ "model.layers.15.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
204
+ "model.layers.15.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
205
+ "model.layers.15.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
206
+ "model.layers.15.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
207
+ "model.layers.15.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
208
+ "model.layers.15.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
209
+ "model.layers.15.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
210
+ "model.layers.15.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
211
+ "model.layers.15.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
212
+ "model.layers.15.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
213
+ "model.layers.15.input_layernorm.weight": "model-00001-of-00001.safetensors",
214
+ "model.layers.15.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
215
+ "model.layers.16.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
216
+ "model.layers.16.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
217
+ "model.layers.16.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
218
+ "model.layers.16.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
219
+ "model.layers.16.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
220
+ "model.layers.16.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
221
+ "model.layers.16.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
222
+ "model.layers.16.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
223
+ "model.layers.16.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
224
+ "model.layers.16.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
225
+ "model.layers.16.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
226
+ "model.layers.16.input_layernorm.weight": "model-00001-of-00001.safetensors",
227
+ "model.layers.16.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
228
+ "model.layers.17.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
229
+ "model.layers.17.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
230
+ "model.layers.17.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
231
+ "model.layers.17.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
232
+ "model.layers.17.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
233
+ "model.layers.17.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
234
+ "model.layers.17.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
235
+ "model.layers.17.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
236
+ "model.layers.17.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
237
+ "model.layers.17.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
238
+ "model.layers.17.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
239
+ "model.layers.17.input_layernorm.weight": "model-00001-of-00001.safetensors",
240
+ "model.layers.17.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
241
+ "model.layers.18.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
242
+ "model.layers.18.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
243
+ "model.layers.18.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
244
+ "model.layers.18.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
245
+ "model.layers.18.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
246
+ "model.layers.18.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
247
+ "model.layers.18.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
248
+ "model.layers.18.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
249
+ "model.layers.18.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
250
+ "model.layers.18.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
251
+ "model.layers.18.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
252
+ "model.layers.18.input_layernorm.weight": "model-00001-of-00001.safetensors",
253
+ "model.layers.18.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
254
+ "model.layers.19.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
255
+ "model.layers.19.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
256
+ "model.layers.19.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
257
+ "model.layers.19.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
258
+ "model.layers.19.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
259
+ "model.layers.19.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
260
+ "model.layers.19.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
261
+ "model.layers.19.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
262
+ "model.layers.19.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
263
+ "model.layers.19.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
264
+ "model.layers.19.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
265
+ "model.layers.19.input_layernorm.weight": "model-00001-of-00001.safetensors",
266
+ "model.layers.19.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
267
+ "model.layers.20.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
268
+ "model.layers.20.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
269
+ "model.layers.20.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
270
+ "model.layers.20.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
271
+ "model.layers.20.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
272
+ "model.layers.20.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
273
+ "model.layers.20.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
274
+ "model.layers.20.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
275
+ "model.layers.20.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
276
+ "model.layers.20.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
277
+ "model.layers.20.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
278
+ "model.layers.20.input_layernorm.weight": "model-00001-of-00001.safetensors",
279
+ "model.layers.20.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
280
+ "model.layers.21.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
281
+ "model.layers.21.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
282
+ "model.layers.21.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
283
+ "model.layers.21.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
284
+ "model.layers.21.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
285
+ "model.layers.21.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
286
+ "model.layers.21.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
287
+ "model.layers.21.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
288
+ "model.layers.21.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
289
+ "model.layers.21.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
290
+ "model.layers.21.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
291
+ "model.layers.21.input_layernorm.weight": "model-00001-of-00001.safetensors",
292
+ "model.layers.21.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
293
+ "model.layers.22.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
294
+ "model.layers.22.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
295
+ "model.layers.22.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
296
+ "model.layers.22.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
297
+ "model.layers.22.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
298
+ "model.layers.22.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
299
+ "model.layers.22.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
300
+ "model.layers.22.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
301
+ "model.layers.22.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
302
+ "model.layers.22.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
303
+ "model.layers.22.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
304
+ "model.layers.22.input_layernorm.weight": "model-00001-of-00001.safetensors",
305
+ "model.layers.22.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
306
+ "model.layers.23.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
307
+ "model.layers.23.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
308
+ "model.layers.23.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
309
+ "model.layers.23.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
310
+ "model.layers.23.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
311
+ "model.layers.23.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
312
+ "model.layers.23.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
313
+ "model.layers.23.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
314
+ "model.layers.23.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
315
+ "model.layers.23.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
316
+ "model.layers.23.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
317
+ "model.layers.23.input_layernorm.weight": "model-00001-of-00001.safetensors",
318
+ "model.layers.23.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
319
+ "model.layers.24.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
320
+ "model.layers.24.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
321
+ "model.layers.24.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
322
+ "model.layers.24.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
323
+ "model.layers.24.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
324
+ "model.layers.24.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
325
+ "model.layers.24.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
326
+ "model.layers.24.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
327
+ "model.layers.24.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
328
+ "model.layers.24.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
329
+ "model.layers.24.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
330
+ "model.layers.24.input_layernorm.weight": "model-00001-of-00001.safetensors",
331
+ "model.layers.24.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
332
+ "model.layers.25.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
333
+ "model.layers.25.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
334
+ "model.layers.25.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
335
+ "model.layers.25.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
336
+ "model.layers.25.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
337
+ "model.layers.25.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
338
+ "model.layers.25.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
339
+ "model.layers.25.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
340
+ "model.layers.25.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
341
+ "model.layers.25.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
342
+ "model.layers.25.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
343
+ "model.layers.25.input_layernorm.weight": "model-00001-of-00001.safetensors",
344
+ "model.layers.25.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
345
+ "model.layers.26.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
346
+ "model.layers.26.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
347
+ "model.layers.26.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
348
+ "model.layers.26.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
349
+ "model.layers.26.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
350
+ "model.layers.26.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
351
+ "model.layers.26.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
352
+ "model.layers.26.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
353
+ "model.layers.26.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
354
+ "model.layers.26.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
355
+ "model.layers.26.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
356
+ "model.layers.26.input_layernorm.weight": "model-00001-of-00001.safetensors",
357
+ "model.layers.26.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
358
+ "model.layers.27.self_attn.q_norm.weight": "model-00001-of-00001.safetensors",
359
+ "model.layers.27.self_attn.k_norm.weight": "model-00001-of-00001.safetensors",
360
+ "model.layers.27.self_attn.q_proj.weight": "model-00001-of-00001.safetensors",
361
+ "model.layers.27.self_attn.k_proj.weight": "model-00001-of-00001.safetensors",
362
+ "model.layers.27.self_attn.v_proj.weight": "model-00001-of-00001.safetensors",
363
+ "model.layers.27.self_attn.o_proj.weight": "model-00001-of-00001.safetensors",
364
+ "model.layers.27.self_attn.r_proj.weight": "model-00001-of-00001.safetensors",
365
+ "model.layers.27.self_attn.r_norm.weight": "model-00001-of-00001.safetensors",
366
+ "model.layers.27.mlp.gate_proj.weight": "model-00001-of-00001.safetensors",
367
+ "model.layers.27.mlp.down_proj.weight": "model-00001-of-00001.safetensors",
368
+ "model.layers.27.mlp.up_proj.weight": "model-00001-of-00001.safetensors",
369
+ "model.layers.27.input_layernorm.weight": "model-00001-of-00001.safetensors",
370
+ "model.layers.27.post_attention_layernorm.weight": "model-00001-of-00001.safetensors",
371
+ "model.norm.weight": "model-00001-of-00001.safetensors"
372
+ }
373
+ }
modeling_parallax.py ADDED
@@ -0,0 +1,299 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Parallax HF modeling file (inherits from Qwen3).
2
+
3
+ Parallax (Parameterized Local Linear Attention) reuses the Qwen3 architecture
4
+ and only overrides the attention class to swap softmax self-attention for the
5
+ parallax op (``attn_type="parallax"``).
6
+
7
+ Reference: https://arxiv.org/abs/2605.29157
8
+
9
+ Design notes
10
+ ------------
11
+ * All boilerplate — RMSNorm, MLP, rotary embeddings, decoder-layer scaffolding,
12
+ the base ``PreTrainedModel`` class, ``Qwen3Model``, ``Qwen3ForCausalLM``,
13
+ mask preparation, cache handling, ``GenerationMixin`` integration, etc. —
14
+ is inherited from ``transformers.models.qwen3``.
15
+ * The only new code is:
16
+ - ``parallax_forward``: a pure-PyTorch kernel implementing the parallax op,
17
+ batched over heads and taking an additive attention mask in the HF shape
18
+ ``(B, 1, q_len, kv_len)``.
19
+ - ``ParallaxAttention``: inherits from ``Qwen3Attention``, adds an
20
+ ``r_proj`` / ``r_norm`` pair when ``config.attn_type == "parallax"``,
21
+ and overrides ``forward`` to dispatch to ``parallax_forward`` in that
22
+ case. For ``attn_type == "sdpa"`` the forward simply delegates to
23
+ ``Qwen3Attention.forward`` unchanged, so all modern HF attention
24
+ backends (sdpa, flash_attention_2, flex_attention, eager) remain
25
+ available for that path.
26
+ - ``ParallaxDecoderLayer``, ``ParallaxModel``, ``ParallaxPreTrainedModel``,
27
+ ``ParallaxForCausalLM``: thin subclasses that rewire parent classes to
28
+ the ``ParallaxAttention`` / ``ParallaxConfig`` below.
29
+ """
30
+
31
+ from __future__ import annotations
32
+
33
+ from typing import Optional
34
+
35
+ import torch
36
+ import torch.nn as nn
37
+ from transformers.cache_utils import Cache
38
+ from transformers.models.qwen3.modeling_qwen3 import (
39
+ Qwen3Attention,
40
+ Qwen3DecoderLayer,
41
+ Qwen3ForCausalLM,
42
+ Qwen3Model,
43
+ Qwen3PreTrainedModel,
44
+ Qwen3RMSNorm,
45
+ apply_rotary_pos_emb,
46
+ repeat_kv,
47
+ )
48
+
49
+ from .configuration_parallax import ParallaxConfig
50
+
51
+
52
+ # ---------------------------------------------------------------------------
53
+ # Parallax op (pure PyTorch)
54
+ # ---------------------------------------------------------------------------
55
+
56
+
57
+ def parallax_forward(
58
+ module: nn.Module,
59
+ query: torch.Tensor,
60
+ r: torch.Tensor,
61
+ key: torch.Tensor,
62
+ value: torch.Tensor,
63
+ attention_mask: Optional[torch.Tensor],
64
+ scaling: float,
65
+ dropout: float = 0.0,
66
+ **kwargs,
67
+ ) -> tuple[torch.Tensor, None]:
68
+ """The parallax op.
69
+
70
+ p = softmax((Q Kᵀ) * scale + mask)
71
+ rk = R Kᵀ
72
+ s = p V
73
+ c = sum(p * rk, -1, keepdim=True)
74
+ r_term = (p * rk) V
75
+ out = s + c * s - r_term
76
+
77
+ Shapes
78
+ ------
79
+ query : (B, H, q_len, D)
80
+ r : (B, H, q_len, D) — Parallax-specific extra projection
81
+ key : (B, H_kv, kv_len, D) — GQA-compressed, expanded internally
82
+ value : (B, H_kv, kv_len, D)
83
+ attention_mask : (B, 1, q_len, kv_len) additive, 0 or -inf (HF convention)
84
+
85
+ Returns
86
+ -------
87
+ attn_output : (B, q_len, H, D) — transposed to match Qwen3 eager impl
88
+ attn_weights : None — not exposed (the parallax op has no
89
+ meaningful "attention matrix" per head)
90
+ """
91
+ # Expand GQA-compressed k/v to match q heads
92
+ key = repeat_kv(key, module.num_key_value_groups)
93
+ value = repeat_kv(value, module.num_key_value_groups)
94
+
95
+ # Upcast to float32 for numerical stability (the softmax accumulates in fp32).
96
+ out_dtype = query.dtype
97
+ qf = query.float()
98
+ rf = r.float()
99
+ kf = key.float()
100
+ vf = value.float()
101
+
102
+ qk = torch.einsum("bhqd,bhkd->bhqk", qf, kf) * scaling
103
+ q_len = qk.shape[-2]
104
+ kv_len = qk.shape[-1]
105
+ if attention_mask is not None:
106
+ # HF causal masks may cover a larger key span than our current
107
+ # kv_len during decode; slice to match.
108
+ qk = qk + attention_mask[..., :q_len, :kv_len].to(qk.dtype)
109
+ elif q_len > 1:
110
+ # HF's `create_causal_mask` returns None when the model's default
111
+ # attention backend (e.g. sdpa) handles causality implicitly. The
112
+ # parallax op is hand-written and needs the explicit additive mask,
113
+ # so build one here. Decode (q_len == 1) is naturally unmasked: the
114
+ # single query can attend to every cached key.
115
+ offset = kv_len - q_len
116
+ row = torch.arange(q_len, device=qk.device)[:, None] + offset
117
+ col = torch.arange(kv_len, device=qk.device)[None, :]
118
+ causal = row >= col
119
+ bias = torch.zeros(q_len, kv_len, dtype=qk.dtype, device=qk.device)
120
+ bias = bias.masked_fill(~causal, float("-inf"))
121
+ qk = qk + bias
122
+
123
+ p = torch.softmax(qk, dim=-1)
124
+ rk = torch.einsum("bhqd,bhkd->bhqk", rf, kf)
125
+
126
+ s = torch.einsum("bhqk,bhkd->bhqd", p, vf)
127
+ c = (p * rk).sum(dim=-1, keepdim=True)
128
+ r_term = torch.einsum("bhqk,bhkd->bhqd", p * rk, vf)
129
+
130
+ attn_output = (s + c * s - r_term).to(out_dtype)
131
+ # Match Qwen3 eager_attention_forward: return transposed (B, q_len, H, D)
132
+ attn_output = attn_output.transpose(1, 2).contiguous()
133
+ return attn_output, None
134
+
135
+
136
+ # ---------------------------------------------------------------------------
137
+ # Attention / DecoderLayer / Model / ForCausalLM
138
+ # ---------------------------------------------------------------------------
139
+
140
+
141
+ class ParallaxAttention(Qwen3Attention):
142
+ """Qwen3 attention plus an optional parallax path."""
143
+
144
+ def __init__(self, config: ParallaxConfig, layer_idx: int) -> None:
145
+ super().__init__(config, layer_idx)
146
+ self.attn_type = config.attn_type
147
+ if self.attn_type == "parallax":
148
+ # Extra projection + RMSNorm for the parallax op.
149
+ self.r_proj = nn.Linear(
150
+ config.hidden_size,
151
+ config.num_attention_heads * self.head_dim,
152
+ bias=config.attention_bias,
153
+ )
154
+ self.r_norm = Qwen3RMSNorm(self.head_dim, eps=config.rms_norm_eps)
155
+
156
+ def forward(
157
+ self,
158
+ hidden_states: torch.Tensor,
159
+ position_embeddings: tuple[torch.Tensor, torch.Tensor],
160
+ attention_mask: Optional[torch.Tensor],
161
+ past_key_values: Optional[Cache] = None,
162
+ **kwargs,
163
+ ) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
164
+ if self.attn_type != "parallax":
165
+ # Plain Qwen3 attention — delegate to the parent, which supports
166
+ # sdpa / flash_attention_2 / flex_attention / eager backends.
167
+ return super().forward(
168
+ hidden_states=hidden_states,
169
+ position_embeddings=position_embeddings,
170
+ attention_mask=attention_mask,
171
+ past_key_values=past_key_values,
172
+ **kwargs,
173
+ )
174
+
175
+ # ---- Parallax path ----
176
+ input_shape = hidden_states.shape[:-1]
177
+ hidden_shape = (*input_shape, -1, self.head_dim)
178
+
179
+ query_states = self.q_norm(
180
+ self.q_proj(hidden_states).view(hidden_shape)
181
+ ).transpose(1, 2)
182
+ key_states = self.k_norm(
183
+ self.k_proj(hidden_states).view(hidden_shape)
184
+ ).transpose(1, 2)
185
+ value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2)
186
+
187
+ # r: same num_heads as q (not num_key_value_heads), rope applied.
188
+ # Note hidden_shape uses -1 for the heads dim, so r_proj (which produces
189
+ # num_attention_heads*head_dim) will correctly view as (..., n_heads, D).
190
+ r_states = self.r_norm(
191
+ self.r_proj(hidden_states).view(hidden_shape)
192
+ ).transpose(1, 2)
193
+
194
+ cos, sin = position_embeddings
195
+ query_states, key_states = apply_rotary_pos_emb(
196
+ query_states, key_states, cos, sin
197
+ )
198
+ r_states, _ = apply_rotary_pos_emb(r_states, r_states, cos, sin)
199
+
200
+ if past_key_values is not None:
201
+ key_states, value_states = past_key_values.update(
202
+ key_states, value_states, self.layer_idx
203
+ )
204
+
205
+ attn_output, attn_weights = parallax_forward(
206
+ self,
207
+ query_states,
208
+ r_states,
209
+ key_states,
210
+ value_states,
211
+ attention_mask,
212
+ dropout=0.0 if not self.training else self.attention_dropout,
213
+ scaling=self.scaling,
214
+ )
215
+
216
+ attn_output = attn_output.reshape(*input_shape, -1).contiguous()
217
+ attn_output = self.o_proj(attn_output)
218
+ return attn_output, attn_weights
219
+
220
+
221
+ class ParallaxDecoderLayer(Qwen3DecoderLayer):
222
+ def __init__(self, config: ParallaxConfig, layer_idx: int) -> None:
223
+ # Call the grandparent (nn.Module) init to avoid Qwen3DecoderLayer
224
+ # building a Qwen3Attention we'd immediately replace.
225
+ nn.Module.__init__(self)
226
+ self.hidden_size = config.hidden_size
227
+ self.attention_type = config.layer_types[layer_idx]
228
+ self.self_attn = ParallaxAttention(config=config, layer_idx=layer_idx)
229
+ # Reuse the MLP + norms from Qwen3 via its own constructor logic.
230
+ # Easiest is to rebuild them directly here to match Qwen3DecoderLayer.
231
+ from transformers.models.qwen3.modeling_qwen3 import Qwen3MLP
232
+
233
+ self.mlp = Qwen3MLP(config)
234
+ self.input_layernorm = Qwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
235
+ self.post_attention_layernorm = Qwen3RMSNorm(
236
+ config.hidden_size, eps=config.rms_norm_eps
237
+ )
238
+
239
+
240
+ class ParallaxPreTrainedModel(Qwen3PreTrainedModel):
241
+ config: ParallaxConfig # type: ignore[assignment]
242
+ config_class = ParallaxConfig
243
+ base_model_prefix = "model"
244
+ _no_split_modules = ["ParallaxDecoderLayer"]
245
+ # The parallax path is hand-written and does not plug into
246
+ # ALL_ATTENTION_FUNCTIONS. The sdpa path (delegated to super) supports the
247
+ # standard backends.
248
+ _supports_flash_attn = True
249
+ _supports_sdpa = True
250
+ _supports_flex_attn = True
251
+
252
+
253
+ class ParallaxModel(ParallaxPreTrainedModel, Qwen3Model):
254
+ def __init__(self, config: ParallaxConfig) -> None:
255
+ # Bypass Qwen3Model.__init__ (which builds Qwen3DecoderLayers) and
256
+ # rebuild the module tree with ParallaxDecoderLayers.
257
+ Qwen3PreTrainedModel.__init__(self, config)
258
+ self.padding_idx = config.pad_token_id
259
+ self.vocab_size = config.vocab_size
260
+ self.embed_tokens = nn.Embedding(
261
+ config.vocab_size, config.hidden_size, self.padding_idx
262
+ )
263
+ self.layers = nn.ModuleList(
264
+ [
265
+ ParallaxDecoderLayer(config, layer_idx)
266
+ for layer_idx in range(config.num_hidden_layers)
267
+ ]
268
+ )
269
+ self.norm = Qwen3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
270
+ # Qwen3Model constructs its rotary embedding from the config; reuse.
271
+ from transformers.models.qwen3.modeling_qwen3 import Qwen3RotaryEmbedding
272
+
273
+ self.rotary_emb = Qwen3RotaryEmbedding(config=config)
274
+ self.gradient_checkpointing = False
275
+ self.has_sliding_layers = "sliding_attention" in (config.layer_types or [])
276
+ self.post_init()
277
+
278
+
279
+ class ParallaxForCausalLM(ParallaxPreTrainedModel, Qwen3ForCausalLM):
280
+ _tied_weights_keys = {"lm_head.weight": "model.embed_tokens.weight"}
281
+
282
+ def __init__(self, config: ParallaxConfig) -> None:
283
+ # Bypass Qwen3ForCausalLM.__init__ (which builds a Qwen3Model) and
284
+ # rebuild with ParallaxModel.
285
+ Qwen3PreTrainedModel.__init__(self, config)
286
+ self.model = ParallaxModel(config)
287
+ self.vocab_size = config.vocab_size
288
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
289
+ self.post_init()
290
+
291
+
292
+ __all__ = [
293
+ "ParallaxAttention",
294
+ "ParallaxDecoderLayer",
295
+ "ParallaxForCausalLM",
296
+ "ParallaxModel",
297
+ "ParallaxPreTrainedModel",
298
+ "parallax_forward",
299
+ ]
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aeb13307a71acd8fe81861d94ad54ab689df773318809eed3cbe794b4492dae4
3
+ size 11422654
tokenizer_config.json ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": false,
3
+ "add_prefix_space": false,
4
+ "added_tokens_decoder": {
5
+ "151643": {
6
+ "content": "<|endoftext|>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false,
11
+ "special": true
12
+ },
13
+ "151644": {
14
+ "content": "<|im_start|>",
15
+ "lstrip": false,
16
+ "normalized": false,
17
+ "rstrip": false,
18
+ "single_word": false,
19
+ "special": true
20
+ },
21
+ "151645": {
22
+ "content": "<|im_end|>",
23
+ "lstrip": false,
24
+ "normalized": false,
25
+ "rstrip": false,
26
+ "single_word": false,
27
+ "special": true
28
+ },
29
+ "151646": {
30
+ "content": "<|object_ref_start|>",
31
+ "lstrip": false,
32
+ "normalized": false,
33
+ "rstrip": false,
34
+ "single_word": false,
35
+ "special": true
36
+ },
37
+ "151647": {
38
+ "content": "<|object_ref_end|>",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false,
43
+ "special": true
44
+ },
45
+ "151648": {
46
+ "content": "<|box_start|>",
47
+ "lstrip": false,
48
+ "normalized": false,
49
+ "rstrip": false,
50
+ "single_word": false,
51
+ "special": true
52
+ },
53
+ "151649": {
54
+ "content": "<|box_end|>",
55
+ "lstrip": false,
56
+ "normalized": false,
57
+ "rstrip": false,
58
+ "single_word": false,
59
+ "special": true
60
+ },
61
+ "151650": {
62
+ "content": "<|quad_start|>",
63
+ "lstrip": false,
64
+ "normalized": false,
65
+ "rstrip": false,
66
+ "single_word": false,
67
+ "special": true
68
+ },
69
+ "151651": {
70
+ "content": "<|quad_end|>",
71
+ "lstrip": false,
72
+ "normalized": false,
73
+ "rstrip": false,
74
+ "single_word": false,
75
+ "special": true
76
+ },
77
+ "151652": {
78
+ "content": "<|vision_start|>",
79
+ "lstrip": false,
80
+ "normalized": false,
81
+ "rstrip": false,
82
+ "single_word": false,
83
+ "special": true
84
+ },
85
+ "151653": {
86
+ "content": "<|vision_end|>",
87
+ "lstrip": false,
88
+ "normalized": false,
89
+ "rstrip": false,
90
+ "single_word": false,
91
+ "special": true
92
+ },
93
+ "151654": {
94
+ "content": "<|vision_pad|>",
95
+ "lstrip": false,
96
+ "normalized": false,
97
+ "rstrip": false,
98
+ "single_word": false,
99
+ "special": true
100
+ },
101
+ "151655": {
102
+ "content": "<|image_pad|>",
103
+ "lstrip": false,
104
+ "normalized": false,
105
+ "rstrip": false,
106
+ "single_word": false,
107
+ "special": true
108
+ },
109
+ "151656": {
110
+ "content": "<|video_pad|>",
111
+ "lstrip": false,
112
+ "normalized": false,
113
+ "rstrip": false,
114
+ "single_word": false,
115
+ "special": true
116
+ },
117
+ "151657": {
118
+ "content": "<tool_call>",
119
+ "lstrip": false,
120
+ "normalized": false,
121
+ "rstrip": false,
122
+ "single_word": false,
123
+ "special": false
124
+ },
125
+ "151658": {
126
+ "content": "</tool_call>",
127
+ "lstrip": false,
128
+ "normalized": false,
129
+ "rstrip": false,
130
+ "single_word": false,
131
+ "special": false
132
+ },
133
+ "151659": {
134
+ "content": "<|fim_prefix|>",
135
+ "lstrip": false,
136
+ "normalized": false,
137
+ "rstrip": false,
138
+ "single_word": false,
139
+ "special": false
140
+ },
141
+ "151660": {
142
+ "content": "<|fim_middle|>",
143
+ "lstrip": false,
144
+ "normalized": false,
145
+ "rstrip": false,
146
+ "single_word": false,
147
+ "special": false
148
+ },
149
+ "151661": {
150
+ "content": "<|fim_suffix|>",
151
+ "lstrip": false,
152
+ "normalized": false,
153
+ "rstrip": false,
154
+ "single_word": false,
155
+ "special": false
156
+ },
157
+ "151662": {
158
+ "content": "<|fim_pad|>",
159
+ "lstrip": false,
160
+ "normalized": false,
161
+ "rstrip": false,
162
+ "single_word": false,
163
+ "special": false
164
+ },
165
+ "151663": {
166
+ "content": "<|repo_name|>",
167
+ "lstrip": false,
168
+ "normalized": false,
169
+ "rstrip": false,
170
+ "single_word": false,
171
+ "special": false
172
+ },
173
+ "151664": {
174
+ "content": "<|file_sep|>",
175
+ "lstrip": false,
176
+ "normalized": false,
177
+ "rstrip": false,
178
+ "single_word": false,
179
+ "special": false
180
+ },
181
+ "151665": {
182
+ "content": "<tool_response>",
183
+ "lstrip": false,
184
+ "normalized": false,
185
+ "rstrip": false,
186
+ "single_word": false,
187
+ "special": false
188
+ },
189
+ "151666": {
190
+ "content": "</tool_response>",
191
+ "lstrip": false,
192
+ "normalized": false,
193
+ "rstrip": false,
194
+ "single_word": false,
195
+ "special": false
196
+ },
197
+ "151667": {
198
+ "content": "<think>",
199
+ "lstrip": false,
200
+ "normalized": false,
201
+ "rstrip": false,
202
+ "single_word": false,
203
+ "special": false
204
+ },
205
+ "151668": {
206
+ "content": "</think>",
207
+ "lstrip": false,
208
+ "normalized": false,
209
+ "rstrip": false,
210
+ "single_word": false,
211
+ "special": false
212
+ }
213
+ },
214
+ "additional_special_tokens": [
215
+ "<|im_start|>",
216
+ "<|im_end|>",
217
+ "<|object_ref_start|>",
218
+ "<|object_ref_end|>",
219
+ "<|box_start|>",
220
+ "<|box_end|>",
221
+ "<|quad_start|>",
222
+ "<|quad_end|>",
223
+ "<|vision_start|>",
224
+ "<|vision_end|>",
225
+ "<|vision_pad|>",
226
+ "<|image_pad|>",
227
+ "<|video_pad|>"
228
+ ],
229
+ "bos_token": null,
230
+ "chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0].role == 'system' %}\n {{- messages[0].content + '\\n\\n' }}\n {%- endif %}\n {{- \"# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0].role == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0].content + '<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}\n{%- for message in messages[::-1] %}\n {%- set index = (messages|length - 1) - loop.index0 %}\n {%- if ns.multi_step_tool and message.role == \"user\" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n{%- endfor %}\n{%- for message in messages %}\n {%- if message.content is string %}\n {%- set content = message.content %}\n {%- else %}\n {%- set content = '' %}\n {%- endif %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) %}\n {{- '<|im_start|>' + message.role + '\\n' + content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {%- set reasoning_content = '' %}\n {%- if message.reasoning_content is string %}\n {%- set reasoning_content = message.reasoning_content %}\n {%- else %}\n {%- if '</think>' in content %}\n {%- set reasoning_content = content.split('</think>')[0].rstrip('\\n').split('<think>')[-1].lstrip('\\n') %}\n {%- set content = content.split('</think>')[-1].lstrip('\\n') %}\n {%- endif %}\n {%- endif %}\n {%- if loop.index0 > ns.last_query_index %}\n {%- if loop.last or (not loop.last and reasoning_content) %}\n {{- '<|im_start|>' + message.role + '\\n<think>\\n' + reasoning_content.strip('\\n') + '\\n</think>\\n\\n' + content.lstrip('\\n') }}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- if message.tool_calls %}\n {%- for tool_call in message.tool_calls %}\n {%- if (loop.first and content) or (not loop.first) %}\n {{- '\\n' }}\n {%- endif %}\n {%- if tool_call.function %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {%- if tool_call.arguments is string %}\n {{- tool_call.arguments }}\n {%- else %}\n {{- tool_call.arguments | tojson }}\n {%- endif %}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.first or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n {%- if enable_thinking is defined and enable_thinking is false %}\n {{- '<think>\\n\\n</think>\\n\\n' }}\n {%- endif %}\n{%- endif %}",
231
+ "clean_up_tokenization_spaces": false,
232
+ "eos_token": "<|im_end|>",
233
+ "errors": "replace",
234
+ "model_max_length": 131072,
235
+ "pad_token": "<|endoftext|>",
236
+ "split_special_tokens": false,
237
+ "tokenizer_class": "Qwen2Tokenizer",
238
+ "unk_token": null
239
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff