Skip to content

Implemented a new test case for LUT quantization #2342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ map_values(int8_t* dst, int8_t* src, int8x16_t lut, int size) {
}

// Call pack_weights every n_step columns

template <int weight_nbit, int nr, int kr, int sr, bool has_lut>
TORCHAO_ALWAYS_INLINE inline void pack_weights_impl(
// Output
Expand Down
19 changes: 8 additions & 11 deletions torchao/experimental/kernels/cpu/aarch64/tests/test_linear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <torchao/experimental/kernels/cpu/aarch64/bitpacking/bitpack.h>
#include <torchao/experimental/kernels/cpu/aarch64/linear/channelwise_8bit_activation_groupwise_lowbit_weight/channelwise_8bit_activation_groupwise_lowbit_weight.h>
#include <torchao/experimental/kernels/cpu/aarch64/tests/test_utils.h>
#include <torchao/experimental/kernels/cpu/aarch64/tests/test_utils_lut.h>

float kTol = 0.0001;

Expand Down Expand Up @@ -454,20 +455,16 @@ void test_channelwise_8bit_activation_groupwise_lowbit_weight_lut(
kr,
sr);

// Define equivalent LUT for affine quantization
constexpr int lut_size = (1 << weight_nbit);
std::vector<int8_t> weight_qval_idxs(test_case.weight_qvals.size());
std::vector<int8_t> lut(lut_size, 0);
constexpr int offset = (1 << (weight_nbit - 1));
for (int i = 0; i < test_case.weight_qvals.size(); i++) {
weight_qval_idxs[i] = test_case.weight_qvals[i] + offset;
}
for (int i = 0; i < lut_size; i++) {
lut[i] = i - offset;
}
using namespace torchao::test_utils::lut;

// This single call replaces all the manual LUT setup logic.
auto [lut, weight_qval_idxs] = generate_random_int8_lut_and_indices(
weight_nbit,
test_case.weight_qvals);

std::vector<char> packed_weights(packed_weights_with_lut_size(
n, k, group_size, weight_nbit, has_weight_zeros, has_bias, nr, kr, sr));
// fill in the packed weights
pack_weights_with_lut<weight_nbit, nr, kr, sr>(
(void*)packed_weights.data(),
n,
Expand Down
Empty file.
Loading
Loading