{"record":{"id":"7b196bbd3dd19be6","repo":"keras-team/keras","slug":"arguments-sample-weight-and-class-weight-canno","errorCode":null,"errorMessage":"Arguments `sample_weight` and `class_weight` cannot be specified at the same time. Received: sample_weight={sample_weight}, class_weight={class_weight}","messagePattern":"Arguments `sample_weight` and `class_weight` cannot be specified at the same time\\. Received: sample_weight=(.+?), class_weight=(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/backend/jax/trainer.py","lineNumber":760,"sourceCode":"                    break\n\n        self.jax_state_sync()\n        callbacks.on_predict_end()\n        self._jax_state = None\n        return tree.map_structure_up_to(batch_outputs, np.concatenate, outputs)\n\n    def train_on_batch(\n        self,\n        x,\n        y=None,\n        sample_weight=None,\n        class_weight=None,\n        return_dict=False,\n    ):\n        self._assert_compile_called(\"train_on_batch\")\n        if class_weight is not None:\n            if sample_weight is not None:\n                raise ValueError(\n                    \"Arguments `sample_weight` and `class_weight` \"\n                    \"cannot be specified at the same time. \"\n                    f\"Received: sample_weight={sample_weight}, \"\n                    f\"class_weight={class_weight}\"\n                )\n            sample_weight = data_adapter_utils.class_weight_to_sample_weights(\n                y, class_weight\n            )\n\n        def data():\n            yield _distribute_data((x, y, sample_weight))\n\n        # Maybe build model\n        self._symbolic_build(data_batch=next(data()))\n        self.make_train_function()\n        self.reset_metrics()\n\n        # Train step","sourceCodeStart":742,"sourceCodeEnd":778,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/backend/jax/trainer.py#L742-L778","documentation":"Mutual-exclusion check in the JAX Trainer.train_on_batch: sample_weight and class_weight are two alternative per-sample weighting mechanisms, and supplying both would make the intended weighting ambiguous, so the trainer rejects the combination when class_weight is not None.","triggerScenarios":"Thrown at keras/src/backend/jax/trainer.py:760 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Keep exactly one of the two: per-sample float weights via sample_weight, or class-to-weight dict via class_weight","Convert a class_weight dict into an explicit sample_weight array if you truly need both semantics"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}