jax-ml/jax · error · ValueError

unsupported keyword arguments for mode '{}': {}

Error message

unsupported keyword arguments for mode '{}': {}

What it means

Each pad mode only accepts certain kwargs (e.g. 'constant' accepts constant_values; 'reflect' accepts reflect_type). Passing kwargs not in the mode's allow-list raises ValueError naming the unsupported kwargs.

Source

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

  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:
  """Join arrays along a new axis.

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Remove kwargs not applicable to the chosen mode
  2. Check the allowed_kwargs table in the jnp.pad source/docstring

Example fix

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

Strategy: validation

Validate before calling

ALLOWED = {'constant': {'constant_values'}, 'reflect': {'reflect_type'}, 'symmetric': {'reflect_type'}}
assert set(kwargs) <= ALLOWED.get(mode, set()), 'bad kwargs for mode'

Prevention

When it happens

Trigger: jnp.pad(x, 2, mode='wrap', constant_values=1) or mode='edge', stat_length=3.

Common situations: Copy-pasting kwargs between modes when switching; passing all possible kwargs defensively.

Related errors


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