Skip to content

Conversation

@JiayiFeng
Copy link
Collaborator

No description provided.

@JiayiFeng JiayiFeng requested review from dzhwinter and reyoung January 1, 2018 17:05

In Neural Network, most models are solved by the backpropagation algorithm(known as **BP**) at present. Technically, BP calculates the gradient of the loss function, then propagates it back through the networks following the chain rule. However, when configuring the model structure, users do not need to define the backward part. So a mechanism is required by the framework which can complete the model's backward part automatically according to the given forward part.

When implementing a specific `op`, the developer is also asked to implement its backward version, called `grad_op`. A `grad_op` takes gradients of its corresponding `op`'s outputs, and calculate gradients of the `op`'s inputs. During the building of a model's backward part, the framework creates each forward `op`'s `grad_op`, and then string them together in reverse order of forwarding part. In this way, gradients spread from the end to the beginning of the model, in another word, from the loss to parameters.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grad_op is not the backward version of the forward operator.

We maintain a mapping between an operator and operators that will produce its gradient. It is not a one-to-one mapping. Operators in backward stage(I do not think there should be a backward stage.However, to make it easy to understand, I just assume operators in Block can be split into two stages) can be used in forward stage.

Copy link
Collaborator Author

@JiayiFeng JiayiFeng Jan 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea! I think we can merge this pr first and I will create an issue to record your idea. I'm going to refine it later.

The issue: #7127

Copy link
Collaborator

@reyoung reyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JiayiFeng JiayiFeng merged commit 6a5cf28 into PaddlePaddle:develop Jan 2, 2018
@JiayiFeng JiayiFeng deleted the Add_backward_doc_and_comments branch January 2, 2018 03:56
@JiayiFeng JiayiFeng mentioned this pull request Jan 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants