File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -350,13 +350,10 @@ def make_linear_q4gsw_op(
350350 ep , match .weight_scales_node , "4 bit linear scales"
351351 ):
352352 weight_scales_tensor = weight_scales_tensor .transpose (0 , 1 ).contiguous ()
353- # Align to multiple of 8 to ensure that data loads from the weight scales
354- # tensor do not go out of bounds. Each thread computes 8 output channels.
355353 utils .align_width_and_update_state_dict (
356354 ep ,
357355 match .weight_scales_node ,
358356 weight_scales_tensor ,
359- align_to = 8 ,
360357 force_update = True ,
361358 )
362359
@@ -414,7 +411,6 @@ def make_linear_dq8ca_q4gsw_op(
414411 ep ,
415412 match .weight_scales_node ,
416413 weight_scales_tensor ,
417- align_to = 1 ,
418414 force_update = True ,
419415 )
420416
Original file line number Diff line number Diff line change 1313def pack_4bit_weight_tensor (
1414 weight_tensor : torch .Tensor ,
1515 * ,
16- even_value_high_nibble : bool = False ,
1716 inner_dim_padding : Optional [int ] = 8 ,
1817) -> torch .Tensor :
1918 """Pack signed 4-bit values stored in int8 into uint8 byte pairs.
2019
2120 The input tensor stores one quantized value per byte in the range [-8, 7].
2221 The returned tensor stores two 4-bit values per byte along the innermost dim.
2322
24- By default this preserves the legacy linear q4gsw packing convention:
23+ This preserves the legacy linear q4gsw packing convention:
2524 packed_byte = (odd_val + 8) << 4 | (even_val + 8)
26-
27- Set `even_value_high_nibble=True` for the embedding q4gsw convention:
28- packed_byte = (even_val + 8) << 4 | (odd_val + 8)
2925 """
3026 min_val , max_val = weight_tensor .min ().item (), weight_tensor .max ().item ()
3127 assert (
@@ -52,6 +48,4 @@ def pack_4bit_weight_tensor(
5248 shifted_weight_tensor = weight_tensor .to (dtype = torch .uint8 ) + 8
5349 even_values = shifted_weight_tensor [:, ::2 ]
5450 odd_values = shifted_weight_tensor [:, 1 ::2 ]
55- if even_value_high_nibble :
56- return even_values << 4 | odd_values
5751 return odd_values << 4 | even_values
Original file line number Diff line number Diff line change @@ -24,22 +24,13 @@ namespace vkcompute {
2424
2525namespace {
2626
27- /*
28- * Currently, only a few shader variants are generated for "compatible" tensor
29- * dtype / scalar dtype pairs. In particular float/half tensor + float scalar,
30- * and int32 tensor + int32 scalar. This function coerces the scalar dtype so
31- * that a "higher precision" tensor dtype (i.e. float, half) can be used with a
32- * "lower precision" scalar dtype (i.e. int32) with the current generated shader
33- * variants. "Lower precision" tensor dtype (i.e. int32) + "higher precision"
34- * scalar dtype (i.e. float/half) are currently not supported because the shader
35- * currently casts the scalar to the tensor dtype before computation. Though
36- * these combinations are not expected to be needed, if they are required in the
37- * future, update the shaders with more robust dtype handling.
38- */
3927vkapi::ScalarType resolve_scalar_extract_dtype (
4028 ComputeGraph& graph,
4129 const ValueRef scalar,
4230 const vkapi::ScalarType tensor_dtype) {
31+ // For float tensors, ensure that the scalar argument is extracted as a float
32+ // to avoid having to generate additional shader variants for float/half
33+ // tensor + int scalar.
4334 if (tensor_dtype == vkapi::kFloat || tensor_dtype == vkapi::kHalf ) {
4435 return vkapi::kFloat ;
4536 }
Original file line number Diff line number Diff line change @@ -2247,6 +2247,6 @@ def get_eq_scalar_inputs():
22472247 "utils::kWidthPacked" ,
22482248 "utils::kChannelsPacked" ,
22492249 ]
2250- test_suite .dtypes = ["at::kInt" ]
2250+ test_suite .dtypes = ["at::kInt" , "at::kFloat" ]
22512251 test_suite .data_gen = "make_seq_tensor"
22522252 return test_suite
You can’t perform that action at this time.
0 commit comments