@@ -263,58 +263,3 @@ def mul_translator(a, b, c=None, *, fd, lc_to_nv_map):
263263 if bsym.sym.name == f"{_symbol.name}_backward" and bsym.sym.executor is custom_op_ex:
264264 bsym_custom_ex_bsym_found = True
265265 assert bsym_custom_ex_bsym_found
266-
267-
268- def test_custom_op_executor_cleanup():
269- """Test that custom_op executor is properly removed from default executors after deregistration.
270-
271- This is a regression test for the issue where the custom_op executor would remain in the
272- default executors list after all custom ops were deregistered, causing failures in tests
273- that check the expected executor list.
274-
275- The original issue manifested when running test_recipes.py after test_torch_library_custom_op.py.
276- The test_recipes tests use get_expected_executors() which filters thunder.get_default_executors(),
277- and they expect that only executors actually used by the model are present. When custom_op
278- executor wasn't properly cleaned up, it would remain in the default executors list even though
279- no custom ops were registered, causing assertions like:
280- assert ex.name in [el.name for el in cd.executors_list]
281- to fail because 'custom_op' was in get_expected_executors() but not in cd.executors_list.
282- """
283- import thunder
284-
285- # Define a test custom op
286- @torch.library.custom_op("test_cleanup::mul", mutates_args=())
287- def cleanup_mul(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:
288- return a * b
289-
290- @torch.library.register_kernel("test_cleanup::mul", "cpu")
291- def _(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:
292- return a * b
293-
294- @torch.library.register_fake("test_cleanup::mul")
295- def _(a: torch.Tensor, b: torch.Tensor) -> torch.Tensor:
296- return torch.empty_like(a)
297-
298- # Get initial state (custom_op should not be in default executors)
299- initial_executors = [ex.name for ex in thunder.get_default_executors()]
300- assert "custom_op" not in initial_executors, "custom_op should not be in default executors initially"
301-
302- # Simulate what happens in test_torch_library_custom_op tests
303- # Register the custom op (this adds custom_op_ex to default executors)
304- symbol = _register_custom_op(cleanup_mul)
305- executors_after_register = [ex.name for ex in thunder.get_default_executors()]
306- assert "custom_op" in executors_after_register, "custom_op should be added after registration"
307-
308- # Simulate the cleanup that happens in the autouse fixture
309- # Without the fix, this would NOT remove custom_op_ex from default executors
310- _deregister_custom_op(cleanup_mul)
311- executors_after_deregister = [ex.name for ex in thunder.get_default_executors()]
312-
313- # This is the critical assertion that would fail with the bug:
314- # After deregistration, custom_op should be removed from default executors
315- assert "custom_op" not in executors_after_deregister, \
316- "custom_op should be removed from default executors when no custom ops remain"
317-
318- # Verify we're back to the initial state, which is what test_recipes.py expects
319- assert executors_after_deregister == initial_executors, \
320- "Should return to initial executor state after deregistration"
0 commit comments