keras-team/keras · error · ValueError

Arguments `sample_weight` and `class_weight` cannot be speci

Error message

Arguments `sample_weight` and `class_weight` cannot be specified at the same time. Received: sample_weight={sample_weight}, class_weight={class_weight}

What it means

Error "Arguments `sample_weight` and `class_weight` cannot be specified at the same time. Received: sample_weight={sample_weight}, class_weight={class_weight}" thrown in keras-team/keras.

Source

Thrown at keras/src/backend/jax/trainer.py:760

                    break

        self.jax_state_sync()
        callbacks.on_predict_end()
        self._jax_state = None
        return tree.map_structure_up_to(batch_outputs, np.concatenate, outputs)

    def train_on_batch(
        self,
        x,
        y=None,
        sample_weight=None,
        class_weight=None,
        return_dict=False,
    ):
        self._assert_compile_called("train_on_batch")
        if class_weight is not None:
            if sample_weight is not None:
                raise ValueError(
                    "Arguments `sample_weight` and `class_weight` "
                    "cannot be specified at the same time. "
                    f"Received: sample_weight={sample_weight}, "
                    f"class_weight={class_weight}"
                )
            sample_weight = data_adapter_utils.class_weight_to_sample_weights(
                y, class_weight
            )

        def data():
            yield _distribute_data((x, y, sample_weight))

        # Maybe build model
        self._symbolic_build(data_batch=next(data()))
        self.make_train_function()
        self.reset_metrics()

        # Train step

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/backend/jax/trainer.py:760 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/7b196bbd3dd19be6. Report an issue: GitHub.