{"record":{"id":"ef05118efd7e164b","repo":"tensorflow/models","slug":"invalid-sequence-length-length-or-shape-heig","errorCode":null,"errorMessage":"Invalid sequence length: {length} or shape: ({height, width}).","messagePattern":"Invalid sequence length: (.+?) or shape: \\((.+?)\\)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/maxvit/modeling/common_ops.py","lineNumber":249,"sourceCode":"  ret_shape = relative_position_tensor.shape.as_list()\n  ret_shape[h_axis] = height * width\n  ret_shape[h_axis + 1] = height * width\n  reindexed_tensor = tf.reshape(reindexed_tensor, ret_shape)\n\n  return reindexed_tensor\n\n\ndef float32_softmax(x: tf.Tensor, *args, **kwargs) -> tf.Tensor:\n  y = tf.cast(tf.nn.softmax(tf.cast(x, tf.float32), *args, **kwargs), x.dtype)\n  return y\n\n\ndef get_shape_from_length(length: int, height: int = 1, width: int = 1):\n  \"\"\"Gets input 2D shape from 1D sequence length.\"\"\"\n  input_height = int(math.sqrt(length * height // width))\n  input_width = input_height * width // height\n  if input_height * input_width != length:\n    raise ValueError(\n        f'Invalid sequence length: {length} or shape: ({height, width}).'\n    )\n  return (input_height, input_width)\n\n\ndef absolute_position_encoding(\n    position: tf.Tensor, hidden_size: int, dtype=tf.float32) -> tf.Tensor:\n  \"\"\"Create absoulte position encoding.\"\"\"\n  position = tf.cast(position, dtype)\n  half_hid = hidden_size // 2\n  freq_seq = tf.cast(tf.range(half_hid), dtype=dtype)\n  inv_freq = 1 / (10000 ** (freq_seq / half_hid))\n  sinusoid = tf.einsum('S,D->SD', position, inv_freq)\n  sin = tf.sin(sinusoid)\n  cos = tf.cos(sinusoid)\n  return tf.concat([sin, cos], axis=-1)\n","sourceCodeStart":231,"sourceCodeEnd":266,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/maxvit/modeling/common_ops.py#L231-L266","documentation":"Error \"Invalid sequence length: {length} or shape: ({height, width}).\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/maxvit/modeling/common_ops.py:249 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"}