{"record":{"id":"c1dd47dc615da8a4","repo":"keras-team/keras","slug":"currently-float8-call-doesn-t-support-lora","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/dense.py","lineNumber":1099,"sourceCode":"                ops.convert_to_tensor(self.kernel_scale),\n                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.matmul(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, self.compute_dtype)\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":1081,"sourceCodeEnd":1117,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/layers/core/dense.py#L1081-L1117","documentation":"Dense's float8 compute path (_float8_call, active under float8 quantization) does not implement the LoRA branch, so a forward pass on a Dense layer with both float8 quantization and lora_enabled=True raises NotImplementedError.","triggerScenarios":"Running forward passes on a Dense layer under a float8 dtype policy after enable_lora() was called on it.","commonSituations":"Mixing float8 training with LoRA fine-tuning; enable_lora loops applied indiscriminately to float8 models.","solutions":["Skip LoRA on float8 layers: check the dtype policy / quantization mode before enable_lora.","Use a float16/bfloat16 or float32 policy for layers you intend to LoRA-finetune.","Track upstream Keras support — this is an explicit 'not yet implemented' gap."],"exampleFix":"# before\nwith keras.dtype_policy.float8('float8_e4m3'):\n    dense = keras.layers.Dense(64)\ndense.build(x.shape)\ndense.enable_lora(8)\ny = dense(x)  # NotImplementedError\n\n# after\ndense = keras.layers.Dense(64)  # default float32 policy\ndense.build(x.shape)\ndense.enable_lora(8)\ny = dense(x)","handlingStrategy":"validation","validationCode":"def lora_dtype_ok(layer) -> bool:\n    return 'float8' not in str(getattr(layer, 'compute_dtype', 'float32'))\n\nfor layer in model.layers:\n    if isinstance(layer, keras.layers.Dense) and lora_dtype_ok(layer):\n        layer.enable_lora(rank)","typeGuard":"def lora_dtype_ok(layer) -> bool:\n    return 'float8' not in str(getattr(layer, 'compute_dtype', 'float32'))","tryCatchPattern":"try:\n    y = dense(x)\nexcept NotImplementedError as e:\n    if 'float8' in str(e):\n        switch_to_float16_policy()","preventionTips":["Don't combine float8 policies with LoRA","Check dtype policy before enable_lora"],"tags":["keras","lora","float8","quantization","unsupported-operation"],"backgroundTag":"lora-quantization-incompatible","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}