keras-team/keras · error · NotImplementedError

Currently, `_float8_call` doesn't support LoRA

Error message

Currently, `_float8_call` doesn't support LoRA

What it means

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.

Source

Thrown at keras/src/layers/core/dense.py:1099

                ops.convert_to_tensor(self.kernel_scale),
                ops.convert_to_tensor(self.kernel_zero),
                ops.convert_to_tensor(self.g_idx),
            )

        if self.lora_enabled:
            lora_x = ops.matmul(inputs, self.lora_kernel_a)
            lora_x = ops.matmul(lora_x, self.lora_kernel_b)
            x = ops.add(x, (self.lora_alpha / self.lora_rank) * lora_x)
            x = ops.cast(x, self.compute_dtype)
        if self.bias is not None:
            x = ops.add(x, self.bias)
        if self.activation is not None:
            x = self.activation(x)
        return x

    def _float8_call(self, inputs, training=None):
        if self.lora_enabled:
            raise NotImplementedError(
                "Currently, `_float8_call` doesn't support LoRA"
            )

        @ops.custom_gradient
        def quantized_dequantize_inputs(inputs, scale, amax_history):
            if training:
                new_scale = quantizers.compute_float8_scale(
                    ops.max(amax_history, axis=0),
                    scale,
                    ops.cast(
                        float(ml_dtypes.finfo("float8_e4m3fn").max), "float32"
                    ),
                )
                new_amax_history = quantizers.compute_float8_amax_history(
                    inputs, amax_history
                )
            else:
                new_scale = None

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Skip LoRA on float8 layers: check the dtype policy / quantization mode before enable_lora.
  2. Use a float16/bfloat16 or float32 policy for layers you intend to LoRA-finetune.
  3. Track upstream Keras support — this is an explicit 'not yet implemented' gap.

Example fix

# before
with keras.dtype_policy.float8('float8_e4m3'):
    dense = keras.layers.Dense(64)
dense.build(x.shape)
dense.enable_lora(8)
y = dense(x)  # NotImplementedError

# after
dense = keras.layers.Dense(64)  # default float32 policy
dense.build(x.shape)
dense.enable_lora(8)
y = dense(x)
Defensive patterns

Strategy: validation

Validate before calling

def lora_dtype_ok(layer) -> bool:
    return 'float8' not in str(getattr(layer, 'compute_dtype', 'float32'))

for layer in model.layers:
    if isinstance(layer, keras.layers.Dense) and lora_dtype_ok(layer):
        layer.enable_lora(rank)

Type guard

def lora_dtype_ok(layer) -> bool:
    return 'float8' not in str(getattr(layer, 'compute_dtype', 'float32'))

Try / catch

try:
    y = dense(x)
except NotImplementedError as e:
    if 'float8' in str(e):
        switch_to_float16_policy()

Prevention

When it happens

Trigger: Running forward passes on a Dense layer under a float8 dtype policy after enable_lora() was called on it.

Common situations: Mixing float8 training with LoRA fine-tuning; enable_lora loops applied indiscriminately to float8 models.

Related errors


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