{"record":{"id":"23fbfd372aae6a35","repo":"keras-team/keras","slug":"dtype-was-passed-both-positionally-and-as-a-keyw","errorCode":null,"errorMessage":"`dtype` was passed both positionally and as a keyword argument.","messagePattern":"`dtype` was passed both positionally and as a keyword argument\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/layer.py","lineNumber":605,"sourceCode":"                    f\"Received: add_weight('{shape_arg}', ...). \"\n                    f\"Use: add_weight(shape=..., name='{shape_arg}').\"\n                )\n            if shape is not None:\n                raise ValueError(\n                    \"`shape` was passed both positionally and as \"\n                    \"a keyword argument.\"\n                )\n            shape = shape_arg\n            if len(args) > 1:\n                if initializer is not None:\n                    raise ValueError(\n                        \"`initializer` was passed both positionally and \"\n                        \"as a keyword argument.\"\n                    )\n                initializer = args[1]\n            if len(args) > 2:\n                if dtype is not None:\n                    raise ValueError(\n                        \"`dtype` was passed both positionally and as a \"\n                        \"keyword argument.\"\n                    )\n                dtype = args[2]\n        if shape is None:\n            shape = ()\n        if dtype is not None:\n            dtype = backend.standardize_dtype(dtype)\n        else:\n            dtype = self.variable_dtype\n        if initializer is None:\n            if \"float\" in dtype:\n                initializer = \"glorot_uniform\"\n            else:\n                initializer = \"zeros\"\n        initializer = initializers.get(initializer)\n        with backend.name_scope(self.name, caller=self):\n            variable = backend.Variable(","sourceCodeStart":587,"sourceCodeEnd":623,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/layer.py#L587-L623","documentation":"Layer.add_weight() in Keras 3 rejects calls where dtype is supplied both positionally (the 3rd positional argument) and via the dtype= keyword. Positional args map to (shape, initializer, dtype), so any overlap with the corresponding keyword raises this ValueError.","triggerScenarios":"add_weight(shape, init, 'float32', dtype='float32') — the 3rd positional collides with the dtype keyword. Typical when Keras 2 code that passed dtype positionally is edited to add dtype= for mixed precision.","commonSituations":"Migrating mixed-precision Keras 2 layers; editing generated add_weight calls; custom layers whose signature changed across Keras versions.","solutions":["Drop one of the two dtype specifications and pass all arguments as keywords","Audit the layer for other positional/keyword overlaps (shape, initializer) since they raise sibling errors"],"exampleFix":"# before\nself.add_weight((64, 64), 'zeros', 'float32', dtype='float32')\n# after\nself.add_weight(shape=(64, 64), initializer='zeros', dtype='float32')","handlingStrategy":"validation","validationCode":"# keep add_weight calls keyword-only: layer.add_weight(shape=s, initializer=i, dtype=d)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Adopt the Keras 3 keyword convention in CI via a code-style check","Never mix legacy positional calls with edited keyword arguments"],"tags":["keras","layers","add-weight","dtype"],"backgroundTag":"duplicate-argument-passed","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}