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

Function _pad_all_input

tensorflow/python/tpu/tpu.py:642–739  ·  view source on GitHub ↗

Pad all input tensors given padded_shapes. The real shape tensors will be concatenated with the padded original inputs. Args: inputs: The original inputs. padded_shapes: A list of padded shapes for each input. Returns: The padded inputs and a PaddingMap list which maps the padde

(inputs, padded_shapes)

Source from the content-addressed store, hash-verified

640
641
642def _pad_all_input(inputs, padded_shapes):
643 """Pad all input tensors given padded_shapes.
644
645 The real shape tensors will be concatenated with the padded original inputs.
646
647 Args:
648 inputs: The original inputs.
649 padded_shapes: A list of padded shapes for each input.
650
651 Returns:
652 The padded inputs and a PaddingMap list which maps the padded input
653 dimension to the real shape argument index.
654 """
655 # maximum_static_shapes[idx][i] indicates the maximum static size of ith
656 # dimension of the idx input among all the replicas.
657 maximum_static_shapes = []
658 # need_padding[idx][i] indicates whether the ith dimension of the idx input
659 # needs padding.
660 need_padding = []
661 input_shape_tensors = []
662 for core_idx, inputs_per_core in enumerate(inputs):
663 for idx, input_tensor in enumerate(inputs_per_core):
664 input_shape = input_tensor.get_shape().as_list()
665 if core_idx == 0:
666 input_shape_tensors.append([])
667 maximum_static_shapes.append(input_shape)
668 need_padding.append(np.full_like(input_shape, False, dtype=bool))
669 else:
670 for i, s in enumerate(input_shape):
671 if not s or s != maximum_static_shapes[idx][i]:
672 need_padding[idx][i] = True
673 maximum_static_shapes[idx] = max(input_shape,
674 maximum_static_shapes[idx])
675 input_shape_tensors[idx].append(array_ops.shape(input_tensor))
676
677 maximum_shapes = []
678 for shapes_per_input in input_shape_tensors:
679 maximum_shapes.append(
680 math_ops.reduce_max(array_ops.stack(shapes_per_input), axis=0))
681
682 padded_inputs = []
683 real_shapes = []
684 padding_maps = []
685 for core_idx, inputs_per_core in enumerate(inputs):
686 padded_inputs.append([])
687 real_shapes.append([])
688 real_shape_idx = len(inputs_per_core) - 1
689 for idx, input_tensor in enumerate(inputs_per_core):
690 input_shape_tensor = input_shape_tensors[idx][core_idx]
691 input_shape = input_tensor.get_shape().as_list()
692 padded_shape = padded_shapes[idx]
693
694 if any(need_padding[idx]):
695 for i, s in enumerate(input_shape):
696 if need_padding[idx][i]:
697 if core_idx == 0:
698 real_shape_idx += 1
699 padding_map = dynamic_padding.PaddingMap()

Callers 1

Calls 13

anyFunction · 0.85
is_fully_definedMethod · 0.80
maxFunction · 0.50
rangeFunction · 0.50
as_listMethod · 0.45
get_shapeMethod · 0.45
appendMethod · 0.45
shapeMethod · 0.45
stackMethod · 0.45
castMethod · 0.45
condMethod · 0.45
constantMethod · 0.45

Tested by

no test coverage detected