{"record":{"id":"ae7d19d24e94e1c7","repo":"keras-team/keras","slug":"lora-is-not-currently-supported-with-gptq-quantiza","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/dense.py","lineNumber":273,"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 correct input dimension for the LoRA A matrix. When\n        # the layer has been int4-quantized, `self._kernel` stores a *packed*\n        # representation whose first dimension is `ceil(input_dim/2)`. We\n        # saved the true, *unpacked* input dimension in `self._orig_input_dim`\n        # during quantization. Use it if available; otherwise fall back to the\n        # first dimension of `self.kernel`.\n        if self.quantization_mode == \"int4\" and hasattr(\n            self, \"_orig_input_dim\"\n        ):\n            input_dim_for_lora = self._orig_input_dim\n        else:\n            input_dim_for_lora = self.kernel.shape[0]\n\n        # LoRA weights should be float32 to avoid the risk of underflow or\n        # overflow during fine-tuning.","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/core/dense.py#L255-L291","documentation":"enable_lora() does not support GPTQ-quantized layers: GPTQ stores a packed int4 kernel whose dimensions don't match the float kernel LoRA needs, so the LoRA A-matrix cannot be sized against it. NotImplementedError fires before any LoRA state is created.","triggerScenarios":"Calling enable_lora() on a Dense layer whose quantization_config uses mode='gptq' — e.g. LoRA-injecting a model quantized for GPTQ.","commonSituations":"QLoRA-style workflows where developers quantize with GPTQ then try to add LoRA; blanket enable_lora loops that don't check quantization_mode.","solutions":["Skip GPTQ layers during injection: if layer.quantization_mode == 'gptq': continue.","Use int8 or unquantized layers for LoRA fine-tuning instead of GPTQ.","Check layer.quantization_mode in your LoRA utility before calling enable_lora."],"exampleFix":"# before\nfor layer in model.layers:\n    layer.enable_lora(8)  # raises NotImplementedError on gptq layers\n\n# after\nfor layer in model.layers:\n    if getattr(layer, 'quantization_mode', None) != 'gptq':\n        layer.enable_lora(8)","handlingStrategy":"validation","validationCode":"for layer in model.layers:\n    if getattr(layer, 'quantization_mode', None) == 'gptq':\n        continue\n    layer.enable_lora(rank)","typeGuard":"def lora_supported(layer) -> bool:\n    return getattr(layer, 'quantization_mode', None) != 'gptq'","tryCatchPattern":"try:\n    layer.enable_lora(rank)\nexcept NotImplementedError:\n    pass  # unsupported quantization; skip layer","preventionTips":["Filter by quantization_mode before enable_lora","Prefer int8 or unquantized layers for LoRA"],"tags":["keras","lora","gptq","quantization","unsupported-operation"],"backgroundTag":"lora-enable-precondition-failed","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}