jax-ml/jax · error · TypeError
Default value must be of type float, got {default} of type {
Error message
Default value must be of type float, got {default} of type {getattr(type(default), '__name__', type(default))} What it means
float_state requires `default` to be a Python float; ints and strings are rejected (unlike the runtime parser, which accepts ints). Non-float defaults raise this TypeError at flag definition.
Source
Thrown at jax/_src/config.py:755
update_thread_local_hook: Callable[[float | None], None] | None = None,
) -> State[float]:
"""Set up thread-local state and return a contextmanager for managing it.
See docstring for ``bool_state``.
Args:
name: string, converted to lowercase to define the name of the config
option (and absl flag). It is converted to uppercase to define the
corresponding shell environment variable.
default: default value.
help: string, used to populate the flag help information as well as the
docstring of the returned context manager.
Returns:
A contextmanager to control the thread-local state value.
"""
if not isinstance(default, float):
raise TypeError(f"Default value must be of type float, got {default} "
f"of type {getattr(type(default), '__name__', type(default))}")
name = name.lower()
default_env = os.getenv(name.upper())
if default_env is not None:
try:
default = float(default_env)
except ValueError:
raise ValueError(f"Invalid value \"{default_env}\" for JAX flag {name}")
config._contextmanager_flags.add(name)
def parser(new_val):
if new_val is not None and not isinstance(new_val, (float, int)):
raise ValueError(
f'new float config value must be None or of type float, '
f'got {new_val} of type {type(new_val)}')
return new_val
s = State[float](name, default, help, update_global_hook,View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Add a decimal point: default=0.5 or default=float(value)
- Wrap externally-sourced defaults with float(...)
Example fix
// before
config.float_state('my_flag', default=1)
// after
config.float_state('my_flag', default=1.0) Defensive patterns
Strategy: type-guard
Validate before calling
assert isinstance(default, float), 'default must be a Python float (write 1.0 not 1)'
Type guard
def is_float(v) -> bool:
return isinstance(v, float) Prevention
- Always include a decimal point in float flag defaults
- Wrap dynamic defaults with float(...)
When it happens
Trigger: Calling config.float_state('my_flag', default=1) or default='0.5'.
Common situations: Defining a tolerance/learning-rate style flag and naturally writing default=0 (int) instead of 0.0.
Related errors
- bool() not supported for instances of type '{0}' (did you me
- Default value must be of type bool, got {default} of type {g
- Default value must be of type str, got {default} of type {ge
- Default value must be of type str or None, got {default} of
- Default value must be of type {enum_class}, got {default} of
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/70cb9c2088c81c9c.
Report an issue: GitHub.