4040@pytest .fixture
4141def standard_input ():
4242 # Shape (2, 4) ensures .chunk(2, dim=-1) splits it into two (2, 2) tensors cleanly
43- return torch .tensor (
44- [[- 1.0 , 2.0 , - 3.0 , 4.0 ], [5.0 , - 6.0 , 7.0 , - 8.0 ]], dtype = torch .float32
45- )
43+ return torch .tensor ([[- 1.0 , 2.0 , - 3.0 , 4.0 ], [5.0 , - 6.0 , 7.0 , - 8.0 ]], dtype = torch .float32 )
4644
4745
4846@pytest .fixture
4947def standard_grad ():
50- return torch .tensor (
51- [[0.5 , 1.5 , 2.5 , 3.5 ], [4.5 , 5.5 , 6.5 , 7.5 ]], dtype = torch .float32
52- )
48+ return torch .tensor ([[0.5 , 1.5 , 2.5 , 3.5 ], [4.5 , 5.5 , 6.5 , 7.5 ]], dtype = torch .float32 )
5349
5450
5551# ==============================================================================
@@ -68,9 +64,7 @@ def test_basic_forwards(standard_input):
6864
6965 # 2. GeGLU
7066 a , b = standard_input .chunk (2 , dim = - 1 )
71- assert torch .allclose (
72- geglu_torch (standard_input , quantizer ), F .gelu (a , approximate = "tanh" ) * b
73- )
67+ assert torch .allclose (geglu_torch (standard_input , quantizer ), F .gelu (a , approximate = "tanh" ) * b )
7468
7569 # 3. Quick-GeLU (qgelu)
7670 assert torch .allclose (
@@ -79,9 +73,7 @@ def test_basic_forwards(standard_input):
7973 )
8074
8175 # 4. Quick-GeGLU (qgeglu)
82- assert torch .allclose (
83- qgeglu_torch (standard_input , quantizer ), a * torch .sigmoid (1.702 * a ) * b
84- )
76+ assert torch .allclose (qgeglu_torch (standard_input , quantizer ), a * torch .sigmoid (1.702 * a ) * b )
8577
8678 # 5. ReLU & ReGLU
8779 assert torch .allclose (relu_torch (standard_input , quantizer ), F .relu (standard_input ))
@@ -91,9 +83,7 @@ def test_basic_forwards(standard_input):
9183 assert torch .allclose (
9284 srelu_torch (standard_input , quantizer ), torch .square (F .relu (standard_input ))
9385 )
94- assert torch .allclose (
95- sreglu_torch (standard_input , quantizer ), torch .square (F .relu (a )) * b
96- )
86+ assert torch .allclose (sreglu_torch (standard_input , quantizer ), torch .square (F .relu (a )) * b )
9787
9888 # 7. SiLU & SwiGLU
9989 assert torch .allclose (silu_torch (standard_input , quantizer ), F .silu (standard_input ))
@@ -140,40 +130,28 @@ def test_basic_backwards(standard_grad, standard_input):
140130 )
141131
142132 # 3. dqgelu & dqgeglu
143- assert (
144- dqgelu_torch (standard_grad , standard_input , quantizer ).shape
145- == standard_input .shape
146- )
133+ assert dqgelu_torch (standard_grad , standard_input , quantizer ).shape == standard_input .shape
147134 assert (
148135 dqgeglu_torch (standard_grad [..., :2 ], standard_input , quantizer ).shape
149136 == standard_input .shape
150137 )
151138
152139 # 4. drelu & dreglu
153- assert (
154- drelu_torch (standard_grad , standard_input , quantizer ).shape
155- == standard_input .shape
156- )
140+ assert drelu_torch (standard_grad , standard_input , quantizer ).shape == standard_input .shape
157141 assert (
158142 dreglu_torch (standard_grad [..., :2 ], standard_input , quantizer ).shape
159143 == standard_input .shape
160144 )
161145
162146 # 5. dsrelu & dsreglu
163- assert (
164- dsrelu_torch (standard_grad , standard_input , quantizer ).shape
165- == standard_input .shape
166- )
147+ assert dsrelu_torch (standard_grad , standard_input , quantizer ).shape == standard_input .shape
167148 assert (
168149 dsreglu_torch (standard_grad [..., :2 ], standard_input , quantizer ).shape
169150 == standard_input .shape
170151 )
171152
172153 # 6. dsilu & dswiglu
173- assert (
174- dsilu_torch (standard_grad , standard_input , quantizer ).shape
175- == standard_input .shape
176- )
154+ assert dsilu_torch (standard_grad , standard_input , quantizer ).shape == standard_input .shape
177155 assert (
178156 dswiglu_torch (standard_grad [..., :2 ], standard_input , quantizer ).shape
179157 == standard_input .shape
0 commit comments