Skip to content
Merged
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
51 changes: 5 additions & 46 deletions backends/vulkan/test/op_tests/quantize_affine_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <limits>

static inline void
_check_dims(c10::string_view name, int64_t expected, int64_t actual) {
_check_dims(std::string_view name, int64_t expected, int64_t actual) {
VK_CHECK_COND(
expected == actual,
name,
Expand All @@ -35,11 +35,11 @@ at::Tensor quantize_affine_reference_impl(
const at::Tensor& input_,
const std::vector<int64_t>& block_size,
const at::Tensor& scale,
const c10::optional<at::Tensor>& zero_point_opt,
const std::optional<at::Tensor>& zero_point_opt,
int64_t quant_min,
int64_t quant_max,
at::ScalarType out_dtype,
c10::optional<std::string> zero_point_domain_opt = std::string("INT")) {
std::optional<std::string> zero_point_domain_opt = std::string("INT")) {
constexpr float kEps = 1e-7f;

const int64_t ndim = input_.dim();
Expand Down Expand Up @@ -138,11 +138,11 @@ at::Tensor dequantize_affine_reference_impl(
const at::Tensor& input_,
const std::vector<int64_t>& block_size,
const at::Tensor& scale,
const c10::optional<at::Tensor>& zero_point_opt,
const std::optional<at::Tensor>& zero_point_opt,
int64_t quant_min,
int64_t quant_max,
at::ScalarType out_dtype,
c10::optional<std::string> zero_point_domain_opt = std::string("INT")) {
std::optional<std::string> zero_point_domain_opt = std::string("INT")) {
const int64_t ndim = input_.dim();
_check_dims("input", block_size.size(), ndim);

Expand Down Expand Up @@ -238,47 +238,6 @@ at::Tensor dequantize_affine_reference_impl(
return dq;
}

// Wrapper function to maintain compatibility with existing test code (above is
// a good reference for how the python implementation works)
at::Tensor quantize_affine_reference_impl(
const at::Tensor& input,
const std::vector<int64_t>& block_size,
const at::Tensor& scale,
const at::Tensor& zero_point,
int64_t quant_min,
int64_t quant_max,
at::ScalarType dtype) {
return quantize_affine_reference_impl(
input,
block_size,
scale,
c10::optional<at::Tensor>(zero_point),
quant_min,
quant_max,
dtype,
std::string("INT"));
}

// Wrapper function for dequantize_affine
at::Tensor dequantize_affine_reference_impl(
const at::Tensor& input,
const std::vector<int64_t>& block_size,
const at::Tensor& scale,
const at::Tensor& zero_point,
int64_t quant_min,
int64_t quant_max,
at::ScalarType dtype) {
return dequantize_affine_reference_impl(
input,
block_size,
scale,
c10::optional<at::Tensor>(zero_point),
quant_min,
quant_max,
dtype,
std::string("INT"));
}

void test_vulkan_quantize_affine_impl(
const std::vector<int>& input_sizes,
const std::vector<int64_t>& block_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_OptionalTensor) {

// Convert optional et to at.
torch::executor::testing::TensorFactory<ScalarType::Int> tf;
auto et_in = std::optional<torch::executor::Tensor>(tf.ones({3}));
std::optional<torch::executor::Tensor> et_in = tf.ones({3});
auto optional_at_out = type_convert<
std::optional<torch::executor::Tensor>,
std::optional<at::Tensor>>(optional_et)
Expand Down Expand Up @@ -403,7 +403,7 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestWrap_EmbeddingByte) {
}

TEST_F(MakeATenFunctorFromETFunctorTest, TestWrap_OptionalScalarAdd) {
std::optional<int64_t> a = std::optional<int64_t>(3);
std::optional<int64_t> a = 3;
std::optional<int64_t> b = std::optional<int64_t>();
at::Tensor out = torch::tensor({0});

Expand All @@ -418,7 +418,7 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestWrap_OptionalScalarAdd) {
}

TEST_F(MakeATenFunctorFromETFunctorTest, TestWrap_OptionalTensorAdd) {
std::optional<at::Tensor> a = std::optional<at::Tensor>(torch::tensor({8}));
std::optional<at::Tensor> a = torch::tensor({8});
std::optional<at::Tensor> b = std::optional<at::Tensor>();
at::Tensor out = torch::tensor({0});

Expand Down Expand Up @@ -465,9 +465,7 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestWrap_ArrayRefTensorAdd) {

TEST_F(MakeATenFunctorFromETFunctorTest, TestWrap_ArrayRefOptional) {
std::vector<std::optional<at::Tensor>> vec{
std::optional<at::Tensor>(torch::tensor({1})),
std::optional<at::Tensor>(),
std::optional<at::Tensor>(torch::tensor({3}))};
torch::tensor({1}), std::optional<at::Tensor>(), torch::tensor({3})};
at::Tensor out = torch::tensor({0});

at::ArrayRef arrayref = at::ArrayRef(vec.data(), vec.size());
Expand Down Expand Up @@ -512,8 +510,7 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestWrap_TupleOut) {

TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_ConstRefOptionals) {
// Test const optional scalar conversion
const std::optional<int64_t> const_optional_at_in =
std::optional<int64_t>(42);
const std::optional<int64_t> const_optional_at_in = 42;
auto const_optional_et =
type_convert<const std::optional<int64_t>, std::optional<int64_t>>(
const_optional_at_in)
Expand All @@ -522,7 +519,7 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_ConstRefOptionals) {
EXPECT_EQ(const_optional_et.value(), 42);

// Test optional scalar reference conversion
std::optional<int64_t> optional_at_ref_in = std::optional<int64_t>(24);
std::optional<int64_t> optional_at_ref_in = 24;
auto optional_et_from_ref =
type_convert<std::optional<int64_t>&, std::optional<int64_t>>(
optional_at_ref_in)
Expand All @@ -531,8 +528,7 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_ConstRefOptionals) {
EXPECT_EQ(optional_et_from_ref.value(), 24);

// Test const optional scalar reference conversion
const std::optional<int64_t> const_optional_at_ref_in =
std::optional<int64_t>(84);
const std::optional<int64_t> const_optional_at_ref_in = 84;
auto const_optional_et_from_ref =
type_convert<const std::optional<int64_t>&, std::optional<int64_t>>(
const_optional_at_ref_in)
Expand All @@ -542,7 +538,7 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_ConstRefOptionals) {

// Test const optional tensor conversion
const std::optional<at::Tensor> const_optional_tensor_at_in =
std::optional<at::Tensor>(torch::tensor({5}));
torch::tensor({5});
auto const_optional_tensor_converter = type_convert<
const std::optional<at::Tensor>,
std::optional<torch::executor::Tensor>>(const_optional_tensor_at_in);
Expand All @@ -551,8 +547,7 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_ConstRefOptionals) {
EXPECT_EQ(const_optional_tensor_et.value().const_data_ptr<int64_t>()[0], 5);

// Test optional tensor reference conversion
std::optional<at::Tensor> optional_tensor_at_ref_in =
std::optional<at::Tensor>(torch::tensor({7}));
std::optional<at::Tensor> optional_tensor_at_ref_in = torch::tensor({7});
auto optional_tensor_converter_from_ref = type_convert<
std::optional<at::Tensor>&,
std::optional<torch::executor::Tensor>>(optional_tensor_at_ref_in);
Expand All @@ -563,7 +558,7 @@ TEST_F(MakeATenFunctorFromETFunctorTest, TestConvert_ConstRefOptionals) {

// Test const optional tensor reference conversion
const std::optional<at::Tensor> const_optional_tensor_at_ref_in =
std::optional<at::Tensor>(torch::tensor({9}));
torch::tensor({9});
auto const_optional_tensor_converter_from_ref = type_convert<
const std::optional<at::Tensor>&,
std::optional<torch::executor::Tensor>>(const_optional_tensor_at_ref_in);
Expand Down
22 changes: 9 additions & 13 deletions extension/llm/custom_ops/op_sdpa_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ TEST(OpScaledDotProductAttentionTest, CorrectnessTest_11) {
executorch::aten::Tensor value = tfFloat.make(
{1, 1, 1, 8},
{99.375, 80.125, -81.0, 8.5, -70.375, -54.25, -80.25, 34.125});
std::optional<executorch::aten::Tensor> attn_mask =
std::optional<executorch::aten::Tensor>(
tfFloat.full({1, 1}, std::numeric_limits<float>::infinity()));
executorch::aten::Tensor attn_mask =
tfFloat.full({1, 1}, std::numeric_limits<float>::infinity());
double dropout_p = 0.0;
bool is_causal = false;
std::optional<double> scale;
Expand Down Expand Up @@ -314,7 +313,7 @@ TEST(OpScaledDotProductAttentionTest, CorrectnessTest_18) {
std::optional<executorch::aten::Tensor> attn_mask;
double dropout_p = 0.0;
bool is_causal = false;
std::optional<double> scale = std::optional<double>(-INFINITY);
double scale = -INFINITY;
executorch::aten::Tensor ret_expected = tfFloat.make(
{3, 2, 2, 6},
{NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN,
Expand Down Expand Up @@ -387,15 +386,14 @@ TEST(OpScaledDotProductAttentionTest, CorrectnessTest_19) {
15.25, 53.75, 44.625, -22.0, -84.0, -7.25, 22.0, 25.875,
17.625, -86.875, 22.75, -74.0, -79.875, -68.0, -71.125, -81.625,
-4.125, 65.875, 1.875, 76.125, -43.75, -15.25, -4.625, -66.125});
std::optional<executorch::aten::Tensor> attn_mask =
std::optional<executorch::aten::Tensor>(tfFloat.make(
executorch::aten::Tensor attn_mask = tfFloat.make(
{3, 1, 2, 2, 4},
{39.0, 49.375, -87.125, -99.125, 49.375, -41.125, 26.25, 79.75,
91.0, -3.125, 65.75, 63.5, -48.375, 43.375, 22.5, -53.625,
-70.0, 2.125, 21.875, 6.375, -6.375, 75.25, -35.875, 86.375,
71.5, -35.875, 19.75, 11.625, -87.25, 49.0, -6.0, 62.875,
7.125, 87.375, -14.75, 55.5, 59.125, 24.75, -66.5, 72.375,
2.25, 81.375, -87.125, 35.125, -39.125, 43.5, 52.875, 39.5}));
2.25, 81.375, -87.125, 35.125, -39.125, 43.5, 52.875, 39.5});
double dropout_p = 0.0;
bool is_causal = false;
std::optional<double> scale;
Expand Down Expand Up @@ -593,12 +591,10 @@ TEST(OpScaledDotProductAttentionTest, CorrectnessTest_51) {
executorch::aten::Tensor value = tfFloat.make(
{1, 1, 3, 3},
{70.375, 30.875, 72.125, 53.0, 39.125, -4.625, 26.5, 79.5, 88.625});
std::optional<executorch::aten::Tensor> attn_mask =
std::optional<executorch::aten::Tensor>(tfFloat.make(
{8, 3},
{-59.25, -26.25, -3.0, -24.125, 47.75, 92.375, 87.5, 21.5,
64.5, 45.0, -54.0, 17.375, -67.75, 14.625, 88.75, 36.0,
88.375, 25.75, 42.5, -13.375, -82.75, -59.625, -21.125, 6.5}));
executorch::aten::Tensor attn_mask = tfFloat.make(
{8, 3}, {-59.25, -26.25, -3.0, -24.125, 47.75, 92.375, 87.5, 21.5,
64.5, 45.0, -54.0, 17.375, -67.75, 14.625, 88.75, 36.0,
88.375, 25.75, 42.5, -13.375, -82.75, -59.625, -21.125, 6.5});
double dropout_p = 0.0;
bool is_causal = false;
std::optional<double> scale;
Expand Down
16 changes: 4 additions & 12 deletions kernels/portable/test/op_div_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ TEST_F(OpDivScalarOutKernelTest, SanityCheckModeTrunc) {
op_div_out_mode(
tf_a.make(sizes, {1, 2, 4, -9}),
tf_a.make(sizes, {2, 2, 2, 2}),
std::optional<std::string_view>("trunc"),
"trunc",
out);

// Check that it matches the expected output.
Expand All @@ -78,7 +78,7 @@ TEST_F(OpDivScalarOutKernelTest, SanityCheckModeFloor) {
op_div_out_mode(
tf_a.make(sizes, {1, 2, 4, -9}),
tf_a.make(sizes, {2, 2, 2, 2}),
std::optional<std::string_view>("floor"),
"floor",
out);

// Check that it matches the expected output.
Expand All @@ -92,11 +92,7 @@ TEST_F(OpDivScalarModeOutKernelTest, SanityCheckModeTrunc) {

Tensor out = tf.zeros(sizes);

op_div_scalar_mode_out(
tf.make(sizes, {1, 2, 4, -9}),
2,
std::optional<std::string_view>("trunc"),
out);
op_div_scalar_mode_out(tf.make(sizes, {1, 2, 4, -9}), 2, "trunc", out);

// Check that it matches the expected output.
EXPECT_TENSOR_EQ(out, tf.make(sizes, {0, 1, 2, -4}));
Expand All @@ -109,11 +105,7 @@ TEST_F(OpDivScalarModeOutKernelTest, SanityCheckModeFloor) {

Tensor out = tf.zeros(sizes);

op_div_scalar_mode_out(
tf.make(sizes, {1, 2, 4, -9}),
2,
std::optional<std::string_view>("floor"),
out);
op_div_scalar_mode_out(tf.make(sizes, {1, 2, 4, -9}), 2, "floor", out);

// Check that it matches the expected output.
EXPECT_TENSOR_EQ(out, tf.make(sizes, {0, 1, 2, -5}));
Expand Down
2 changes: 1 addition & 1 deletion kernels/test/op_avg_pool2d_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class OpAvgPool2DOutTest : public OperatorTest {
padding_vec.data(), padding_vec.size());
bool ceil_mode = false;
bool count_include_pad = true;
std::optional<int64_t> divisor_override = std::optional<int64_t>(10);
int64_t divisor_override = 10;
executorch::aten::Tensor out = tfFloat.zeros({2, 3, 3, 4});
executorch::aten::Tensor out_expected = tfFloat.make(
{2, 3, 3, 4},
Expand Down
16 changes: 8 additions & 8 deletions kernels/test/op_convolution_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ TEST_F(OpConvCorrectnessTest, GenericSmokeTest) {
op_convolution_out(
input,
weight,
std::optional<Tensor>(bias),
bias,
executorch::aten::ArrayRef<int64_t>{stride, 1},
executorch::aten::ArrayRef<int64_t>{padding, 1},
executorch::aten::ArrayRef<int64_t>{dilation, 1},
Expand Down Expand Up @@ -493,7 +493,7 @@ TEST_F(OpConvCorrectnessTest, InvalidInputShape) {
op_convolution_out(
input,
weight,
std::optional<Tensor>(bias),
bias,
executorch::aten::ArrayRef<int64_t>{stride, 1},
executorch::aten::ArrayRef<int64_t>{padding, 1},
executorch::aten::ArrayRef<int64_t>{dilation, 1},
Expand All @@ -507,7 +507,7 @@ TEST_F(OpConvCorrectnessTest, InvalidInputShape) {
op_convolution_out(
input,
weight,
std::optional<Tensor>(bias),
bias,
executorch::aten::ArrayRef<int64_t>{stride, 1},
executorch::aten::ArrayRef<int64_t>{padding, 1},
executorch::aten::ArrayRef<int64_t>{dilation, 1},
Expand Down Expand Up @@ -539,7 +539,7 @@ TEST_F(OpConvCorrectnessTest, TransposedDefaultParams) {
op_convolution_out(
input,
weight,
std::optional<Tensor>(bias),
bias,
executorch::aten::ArrayRef<int64_t>{stride, 1},
executorch::aten::ArrayRef<int64_t>{padding, 1},
executorch::aten::ArrayRef<int64_t>{dilation, 1},
Expand Down Expand Up @@ -576,7 +576,7 @@ TEST_F(OpConvCorrectnessTest, TransposedNonDefaultParams) {
op_convolution_out(
input,
weight,
std::optional<Tensor>(bias),
bias,
executorch::aten::ArrayRef<int64_t>{stride, 1},
executorch::aten::ArrayRef<int64_t>{padding, 1},
executorch::aten::ArrayRef<int64_t>{dilation, 1},
Expand Down Expand Up @@ -644,7 +644,7 @@ TEST_F(OpConvCorrectnessTest, TransposedDefaultParamsChannelsLast) {
op_convolution_out(
input,
weight,
std::optional<Tensor>(bias),
bias,
executorch::aten::ArrayRef<int64_t>{stride, 1},
executorch::aten::ArrayRef<int64_t>{padding, 1},
executorch::aten::ArrayRef<int64_t>{dilation, 1},
Expand Down Expand Up @@ -688,7 +688,7 @@ TEST_F(OpConvCorrectnessTest, TransposedNonDefaultParamsChannelsLast) {
op_convolution_out(
input,
weight,
std::optional<Tensor>(bias),
bias,
executorch::aten::ArrayRef<int64_t>{stride, 1},
executorch::aten::ArrayRef<int64_t>{padding, 1},
executorch::aten::ArrayRef<int64_t>{dilation, 1},
Expand Down Expand Up @@ -720,7 +720,7 @@ TEST_F(OpConvCorrectnessTest, InvalidOutputPadding) {
op_convolution_out(
input,
weight,
std::optional<Tensor>(bias),
bias,
executorch::aten::ArrayRef<int64_t>{stride, 1},
executorch::aten::ArrayRef<int64_t>{padding, 1},
executorch::aten::ArrayRef<int64_t>{dilation, 1},
Expand Down
Loading
Loading