Skip to content

Commit

Permalink
[Functorch] Skip docs setup if called in optimize mode (#100750)
Browse files Browse the repository at this point in the history
Test plan: `python3 -OO -c "import torch._functorch.deprecated"`

Fixes #100680

Pull Request resolved: #100750
Approved by: https://github.com/albanD
  • Loading branch information
malfet authored and pytorchmergebot committed May 8, 2023
1 parent 16a4075 commit 660a0d8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 2 additions & 4 deletions test/test_stateless.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,12 +887,10 @@ def test_stateless_functional_call_warns(self):

class TestPythonOptimizeMode(TestCase):
def test_runs_with_optimize_flag(self):
script = """
import torch
"""
script = "import torch; import torch._functorch.deprecated"
try:
subprocess.check_output(
[sys.executable, '-OO', '-c', script],
[sys.executable, "-OO", "-c", script],
stderr=subprocess.STDOUT,
# On Windows, opening the subprocess with the default CWD makes `import torch`
# fail, so just set CWD to this script's directory
Expand Down
3 changes: 3 additions & 0 deletions torch/_functorch/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ def setup_docs(functorch_api, torch_func_api=None, new_api_name=None):
api_name = functorch_api.__name__
if torch_func_api is None:
torch_func_api = getattr(_impl, api_name)
# See https://docs.python.org/3/using/cmdline.html#cmdoption-OO
if torch_func_api.__doc__ is None:
return

warning = get_warning(api_name, new_api_name)
warning_note = "\n.. warning::\n\n" + textwrap.indent(warning, " ")
Expand Down

0 comments on commit 660a0d8

Please sign in to comment.