{"record":{"id":"632be85b2c1a1f2d","repo":"jax-ml/jax","slug":"config-option-name-already-defined","errorCode":null,"errorMessage":"Config option {name} already defined","messagePattern":"Config option (.+?) already defined","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"jax/_src/config.py","lineNumber":120,"sourceCode":"    if name in self._contextmanager_flags:\n      raise AttributeError(\n          \"For flags with a corresponding contextmanager, read their value \"\n          f\"via e.g. `config.{name}` rather than `config.FLAGS.{name}`.\")\n    return self._read(name)\n\n  def _read(self, name):\n    try:\n      return self._value_holders[name].value\n    except KeyError:\n      raise AttributeError(f\"Unrecognized config option: {name}\")\n\n  @property\n  def values(self):\n    return {name: holder.value for name, holder in self._value_holders.items()}\n\n  def add_option(self, name, holder, opt_type, meta_args, meta_kwargs):\n    if name in self._value_holders:\n      raise Exception(f\"Config option {name} already defined\")\n    self._value_holders[name] = holder\n    self.meta[name] = (opt_type, meta_args, meta_kwargs)\n\n  def config_with_absl(self):\n    \"\"\"Registers absl flags for the JAX configs.\n\n    E.g., for each JAX config defined using bool_state(), this method\n    registers an absl boolean flag, with the same name.\n\n    This is the recommended method to call if you use `app.run(main)` and you\n    need JAX flags.\n\n    Examples:\n\n    ```python\n    from absl import app\n    import jax\n    ...","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/config.py#L102-L138","documentation":"When JAX (or user code) registers a new config option, add_option guards against double registration by raising a generic Exception. Duplicate names would make the flag's value ambiguous (two thread-local holders, one absl flag), so registration fails fast. This commonly fires when jax.config.config_with_absl or module-level define_*_state calls execute twice.","triggerScenarios":"Re-importing/re-executing a module that calls jax.config.define_bool_state('jax_my_flag', ...) without reloading; manually calling config_with_absl() twice; copy-pasting a define_* block into two modules with the same option name.","commonSituations":"Notebook re-running a cell that defines a custom flag; plugins/extensions registering a flag that core JAX already added in a newer version (name collision after upgrade).","solutions":["Guard registration: if 'jax_my_flag' not in jax.config.values: jax.config.define_bool_state(...)","If the flag now exists in JAX core, drop your custom definition and use the built-in one","Move define_* calls to a single module-level location executed once"],"exampleFix":"# before\njax.config.define_bool_state('jax_my_flag', False, 'my flag')  # re-run cell -> Exception\n# after\nif 'jax_my_flag' not in jax.config.values:\n    jax.config.define_bool_state('jax_my_flag', False, 'my flag')","handlingStrategy":"validation","validationCode":"import jax\n\ndef define_flag_once(name, default, help):\n    if name not in jax.config.values:\n        jax.config.define_bool_state(name, default, help)\n\ndefine_flag_once('jax_my_flag', False, 'my flag')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Guard all define_*_state calls with a jax.config.values membership check","Define custom flags in exactly one module, imported once","After JAX upgrades, check your custom flag names don't collide with new core flags"],"tags":["jax","config","duplicate-registration","startup"],"backgroundTag":"duplicate-config-registration","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}