{"record":{"id":"d25ca483fde6489c","repo":"keras-team/keras","slug":"lora-is-not-currently-supported-with-gptq-quantiza-d25ca4","errorCode":null,"errorMessage":"lora is not currently supported with GPTQ quantization.","messagePattern":"lora is not currently supported with GPTQ quantization\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/core/einsum_dense.py","lineNumber":349,"sourceCode":"        a_initializer=\"he_uniform\",\n        b_initializer=\"zeros\",\n    ):\n        if self.kernel_constraint:\n            raise ValueError(\n                \"Lora is incompatible with kernel constraints. \"\n                \"In order to enable lora on this layer, remove the \"\n                \"`kernel_constraint` argument.\"\n            )\n        if not self.built:\n            raise ValueError(\n                \"Cannot enable lora on a layer that isn't yet built.\"\n            )\n        if self.lora_enabled:\n            raise ValueError(\n                \"lora is already enabled. This can only be done once per layer.\"\n            )\n        if self.quantization_mode == \"gptq\":\n            raise NotImplementedError(\n                \"lora is not currently supported with GPTQ quantization.\"\n            )\n        self._tracker.unlock()\n        # Determine the appropriate (unpacked) kernel shape for LoRA.\n        if self.quantization_mode == \"int4\":\n            # INT4 weights are stored in a flattened 2D layout that loses\n            # the original N-dimensional structure required by the einsum\n            # equation. We use `original_kernel_shape`` to ensure LoRA adapters\n            # operate in the correct logical dimension space.\n            kernel_shape_for_lora = tuple(self.original_kernel_shape)\n        else:\n            kernel_shape_for_lora = self.kernel.shape\n\n        # LoRA weights should be float32 to avoid the risk of underflow or\n        # overflow during fine-tuning.\n        # When deploying the model, these weights should be merged with the\n        # original kernel while maintaining the original kernel's dtype.\n        self.lora_kernel_a = self.add_weight(","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/core/einsum_dense.py#L331-L367","documentation":"EinsumDense.enable_lora() does not support GPTQ post-training quantization: a GPTQ-quantized kernel is packed and permuted in a way the LoRA A/B decomposition cannot wrap. The guard raises NotImplementedError before any LoRA variables are created, leaving the layer unchanged.","triggerScenarios":"Calling enable_lora on a layer whose quantization_mode is 'gptq' — after model.quantize(...) with a GPTQ config covering this layer, or after loading a GPTQ-quantized checkpoint.","commonSituations":"Combining PEFT LoRA fine-tuning with GPTQ-quantized LLM weights (common when adapting quantized open-weight models); enabling LoRA after a quantization pass already ran over the projection layers.","solutions":["Enable LoRA before quantizing, if your pipeline allows the LoRA-then-quantize order (verify the target mode supports it).","Exclude this layer from GPTQ using the quantization filters argument, or switch it to a mode compatible with LoRA (e.g. the int8/int4 paths).","Fine-tune in a non-GPTQ representation and apply GPTQ afterwards."],"exampleFix":"# before\nmodel.quantize(config_with_gptq)  # covers EinsumDense layers\nlayer.enable_lora(rank=8)  # NotImplementedError\n\n# after\nlayer.enable_lora(rank=8)  # LoRA first\n# then quantize with filters that skip this layer, or a LoRA-compatible mode","handlingStrategy":"validation","validationCode":"if layer.quantization_mode == 'gptq':\n    raise RuntimeError('LoRA unsupported with GPTQ; reorder or exclude layer')\nlayer.enable_lora(rank)","typeGuard":null,"tryCatchPattern":"try:\n    layer.enable_lora(rank)\nexcept NotImplementedError:\n    # fall back to excluding this layer from LoRA\n    ...","preventionTips":["Enable LoRA before quantization.","Exclude GPTQ-quantized layers from LoRA sweeps."],"tags":["keras","lora","gptq","quantization","einsum-dense"],"backgroundTag":"lora-quantization-incompatible","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}