MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / body

Function body

tensorflow/contrib/seq2seq/python/ops/decoder.py:395–454  ·  view source on GitHub ↗

Internal while_loop body. Args: time: scalar int32 tensor. outputs_ta: structure of TensorArray. state: (structure of) state tensors and TensorArrays. inputs: (structure of) input tensors. finished: bool tensor (keeping track of what's finished).

(time, outputs_ta, state, inputs, finished, sequence_lengths)

Source from the content-addressed store, hash-verified

393 return math_ops.logical_not(math_ops.reduce_all(finished))
394
395 def body(time, outputs_ta, state, inputs, finished, sequence_lengths):
396 """Internal while_loop body.
397
398 Args:
399 time: scalar int32 tensor.
400 outputs_ta: structure of TensorArray.
401 state: (structure of) state tensors and TensorArrays.
402 inputs: (structure of) input tensors.
403 finished: bool tensor (keeping track of what's finished).
404 sequence_lengths: int32 tensor (keeping track of time of finish).
405
406 Returns:
407 `(time + 1, outputs_ta, next_state, next_inputs, next_finished,
408 next_sequence_lengths)`.
409 ```
410 """
411 (next_outputs, decoder_state, next_inputs,
412 decoder_finished) = decoder.step(time, inputs, state)
413 if decoder.tracks_own_finished:
414 next_finished = decoder_finished
415 else:
416 next_finished = math_ops.logical_or(decoder_finished, finished)
417 next_sequence_lengths = array_ops.where(
418 math_ops.logical_not(finished),
419 array_ops.fill(array_ops.shape(sequence_lengths), time + 1),
420 sequence_lengths)
421
422 nest.assert_same_structure(state, decoder_state)
423 nest.assert_same_structure(outputs_ta, next_outputs)
424 nest.assert_same_structure(inputs, next_inputs)
425
426 # Zero out output values past finish
427 if impute_finished:
428 emit = nest.map_structure(
429 lambda out, zero: array_ops.where(finished, zero, out),
430 next_outputs,
431 zero_outputs)
432 else:
433 emit = next_outputs
434
435 # Copy through states past finish
436 def _maybe_copy_state(new, cur):
437 # TensorArrays and scalar states get passed through.
438 if isinstance(cur, tensor_array_ops.TensorArray):
439 pass_through = True
440 else:
441 new.set_shape(cur.shape)
442 pass_through = (new.shape.ndims == 0)
443 return new if pass_through else array_ops.where(finished, cur, new)
444
445 if impute_finished:
446 next_state = nest.map_structure(
447 _maybe_copy_state, decoder_state, state)
448 else:
449 next_state = decoder_state
450
451 outputs_ta = nest.map_structure(lambda ta, out: ta.write(time, out),
452 outputs_ta, emit)

Callers 3

tfl_ops.ccFile · 0.50
GPU_1D_KERNEL_LOOPFunction · 0.50
CreateBodyFunction · 0.50

Calls 4

fillMethod · 0.80
stepMethod · 0.45
shapeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected