jax-ml/jax · error · ValueError
new int config value must be None or of type int, got {new_v
Error message
new int config value must be None or of type int, got {new_val} of type {type(new_val)} What it means
The parser for int_state rejects new values that are not None and not int (bool passes since bool subclasses int; str and float do not). Raised when setting the flag via context manager or config.update.
Source
Thrown at jax/_src/config.py:716
Returns:
A contextmanager to control the thread-local state value.
"""
if not isinstance(default, int):
raise TypeError(f"Default value must be of type int, 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 = int(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, int):
raise ValueError(f'new int config value must be None or of type int, '
f'got {new_val} of type {type(new_val)}')
if new_val is not None and validator is not None:
validator(new_val)
return new_val
s = State[int](name, default, help, update_global_hook,
update_thread_local_hook, parser,
include_in_jit_key=include_in_jit_key,
include_in_trace_context=include_in_trace_context)
config.add_option(name, s, int, meta_args=[], meta_kwargs={"help": help})
setattr(Config, name, property(lambda _: s.value))
return s
def float_state(
name: str,
default: float,
help: str,View on GitHub (pinned to 1e1c6a8fc0)
Solutions
- Convert before setting: int(value)
- Validate the raw input is an integer string early (e.g. argparse type=int)
Example fix
// before
jax.config.update('jax_my_flag', args.limit) # argparse str
// after
jax.config.update('jax_my_flag', int(args.limit)) Defensive patterns
Strategy: validation
Validate before calling
if new_val is not None and (isinstance(new_val, bool) or not isinstance(new_val, int)):
raise ValueError(f'expected int or None, got {type(new_val)}') Type guard
def is_int_or_none(v) -> bool:
return v is None or (isinstance(v, int) and not isinstance(v, bool)) Try / catch
try:
jax.config.update('jax_my_flag', val)
except ValueError:
jax.config.update('jax_my_flag', int(val)) Prevention
- Use argparse type=int for CLI values destined for int flags
- Convert strings from JSON/YAML with int() before config.update
When it happens
Trigger: jax.config.update('jax_my_flag', '128') or with my_flag(3.5): — string or float instead of int.
Common situations: Values sourced from argparse (strings), JSON/YAML configs, or user input being passed to an int-backed flag without conversion.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Invalid value "{default_env}" for JAX flag {name}
- Invalid value "{default}" for JAX flag {name}
- new enum value must be in {enum_values}, got {new_val} of ty
- new enum value must be None or in {enum_values}, got {new_va
- Invalid value "{default_str}" for JAX flag {name}
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/8334e7fa4c3114e3.
Report an issue: GitHub.