From 5c67b1e6c88f0b4553a09b6b63699b6885091111 Mon Sep 17 00:00:00 2001 From: NikhilAPatel Date: Thu, 23 Apr 2026 08:09:58 -0700 Subject: [PATCH] [Inductor] Fix flaky epilogue fusion tests by adding missing tearDownClass (#180736) TestPrologueFusion and TestEpilogueFusionStaticAnalysis both use ExitStack in setUpClass to apply config.patch(), but neither defined tearDownClass to close the stack. When TestPrologueFusion runs before TestEpilogueFusionStaticAnalysis in the same process, config values like max_autotune_gemm_backends="TRITON" leak through, removing the aten kernel choice from autotuning and causing test failures. Fixes #179693 Pull Request resolved: https://github.com/pytorch/pytorch/pull/180736 Approved by: https://github.com/Skylion007 --- test/inductor/test_max_autotune.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/inductor/test_max_autotune.py b/test/inductor/test_max_autotune.py index f5339774368d9..58f1ae439abdf 100644 --- a/test/inductor/test_max_autotune.py +++ b/test/inductor/test_max_autotune.py @@ -4149,6 +4149,11 @@ def setUpClass(cls): ) ) + @classmethod + def tearDownClass(cls): + cls._stack.close() + super().tearDownClass() + def check_code(self, code_str, num_kernels, num_allocs, num_deallocs): FileCheck().check(get_func_call()).check_count( get_kernel_launch(), @@ -4642,6 +4647,11 @@ def setUpClass(cls): ) ) + @classmethod + def tearDownClass(cls): + cls._stack.close() + super().tearDownClass() + @contextlib.contextmanager def get_common_patches( self,