diff --git a/libref/ref_moe.cpp b/libref/ref_moe.cpp index 9684bf86..742d0064 100644 --- a/libref/ref_moe.cpp +++ b/libref/ref_moe.cpp @@ -884,7 +884,7 @@ int ref_moe_gemm_w4a4(const RadArgs* a, RadStream) { if (M <= 0 || numel(AS) < ar * (K / 128) || numel(ST) < T || numel(OF) < n_expert + 1) return RAD_E_SHAPE; - const int64_t a_ld = A->rank >= 2 ? A->stride[0] : K / 2; // BYTES per activation row (K int4) + const int64_t a_ld = A->rank >= 2 ? A->stride[0] / 2 : K / 2; // BYTES per activation row (K int4 = K/2 bytes) const int64_t y_ld = Y->rank >= 2 ? Y->stride[0] : N; const int64_t w_ld = W->stride[1]; // nibbles per weight row const int64_t ws_ld = WS->stride[1]; // scales per weight row diff --git a/libref/ref_shapes.cpp b/libref/ref_shapes.cpp index 27fecdd6..c7720727 100644 --- a/libref/ref_shapes.cpp +++ b/libref/ref_shapes.cpp @@ -1341,7 +1341,7 @@ int ref_dequant_w4_shape(const RadParam* p, int n_p, int operand, RadOpdDesc* ou const int64_t group = gi(p, n_p, "group", 128); if (N < 1 || K < 1 || N % 16 || K % 64 || group < 1 || K % group) return RAD_E_UNSUPPORTED; Opd o; - o.t(RAD_I4, { N * K / 8 }); /* wq -- packed int4 */ + o.t(RAD_I4, { N * K }); /* wq -- packed int4: N*K nibbles = N*K/2 bytes = N*K/8 dwords */ o.t(RAD_F32, { N * K / group }); /* ws -- scale (f16 in a dword, but declared f32) */ o.t(RAD_BF16, { N, K }); /* y */ return o.finish("dequant_w4", operand, out);