From 542c8765a17a431b071617fcd6bfcde40f81c7fa Mon Sep 17 00:00:00 2001 From: "Jason Ansel (Meta Employee)" Date: Mon, 12 Feb 2024 10:45:04 -0800 Subject: [PATCH] Improve support for backwards hooks (#119525) Summary: X-link: https://github.com/pytorch/pytorch/pull/119525 Approved by: https://github.com/yanboliang, https://github.com/anijain2305 Reviewed By: huydhn Differential Revision: D53634801 Pulled By: jansel fbshipit-source-id: d18819e331cd408f099ef5101cdbe9bc3d1ae172 --- userbenchmark/dynamo/dynamobench/_dynamo/utils.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/userbenchmark/dynamo/dynamobench/_dynamo/utils.py b/userbenchmark/dynamo/dynamobench/_dynamo/utils.py index 62bc8bfc4e..b8461bc084 100644 --- a/userbenchmark/dynamo/dynamobench/_dynamo/utils.py +++ b/userbenchmark/dynamo/dynamobench/_dynamo/utils.py @@ -50,6 +50,7 @@ ValuesView, ) +from ..utils.hooks import RemovableHandle try: import numpy as np @@ -2494,3 +2495,11 @@ def inner_compiler(gm_, example_inputs_): yield ctx else: yield + + +def invalid_removeable_handle(): + # need a subclass so weakref works + class Invalid(dict): # type: ignore[type-arg] + pass + + return RemovableHandle(Invalid())