keras-team/keras · error · ValueError

Unknown target_spec attribute

Error message

Unknown target_spec attribute '{spec_key}'

What it means

Raised by _apply_converter_kwargs in keras/src/export/litert.py: user-supplied kwargs may configure nested target_spec settings via a dict, but each key in that dict must be an existing attribute of the tf.lite converter's target_spec object. The given spec_key does not exist on target_spec (typo or unsupported setting), so the ValueError fires.

Solutions

  1. Use valid target_spec attribute names, e.g. "supported_ops" or "supported_types"
  2. Check dir(converter.target_spec) on a tf.lite.TFLiteConverter for valid keys
  3. Fix typos in the nested target_spec dict passed to export_litert
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at keras/src/export/litert.py:183 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at keras/src/export/litert.py:183

            return converter.convert()

    def _apply_converter_kwargs(self, converter):
        """Apply additional converter settings from kwargs.

        Args:
            converter: tf.lite.TFLiteConverter instance to configure

        Raises:
            ValueError: If any kwarg is not a valid converter attribute
        """
        for attr, value in self.kwargs.items():
            if attr == "target_spec" and isinstance(value, dict):
                # Handle nested target_spec settings
                for spec_key, spec_value in value.items():
                    if hasattr(converter.target_spec, spec_key):
                        setattr(converter.target_spec, spec_key, spec_value)
                    else:
                        raise ValueError(
                            f"Unknown target_spec attribute '{spec_key}'"
                        )
            elif hasattr(converter, attr):
                setattr(converter, attr, value)
            else:
                raise ValueError(f"Unknown converter attribute '{attr}'")


def export_litert_via_torch(
    model, filepath, input_signature=None, verbose=None, **kwargs
):
    """Export Keras model to LiteRT via PyTorch backend."""
    from keras.src.backend.torch.core import device_scope
    from keras.src.backend.torch.core import get_device

    device = get_device()

    # litert_torch internally imports JAX and unconditionally enables

View on GitHub (pinned to 7a34a03db6)