tensorflow/models · error · ValueError

Shape not supported

Error message

Shape not supported, {}, {}

What it means

Shape guard in var_to_var: the source and destination variable shapes do not satisfy any supported expansion relation (dst = 2xsrc on first dim, last dim, or both). The variable-shape pairs passed to the progressive-widening transfer are incompatible.

Solutions

  1. Ensure destination shapes are exactly 1x or 2x the source shapes in the supported dimensions
  2. Check the widened model construction so variable shapes follow the 2x-wide expansion pattern
  3. Fall back to from-scratch initialization for non-conforming variables
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

    var_to.assign(expand_vector(var_from_np))
    return

  a_from, z_from = shape_from[0], shape_from[-1]
  a_to, z_to = shape_to[0], shape_to[-1]

  if a_to == 2 * a_from and z_to == z_from:
    var_to.assign(expand_1_axis(var_from_np, epsilon=epsilon, axis=0))
    return

  if a_to == a_from and z_to == 2 * z_from:
    var_to.assign(expand_1_axis(var_from_np, epsilon=epsilon, axis=-1))
    return

  if a_to == 2 * a_from and z_to == 2 * z_from:
    var_to.assign(expand_2_axes(var_from_np, epsilon=epsilon))
    return

  raise ValueError("Shape not supported, {}, {}".format(shape_from, shape_to))


def model_to_model_2x_wide(model_from: tf.Module,
                           model_to: tf.Module,
                           epsilon: float = 0.1):
  """Expands a model to a wider version.

  Also makes sure that the output of the model is not changed after expanding.
  For example:
  ```
  model_narrow = tf_keras.Sequential()
  model_narrow.add(tf_keras.Input(shape=(3,)))
  model_narrow.add(tf_keras.layers.Dense(4))
  model_narrow.add(tf_keras.layers.Dense(1))

  model_wide = tf_keras.Sequential()
  model_wide.add(tf_keras.Input(shape=(6,)))
  model_wide.add(tf_keras.layers.Dense(8))

View on GitHub (pinned to e006f5f0d5)