@@ -221,7 +221,7 @@ def _convert_humming(
221221 weight_scale = weight_scale .view (torch .float8_e8m0fnu )
222222 elif self .format .startswith ("nvfp4" ):
223223 weight_scale = weight_scale .view (torch .float8_e4m3fn )
224- else :
224+ elif self . strategy != "tensor" :
225225 weight_scale = weight_scale .to (param_dtype )
226226
227227 if self .strategy in ["group" , "tensor_group" ]:
@@ -232,21 +232,14 @@ def _convert_humming(
232232 weight_scale = weight_scale .repeat_interleave (self .block_structure [0 ], - 2 )
233233 group_size = self .block_structure [1 ]
234234 elif self .strategy == "tensor" :
235- weight_scale = self ._may_process_global_scale (
236- weight_scale ,
237- shape_n_stacks = shape_n_stacks ,
238- shape_k_stacks = shape_k_stacks ,
239- num_experts = num_experts ,
240- force_repeat = True ,
241- ).to (param_dtype )
242235 group_size = 0
243236 else :
244237 assert self .strategy == "channel"
245238 group_size = 0
246239
247240 output_tensors = {"weight" : weight , "weight_scale" : weight_scale }
248241
249- weight_scale_type = None
242+ weight_scale_type = WeightScaleType . TENSOR if self . strategy == "tensor" else None
250243 weight_scale_2_type = None
251244 if self .format == "nvfp4-pack-quantized" :
252245 weight_scale_2 = tensors ["weight_global_scale" ]
@@ -263,17 +256,20 @@ def _convert_humming(
263256 if has_tensor_scale :
264257 weight_scale_2_type = WeightScale2Type .TENSOR
265258 output_tensors ["weight_scale_2" ] = weight_scale_2 .float ()
259+ elif len (shape_n_stacks ) > 1 :
260+ weight_scale_2_type = WeightScale2Type .CHANNEL
261+ output_tensors ["weight_scale_2" ] = weight_scale_2 .squeeze (- 1 ).to (param_dtype )
266262 else :
267263 weight_scale = weight_scale .float () * weight_scale_2 .float ()
268264 output_tensors ["weight_scale" ] = weight_scale .to (param_dtype )
269265
270- bs_dtype = None
266+ bs_dtype = dtypes . float32 if self . strategy == "tensor" else None
271267 if self .format in ["int-quantized" , "float-quantized" , "naive-quantized" ]:
272268 assert self .num_bits == 8
273269 b_dtype = dtypes .uint8 if self .type == "int" else dtypes .float8e4m3
274270 elif "nvfp4" in self .format :
275271 b_dtype = dtypes .float4e2m1
276- bs_dtype = dtypes .float8e4m3 if has_tensor_scale else None
272+ bs_dtype = dtypes .float8e4m3 if weight_scale_2_type is not None else None
277273 elif "mxfp4" in self .format :
278274 b_dtype = dtypes .float4e2m1
279275 bs_dtype = dtypes .float8e8m0
@@ -298,6 +294,10 @@ def _convert_humming(
298294 has_zero_point = not self .symmetric ,
299295 )
300296
297+ if self .strategy == "tensor" :
298+ return schema ._convert_humming (
299+ output_tensors , shape_n_stacks , shape_k_stacks , param_dtype , num_experts
300+ )
301301 return schema , output_tensors
302302
303303
0 commit comments