{"record":{"id":"f979eb7f53754380","repo":"keras-team/keras","slug":"currently-float8-call-doesn-t-support-lora-f979eb","errorCode":null,"errorMessage":"Currently, `_float8_call` doesn't support LoRA","messagePattern":"Currently, `_float8_call` doesn't support LoRA","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"keras/src/layers/core/einsum_dense.py","lineNumber":1265,"sourceCode":"                ops.convert_to_tensor(self.kernel_zero),\n                ops.convert_to_tensor(self.g_idx),\n            )\n\n        if self.lora_enabled:\n            lora_x = ops.einsum(self.equation, inputs, self.lora_kernel_a)\n            lora_x = ops.matmul(lora_x, self.lora_kernel_b)\n            x = ops.add(x, (self.lora_alpha / self.lora_rank) * lora_x)\n            x = ops.cast(x, dtype=self.compute_dtype)\n        # Bias & activation\n        if self.bias is not None:\n            x = ops.add(x, self.bias)\n        if self.activation is not None:\n            x = self.activation(x)\n        return x\n\n    def _float8_call(self, inputs, training=None):\n        if self.lora_enabled:\n            raise NotImplementedError(\n                \"Currently, `_float8_call` doesn't support LoRA\"\n            )\n\n        @ops.custom_gradient\n        def quantized_dequantize_inputs(inputs, scale, amax_history):\n            if training:\n                new_scale = quantizers.compute_float8_scale(\n                    ops.max(amax_history, axis=0),\n                    scale,\n                    ops.cast(\n                        float(ml_dtypes.finfo(\"float8_e4m3fn\").max), \"float32\"\n                    ),\n                )\n                new_amax_history = quantizers.compute_float8_amax_history(\n                    inputs, amax_history\n                )\n            else:\n                new_scale = None","sourceCodeStart":1247,"sourceCodeEnd":1283,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/core/einsum_dense.py#L1247-L1283","documentation":"The float8 quantized forward path (_float8_call) of EinsumDense does not implement LoRA merging, so a layer with both lora_enabled=True and quantization_mode 'float8' raises NotImplementedError at runtime on the first forward pass.","triggerScenarios":"layer.enable_lora(...) on a layer that is (or later becomes) float8-quantized, then running model(x) or model.fit; a float8 quantization config covering an EinsumDense combined with LoRA fine-tuning.","commonSituations":"PEFT pipelines on float8 training configs; enabling LoRA broadly across a model that also applies float8 quantization to projections; upgrading configs to float8 while existing LoRA setup code remains.","solutions":["Exclude float8-quantized layers from LoRA enabling (check layer.quantization_mode before enable_lora).","Or exclude this layer from float8 quantization via filters if it must be LoRA-trained.","Use a supported combination, e.g. LoRA on a non-quantized or int8 path for this layer."],"exampleFix":"# before\nlayer.enable_lora(rank=8)\nmodel.quantize(float8_config)  # covers layer\nmodel(x)  # NotImplementedError\n\n# after\nif layer.quantization_mode != 'float8':\n    layer.enable_lora(rank=8)","handlingStrategy":"validation","validationCode":"for l in model.layers:\n    if getattr(l, 'lora_enabled', False) and getattr(l, 'quantization_mode', None) == 'float8':\n        raise RuntimeError(f'{l.name}: float8 + LoRA unsupported')","typeGuard":"def lora_forward_safe(layer) -> bool:\n    return not (layer.lora_enabled and layer.quantization_mode == 'float8')","tryCatchPattern":"try:\n    out = model(x)\nexcept NotImplementedError as e:\n    if 'float8' in str(e):\n        disable_lora_on_float8_layers(model)\n    else:\n        raise","preventionTips":["Check quantization_mode before enable_lora.","Exclude float8 layers from LoRA configs."],"tags":["keras","float8","quantization","lora","einsum-dense"],"backgroundTag":"lora-quantization-incompatible","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}