提交 f2e76008 编写于 作者: F fengjiayi

update

上级 9956d5f7
from paddle.v2.fluid import framework as framework
from . import core
__all__ = ['append_backward_ops']
def backward_impl(block, target_block, no_grad_set, grad_to_var, callback):
grad_op_descs = []
program = block.program
for each_op in block.ops:
grad_sub_block_list = []
if each_op.has_attr("sub_block"):
sub_block_idx = each_op.block_attr("sub_block")
sub_block = program.block(sub_block_idx)
grad_sub_block = program.create_block(parent_idx=sub_block_idx)
backward_impl(sub_block, grad_sub_block, no_grad_set, grad_to_var,
callback)
grad_sub_block_list.append(grad_sub_block)
grad_op_desc = core.get_grad_op_desc(each_op.desc,
no_grad_set[block.idx],
grad_to_var, grad_sub_block_list)
grad_op_descs.append(grad_op_desc)
def append_backward_ops(loss, parameter_list=None, no_grad_set=None):
"""
Create and add gradient Operators in BlockDesc to compute
......
......@@ -806,9 +806,11 @@ class Program(object):
self.sync_with_cpp()
return param_to_grad_info
def create_block(self):
def create_block(self, parent_idx=None):
new_block_idx = len(self.blocks)
self.desc.append_block(self.current_block().desc)
parent = self.current_block() if parent_idx is None else self.block(
parent_idx)
self.desc.append_block(parent.desc)
self.current_block_idx = new_block_idx
self.blocks.append(Block(self, self.current_block_idx))
return self.current_block()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册