|
1 | | -# Copyright (c) Samsung Electronics Co. LTD |
| 1 | +# Copyright (c) 2025 Samsung Electronics Co. LTD |
2 | 2 | # All rights reserved |
3 | 3 | # |
4 | 4 | # Licensed under the BSD License (the "License"); you may not use this file |
|
13 | 13 | gen_samsung_backend_compile_spec, |
14 | 14 | ) |
15 | 15 | from executorch.backends.samsung.test.tester import SamsungTester |
| 16 | +from executorch.backends.samsung.test.utils.datasets import get_quant_test_data_classify |
| 17 | +from executorch.backends.samsung.test.utils.quant_checkers import CheckerConfig |
16 | 18 | from executorch.backends.samsung.test.utils.utils import TestConfig |
17 | 19 | from executorch.examples.models.inception_v4 import InceptionV4Model |
| 20 | +from torchvision import transforms |
18 | 21 |
|
19 | 22 |
|
20 | 23 | def patch_iv4(weight_path: str): |
@@ -66,3 +69,36 @@ def test_inception_v4_fp16(self): |
66 | 69 | .to_executorch() |
67 | 70 | .run_method_and_compare_outputs(inputs=example_input, atol=0.02, rtol=0.02) |
68 | 71 | ) |
| 72 | + |
| 73 | + def test_inception_v4_a8w8(self): |
| 74 | + transform_compose = transforms.Compose( |
| 75 | + [ |
| 76 | + transforms.Resize((299, 299)), |
| 77 | + transforms.ToTensor(), |
| 78 | + transforms.Normalize( |
| 79 | + mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225] |
| 80 | + ), |
| 81 | + transforms.Lambda(lambda x: x.unsqueeze(0)), # Add batch dim |
| 82 | + ] |
| 83 | + ) |
| 84 | + example_input, cali, testdata = get_quant_test_data_classify( |
| 85 | + os.path.join(os.environ["DATASET_PATH"], "imagenet_ptq_subset"), |
| 86 | + transform_compose=transform_compose, |
| 87 | + ) |
| 88 | + checker_config = CheckerConfig( |
| 89 | + "classifier", |
| 90 | + { |
| 91 | + "dataset": testdata, |
| 92 | + }, |
| 93 | + ) |
| 94 | + model = InceptionV4Model().get_eager_model() |
| 95 | + tester = SamsungTester( |
| 96 | + model, example_input, [gen_samsung_backend_compile_spec(TestConfig.chipset)] |
| 97 | + ) |
| 98 | + ( |
| 99 | + tester.quantize(cali_dataset=cali, checker_config=checker_config) |
| 100 | + .export() |
| 101 | + .to_edge_transform_and_lower() |
| 102 | + .to_executorch() |
| 103 | + .run_method_and_compare_outputs(inputs=example_input, atol=1, rtol=1) |
| 104 | + ) |
0 commit comments