Skip to content

Commit 24a1865

Browse files
authored
Fix linear_dq8ca_q4gsw wrong output when M > K
Differential Revision: D113962415 Pull Request resolved: pytorch#21444
1 parent 85a204a commit 24a1865

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

‎backends/vulkan/runtime/graph/ops/impl/QuantizedLinear.cpp‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -833,10 +833,18 @@ void quantized_linear_impl(
833833
num_groups = graph.size_at<int64_t>(-2, weight_scales_data);
834834
}
835835

836+
// Per-group int8 input sums buffer, indexed as ivec4[group_idx * M4 + m4]
837+
// by both the producer (quantize_and_pack_4h4w_with_group_sums.glsl) and the
838+
// consumer (linear_int8_input_sums_load.glslh). Capacity must therefore be
839+
// num_groups * M4 ivec4 texels, sized by the input row count M -- NOT K.
840+
// dtype is kInt to match the shaders' `int`/ivec4 binding (each texel is 4
841+
// int32 sums = 16 bytes).
842+
const int64_t M = utils::val_at(-2, input_sizes);
843+
const int64_t M4 = utils::div_up(M, int64_t(4));
836844
TmpTensor int_input_sums(
837845
&graph,
838-
{num_groups, K},
839-
graph.dtype_of(output),
846+
{num_groups * M4 * 4},
847+
vkapi::kInt,
840848
utils::kBuffer,
841849
utils::kWidthPacked);
842850

‎backends/vulkan/test/custom_ops/test_q4gsw_linear.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ std::vector<TestCase> generate_quantized_linear_test_cases() {
269269
{32, 64, 32, 16},
270270
{32, 128, 64, 32},
271271
{32, 256, 128, 64},
272+
{256, 128, 128, 32}, // M=256 > K=128; all dims < kRefDimSizeLimit
273+
272274
// Coopmat-eligible correctness shapes (M%64==0, N%64==0, K%32==0,
273275
// group_size%32==0). The Buffer+Half variant fires linear_q4gsw_coopmat /
274276
// linear_dq8ca_q4gsw_coopmat and is validated against the CPU reference.

0 commit comments

Comments
 (0)