{"record":{"id":"f32c392cc923bd22","repo":"keras-team/keras","slug":"for-mode-a-valid-quantization-structure-must-b","errorCode":null,"errorMessage":"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'.","messagePattern":"For (.+?), 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'\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/models/model.py","lineNumber":609,"sourceCode":"        # missing/invalid structure leaves the model completely untouched\n        # instead of half-quantized (buffers allocated, dtype policies\n        # swapped). Only structure-covered layers are calibrated afterwards;\n        # quantizing any other layer would leave it uncalibrated, and its\n        # uninitialized quantized weights would silently replace the real\n        # ones when the model is saved and reloaded.\n        structure = None\n        structure_layer_ids = None\n        if mode in (\"gptq\", \"awq\"):\n            # 1. If quantization_layer_structure is provided inside the\n            # config, use that.\n            structure = config.quantization_layer_structure\n            # 2. If no layer structure is provided in the config, try to\n            # fetch it using the `get_quantization_layer_structure` hook.\n            if structure is None:\n                structure = self.get_quantization_layer_structure(mode)\n\n            if structure is None:\n                raise ValueError(\n                    f\"For {mode=}, a valid quantization structure must be \"\n                    \"provided either via `config.quantization_layer_structure` \"\n                    \"or by overriding \"\n                    \"`model.get_quantization_layer_structure(mode)`. The \"\n                    \"structure should be a dictionary with keys \"\n                    \"'pre_block_layers' and 'sequential_blocks'.\"\n                )\n            structure_layer_ids = set()\n            for block in structure.get(\"sequential_blocks\", []):\n                for sub_layer in find_layers_in_block(block).values():\n                    structure_layer_ids.add(id(sub_layer))\n\n        report = QuantizationReport(mode=mode)\n        graph_modified = False\n        for layer in self._flatten_layers():\n            # Skip nested models: this walk already visits their layers\n            # directly (`_flatten_layers` is recursive), and calling\n            # `quantize` on a sub-model would recurse into a second full","sourceCodeStart":591,"sourceCodeEnd":627,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/models/model.py#L591-L627","documentation":"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.","triggerScenarios":"Thrown at keras/src/models/model.py:609 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}