tensorflow/models · error · ValueError

Only support expanding the first or the last dimension. Got:

Error message

Only support expanding the first or the last dimension. Got: {}

What it means

Error "Only support expanding the first or the last dimension. Got: {}" thrown in tensorflow/models.

Source

Thrown at official/modeling/fast_training/experimental/tf2_utils_2x_wide.py:60

  matmul(x, w) ==
      matmul(expand_vector(x), expand_1_axis(w, axis=0))

  If `axis = -1` and `epsilon = 0.0`, the following constraint will be
  satisfied:
  expand_vector(matmul(x, w)) ==
      2 * matmul(x, expand_1_axis(w, epsilon=0.0, axis=-1))

  Args:
    w: Numpy array of shape [a_0, a_1, ..., a_i-1, a_i].
    epsilon: Symmetric Noise added to expanded tensor.
    axis: Must be either 0 or -1.

  Returns:
    Expanded numpy array.
  """

  if axis not in (0, -1):
    raise ValueError(
        "Only support expanding the first or the last dimension. "
        "Got: {}".format(axis)
    )

  rank = len(w.shape)

  d_w = np.random.normal(np.zeros_like(w), np.fabs(w) * epsilon, w.shape)
  d_w = np.repeat(d_w, 2, axis=axis)

  sign_flip = np.array([1, -1])
  for _ in range(rank - 1):
    sign_flip = np.expand_dims(sign_flip, axis=axis - 1)
  sign_flip = np.tile(sign_flip,
                      [w.shape[0]] + [1] * (rank - 2) + [w.shape[-1]])

  d_w *= sign_flip
  w_expand = (np.repeat(w, 2, axis=axis) + d_w) / 2
  return w_expand

View on GitHub (pinned to e006f5f0d5)

When it happens

Trigger: Thrown at official/modeling/fast_training/experimental/tf2_utils_2x_wide.py:60 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/0577c006a899316e. Report an issue: GitHub.