keras-team/keras · error · NotImplementedError

lora is not currently supported with GPTQ quantization.

Error message

lora is not currently supported with GPTQ quantization.

What it means

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.

Source

Thrown at keras/src/layers/core/einsum_dense.py:349

        a_initializer="he_uniform",
        b_initializer="zeros",
    ):
        if self.kernel_constraint:
            raise ValueError(
                "Lora is incompatible with kernel constraints. "
                "In order to enable lora on this layer, remove the "
                "`kernel_constraint` argument."
            )
        if not self.built:
            raise ValueError(
                "Cannot enable lora on a layer that isn't yet built."
            )
        if self.lora_enabled:
            raise ValueError(
                "lora is already enabled. This can only be done once per layer."
            )
        if self.quantization_mode == "gptq":
            raise NotImplementedError(
                "lora is not currently supported with GPTQ quantization."
            )
        self._tracker.unlock()
        # Determine the appropriate (unpacked) kernel shape for LoRA.
        if self.quantization_mode == "int4":
            # INT4 weights are stored in a flattened 2D layout that loses
            # the original N-dimensional structure required by the einsum
            # equation. We use `original_kernel_shape`` to ensure LoRA adapters
            # operate in the correct logical dimension space.
            kernel_shape_for_lora = tuple(self.original_kernel_shape)
        else:
            kernel_shape_for_lora = self.kernel.shape

        # LoRA weights should be float32 to avoid the risk of underflow or
        # overflow during fine-tuning.
        # When deploying the model, these weights should be merged with the
        # original kernel while maintaining the original kernel's dtype.
        self.lora_kernel_a = self.add_weight(

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Enable LoRA before quantizing, if your pipeline allows the LoRA-then-quantize order (verify the target mode supports it).
  2. 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).
  3. Fine-tune in a non-GPTQ representation and apply GPTQ afterwards.

Example fix

# before
model.quantize(config_with_gptq)  # covers EinsumDense layers
layer.enable_lora(rank=8)  # NotImplementedError

# after
layer.enable_lora(rank=8)  # LoRA first
# then quantize with filters that skip this layer, or a LoRA-compatible mode
Defensive patterns

Strategy: validation

Validate before calling

if layer.quantization_mode == 'gptq':
    raise RuntimeError('LoRA unsupported with GPTQ; reorder or exclude layer')
layer.enable_lora(rank)

Try / catch

try:
    layer.enable_lora(rank)
except NotImplementedError:
    # fall back to excluding this layer from LoRA
    ...

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/d25ca483fde6489c. Report an issue: GitHub.