tensorflow/models · error · ValueError
Invalid sequence length: {length} or shape: ({height, width}
Error message
Invalid sequence length: {length} or shape: ({height, width}). What it means
Error "Invalid sequence length: {length} or shape: ({height, width})." thrown in tensorflow/models.
Source
Thrown at official/projects/maxvit/modeling/common_ops.py:249
ret_shape = relative_position_tensor.shape.as_list()
ret_shape[h_axis] = height * width
ret_shape[h_axis + 1] = height * width
reindexed_tensor = tf.reshape(reindexed_tensor, ret_shape)
return reindexed_tensor
def float32_softmax(x: tf.Tensor, *args, **kwargs) -> tf.Tensor:
y = tf.cast(tf.nn.softmax(tf.cast(x, tf.float32), *args, **kwargs), x.dtype)
return y
def get_shape_from_length(length: int, height: int = 1, width: int = 1):
"""Gets input 2D shape from 1D sequence length."""
input_height = int(math.sqrt(length * height // width))
input_width = input_height * width // height
if input_height * input_width != length:
raise ValueError(
f'Invalid sequence length: {length} or shape: ({height, width}).'
)
return (input_height, input_width)
def absolute_position_encoding(
position: tf.Tensor, hidden_size: int, dtype=tf.float32) -> tf.Tensor:
"""Create absoulte position encoding."""
position = tf.cast(position, dtype)
half_hid = hidden_size // 2
freq_seq = tf.cast(tf.range(half_hid), dtype=dtype)
inv_freq = 1 / (10000 ** (freq_seq / half_hid))
sinusoid = tf.einsum('S,D->SD', position, inv_freq)
sin = tf.sin(sinusoid)
cos = tf.cos(sinusoid)
return tf.concat([sin, cos], axis=-1)
View on GitHub (pinned to e006f5f0d5)
When it happens
Trigger: Thrown at official/projects/maxvit/modeling/common_ops.py:249 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/ef05118efd7e164b.
Report an issue: GitHub.