keras-team/keras · error · AttributeError

Variable is not properly initialized (raw_value missing)…

Error message

Variable is not properly initialized (raw_value missing) and has no initializer.

What it means

Raised in the JAX backend variable patch (core.py) when a JaxVariable/KerasVariable was created under a stateless scope with a callable initializer, leaving _raw_value unset, and initialization never happened. Reading .value then finds neither a stored value nor an initializer to lazily compute one, and this guard reports the uninitialized variable.

Solutions

  1. Trigger variable initialization before use (e.g. call layer.build or run a forward pass outside the stateless scope)
  2. Create the variable with an initial value or with both initializer and shape so it can be initialized
  3. Supply the variable's value in the StatelessScope state_mapping so a current value exists
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/backend/jax/ops/core.py:287 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/70eaaf7c3e1abf2a. Report an issue: GitHub.

Appendix: source

Thrown at keras/src/backend/jax/ops/core.py:287

        @property
        def value(self):
            if in_stateless_scope():
                scope = get_stateless_scope()
                stateless_value = scope.get_current_value(self)
                if stateless_value is not None:
                    return self._maybe_autocast(stateless_value)
            current_value = _get_raw_value(self)
            if current_value is None:
                # Uninitialized variable (created under a stateless scope,
                # which defers initialization). Return a placeholder, like
                # `KerasVariable.value`, without mutating the variable.
                if self._initializer is not None:
                    return self._maybe_autocast(
                        self._initializer(self._shape, dtype=self._dtype)
                    )
                else:
                    raise AttributeError(
                        "Variable is not properly initialized (raw_value "
                        "missing) and has no initializer."
                    )
            if (
                hasattr(self, "_var_metadata")
                and "on_get_value" in self._var_metadata
            ):
                current_value = self._var_metadata["on_get_value"](
                    self, current_value
                )
            return self._maybe_autocast(current_value)

    Variable = NnxVariable

    def _flatten_nnx_variable(variable):
        children = (_get_raw_value(variable),)
        # We copy __dict__ to avoid side effects
        keras_state = variable.__dict__.copy()

View on GitHub (pinned to 7a34a03db6)