@@ -86,3 +86,52 @@ std::vector<paddle::Tensor> MacheteMMKernel(
8686 maybe_schedule);
8787 return {out};
8888}
89+
90+ std::vector<std::vector<int64_t >> MacheteMMKernelInferShape (
91+ std::vector<int64_t > const & A_shape,
92+ std::vector<int64_t > const & B_shape,
93+ paddle::optional<std::vector<int64_t >> const & maybe_group_scales_shape,
94+ paddle::optional<std::vector<int64_t >> const & maybe_group_zeros_shape,
95+ paddle::optional<std::vector<int64_t >> const & maybe_channel_scales_shape,
96+ paddle::optional<std::vector<int64_t >> const & maybe_token_scales_shape,
97+ std::string const & b_type_str,
98+ std::string const & maybe_out_type_str,
99+ int64_t const & maybe_group_size,
100+ std::string const & maybe_schedule) {
101+ return {{A_shape[0 ], B_shape[1 ]}};
102+ }
103+
104+ std::vector<paddle::DataType> MacheteMMKernelInferDtype (
105+ paddle::DataType const & A_dtype,
106+ paddle::DataType const & B_dtype,
107+ paddle::optional<paddle::DataType> const & maybe_group_scales_dtype,
108+ paddle::optional<paddle::DataType> const & maybe_group_zeros_dtype,
109+ paddle::optional<paddle::DataType> const & maybe_channel_scales_dtype,
110+ paddle::optional<paddle::DataType> const & maybe_token_scales_dtype,
111+ std::string const & b_type_str,
112+ std::string const & maybe_out_type_str,
113+ int64_t const & maybe_group_size,
114+ std::string const & maybe_schedule) {
115+
116+ paddle::DataType maybe_out_type;
117+ if (maybe_out_type_str == " float16" ) {
118+ maybe_out_type = paddle::DataType::FLOAT16 ;
119+ } else if (maybe_out_type_str == " bfloat16" ) {
120+ maybe_out_type = paddle::DataType::BFLOAT16 ;
121+ } else {
122+ maybe_out_type = A_dtype;
123+ }
124+ return {maybe_out_type};
125+ }
126+
127+ PD_BUILD_STATIC_OP (machete_mm)
128+ .Inputs({" A" , " B" ,
129+ paddle::Optional (" maybe_group_scales" ),
130+ paddle::Optional (" maybe_group_zeros" ),
131+ paddle::Optional (" maybe_channel_scales" ),
132+ paddle::Optional (" maybe_token_scales" )})
133+ .Outputs({" out" })
134+ .Attrs({" b_type_str:std::string" , " maybe_out_type_str:std::string" , " maybe_group_size:int64_t" , " maybe_schedule:std::string" })
135+ .SetKernelFn(PD_KERNEL (MacheteMMKernel))
136+ .SetInferShapeFn(PD_INFER_SHAPE (MacheteMMKernelInferShape))
137+ .SetInferDtypeFn(PD_INFER_DTYPE (MacheteMMKernelInferDtype));
0 commit comments