Skip to content

Commit 276dfe8

Browse files
anijain2305pytorchmergebot
authored andcommitted
[dynamo][cpp-guards] Disable dict-tag optim if the guard_manager has child accessors (pytorch#147694)
Pull Request resolved: pytorch#147694 Approved by: https://github.com/isuruf
1 parent 8e7e5ba commit 276dfe8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

torch/csrc/dynamo/guards.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2535,6 +2535,10 @@ class GuardManager {
25352535
return GuardDebugInfo(true, num_guards_executed);
25362536
}
25372537

2538+
bool has_no_accessors() {
2539+
return _accessors.empty();
2540+
}
2541+
25382542
int64_t fail_count() const {
25392543
return _fail_count;
25402544
}
@@ -3780,8 +3784,12 @@ class DictGetItemGuardAccessor : public GuardAccessor {
37803784
// NB: Intentional duplication between check_nopybind and
37813785
// check_verbose_nopybind.
37823786
bool check_nopybind(PyObject* obj, bool matches_dict_tag = false) override {
3783-
if (matches_dict_tag && _is_immutable_object) {
3787+
if (matches_dict_tag && _is_immutable_object &&
3788+
_guard_manager->has_no_accessors()) {
37843789
// immutable object and dict tag matches, we can skip the guard subtree.
3790+
// NB: We only skip the subtree if there are no accessors in the subtree.
3791+
// This is specificallly for tensors which are used in symbolic shape C++
3792+
// guards, and therefore have accessors on the tensor GuardManager itself.
37853793
return true;
37863794
}
37873795

0 commit comments

Comments
 (0)