keras-team/keras · error · TypeError
ldexp exponent must be an integer type. Received: x2 dtype=
Error message
ldexp exponent must be an integer type. Received: x2 dtype={x2.dtype} What it means
A dtype guard in the NumPy `ldexp` implementation (x1 * 2**x2). ldexp requires the exponent `x2` to be an integer array; if x2 arrives with a float dtype the underlying operation is undefined. The guard checks x2's dtype against the integer type list and, on failure, raises a TypeError reporting the offending dtype. Used by mixed-precision benchmark entry points (e.g. BERT/image classification benchmarks), so it typically fires when an exponent tensor was upcast to float32 by a mixed-precision policy.
Solutions
- Cast the exponent to an integer dtype before calling ldexp: keras.ops.cast(x2, 'int32')
- Compute x1 * 2**x2 with explicit power ops if a float exponent must be kept
- Audit mixed-precision dtype policies that upcast all tensors to float and exempt integer-valued exponent inputs
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at keras/src/backend/numpy/numpy.py:877 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25).
Data as JSON: /api/errors/5fc3c0e674c6d304.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/backend/numpy/numpy.py:877
x2 = convert_to_tensor(x2)
dtype = dtypes.result_type(x1.dtype, x2.dtype)
return np.kron(x1, x2).astype(dtype)
def lcm(x1, x2):
x1 = convert_to_tensor(x1)
x2 = convert_to_tensor(x2)
dtype = dtypes.result_type(x1.dtype, x2.dtype)
return np.lcm(x1, x2).astype(dtype)
def ldexp(x1, x2):
x1 = convert_to_tensor(x1)
x2 = convert_to_tensor(x2)
dtype = dtypes.result_type(x1.dtype, x2.dtype, float)
if standardize_dtype(x2.dtype) not in dtypes.INT_TYPES:
raise TypeError(
f"ldexp exponent must be an integer type. "
f"Received: x2 dtype={x2.dtype}"
)
return np.ldexp(x1, x2).astype(dtype)
def less(x1, x2):
return np.less(x1, x2)
def less_equal(x1, x2):
return np.less_equal(x1, x2)
def linspace(
start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0
):
axis = standardize_axis_for_numpy(axis)View on GitHub (pinned to 7a34a03db6)