Skip to content

Commit b57b75f

Browse files
authored
[ET-VK][testing] Fix qdq8ta_conv2d_activations test failures via configurable shader filtering (pytorch#16410)
The qdq8ta_conv2d_activations correctness tests were failing because the GPU timing collection function was filtering out quantize_and_pack_4w4c and unpack_4w4c_and_dequantize shaders from timing measurements. For these tests, these shaders ARE the operations being tested, not overhead. This change refactors shader filtering to be configurable per test case: - Added shader_filter member to TestCase class with getter/setter methods - Created kDefaultShaderFilter (filters layout conversions + quantization) for backward compatibility - Created kLayoutOnlyShaderFilter (filters only layout conversions) for tests where quantization is the primary operation - Updated collect_gpu_timing_us() to accept shader_filter parameter - Updated qdq8ta_conv2d_activations to use kLayoutOnlyShaderFilter This allows tests to control what shaders are excluded from timing measurements based on what they're actually testing, while maintaining backward compatibility for all existing tests. Differential Revision: [D89832383](https://our.internmc.facebook.com/intern/diff/D89832383/)
1 parent 75d26cf commit b57b75f

3 files changed

Lines changed: 59 additions & 11 deletions

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ TestCase create_test_case_from_config(
8282

8383
test_case.set_abs_tolerance(scale_val + 1e-4);
8484

85+
// Use layout-only filter for this test since quantize/dequantize ARE the
86+
// operations being tested, not overhead
87+
test_case.set_shader_filter(kLayoutOnlyShaderFilter);
88+
8589
return test_case;
8690
}
8791

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -653,19 +653,27 @@ bool ValueSpec::validate_against_reference(
653653
}
654654

655655
// Helper function to collect GPU timing from querypool
656-
float collect_gpu_timing_us(ComputeGraph& graph) {
656+
float collect_gpu_timing_us(
657+
ComputeGraph& graph,
658+
const std::vector<std::string>& shader_filter) {
657659
graph.context()->querypool().extract_results();
658660
const auto results = graph.context()->querypool().get_shader_timestamp_data();
659661
if (!results.empty()) {
660-
// Sum durations of all shaders that don't contain nchw_to or to_nchw
662+
// Sum durations of all shaders that don't match any pattern in
663+
// shader_filter
661664
float total_duration_us = 0.0f;
662665
for (const auto& shader_result : results) {
663-
if (shader_result.kernel_name.find("nchw_to") == std::string::npos &&
664-
shader_result.kernel_name.find("to_nchw") == std::string::npos &&
665-
shader_result.kernel_name.find("quantize_and_pack_4w4c") ==
666-
std::string::npos &&
667-
shader_result.kernel_name.find("unpack_4w4c_and_dequantize") ==
668-
std::string::npos) {
666+
bool filtered = false;
667+
// Check if this shader matches any filter pattern
668+
for (const auto& filter_pattern : shader_filter) {
669+
if (shader_result.kernel_name.find(filter_pattern) !=
670+
std::string::npos) {
671+
filtered = true;
672+
break;
673+
}
674+
}
675+
676+
if (!filtered) {
669677
// Calculate duration from start and end times, convert from ns to μs
670678
uint64_t duration_ns =
671679
shader_result.end_time_ns - shader_result.start_time_ns;
@@ -1192,7 +1200,8 @@ execute_test_case(TestCase& test_case, int warmup_runs, int benchmark_runs) {
11921200
total_cpu_time_us += cpu_time_us;
11931201

11941202
// Collect GPU timing using helper function
1195-
float gpu_time_us = collect_gpu_timing_us(graph);
1203+
float gpu_time_us =
1204+
collect_gpu_timing_us(graph, test_case.get_shader_filter());
11961205
total_gpu_time_us += gpu_time_us;
11971206

11981207
// Add the appropriate timing based on the flag

‎backends/vulkan/test/custom_ops/utils.h‎

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,24 @@ void set_use_gpu_timestamps(bool use_timestamps);
3939
bool debugging();
4040
void set_debugging(bool enable_debugging);
4141

42+
//
43+
// Shader filter defaults
44+
//
45+
46+
// Default shader filter: excludes layout conversions and quantization overhead
47+
// This is used for tests where quantize/dequantize are overhead operations
48+
inline const std::vector<std::string> kDefaultShaderFilter = {
49+
"nchw_to",
50+
"to_nchw",
51+
"quantize_and_pack_4w4c",
52+
"unpack_4w4c_and_dequantize"};
53+
54+
// Layout-only filter: only excludes layout conversions
55+
// Use this for tests where quantize/dequantize ARE the operations being tested
56+
inline const std::vector<std::string> kLayoutOnlyShaderFilter = {
57+
"nchw_to",
58+
"to_nchw"};
59+
4260
//
4361
// ValueSpec class
4462
//
@@ -332,9 +350,15 @@ struct ValueSpec {
332350

333351
class TestCase {
334352
public:
335-
TestCase() : abs_tolerance_(2e-3f), rel_tolerance_(1e-3f) {}
353+
TestCase()
354+
: abs_tolerance_(2e-3f),
355+
rel_tolerance_(1e-3f),
356+
shader_filter_(kDefaultShaderFilter) {}
336357
TestCase(const std::string& name)
337-
: name_(name), abs_tolerance_(2e-3f), rel_tolerance_(1e-3f) {}
358+
: name_(name),
359+
abs_tolerance_(2e-3f),
360+
rel_tolerance_(1e-3f),
361+
shader_filter_(kDefaultShaderFilter) {}
338362

339363
void set_name(const std::string& name) {
340364
name_ = name;
@@ -365,6 +389,15 @@ class TestCase {
365389
return rel_tolerance_;
366390
}
367391

392+
// Shader filter settings - list of shader name patterns to exclude from
393+
// timing
394+
void set_shader_filter(const std::vector<std::string>& filter) {
395+
shader_filter_ = filter;
396+
}
397+
const std::vector<std::string>& get_shader_filter() const {
398+
return shader_filter_;
399+
}
400+
368401
void add_input_spec(const ValueSpec& spec) {
369402
inputs_.push_back(spec);
370403
}
@@ -407,6 +440,7 @@ class TestCase {
407440
operator_name_.clear();
408441
abs_tolerance_ = 2e-3f;
409442
rel_tolerance_ = 1e-3f;
443+
shader_filter_ = kDefaultShaderFilter;
410444
}
411445

412446
private:
@@ -416,6 +450,7 @@ class TestCase {
416450
std::vector<ValueSpec> outputs_;
417451
float abs_tolerance_;
418452
float rel_tolerance_;
453+
std::vector<std::string> shader_filter_;
419454
};
420455

421456
//

0 commit comments

Comments
 (0)