2727E8M0_NEUTRAL_SCALE : int = 127
2828
2929
30- # pyre-ignore[56]
3130@dsl_user_op
3231def pack_4xu8_to_u32 (
33- # pyre-ignore[11]
3432 b0 : Uint8 ,
3533 b1 : Uint8 ,
3634 b2 : Uint8 ,
3735 b3 : Uint8 ,
3836 * ,
3937 loc : object | None = None ,
4038 ip : object | None = None ,
41- # pyre-ignore[11]
4239) -> Uint32 :
4340 """Pack 4 Uint8 values into a Uint32 (little-endian: b0 is lowest byte)."""
4441 return Uint32 (
@@ -71,10 +68,8 @@ def pack_4xu8_to_u32(
7168 )
7269
7370
74- # pyre-ignore[56]
7571@dsl_user_op
7672def store_u32_shared (
77- # pyre-ignore[11]
7873 ptr : Int64 ,
7974 val : Uint32 ,
8075 * ,
@@ -96,10 +91,8 @@ def store_u32_shared(
9691 )
9792
9893
99- # pyre-ignore[56]
10094@dsl_user_op
10195def tanh (
102- # pyre-ignore[11]
10396 a : float | Float32 ,
10497 * ,
10598 loc : object | None = None ,
@@ -118,7 +111,6 @@ def tanh(
118111 )
119112
120113
121- # pyre-ignore[56]
122114@dsl_user_op
123115def max_f32 (
124116 a : float | Float32 ,
@@ -141,7 +133,6 @@ def max_f32(
141133 )
142134
143135
144- # pyre-ignore[56]
145136@dsl_user_op
146137def step_f32 (
147138 x : float | Float32 , * , loc : object | None = None , ip : object | None = None
@@ -162,7 +153,6 @@ def step_f32(
162153 )
163154
164155
165- # pyre-ignore[56]
166156@dsl_user_op
167157def abs_f32 (
168158 val : Float32 , * , loc : object | None = None , ip : object | None = None
@@ -181,7 +171,6 @@ def abs_f32(
181171 )
182172
183173
184- # pyre-ignore[56]
185174@dsl_user_op
186175def max3_f32 (
187176 a : float | Float32 ,
@@ -213,7 +202,6 @@ def max3_f32(
213202 )
214203
215204
216- # pyre-ignore[56]
217205@dsl_user_op
218206def mul_cvt_relu_8x_e4m3 (
219207 in_0 : Float32 ,
@@ -290,7 +278,6 @@ def mul_cvt_relu_8x_e4m3(
290278 )
291279
292280
293- # pyre-ignore[56]
294281@dsl_user_op
295282def unpack_i64_to_u32_pair (
296283 packed : Int64 , * , loc : object | None = None , ip : object | None = None
@@ -314,7 +301,6 @@ def unpack_i64_to_u32_pair(
314301 return lo , hi
315302
316303
317- # pyre-ignore[56]
318304@dsl_user_op
319305def cvt_relu_8x_e4m3 (
320306 s0 : Float32 ,
@@ -377,7 +363,6 @@ def cvt_relu_8x_e4m3(
377363 )
378364
379365
380- # pyre-ignore[56]
381366@dsl_user_op
382367def cvt_8x_e4m3 (
383368 s0 : Float32 ,
@@ -440,7 +425,6 @@ def cvt_8x_e4m3(
440425 )
441426
442427
443- # pyre-ignore[56]
444428@dsl_user_op
445429def fused_amax_to_e8m0_scale_f32 (
446430 amax : Float32 ,
@@ -524,7 +508,6 @@ class Relu:
524508 ReLU gradient: 1 if x >= 0, else 0
525509 """
526510
527- # pyre-ignore[11]
528511 def __init__ (
529512 self ,
530513 scale_qk : Float32 ,
@@ -533,19 +516,16 @@ def __init__(
533516 self .c_zero : object = (Float32 (0.0 ), Float32 (0.0 ))
534517 self .c_one : object = (Float32 (1.0 ), Float32 (1.0 ))
535518
536- # pyre-ignore[56]
537519 @cute .jit
538520 def relu (self , x : tuple [Float32 , Float32 ]) -> tuple [Float32 , Float32 ]:
539521 """Apply ReLU activation: max(0, x) for packed f32x2."""
540522 return (max_f32 (x [0 ], Float32 (0.0 )), max_f32 (x [1 ], Float32 (0.0 )))
541523
542- # pyre-ignore[56]
543524 @cute .jit
544525 def grad_relu (self , x : tuple [Float32 , Float32 ]) -> tuple [Float32 , Float32 ]:
545526 """Compute ReLU gradient: 1 if x >= 0, else 0 for packed f32x2."""
546527 return (step_f32 (x [0 ]), step_f32 (x [1 ]))
547528
548- # pyre-ignore[56]
549529 @cute .jit
550530 def activation_and_gradient_relu (
551531 self , x : tuple [Float32 , Float32 ]
@@ -556,17 +536,13 @@ def activation_and_gradient_relu(
556536 """
557537 act = self .relu (x )
558538 grad = self .grad_relu (x )
559- # pyre-ignore[60]
560539 return * act , * grad
561540
562- # pyre-ignore[56]
563541 @cute .jit
564542 def relu_and_convert (
565543 self ,
566- # pyre-ignore[11]
567544 acc_S_row : cute .Tensor ,
568545 acc_S_row_converted : cute .Tensor ,
569- # pyre-ignore[11]
570546 e2e_freq : cutlass .Constexpr [int ] = 16 ,
571547 e2e_res : cutlass .Constexpr [int ] = 4 ,
572548 e2e_frg_limit : cutlass .Constexpr [int ] = 1 ,
@@ -591,7 +567,6 @@ def relu_and_convert(
591567 acc_S_row_frg [None , j ].load ().to (acc_S_row_converted .element_type )
592568 )
593569
594- # pyre-ignore[56]
595570 @cute .jit
596571 def grad_relu_and_convert (
597572 self ,
@@ -631,7 +606,6 @@ def grad_relu_and_convert(
631606 acc_P_row_frg [None , j ].load ().to (acc_P_row_f16_frg .element_type )
632607 )
633608
634- # pyre-ignore[56]
635609 @cute .jit
636610 def relu_and_convert_blockscaled (
637611 self ,
@@ -821,7 +795,6 @@ def relu_and_convert_blockscaled(
821795
822796
823797class Gelu :
824- # pyre-ignore[11]
825798 def __init__ (
826799 self ,
827800 scale_qk : Float32 ,
@@ -870,25 +843,18 @@ def __init__(
870843 Float32 (0.0001171766272366646 ),
871844 )
872845 self .c_talyor_2_mul_c2 : object = (
873- # pyre-ignore[16]
874846 Float32 (self .c_taylor_c2 [0 ] * self .c_two [0 ]),
875- # pyre-ignore[16]
876847 Float32 (self .c_taylor_c2 [1 ] * self .c_two [1 ]),
877848 )
878849 self .c_taylor_4_mul_c4 : object = (
879- # pyre-ignore[16]
880850 Float32 (self .c_taylor_c4 [0 ] * self .c_four [0 ]),
881- # pyre-ignore[16]
882851 Float32 (self .c_taylor_c4 [1 ] * self .c_four [1 ]),
883852 )
884853 self .c_taylor_6_mul_c6 : object = (
885- # pyre-ignore[16]
886854 Float32 (self .c_taylor_c6 [0 ] * self .c_six [0 ]),
887- # pyre-ignore[16]
888855 Float32 (self .c_taylor_c6 [1 ] * self .c_six [1 ]),
889856 )
890857
891- # pyre-ignore[56]
892858 @cute .jit
893859 def gelu_tanh (self , x : tuple [Float32 , Float32 ]) -> tuple [Float32 , Float32 ]:
894860 # x^2
@@ -906,7 +872,6 @@ def gelu_tanh(self, x: tuple[Float32, Float32]) -> tuple[Float32, Float32]:
906872
907873 return (t_x , t_y )
908874
909- # pyre-ignore[56]
910875 @cute .jit
911876 def activation_and_gradient_fast_gelu (
912877 self , x : tuple [Float32 , Float32 ]
@@ -925,10 +890,8 @@ def activation_and_gradient_fast_gelu(
925890 grad = cute .arch .fma_packed_f32x2 (tanh_1 , self .c_half , term1 )
926891 act = cute .arch .mul_packed_f32x2 (half_x , tanh_1 )
927892
928- # pyre-ignore[60]
929893 return * act , * grad
930894
931- # pyre-ignore[56]
932895 @cute .jit
933896 def fast_gelu (self , x : tuple [Float32 , Float32 ]) -> tuple [Float32 , Float32 ]:
934897 # TODO: Seems like the complier may be able to handle this, without explicitly calling packed_f32x2:
@@ -940,7 +903,6 @@ def fast_gelu(self, x: tuple[Float32, Float32]) -> tuple[Float32, Float32]:
940903 out = cute .arch .mul_packed_f32x2 (out , tanh_1 )
941904 return out
942905
943- # pyre-ignore[56]
944906 @cute .jit
945907 def grad_fast_gelu (self , x : tuple [Float32 , Float32 ]) -> tuple [Float32 , Float32 ]:
946908 # TODO: Seems like the complier may be able to handle this, without explicitly calling packed_f32x2:
@@ -960,7 +922,6 @@ def grad_fast_gelu(self, x: tuple[Float32, Float32]) -> tuple[Float32, Float32]:
960922 out = cute .arch .fma_packed_f32x2 (one_plus_tanh , self .c_half , term1 )
961923 return out
962924
963- # pyre-ignore[56]
964925 @cute .jit
965926 def activation_and_gradient_gelu_taylor_deg6 (
966927 self , x : tuple [Float32 , Float32 ]
@@ -989,10 +950,8 @@ def activation_and_gradient_gelu_taylor_deg6(
989950
990951 grad = cute .arch .add_packed_f32x2 (part1 , part2 )
991952 act = cute .arch .fma_packed_f32x2 (x2 , tmp , x_half ) # 0.5*x + x2*tmp
992- # pyre-ignore[60]
993953 return * act , * grad
994954
995- # pyre-ignore[56]
996955 @cute .jit
997956 def grad_gelu_taylor_deg6 (
998957 self , x : tuple [Float32 , Float32 ]
@@ -1020,7 +979,6 @@ def grad_gelu_taylor_deg6(
1020979
1021980 return grad
1022981
1023- # pyre-ignore[56]
1024982 @cute .jit
1025983 def gelu_taylor_deg6 (self , x : tuple [Float32 , Float32 ]) -> tuple [Float32 , Float32 ]:
1026984 # 0.5*x + x2*(c2 + x2*(c4 + x2*c6))
@@ -1033,7 +991,6 @@ def gelu_taylor_deg6(self, x: tuple[Float32, Float32]) -> tuple[Float32, Float32
1033991 out = cute .arch .fma_packed_f32x2 (x2 , tmp , x_half ) # 0.5*x + x2*tmp
1034992 return out
1035993
1036- # pyre-ignore[56]
1037994 @cute .jit
1038995 def gelu_taylor_deg10 (self , x : tuple [Float32 , Float32 ]) -> tuple [Float32 , Float32 ]:
1039996 # 0.5*x + x^2*(c2 + x^2*(c4 + x^2*(c6 + x^2*(c8 + x^2*c10))))
@@ -1048,7 +1005,6 @@ def gelu_taylor_deg10(self, x: tuple[Float32, Float32]) -> tuple[Float32, Float3
10481005 out = cute .arch .fma_packed_f32x2 (x2 , tmp , x_half ) # 0.5*x + x^2*tmp
10491006 return out
10501007
1051- # pyre-ignore[56]
10521008 @cute .jit
10531009 def gelu_and_convert (
10541010 self ,
@@ -1085,7 +1041,6 @@ def gelu_and_convert(
10851041 acc_S_row_frg [None , j ].load ().to (acc_S_row_converted .element_type )
10861042 )
10871043
1088- # pyre-ignore[56]
10891044 @cute .jit
10901045 def grad_gelu_and_convert (
10911046 self ,
@@ -1135,7 +1090,6 @@ def grad_gelu_and_convert(
11351090 acc_P_row_frg [None , j ].load ().to (acc_P_row_f16_frg .element_type )
11361091 )
11371092
1138- # pyre-ignore[56]
11391093 @cute .jit
11401094 def gelu_and_convert_blockscaled (
11411095 self ,
0 commit comments