keras-team/keras · error · ValueError
Invalid value for argument `dtype`. Expected one of
Error message
Invalid value for argument `dtype`. Expected one of {ALLOWED_DTYPES}. Received: dtype={dtype} What it means
Guard in the weak-type resolution helper (_respect_weak_type): a dtype flagged as a weak Python type did not fall into any recognized category (bool, float, int, complex). This is a generic sentinel for an unrecognized dtype string reaching internal dtype standardization.
Solutions
- Pass one of the allowed dtype names ('float16'/'float32'/'float64', 'int8'...'int64', 'uint8'...'uint64', 'bool', 'complex64'/'complex128', 'bfloat16', or weak names 'float'/'int'/'complex').
- Check for typos like 'fp32' or 'float32x' in dtype arguments.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at keras/src/backend/common/dtypes.py:199 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/dd4dfcd778abdbba.
Report an issue: GitHub.
Appendix: source
Thrown at keras/src/backend/common/dtypes.py:199
# e.g, tf.float32 == float is True
is_weak_type = True
return standardize_dtype(value), is_weak_type
@functools.lru_cache(maxsize=None)
def _respect_weak_type(dtype, weak_type):
"""Return the weak dtype of `dtype` if `weak_type==True`."""
if weak_type:
if dtype == "bool":
return dtype
elif "float" in dtype:
return "float"
elif "int" in dtype:
return "int"
elif "complex" in dtype:
return "complex"
else:
raise ValueError(
"Invalid value for argument `dtype`. Expected one of "
f"{ALLOWED_DTYPES}. Received: dtype={dtype}"
)
return dtype
@functools.lru_cache(maxsize=None)
def _resolve_weak_type(dtype, precision="32"):
"""Resolve weak type by the precision of `backend.floatx()`."""
extended_allowed_dtypes = set(ALLOWED_DTYPES).union(WEAK_TYPES)
if dtype not in extended_allowed_dtypes:
raise ValueError(
"Invalid value for argument `dtype`. Expected one of "
f"{extended_allowed_dtypes}. Received: dtype={dtype}"
)
if precision not in ["16", "32", "64"]:
raise ValueError(
f"Invalid value for argument `precision`. Expected one of "View on GitHub (pinned to 7a34a03db6)