From 3aa5886bdd9654b002084b02c09d4698d3d376fc Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Wed, 17 Jan 2018 12:31:01 +0800 Subject: [PATCH] update_error_clip_doc --- doc/design/error_clip.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/doc/design/error_clip.md b/doc/design/error_clip.md index 8e845462cce..58aa73b8cd3 100644 --- a/doc/design/error_clip.md +++ b/doc/design/error_clip.md @@ -46,12 +46,12 @@ class ErrorClipByValue(BaseErrorClipAttr): self.min = min def append_clip_op(self, block, grad_name): - block.append_op( - type="clip", - inputs={"X": grad_name}, - outputs={"Out": grad_name}, - attrs={"min": self.min, - "max": self.max}) + clip_op_desc = block.desc.append_op() + clip_op_desc.set_type("clip") + clip_op_desc.set_input("X", [grad_name]) + clip_op_desc.set_output("Out", [grad_name]) + clip_op_desc.set_attr("min", self.min) + clip_op_desc.set_attr("max", self.max) ``` The `BaseErrorClipAttr` have one main member functions: `append_clip_op(self, block, grad_name)`. @@ -80,6 +80,11 @@ def error_clip_callback(block, context): op_desc.output_arg_names()): fwd_var = block.var_recursive(grad_to_var[grad_n]) error_clip = getattr(fwd_var, "error_clip", None) + if not (error_clip is None or isinstance(error_clip, + BaseErrorClipAttr)): + raise TypeError( + "Variable's error_clip should be an instance of BaseErrorClipAttr or None." + ) if error_clip is not None: error_clip.append_clip_op(block, grad_n) ``` -- GitLab