jax-ml/jax · error · NotImplementedError

Unimplemented padding mode '{}' for np.pad.

Error message

Unimplemented padding mode '{}' for np.pad.

What it means

jnp.pad supports a fixed set of modes (constant, edge, wrap, reflect, symmetric, empty, linear_ramp, maximum, mean, median, minimum). An unrecognized mode string hits a KeyError in the allowed-kwargs lookup and is re-raised as NotImplementedError.

Source

Thrown at jax/_src/numpy/lax_numpy.py:4364

  if callable(mode):
    return _pad_func(asarray(array), pad_width, mode, **kwargs)

  allowed_kwargs = {
      'empty': [], 'edge': [], 'wrap': [],
      'constant': ['constant_values'],
      'linear_ramp': ['end_values'],
      'maximum': ['stat_length'],
      'mean': ['stat_length'],
      'median': ['stat_length'],
      'minimum': ['stat_length'],
      'reflect': ['reflect_type'],
      'symmetric': ['reflect_type'],
  }
  try:
    unsupported_kwargs = set(kwargs) - set(allowed_kwargs[mode])
  except KeyError:
    msg = "Unimplemented padding mode '{}' for np.pad."
    raise NotImplementedError(msg.format(mode))
  if unsupported_kwargs:
    raise ValueError("unsupported keyword arguments for mode '{}': {}"
                     .format(mode, unsupported_kwargs))
  # Set default value if not given.
  constant_values = kwargs.get('constant_values', 0)
  stat_length = kwargs.get('stat_length', None)
  end_values = kwargs.get('end_values', 0)
  reflect_type = kwargs.get('reflect_type', "even")

  return _pad(array, pad_width, mode, constant_values, stat_length, end_values,
              reflect_type)

### Array-creation functions


@export
def stack(arrays: np.ndarray | Array | Sequence[ArrayLike],
          axis: int = 0, out: None = None, dtype: DTypeLike | None = None) -> Array:

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Use one of the supported modes; 'wrap' is the circular equivalent
  2. Check jnp.pad docstring for the current supported list in your JAX version

Example fix

// before
jnp.pad(x, 2, mode='circular')
// after
jnp.pad(x, 2, mode='wrap')
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED = {'constant','edge','wrap','reflect','symmetric','empty','linear_ramp','maximum','mean','median','minimum'}
assert mode in SUPPORTED, f'unsupported pad mode {mode}'

Prevention

When it happens

Trigger: jnp.pad(x, 2, mode='circular') (numpy has no such mode either) or typo like mode='const'.

Common situations: Porting code expecting scipy-style mode names ('grid-wrap', 'grid-constant'); typos; newer numpy modes not yet implemented in JAX.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/117dafc83da53f48. Report an issue: GitHub.