{"record":{"id":"d0d40e20e75f6ebd","repo":"tensorflow/models","slug":"for-the-tensor-s-the-actual-tensor-rank-d","errorCode":null,"errorMessage":"For the tensor `%s`, the actual tensor rank `%d` (shape = %s) is not equal to the expected tensor rank `%s`","messagePattern":"For the tensor `(.+?)`, the actual tensor rank `(.+?)` \\(shape = (.+?)\\) is not equal to the expected tensor rank `(.+?)`","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/modeling/tf_utils.py","lineNumber":196,"sourceCode":"\n  Args:\n    tensor: A tf.Tensor to check the rank of.\n    expected_rank: Python integer or list of integers, expected rank.\n    name: Optional name of the tensor for the error message.\n\n  Raises:\n    ValueError: If the expected shape doesn't match the actual shape.\n  \"\"\"\n  expected_rank_dict = {}\n  if isinstance(expected_rank, six.integer_types):\n    expected_rank_dict[expected_rank] = True\n  else:\n    for x in expected_rank:\n      expected_rank_dict[x] = True\n\n  actual_rank = tensor.shape.ndims\n  if actual_rank not in expected_rank_dict:\n    raise ValueError(\n        \"For the tensor `%s`, the actual tensor rank `%d` (shape = %s) is not \"\n        \"equal to the expected tensor rank `%s`\" %\n        (name, actual_rank, str(tensor.shape), str(expected_rank)))\n\n\ndef safe_mean(losses):\n  \"\"\"Computes a safe mean of the losses.\n\n  Args:\n    losses: `Tensor` whose elements contain individual loss measurements.\n\n  Returns:\n    A scalar representing the mean of `losses`. If `num_present` is zero,\n      then zero is returned.\n  \"\"\"\n  total = tf.reduce_sum(losses)\n  num_elements = tf.cast(tf.size(losses), dtype=losses.dtype)\n  return tf.math.divide_no_nan(total, num_elements)","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/modeling/tf_utils.py#L178-L214","documentation":"Error \"For the tensor `%s`, the actual tensor rank `%d` (shape = %s) is not equal to the expected tensor rank `%s`\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/modeling/tf_utils.py:196 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}