From 08b14936aea7f33f36e7eb3bc77e8064ec3de3ee Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Mon, 3 Feb 2025 03:22:35 +0000 Subject: [PATCH] Disable has_relational_guards check for dict_tag optimization for now (#146232) has_relational_guards evaluates to true almost always, and leads to a slowdown in guards runtime Pull Request resolved: https://github.com/pytorch/pytorch/pull/146232 Approved by: https://github.com/anijain2305 --- torch/csrc/dynamo/guards.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/torch/csrc/dynamo/guards.cpp b/torch/csrc/dynamo/guards.cpp index b080ffe75c4..36b7c8a2de6 100644 --- a/torch/csrc/dynamo/guards.cpp +++ b/torch/csrc/dynamo/guards.cpp @@ -2277,8 +2277,6 @@ class GuardManager { return _root; } - bool has_relational_guards(); - std::string get_source() { return _source; } @@ -2411,7 +2409,7 @@ class GuardManager { // to avoid early exits when dict_tag matches and the object is // immutable. new_tag = get_dict_version_unchecked(value); - matches_dict_tag = (new_tag == _dict_tag) && !has_relational_guards(); + matches_dict_tag = (new_tag == _dict_tag); } } @@ -2634,10 +2632,6 @@ class RootGuardManager : public GuardManager { _relational_guard_resetters.emplace_back(std::move(relational_guard)); } - bool has_relational_guards() { - return !_relational_guard_resetters.empty(); - } - // Python visible API to check guard function. bool check(py::handle value) { return check_nopybind(value.ptr()); @@ -2854,9 +2848,6 @@ class RootGuardManager : public GuardManager { bool _init_local_state = false; }; -bool GuardManager::has_relational_guards() { - return _root->has_relational_guards(); -} /* * Dicts are common in python code. Therefore, we handle guards for dicts * differently and use PyDict_* APIs which are faster than PyObject_* APIs