{"record":{"id":"514fb67cc3ccb941","repo":"tensorflow/models","slug":"static-rank-of-tensor-must-be-known","errorCode":null,"errorMessage":"Static rank of `tensor` must be known.","messagePattern":"Static rank of `tensor` must be known\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/triviaqa/inputs.py","lineNumber":50,"sourceCode":"  Args:\n    tensor: [..., first_dim_size, ...middle_dims..., last_dim_size, ...] shaped\n      Tensor.\n    first_dim: The first dimension to flatten (inclusive). Must be a valid index\n      for the rank of `tensor`. Default is 0.\n    last_dim: The last dimension to flatten (inclusive). Must be a valid index\n      for the rank of `tensor`. Default is -1.\n    name: A name for the operation (optional).\n\n  Returns:\n    Tensor of shape [..., flattened_dim_size, ...] where\n    flattened_dim_size = first_dim_size * ...middle_dims... * last_dim_size.\n  \"\"\"\n  with tf.name_scope(name or 'flatten_dims'):\n    tensor = tf.convert_to_tensor(tensor)\n\n    rank = tensor.shape.rank\n    if rank is None:\n      raise ValueError('Static rank of `tensor` must be known.')\n    if first_dim < 0:  # pytype: disable=unsupported-operands\n      first_dim += rank\n    if first_dim < 0 or first_dim >= rank:  # pytype: disable=unsupported-operands\n      raise ValueError('`first_dim` out of bounds for `tensor` rank.')\n    if last_dim < 0:  # pytype: disable=unsupported-operands\n      last_dim += rank\n    if last_dim < 0 or last_dim >= rank:  # pytype: disable=unsupported-operands\n      raise ValueError('`last_dim` out of bounds for `tensor` rank.')\n    if first_dim > last_dim:  # pytype: disable=unsupported-operands\n      raise ValueError('`first_dim` must not be larger than `last_dim`.')\n\n    # Try to calculate static flattened dim size if all input sizes to flatten\n    # are statically known. Otherwise, just use -1.\n    flat_dims_shape = tensor.shape[first_dim:(last_dim + 1)].as_list()\n    flattened_dim_size = 1\n    for size in flat_dims_shape:\n      if size is None:\n        flattened_dim_size = -1","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/triviaqa/inputs.py#L32-L68","documentation":"Error \"Static rank of `tensor` must be known.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/triviaqa/inputs.py:50 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"}