{"record":{"id":"07001b7a937d1583","repo":"keras-team/keras","slug":"invalid-tensor-type-tensor-type","errorCode":null,"errorMessage":"Invalid tensor type: {tensor_type}","messagePattern":"Invalid tensor type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/core/einsum_dense.py","lineNumber":1672,"sourceCode":"        This is the forward order of operations used when building the layer.\n\n        Args:\n            scale: The scale tensor to adjust.\n            tensor_type: The type of tensor to adjust the scale for.\n                \"kernel\" or \"input\".\n        Returns:\n            The adjusted scale tensor.\n        \"\"\"\n        if tensor_type == \"kernel\":\n            transpose_axes = self._kernel_transpose_axes\n            expand_axes = self._kernel_expand_axes\n            squeeze_axes = self._kernel_squeeze_axes\n        elif tensor_type == \"input\":\n            transpose_axes = self._input_transpose_axes\n            expand_axes = self._input_expand_axes\n            squeeze_axes = self._input_squeeze_axes\n        else:\n            raise ValueError(f\"Invalid tensor type: {tensor_type}\")\n\n        if transpose_axes:\n            scale = ops.transpose(scale, transpose_axes)\n        if expand_axes:\n            scale = ops.expand_dims(scale, axis=expand_axes)\n        if squeeze_axes:\n            scale = ops.squeeze(scale, axis=squeeze_axes)\n        return scale\n\n    def _set_quantization_info(self):\n        if hasattr(self, \"_input_reduced_axes\"):\n            # Already set.\n            return\n        (\n            self._input_reduced_axes,\n            self._kernel_reduced_axes,\n            self._input_transpose_axes,\n            self._kernel_transpose_axes,","sourceCodeStart":1654,"sourceCodeEnd":1690,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/core/einsum_dense.py#L1654-L1690","documentation":"_adjust_scale_for_quant in EinsumDense accepts only tensor_type 'kernel' or 'input' when reshaping a quantization scale. Any other string reaches the else branch and raises ValueError. This is an internal helper, so hitting it usually means a subclass or custom quantization path passed an unsupported type.","triggerScenarios":"Calling einsum_with_inputs_gradient, einsum_per_channel_with_inputs_gradient, quantize, or _get_kernel_with_merged_lora after the tensor_type argument was changed to a value other than 'kernel'/'input' (e.g. 'weight', 'bias', None) in a subclass override.","commonSituations":"Custom EinsumDense subclasses or custom quantizers that override quantization helpers and pass a renamed tensor type; version upgrades that renamed 'kernel' to 'weight' without updating call sites.","solutions":["Pass exactly 'kernel' or 'input' as tensor_type","Check the two branches above the raise to see accepted values","If a new tensor kind is genuinely needed, extend the if/elif chain before the else branch"],"exampleFix":"# before\n_scale = layer._adjust_scale_for_quant(scale, 'weight')\n# after\n_scale = layer._adjust_scale_for_quant(scale, 'kernel')","handlingStrategy":"validation","validationCode":"TENSOR_TYPES = {'kernel', 'input'}\nassert tensor_type in TENSOR_TYPES","typeGuard":"def is_valid_tensor_type(t):\n    return t in ('kernel', 'input')","tryCatchPattern":null,"preventionTips":["Treat _adjust_scale_for_quant as internal API; pin call sites to the literals 'kernel' and 'input'","Add unit tests for custom quantization paths covering both tensor types"],"tags":["keras","einsum-dense","quantization","internal-api"],"backgroundTag":"invalid-enum-argument","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}