keras-team/keras · error · ValueError

Received an invalid value for `units`, expected a positive i

Error message

Received an invalid value for `units`, expected a positive integer. Received: units={units}

What it means

Error "Received an invalid value for `units`, expected a positive integer. Received: units={units}" thrown in keras-team/keras.

Source

Thrown at keras/src/layers/core/ternary_dense.py:125

    """

    def __init__(
        self,
        units,
        threshold=None,
        activation=None,
        use_bias=True,
        kernel_initializer="glorot_uniform",
        bias_initializer="zeros",
        kernel_regularizer=None,
        bias_regularizer=None,
        activity_regularizer=None,
        kernel_constraint=None,
        bias_constraint=None,
        **kwargs,
    ):
        if not isinstance(units, int) or units <= 0:
            raise ValueError(
                "Received an invalid value for `units`, expected a positive "
                f"integer. Received: units={units}"
            )
        if threshold is not None and not isinstance(threshold, (int, float)):
            raise ValueError(
                "Received an invalid value for `threshold`, expected a float "
                f"or None. Received: threshold={threshold}"
            )
        if threshold is not None and threshold < 0:
            raise ValueError(
                "Received an invalid value for `threshold`, expected a "
                "non-negative float or None. "
                f"Received: threshold={threshold}"
            )

        super().__init__(activity_regularizer=activity_regularizer, **kwargs)
        self.units = units
        self.threshold = threshold

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/layers/core/ternary_dense.py:125 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/c0eba575e3fb62b1. Report an issue: GitHub.