Enable rcb lookup for typing (#60413)

Summary:
-----------

For FX traced models, types from typing modules are not available during the lookup for the function to be traced. Because of which the resolving the type results to a None type object. By enabling lookup for `typing` module in `_jit_internal.py`, we can mitigate this issue with FX_Tracing and scripting.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/60413

Test Plan:
--------
with-proxy python test/test_jit.py -k TestPDT.test_fx_tracing_with_typing

Reviewed By: bhosmer

Differential Revision: D29314531

Pulled By: nikithamalgifb

fbshipit-source-id: 1aa651430b1074c7e6fa74ba02bbcc4e1b00b01b
This commit is contained in:
nikithamalgi
2021-06-22 18:52:02 -07:00
committed by Facebook GitHub Bot
parent 135e203e5e
commit 7589d9c58b
2 changed files with 18 additions and 1 deletions

View File

@ -15,6 +15,7 @@ from textwrap import dedent
import torch
import sys
import builtins
import typing
import io
import pickle
import functools
@ -222,6 +223,8 @@ def createResolutionCallbackFromClosure(fn):
def __getattr__(self, key):
if key in closure:
return closure[key]
elif hasattr(typing, key):
return getattr(typing, key)
elif hasattr(builtins, key):
return getattr(builtins, key)
return None