From 1d7c2fa60f717dea7239970d96f7d4bf96842039 Mon Sep 17 00:00:00 2001 From: ImSheridan Date: Fri, 30 Mar 2018 02:11:55 +0800 Subject: [PATCH] Raise a nicer error message when trying to call gradients with while loop (#18052) * Produce a nicer error message when trying to call gradients on a while loop without properly serializing graph via MetaGraphDef * Fix syntax and lint error * Fix minor intent: Wrong continued indentation (add 2 spaces) --- tensorflow/python/ops/control_flow_ops.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tensorflow/python/ops/control_flow_ops.py b/tensorflow/python/ops/control_flow_ops.py index 1278768d8bdc9f..710287012eadea 100644 --- a/tensorflow/python/ops/control_flow_ops.py +++ b/tensorflow/python/ops/control_flow_ops.py @@ -833,6 +833,9 @@ def __init__(self, forward_ctxt, outer_grad_state): if outer_grad_state: outer_forward_ctxt = outer_grad_state.forward_context else: + if not hasattr(forward_ctxt, 'outer_context'): + raise ValueError("Failed to call gradients on a while loop without" + "properly serializing graph via MetaGraphDef") outer_forward_ctxt = forward_ctxt.outer_context # Add the forward loop counter.