MCPcopy Create free account
hub / github.com/alibaba/bigcomputing / body

Function body

DIEN/rnn.py:1038–1087  ·  view source on GitHub ↗

Internal while loop body for raw_rnn. Args: time: time scalar. elements_finished: batch-size vector. current_input: possibly nested tuple of input tensors. emit_ta: possibly nested tuple of output TensorArrays. state: possibly nested tuple of state tens

(time, elements_finished, current_input,
             emit_ta, state, loop_state)

Source from the content-addressed store, hash-verified

1036 return math_ops.logical_not(math_ops.reduce_all(elements_finished))
1037
1038 def body(time, elements_finished, current_input,
1039 emit_ta, state, loop_state):
1040 """Internal while loop body for raw_rnn.
1041
1042 Args:
1043 time: time scalar.
1044 elements_finished: batch-size vector.
1045 current_input: possibly nested tuple of input tensors.
1046 emit_ta: possibly nested tuple of output TensorArrays.
1047 state: possibly nested tuple of state tensors.
1048 loop_state: possibly nested tuple of loop state tensors.
1049
1050 Returns:
1051 Tuple having the same size as Args but with updated values.
1052 """
1053 (next_output, cell_state) = cell(current_input, state)
1054
1055 nest.assert_same_structure(state, cell_state)
1056 nest.assert_same_structure(cell.output_size, next_output)
1057
1058 next_time = time + 1
1059 (next_finished, next_input, next_state, emit_output,
1060 next_loop_state) = loop_fn(
1061 next_time, next_output, cell_state, loop_state)
1062
1063 nest.assert_same_structure(state, next_state)
1064 nest.assert_same_structure(current_input, next_input)
1065 nest.assert_same_structure(emit_ta, emit_output)
1066
1067 # If loop_fn returns None for next_loop_state, just reuse the
1068 # previous one.
1069 loop_state = loop_state if next_loop_state is None else next_loop_state
1070
1071 def _copy_some_through(current, candidate):
1072 """Copy some tensors through via array_ops.where."""
1073 def copy_fn(cur_i, cand_i):
1074 with ops.colocate_with(cand_i):
1075 return array_ops.where(elements_finished, cur_i, cand_i)
1076 return nest.map_structure(copy_fn, current, candidate)
1077
1078 emit_output = _copy_some_through(zero_emit, emit_output)
1079 next_state = _copy_some_through(state, next_state)
1080
1081 emit_ta = nest.map_structure(
1082 lambda ta, emit: ta.write(time, emit), emit_ta, emit_output)
1083
1084 elements_finished = math_ops.logical_or(elements_finished, next_finished)
1085
1086 return (next_time, elements_finished, next_input,
1087 emit_ta, next_state, loop_state)
1088
1089 returned = control_flow_ops.while_loop(
1090 condition, body, loop_vars=[

Callers

nothing calls this directly

Calls 1

_copy_some_throughFunction · 0.85

Tested by

no test coverage detected