MCPcopy Create free account
hub / github.com/NVIDIA/FasterTransformer / assert_rank

Function assert_rank

examples/tensorflow/encoder/utils/encoder.py:183–200  ·  view source on GitHub ↗
(tensor, expected_rank, name=None)

Source from the content-addressed store, hash-verified

181
182
183def assert_rank(tensor, expected_rank, name=None):
184 if name is None:
185 name = tensor.name
186
187 expected_rank_dict = {}
188 if isinstance(expected_rank, six.integer_types):
189 expected_rank_dict[expected_rank] = True
190 else:
191 for x in expected_rank:
192 expected_rank_dict[x] = True
193
194 actual_rank = tensor.shape.ndims
195 if actual_rank not in expected_rank_dict:
196 scope_name = tf.get_variable_scope().name
197 raise ValueError(
198 "For the tensor `%s` in scope `%s`, the actual rank "
199 "`%d` (shape = %s) is not equal to the expected rank `%s`" %
200 (name, scope_name, actual_rank, str(tensor.shape), str(expected_rank)))
201
202
203def ft_encoder_opennmt(inputs,

Callers 1

get_shape_listFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected