René's URL Explorer Experiment


Title: Custom Autograd Functions — PyTorch main documentation

Description: Custom autograd functions in PyTorch C++ — defining forward and backward passes with torch::autograd::Function.

Keywords:

direct link

Domain: docs.pytorch.org


Hey, it has json ld scripts:
    {
       "@context": "https://schema.org",
       "@type": "Article",
       "name": "Custom Autograd Functions",
       "headline": "Custom Autograd Functions",
       "description": "Custom autograd functions in PyTorch C++ \u2014 defining forward and backward passes with torch::autograd::Function.",
       "url": "/api/autograd/custom_functions.html",
       "articleBody": "Custom Autograd Functions# PyTorch allows you to define custom autograd functions with custom forward and backward implementations. Function Base Class# template\u003cclass T\u003estruct Function# To use custom autograd operations, implement a Function subclass with static forward and backward functions: forward can take as many arguments as you want and should return either a variable list or a Variable. Use of any direct Variable arguments will be registered in the graph but no vectors/sets or any other data structures will be traversed. You can use std::optional\u003cTensor\u003e as one of the arguments and it will be registered as a variable in the graph if the argument has a value. It should take a pointer to torch::autograd::AutogradContext as the first argument. Variables can be saved in the ctx using ctx-\u003esave_for_backward (see torch::autograd::AutogradContext::save_for_backward) and other data can be saved in the ctx-\u003esaved_data map (see torch::autograd::AutogradContext::saved_data) in the form of \u003cstd::string, at::IValue\u003e pairs. backward should take a pointer to torch::autograd::AutogradContext and a variable list containing as many Variables as there were outputs from forward as arguments. It should return as many Variables as there were inputs with each of them containing the gradient w.r.t. its corresponding input. Variables saved in forward can be accessed with ctx-\u003eget_saved_variables (see torch::autograd::AutogradContext::get_saved_variables) and other saved data can be accessed from ctx-\u003esaved_data. To enable compiled autograd support (torch.compile for backward) for your custom autograd operation, you can set MyFunction::is_traceable (see Function::istraceable notes below). For example: class MyFunction : public Function\u003cMyFunction\u003e { public: static constexpr bool is_traceable = true; static variable_list forward(AutogradContext *ctx, int n, Variable var) { // Save data for backward in context ctx-\u003esaved_data[\"n\"] = n; var.mul_(n); // Mark var as modified by inplace operation ctx-\u003emark_dirty({var}); return {var}; } static variable_list backward(AutogradContext *ctx, variable_list grad_output) { // Use data saved in forward auto n = ctx-\u003esaved_data[\"n\"].toInt(); return {grad_output[0]*n}; } }; To use MyFunction: Variable x; auto y = MyFunction::apply(6, x); // Example backward call y[0].sum().backward(); Public Static Functions template\u003ctypename X = T, typename ...Args\u003estatic auto apply(Args\u0026\u0026... args) -\u003e std::enable_if_t\u003cstd::is_same_v\u003cX, T\u003e, forward_t\u003cX, Args...\u003e\u003e# Public Static Attributes static constexpr bool is_traceable = false# AutogradContext# struct AutogradContext# Context to save information during forward that can be accessed in backward in custom autograd operations (see torch::autograd::Function for details). Public Functions AutogradContext() = default# AutogradContext(const AutogradContext \u0026other) = delete# AutogradContext \u0026operator=(const AutogradContext \u0026other) = delete# AutogradContext(AutogradContext \u0026\u0026other) = delete# AutogradContext \u0026operator=(AutogradContext \u0026\u0026other) = delete# ~AutogradContext() = default# AutogradContext(PackedArgs \u0026packed_args)# void save_for_backward(variable_list to_save)# Saves the list of variables for a future call to backward. This should be called at most once from inside of forward. void mark_dirty(const variable_list \u0026inputs)# Marks variables in the list as modified in an in-place operation. This should be called at most once from inside of forward and all arguments should be inputs. void mark_non_differentiable(const variable_list \u0026outputs)# Marks outputs in the list as not requiring gradients. This should be called at most once from inside of forward and all arguments should be outputs. void set_materialize_grads(bool value)# variable_list get_saved_variables() const# Get the list of variables that were saved in forward using save_for_backward(). Before returning them to the user, a check is made to ensure that they were not modified by any in-place operations. const std::unordered_set\u003cat::TensorImpl*\u003e \u0026get_and_bump_dirty() const# const std::unordered_set\u003cat::TensorImpl*\u003e \u0026get_non_differentiable() const# bool needs_input_grad(size_t output_edge_index) const# Expose the Node\u2019s task_should_compute_output method to the cpp custom autograd Function as needs_input_grad. bool needs_input_grad(std::initializer_list\u003cIndexRange\u003e idxs) const# Public Members ska::flat_hash_map\u003cstd::string, at::IValue\u003e saved_data# Can be used to save non-variable data for backward. Creating Custom Functions# To create a custom autograd function, inherit from torch::autograd::Function and implement the static forward and backward methods: Example: class MyReLU : public torch::autograd::Function\u003cMyReLU\u003e { public: static torch::Tensor forward( torch::autograd::AutogradContext* ctx, torch::Tensor input) { ctx-\u003esave_for_backward({input}); return input.clamp_min(0); } static torch::autograd::variable_list backward( torch::autograd::AutogradContext* ctx, torch::autograd::variable_list grad_outputs) { auto saved = ctx-\u003eget_saved_variables(); auto input = saved[0]; auto grad_output = grad_outputs[0]; auto grad_input = grad_output * (input \u003e 0).to(grad_output.dtype()); return {grad_input}; } }; // Usage auto output = MyReLU::apply(input); Custom Kernels and AutoDispatchBelowADInplaceOrView# For users implementing custom kernels who want to redispatch below Autograd dispatch keys, use at::AutoDispatchBelowADInplaceOrView instead of InferenceMode: class ROIAlignFunction : public torch::autograd::Function\u003cROIAlignFunction\u003e { public: static torch::autograd::variable_list forward( torch::autograd::AutogradContext* ctx, const torch::autograd::Variable\u0026 input, const torch::autograd::Variable\u0026 rois, double spatial_scale, int64_t pooled_height, int64_t pooled_width, int64_t sampling_ratio, bool aligned) { ctx-\u003esaved_data[\"spatial_scale\"] = spatial_scale; ctx-\u003esaved_data[\"pooled_height\"] = pooled_height; ctx-\u003esaved_data[\"pooled_width\"] = pooled_width; ctx-\u003esaved_data[\"sampling_ratio\"] = sampling_ratio; ctx-\u003esaved_data[\"aligned\"] = aligned; ctx-\u003esaved_data[\"input_shape\"] = input.sizes(); ctx-\u003esave_for_backward({rois}); at::AutoDispatchBelowADInplaceOrView guard; auto result = roi_align( input, rois, spatial_scale, pooled_height, pooled_width, sampling_ratio, aligned); return {result}; } }; For customized inplace and view kernels, see the custom kernel tutorial for more details.",
       "author": {
         "@type": "Organization",
         "name": "PyTorch Contributors",
         "url": "https://pytorch.org"
       },
       "image": "https://pytorch.org/docs/stable/_static/img/pytorch_seo.png",
       "mainEntityOfPage": {
         "@type": "WebPage",
         "@id": "/api/autograd/custom_functions.html"
       },
       "datePublished": "2023-01-01T00:00:00Z",
       "dateModified": "2023-01-01T00:00:00Z"
     }
 

docsearch:languageen
llm:site-typedocumentation
llm:frameworkPyTorch
llm:descriptionCustom autograd functions in PyTorch C++ — defining forward and backward passes with torch::autograd::Function.
llm:navigation-filehttps://pytorch.org/docs/stable/llms.txt
llm:sitemaphttps://pytorch.org/docs/stable/sitemap.xml
llm:versionmain
llm:projectPyTorch
llm:page-typedocumentation
og:imagehttps://docs.pytorch.org/docs/stable/_static/img/pytorch_seo.png
None3

Links:

Skip to main contenthttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#main-content
Home https://docs.pytorch.org/cppdocs/index.html
mainhttps://docs.pytorch.org/cppdocs/index.html
Installing C++ Distributions of PyTorch https://docs.pytorch.org/cppdocs/installing.html
The C++ Frontend https://docs.pytorch.org/cppdocs/frontend.html
C++ API Reference https://docs.pytorch.org/cppdocs/api/index.html
ATen: Tensor Library https://docs.pytorch.org/cppdocs/api/aten/index.html
C10: Core Utilities https://docs.pytorch.org/cppdocs/api/c10/index.html
Autograd: Automatic Differentiation https://docs.pytorch.org/cppdocs/api/autograd/index.html
CUDA Support https://docs.pytorch.org/cppdocs/api/cuda/index.html
XPU Support https://docs.pytorch.org/cppdocs/api/xpu/index.html
Neural Network Modules (torch::nn) https://docs.pytorch.org/cppdocs/api/nn/index.html
Optimizers (torch::optim) https://docs.pytorch.org/cppdocs/api/optim/index.html
Data Loading (torch::data) https://docs.pytorch.org/cppdocs/api/data/index.html
Serialization (torch::serialize) https://docs.pytorch.org/cppdocs/api/serialize/index.html
Torch Library API https://docs.pytorch.org/cppdocs/api/library/index.html
Torch Stable API https://docs.pytorch.org/cppdocs/api/stable/index.html
FAQ https://docs.pytorch.org/cppdocs/faq.html
Go to pytorch.org https://pytorch.org
Xhttps://x.com/PyTorch
GitHubhttps://github.com/pytorch/pytorch
PyTorch Forumhttps://discuss.pytorch.org/
PyPihttps://pypi.org/project/torch/
mainhttps://docs.pytorch.org/cppdocs/index.html
Installing C++ Distributions of PyTorch https://docs.pytorch.org/cppdocs/installing.html
The C++ Frontend https://docs.pytorch.org/cppdocs/frontend.html
C++ API Reference https://docs.pytorch.org/cppdocs/api/index.html
ATen: Tensor Library https://docs.pytorch.org/cppdocs/api/aten/index.html
C10: Core Utilities https://docs.pytorch.org/cppdocs/api/c10/index.html
Autograd: Automatic Differentiation https://docs.pytorch.org/cppdocs/api/autograd/index.html
CUDA Support https://docs.pytorch.org/cppdocs/api/cuda/index.html
XPU Support https://docs.pytorch.org/cppdocs/api/xpu/index.html
Neural Network Modules (torch::nn) https://docs.pytorch.org/cppdocs/api/nn/index.html
Optimizers (torch::optim) https://docs.pytorch.org/cppdocs/api/optim/index.html
Data Loading (torch::data) https://docs.pytorch.org/cppdocs/api/data/index.html
Serialization (torch::serialize) https://docs.pytorch.org/cppdocs/api/serialize/index.html
Torch Library API https://docs.pytorch.org/cppdocs/api/library/index.html
Torch Stable API https://docs.pytorch.org/cppdocs/api/stable/index.html
FAQ https://docs.pytorch.org/cppdocs/faq.html
Go to pytorch.org https://pytorch.org
Xhttps://x.com/PyTorch
GitHubhttps://github.com/pytorch/pytorch
PyTorch Forumhttps://discuss.pytorch.org/
PyPihttps://pypi.org/project/torch/
ATen: Tensor Libraryhttps://docs.pytorch.org/cppdocs/api/aten/index.html
Tensor Classhttps://docs.pytorch.org/cppdocs/api/aten/tensor.html
Tensor Creationhttps://docs.pytorch.org/cppdocs/api/aten/creation.html
Tensor Indexinghttps://docs.pytorch.org/cppdocs/api/aten/indexing.html
Tensor Accessorshttps://docs.pytorch.org/cppdocs/api/aten/accessors.html
C10: Core Utilitieshttps://docs.pytorch.org/cppdocs/api/c10/index.html
Device and DeviceTypehttps://docs.pytorch.org/cppdocs/api/c10/device.html
Device Guardshttps://docs.pytorch.org/cppdocs/api/c10/guards.html
Streamshttps://docs.pytorch.org/cppdocs/api/c10/streams.html
Core Typeshttps://docs.pytorch.org/cppdocs/api/c10/types.html
Utilitieshttps://docs.pytorch.org/cppdocs/api/c10/utilities.html
Autograd: Automatic Differentiationhttps://docs.pytorch.org/cppdocs/api/autograd/index.html
Gradient Computationhttps://docs.pytorch.org/cppdocs/api/autograd/gradient.html
Custom Autograd Functionshttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html
Gradient Modeshttps://docs.pytorch.org/cppdocs/api/autograd/modes.html
CUDA Supporthttps://docs.pytorch.org/cppdocs/api/cuda/index.html
CUDA Streamshttps://docs.pytorch.org/cppdocs/api/cuda/streams.html
CUDA Guardshttps://docs.pytorch.org/cppdocs/api/cuda/guards.html
CUDA Utility Functionshttps://docs.pytorch.org/cppdocs/api/cuda/utilities.html
XPU Supporthttps://docs.pytorch.org/cppdocs/api/xpu/index.html
XPU Streamshttps://docs.pytorch.org/cppdocs/api/xpu/streams.html
XPU Utility Functionshttps://docs.pytorch.org/cppdocs/api/xpu/utilities.html
Neural Network Modules (torch::nn)https://docs.pytorch.org/cppdocs/api/nn/index.html
Containershttps://docs.pytorch.org/cppdocs/api/nn/containers.html
Convolution Layershttps://docs.pytorch.org/cppdocs/api/nn/convolution.html
Pooling Layershttps://docs.pytorch.org/cppdocs/api/nn/pooling.html
Linear Layershttps://docs.pytorch.org/cppdocs/api/nn/linear.html
Activation Functionshttps://docs.pytorch.org/cppdocs/api/nn/activation.html
Normalization Layershttps://docs.pytorch.org/cppdocs/api/nn/normalization.html
Dropout Layershttps://docs.pytorch.org/cppdocs/api/nn/dropout.html
Embedding Layershttps://docs.pytorch.org/cppdocs/api/nn/embedding.html
Recurrent Layershttps://docs.pytorch.org/cppdocs/api/nn/recurrent.html
Transformer Layershttps://docs.pytorch.org/cppdocs/api/nn/transformer.html
Loss Functionshttps://docs.pytorch.org/cppdocs/api/nn/loss.html
Functional APIhttps://docs.pytorch.org/cppdocs/api/nn/functional.html
Utilitieshttps://docs.pytorch.org/cppdocs/api/nn/utilities.html
Optimizers (torch::optim)https://docs.pytorch.org/cppdocs/api/optim/index.html
Gradient Descent Optimizershttps://docs.pytorch.org/cppdocs/api/optim/gradient_descent.html
Adaptive Learning Rate Optimizershttps://docs.pytorch.org/cppdocs/api/optim/adaptive.html
Second-Order Optimizershttps://docs.pytorch.org/cppdocs/api/optim/second_order.html
Learning Rate Schedulershttps://docs.pytorch.org/cppdocs/api/optim/schedulers.html
Data Loading (torch::data)https://docs.pytorch.org/cppdocs/api/data/index.html
Datasetshttps://docs.pytorch.org/cppdocs/api/data/datasets.html
DataLoaderhttps://docs.pytorch.org/cppdocs/api/data/dataloader.html
Samplershttps://docs.pytorch.org/cppdocs/api/data/samplers.html
Transformshttps://docs.pytorch.org/cppdocs/api/data/transforms.html
Serialization (torch::serialize)https://docs.pytorch.org/cppdocs/api/serialize/index.html
Saving and Loadinghttps://docs.pytorch.org/cppdocs/api/serialize/save_load.html
Archiveshttps://docs.pytorch.org/cppdocs/api/serialize/archives.html
Checkpointshttps://docs.pytorch.org/cppdocs/api/serialize/checkpoints.html
Torch Library APIhttps://docs.pytorch.org/cppdocs/api/library/index.html
Operator Registrationhttps://docs.pytorch.org/cppdocs/api/library/registration.html
Custom Classeshttps://docs.pytorch.org/cppdocs/api/library/custom_classes.html
Library Versioninghttps://docs.pytorch.org/cppdocs/api/library/versioning.html
Torch Stable APIhttps://docs.pytorch.org/cppdocs/api/stable/index.html
Library Registration Macroshttps://docs.pytorch.org/cppdocs/api/stable/registration.html
Stable Operatorshttps://docs.pytorch.org/cppdocs/api/stable/operators.html
Utilitieshttps://docs.pytorch.org/cppdocs/api/stable/utilities.html
https://docs.pytorch.org/cppdocs/index.html
C++ API Referencehttps://docs.pytorch.org/cppdocs/api/index.html
Autograd: Automatic Differentiationhttps://docs.pytorch.org/cppdocs/api/autograd/index.html
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#custom-autograd-functions
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#function-base-class
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4I0EN5torch8autograd8FunctionE
Functionhttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#PyTorchstructtorch_1_1autograd_1_1_function
torch::autograd::AutogradContexthttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#PyTorchstructtorch_1_1autograd_1_1_autograd_context
torch::autograd::AutogradContext::save_for_backwardhttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#PyTorchstructtorch_1_1autograd_1_1_autograd_context_1a2150f73ad822cb634fe098065aaf4545
torch::autograd::AutogradContext::saved_datahttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#PyTorchstructtorch_1_1autograd_1_1_autograd_context_1a382fceaf530cd9f5cce8f34eaedcab83
torch::autograd::AutogradContexthttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#PyTorchstructtorch_1_1autograd_1_1_autograd_context
torch::autograd::AutogradContext::get_saved_variableshttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#PyTorchstructtorch_1_1autograd_1_1_autograd_context_1afb8b53cd27bbcb7662544c27d2a94151
Thttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4I0EN5torch8autograd8FunctionE
Argshttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4I0DpEN5torch8autograd8Function5applyENSt11enable_if_tINSt9is_same_vI1X1TEE9forward_tI1XDp4ArgsEEEDpRR4Args
Xhttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4I0DpEN5torch8autograd8Function5applyENSt11enable_if_tINSt9is_same_vI1X1TEE9forward_tI1XDp4ArgsEEEDpRR4Args
Thttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4I0EN5torch8autograd8FunctionE
Xhttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4I0DpEN5torch8autograd8Function5applyENSt11enable_if_tINSt9is_same_vI1X1TEE9forward_tI1XDp4ArgsEEEDpRR4Args
Argshttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4I0DpEN5torch8autograd8Function5applyENSt11enable_if_tINSt9is_same_vI1X1TEE9forward_tI1XDp4ArgsEEEDpRR4Args
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4I0DpEN5torch8autograd8Function5applyENSt11enable_if_tINSt9is_same_vI1X1TEE9forward_tI1XDp4ArgsEEEDpRR4Args
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd8Function12is_traceableE
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#autogradcontext
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContextE
torch::autograd::Functionhttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#PyTorchstructtorch_1_1autograd_1_1_function
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext15AutogradContextEv
AutogradContexthttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext15AutogradContextERK15AutogradContext
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext15AutogradContextERK15AutogradContext
AutogradContexthttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContextE
AutogradContexthttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContextE
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContextaSERK15AutogradContext
AutogradContexthttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext15AutogradContextERR15AutogradContext
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext15AutogradContextERR15AutogradContext
AutogradContexthttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContextE
AutogradContexthttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContextE
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContextaSERR15AutogradContext
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContextD0Ev
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext15AutogradContextER10PackedArgs
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext17save_for_backwardE13variable_list
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext10mark_dirtyERK13variable_list
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext23mark_non_differentiableERK13variable_list
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext21set_materialize_gradsEb
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4NK5torch8autograd15AutogradContext19get_saved_variablesEv
save_for_backward()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#PyTorchstructtorch_1_1autograd_1_1_autograd_context_1a2150f73ad822cb634fe098065aaf4545
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4NK5torch8autograd15AutogradContext18get_and_bump_dirtyEv
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4NK5torch8autograd15AutogradContext22get_non_differentiableEv
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4NK5torch8autograd15AutogradContext16needs_input_gradE6size_t
Functionhttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#PyTorchstructtorch_1_1autograd_1_1_function
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4NK5torch8autograd15AutogradContext16needs_input_gradENSt16initializer_listI10IndexRangeEE
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext10saved_dataE
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#creating-custom-functions
#https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#custom-kernels-and-autodispatchbelowadinplaceorview
custom kernel tutorialhttps://pytorch.org/tutorials/advanced/cpp_extension.html#backward-pass
previous Gradient Computation https://docs.pytorch.org/cppdocs/api/autograd/gradient.html
next Gradient Modes https://docs.pytorch.org/cppdocs/api/autograd/modes.html
PyData Sphinx Themehttps://pydata-sphinx-theme.readthedocs.io/en/stable/index.html
previous Gradient Computation https://docs.pytorch.org/cppdocs/api/autograd/gradient.html
next Gradient Modes https://docs.pytorch.org/cppdocs/api/autograd/modes.html
Function Base Classhttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#function-base-class
torch::autograd::Functionhttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4I0EN5torch8autograd8FunctionE
apply()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4I0DpEN5torch8autograd8Function5applyENSt11enable_if_tINSt9is_same_vI1X1TEE9forward_tI1XDp4ArgsEEEDpRR4Args
is_traceablehttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd8Function12is_traceableE
AutogradContexthttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#autogradcontext
torch::autograd::AutogradContexthttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContextE
AutogradContext()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext15AutogradContextEv
AutogradContext()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext15AutogradContextERK15AutogradContext
operator=()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContextaSERK15AutogradContext
AutogradContext()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext15AutogradContextERR15AutogradContext
operator=()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContextaSERR15AutogradContext
~AutogradContext()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContextD0Ev
AutogradContext()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext15AutogradContextER10PackedArgs
save_for_backward()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext17save_for_backwardE13variable_list
mark_dirty()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext10mark_dirtyERK13variable_list
mark_non_differentiable()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext23mark_non_differentiableERK13variable_list
set_materialize_grads()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext21set_materialize_gradsEb
get_saved_variables()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4NK5torch8autograd15AutogradContext19get_saved_variablesEv
get_and_bump_dirty()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4NK5torch8autograd15AutogradContext18get_and_bump_dirtyEv
get_non_differentiable()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4NK5torch8autograd15AutogradContext22get_non_differentiableEv
needs_input_grad()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4NK5torch8autograd15AutogradContext16needs_input_gradE6size_t
needs_input_grad()https://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4NK5torch8autograd15AutogradContext16needs_input_gradENSt16initializer_listI10IndexRangeEE
saved_datahttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#_CPPv4N5torch8autograd15AutogradContext10saved_dataE
Creating Custom Functionshttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#creating-custom-functions
Custom Kernels and AutoDispatchBelowADInplaceOrViewhttps://docs.pytorch.org/cppdocs/api/autograd/custom_functions.html#custom-kernels-and-autodispatchbelowadinplaceorview
Show Source https://docs.pytorch.org/cppdocs/_sources/api/autograd/custom_functions.md.txt
ExecuTorchhttps://docs.pytorch.org/executorch
Helionhttps://docs.pytorch.org/helion
torchaohttps://docs.pytorch.org/ao
kinetohttps://github.com/pytorch/kineto
torchtitanhttps://github.com/pytorch/torchtitan
TorchRLhttps://docs.pytorch.org/rl
torchvisionhttps://docs.pytorch.org/vision
torchaudiohttps://docs.pytorch.org/audio
tensordicthttps://docs.pytorch.org/tensordict
PyTorch on XLA Deviceshttps://docs.pytorch.org/xla
View Docshttps://docs.pytorch.org/docs/stable/index.html
View Tutorialshttps://docs.pytorch.org/tutorials
View Resourceshttps://pytorch.org/resources
Privacy Policyhttps://www.linuxfoundation.org/privacy/
https://www.facebook.com/pytorch
https://twitter.com/pytorch
https://www.youtube.com/pytorch
https://www.linkedin.com/company/pytorch
https://pytorch.slack.com
https://pytorch.org/wechat
Policieshttps://www.linuxfoundation.org/legal/policies
Trademark Usagehttps://www.linuxfoundation.org/trademark-usage
Privacy Policyhttp://www.linuxfoundation.org/privacy
Cookies Policyhttps://opensource.fb.com/legal/cookie-policy
Sphinxhttps://www.sphinx-doc.org/
PyData Sphinx Themehttps://pydata-sphinx-theme.readthedocs.io/en/stable/index.html

Viewport: width=device-width, initial-scale=1


URLs of crawlers that visited me.