Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to analyze Function function

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you an analysis of how to carry out the Function function. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

The original text and translation:

Function function torch.autograd.FunctionRecords operation history and defines formulas for differentiating ops. Record the operation history and define the formula for deriving the operation. Very operation performed on Tensor s creates a new function object, that performs the computation, and records that it happened. The history is retained in the form of a DAG of functions, with edges denoting data dependencies (input class Exp (Function): > @ staticmethod > def forward (ctx, I): > > result = i.exp () > > ctx.save_for_backward (result) > > return result > @ staticmethod > def backward (ctx, grad_output): > result, = ctx.saved_tensors > return grad_output * resultstatic backward (ctx) * grad_outputs) Defines a formula for differentiating the operation. Define the formula for derivation operation. This function is to be overridden by all subclasses. This function will be overridden by all subclasses. It must accept a context ctx as the first argument, followed by as many outputs did forward () return, and it should return as many tensors, as there were inputs to forward (). Each argument is the gradient w.r.t the given output, and each returned value should be the gradient w.r.t. The corresponding input. It must take a context ctx as the first argument, then all the parameters returned by the forward () function, and it must return all the tensor tensor received by the forward () function. Each parameter is a gradient relative to a given output. And each returned value should be the gradient of the corresponding input. The context can be used to retrieve tensors saved during the forward pass. It also has an attribute ctx.needs_input_grad as a tuple of booleans representing whether each input needs gradient. E. g., backward () will have ctx.needs_input_grad [0] = True if the first input to forward () needs gradient computated w.r.t. The output. We can use context context to obtain the tensor saved during forward transfer. It also has the attribute ctx.needs_input_grad, which is a tuple of Boolean type, and a Boolean value indicates whether a gradient is required for each input data. For example, if the first input data of the forward () function needs to calculate the gradient based on the output, then the attribute ctx.needs_input_grad [0] = True in backward (). Static forward (ctx, * args, * * kwargs) Performs the operation. Perform the operation. This function is to be overridden by all subclasses. This function will be overridden by all subclasses. It must accept a context ctx as the first argument, followed by any number of arguments (tensors or other types). It must receive a context ctx as the first parameter, and then it can then receive any number of parameters (tensor or other type) The context can be used to store tensors that can be then retrieved during the backward pass. Context can be used to store tensors so that they can be obtained during backward transmission. The above is the editor for you to share how to analyze the Function function, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report