Python tensorflow.python.ops.control_flow_ops.IsLoopExit() Examples

The following are 5 code examples of tensorflow.python.ops.control_flow_ops.IsLoopExit(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tensorflow.python.ops.control_flow_ops , or try the search function .
Example #1
Source File: gradients_impl.py    From lambda-packs with MIT License 5 votes vote down vote up
def _UpdatePendingAndEnqueueReady(grads, op, queue, pending_count, loop_state):
  """Update pending count for the inputs of op and enqueue ready ops."""
  for x in op.inputs:
    # pylint: disable=protected-access
    pending_count[x.op._id] -= 1
    ready = (pending_count[x.op._id] == 0)
    if loop_state and not ready:
      ready = (pending_count[x.op._id] > 0 and
               control_flow_ops.IsLoopSwitch(x.op))
    # pylint: enable=protected-access
    if ready:
      if control_flow_ops.IsLoopExit(x.op):
        # if x is an exit without real gradient, defer processing them.
        grad_state = loop_state.GetGradState(x.op, before=False)
        grad_state.deferred_exits.append(x)
        grad_state.pending_exits_count -= 1
        if grad_state.pending_exits_count == 0:
          # We now have all the exits so process them.
          has_real_grad = False
          for y in grad_state.deferred_exits:
            if _HasAnyNotNoneGrads(grads, y.op):
              has_real_grad = True
              queue.append(y.op)
            else:
              grad_state.unused_exits.append(y)
          if has_real_grad:
            # For an unused exit, if it has floating-point outputs, backprop
            # a zero gradient. Otherwise, just ignore it.
            for y in grad_state.unused_exits:
              if _IsTrainable(y):
                _SetGrad(grads, y, loop_state.ZerosLikeForExit(y))
              queue.append(y.op)
          else:
            # All exits are "unused" so use None as gradient.
            for y in grad_state.unused_exits:
              queue.append(y.op)
      else:
        queue.append(x.op) 
Example #2
Source File: gradients_impl.py    From auto-alt-text-lambda-api with MIT License 5 votes vote down vote up
def _UpdatePendingAndEnqueueReady(grads, op, queue, pending_count, loop_state):
  """Update pending count for the inputs of op and enqueue ready ops."""
  for x in op.inputs:
    # pylint: disable=protected-access
    pending_count[x.op._id] -= 1
    ready = (pending_count[x.op._id] == 0)
    if loop_state and not ready:
      ready = (pending_count[x.op._id] > 0 and
               control_flow_ops.IsLoopSwitch(x.op))
    # pylint: enable=protected-access
    if ready:
      if control_flow_ops.IsLoopExit(x.op):
        # if x is an exit without real gradient, defer processing them.
        grad_state = loop_state.GetGradState(x.op, before=False)
        grad_state.deferred_exits.append(x)
        grad_state.pending_exits_count -= 1
        if grad_state.pending_exits_count == 0:
          # We now have all the exits so process them.
          has_real_grad = False
          for y in grad_state.deferred_exits:
            if _HasAnyNotNoneGrads(grads, y.op):
              has_real_grad = True
              queue.append(y.op)
            else:
              grad_state.unused_exits.append(y)
          if has_real_grad:
            # For an unused exit, if it has floating-point outputs, backprop
            # a zero gradient. Otherwise, just ignore it.
            for y in grad_state.unused_exits:
              if _IsTrainable(y):
                _SetGrad(grads, y, loop_state.ZerosLikeForExit(y))
              queue.append(y.op)
          else:
            # All exits are "unused" so use None as gradient.
            for y in grad_state.unused_exits:
              queue.append(y.op)
      else:
        queue.append(x.op) 
Example #3
Source File: gradients_impl.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def _UpdatePendingAndEnqueueReady(grads, op, queue, pending_count, loop_state):
  """Update pending count for the inputs of op and enqueue ready ops."""
  for x in op.inputs:
    # pylint: disable=protected-access
    pending_count[x.op._id] -= 1
    ready = (pending_count[x.op._id] == 0)
    if loop_state and not ready:
      ready = (pending_count[x.op._id] > 0 and
               control_flow_ops.IsLoopSwitch(x.op))
    # pylint: enable=protected-access
    if ready:
      if control_flow_ops.IsLoopExit(x.op):
        # if x is an exit without real gradient, defer processing them.
        grad_state = loop_state.GetGradState(x.op, before=False)
        grad_state.deferred_exits.append(x)
        grad_state.pending_exits_count -= 1
        if grad_state.pending_exits_count == 0:
          # We now have all the exits so process them.
          has_real_grad = False
          for y in grad_state.deferred_exits:
            if _HasAnyNotNoneGrads(grads, y.op):
              has_real_grad = True
              queue.append(y.op)
            else:
              grad_state.unused_exits.append(y)
          if has_real_grad:
            # For an unused exit, if it has floating-point outputs, backprop
            # a zero gradient. Otherwise, just ignore it.
            for y in grad_state.unused_exits:
              if _IsTrainable(y):
                _SetGrad(grads, y, loop_state.ZerosLikeForExit(y))
              queue.append(y.op)
          else:
            # All exits are "unused" so use None as gradient.
            for y in grad_state.unused_exits:
              queue.append(y.op)
      else:
        queue.append(x.op) 
Example #4
Source File: gradients_impl.py    From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License 5 votes vote down vote up
def _UpdatePendingAndEnqueueReady(grads, op, queue, pending_count, loop_state):
  """Update pending count for the inputs of op and enqueue ready ops."""
  for x in op.inputs:
    # pylint: disable=protected-access
    pending_count[x.op._id] -= 1
    ready = (pending_count[x.op._id] == 0)
    if loop_state and not ready:
      ready = (pending_count[x.op._id] > 0 and
               control_flow_ops.IsLoopSwitch(x.op))
    # pylint: enable=protected-access
    if ready:
      if control_flow_ops.IsLoopExit(x.op):
        # if x is an exit without real gradient, defer processing them.
        grad_state = loop_state.GetGradState(x.op, before=False)
        grad_state.deferred_exits.append(x)
        grad_state.pending_exits_count -= 1
        if grad_state.pending_exits_count == 0:
          # We now have all the exits so process them.
          has_real_grad = False
          for y in grad_state.deferred_exits:
            if _HasAnyNotNoneGrads(grads, y.op):
              has_real_grad = True
              queue.append(y.op)
            else:
              grad_state.unused_exits.append(y)
          if has_real_grad:
            # For an unused exit, if it has floating-point outputs, backprop
            # a zero gradient. Otherwise, just ignore it.
            for y in grad_state.unused_exits:
              if _IsTrainable(y):
                _SetGrad(grads, y, loop_state.ZerosLikeForExit(y))
              queue.append(y.op)
          else:
            # All exits are "unused" so use None as gradient.
            for y in grad_state.unused_exits:
              queue.append(y.op)
      else:
        queue.append(x.op) 
Example #5
Source File: gradients_impl.py    From keras-lambda with MIT License 5 votes vote down vote up
def _UpdatePendingAndEnqueueReady(grads, op, queue, pending_count, loop_state):
  """Update pending count for the inputs of op and enqueue ready ops."""
  for x in op.inputs:
    # pylint: disable=protected-access
    pending_count[x.op._id] -= 1
    ready = (pending_count[x.op._id] == 0)
    if loop_state and not ready:
      ready = (pending_count[x.op._id] > 0 and
               control_flow_ops.IsLoopSwitch(x.op))
    # pylint: enable=protected-access
    if ready:
      if control_flow_ops.IsLoopExit(x.op):
        # if x is an exit without real gradient, defer processing them.
        grad_state = loop_state.GetGradState(x.op, before=False)
        grad_state.deferred_exits.append(x)
        grad_state.pending_exits_count -= 1
        if grad_state.pending_exits_count == 0:
          # We now have all the exits so process them.
          has_real_grad = False
          for y in grad_state.deferred_exits:
            if _HasAnyNotNoneGrads(grads, y.op):
              has_real_grad = True
              queue.append(y.op)
            else:
              grad_state.unused_exits.append(y)
          if has_real_grad:
            # For an unused exit, if it has floating-point outputs, backprop
            # a zero gradient. Otherwise, just ignore it.
            for y in grad_state.unused_exits:
              if _IsTrainable(y):
                _SetGrad(grads, y, loop_state.ZerosLikeForExit(y))
              queue.append(y.op)
          else:
            # All exits are "unused" so use None as gradient.
            for y in grad_state.unused_exits:
              queue.append(y.op)
      else:
        queue.append(x.op)