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

Function assert_rank

examples/tensorflow/bert/utils/bert.py:325–342  ·  view source on GitHub ↗
(tensor, expected_rank, name=None)

Source from the content-addressed store, hash-verified

323
324
325def assert_rank(tensor, expected_rank, name=None):
326 if name is None:
327 name = tensor.name
328
329 expected_rank_dict = {}
330 if isinstance(expected_rank, six.integer_types):
331 expected_rank_dict[expected_rank] = True
332 else:
333 for x in expected_rank:
334 expected_rank_dict[x] = True
335
336 actual_rank = tensor.shape.ndims
337 if actual_rank not in expected_rank_dict:
338 scope_name = tf.get_variable_scope().name
339 raise ValueError(
340 "For the tensor `%s` in scope `%s`, the actual rank "
341 "`%d` (shape = %s) is not equal to the expected rank `%s`" %
342 (name, scope_name, actual_rank, str(tensor.shape), str(expected_rank)))
343
344def ft_bert(inputs,
345 encoder_args,

Callers 1

get_shape_listFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected