Skip to content

Commit

Permalink
[Functorch] Don't try to setup docs if called with optimize
Browse files Browse the repository at this point in the history
Test plan: `python3 -OO -c "import torch._functorch.deprecated"`
  • Loading branch information
malfet committed May 5, 2023
1 parent 2653334 commit 6a9ba3f
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions torch/_functorch/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import textwrap
from typing import Any, Callable, Optional, Tuple, Union
import warnings
import sys

"""
The APIs in this file are exposed as `functorch.*`. They are thin wrappers
Expand Down Expand Up @@ -105,18 +106,20 @@ def combine_state_for_ensemble(models):
warn_deprecated('combine_state_for_ensemble', 'torch.func.stack_module_state')
return _nn_impl.combine_state_for_ensemble(models)

setup_docs(vmap, _vmap_impl.vmap, 'torch.vmap')
setup_docs(grad)
setup_docs(grad_and_value)
setup_docs(vjp)
setup_docs(jvp)
setup_docs(jacrev)
setup_docs(jacfwd)
setup_docs(hessian)
setup_docs(functionalize)
setup_docs(make_functional, _nn_impl.make_functional,
'torch.func.functional_call')
setup_docs(make_functional_with_buffers, _nn_impl.make_functional,
'torch.func.functional_call')
setup_docs(combine_state_for_ensemble, _nn_impl.combine_state_for_ensemble,
'torch.func.stack_module_state')
if sys.flags.optimize < 2:
setup_docs(vmap, _vmap_impl.vmap, 'torch.vmap')
setup_docs(grad)
setup_docs(grad_and_value)
setup_docs(vjp)
setup_docs(jvp)
setup_docs(jacrev)
setup_docs(jacfwd)
setup_docs(hessian)
setup_docs(functionalize)
setup_docs(make_functional, _nn_impl.make_functional,
'torch.func.functional_call')
setup_docs(make_functional_with_buffers, _nn_impl.make_functional,
'torch.func.functional_call')
setup_docs(combine_state_for_ensemble, _nn_impl.combine_state_for_ensemble,
'torch.func.stack_module_state')

0 comments on commit 6a9ba3f

Please sign in to comment.