importtorch._functorch.vmapas_vmap_implimporttorch._functorch.eager_transformsas_implimporttorch._functorch.make_functionalas_nn_implfromtorch._functorch.vmapimportin_dims_t,out_dims_tfromtorch._functorch.eager_transformsimportargnums_timporttorch.nnasnnimporttextwrapfromtypingimportAny,Callable,Optional,Tuple,Unionimportwarnings"""The APIs in this file are exposed as `functorch.*`. They are thin wrappersaround the torch.func.* APIs that have deprecation warnings -- we're tryingto move people to the torch.func.* equivalents.NB: We don't use *args, **kwargs in the signatures because that changes thedocumentation."""defget_warning(api,new_api=None,replace_newlines=False):ifnew_apiisNone:new_api=f'torch.func.{api}'warning=(f"We've integrated functorch into PyTorch. As the final step of the \n"f"integration, functorch.{api} is deprecated as of PyTorch \n"f"2.0 and will be deleted in a future version of PyTorch >= 2.3. \n"f"Please use {new_api} instead; see the PyTorch 2.0 release notes \n"f"and/or the torch.func migration guide for more details \n"f"https://pytorch.org/docs/master/func.migrating.html")ifreplace_newlines:warning=warning.replace("\n","")returnwarningdefwarn_deprecated(api,new_api=None):warning=get_warning(api,new_api,replace_newlines=True)warnings.warn(warning,stacklevel=2)defsetup_docs(functorch_api,torch_func_api=None,new_api_name=None):api_name=functorch_api.__name__iftorch_func_apiisNone:torch_func_api=getattr(_impl,api_name)warning=get_warning(api_name,new_api_name)warning_note="\n.. warning::\n\n"+textwrap.indent(warning," ")warning_note=textwrap.indent(warning_note," ")functorch_api.__doc__=torch_func_api.__doc__+warning_note
To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.