pytorch
8747e4c8 - [dynamo] Add specialized variable tracker for sys.modules (#110990)

Commit
1 year ago
[dynamo] Add specialized variable tracker for sys.modules (#110990) `sys.modules` is currently treated as a constant dictionary and any reference to it will result in guards on the full contents of `sys.modules`. This instead adds a specialized variable tracker which tries to guard only on the modules referenced by the code. e.g. ``` sys.modules["operator"].add(x, x) ``` will generate the guard ``` ___dict_contains('operator', G['sys'].modules) ``` It does this with special support for `__contains__` `__getitem__` and `.get` which are probably the most commonly used with `sys.modules`. For anything else we just fall back to building the dict tracker as normal. While accessing `sys.modules` may seem unusual, it actually comes up when inlining the `warnings.catch_warnings` context manager which internally accesses `sys.modules["warnings"]`. Pull Request resolved: https://github.com/pytorch/pytorch/pull/110990 Approved by: https://github.com/ezyang
Author
Committer
Parents
Loading