keras-team/keras · error · ValueError

For {mode=}, a valid quantization structure must be provided

Error message

For {mode=}, a valid quantization structure must be provided either via `config.quantization_layer_structure` or by overriding `model.get_quantization_layer_structure(mode)`. The structure should be a dictionary with keys 'pre_block_layers' and 'sequential_blocks'.

What it means

Error "For {mode=}, a valid quantization structure must be provided either via `config.quantization_layer_structure` or by overriding `model.get_quantization_layer_structure(mode)`. The structure should be a dictionary with keys 'pre_block_layers' and 'sequential_blocks'." thrown in keras-team/keras.

Source

Thrown at keras/src/models/model.py:609

        # missing/invalid structure leaves the model completely untouched
        # instead of half-quantized (buffers allocated, dtype policies
        # swapped). Only structure-covered layers are calibrated afterwards;
        # quantizing any other layer would leave it uncalibrated, and its
        # uninitialized quantized weights would silently replace the real
        # ones when the model is saved and reloaded.
        structure = None
        structure_layer_ids = None
        if mode in ("gptq", "awq"):
            # 1. If quantization_layer_structure is provided inside the
            # config, use that.
            structure = config.quantization_layer_structure
            # 2. If no layer structure is provided in the config, try to
            # fetch it using the `get_quantization_layer_structure` hook.
            if structure is None:
                structure = self.get_quantization_layer_structure(mode)

            if structure is None:
                raise ValueError(
                    f"For {mode=}, a valid quantization structure must be "
                    "provided either via `config.quantization_layer_structure` "
                    "or by overriding "
                    "`model.get_quantization_layer_structure(mode)`. The "
                    "structure should be a dictionary with keys "
                    "'pre_block_layers' and 'sequential_blocks'."
                )
            structure_layer_ids = set()
            for block in structure.get("sequential_blocks", []):
                for sub_layer in find_layers_in_block(block).values():
                    structure_layer_ids.add(id(sub_layer))

        report = QuantizationReport(mode=mode)
        graph_modified = False
        for layer in self._flatten_layers():
            # Skip nested models: this walk already visits their layers
            # directly (`_flatten_layers` is recursive), and calling
            # `quantize` on a sub-model would recurse into a second full

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/models/model.py:609 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/f32c392cc923bd22. Report an issue: GitHub.