keras-team/keras · error · ValueError

Could not determine row/column split.

Error message

Could not determine row/column split.

What it means

During GPTQ quantized_build, EinsumDense._gptq_build derives a (rows, columns) split from the kernel shape. It handles 2D kernels directly and 3D kernels whose layout decomposes into (heads, head_dim, out_features) via the equation; when the einsum equation or shape does not expose a usable split, it raises this ValueError because the group-size math (rows / group_size) needs concrete dimensions.

Source

Thrown at keras/src/layers/core/einsum_dense.py:690

            columns = kernel_shape[1]
        elif len(kernel_shape) == 3:
            shape = list(self.original_kernel_shape)
            d_model_dim_index = shape.index(max(shape))

            if d_model_dim_index == 0:  # QKV projection case
                in_features, heads, head_dim = shape
                rows, columns = (
                    in_features,
                    heads * head_dim,
                )
            elif d_model_dim_index in [1, 2]:  # Attention Output case
                heads, head_dim, out_features = shape
                rows, columns = (
                    heads * head_dim,
                    out_features,
                )
            else:
                raise ValueError("Could not determine row/column split.")

        group_size = gptq_core.get_group_size_for_layer(self, config)
        n_groups = 1 if group_size == -1 else math.ceil(rows / group_size)

        self.gptq_unpacked_column_size = columns

        weight_bits = gptq_core.get_weight_bits_for_layer(self, config)
        # 4-bit weights pack two values per byte; 2-bit weights pack four.
        # Other bit-widths (e.g. 3, 8) are stored one value per byte.
        if weight_bits == 4:
            kernel_columns = (columns + 1) // 2
        elif weight_bits == 2:
            kernel_columns = (columns + 3) // 4
        else:
            kernel_columns = columns

        self._set_quantization_info()

View on GitHub (pinned to 7a34a03db6)

Solutions

  1. Restructure the layer to a standard 2D kernel ('ab,bc->ac') or a recognized 3D attention layout.
  2. Exclude this layer from the quantization structure via filters so _gptq_build never runs on it.
  3. Check the equation and output_dim: ensure the kernel resolves to (in_features, out_features) or (heads, head_dim, out_features).

Example fix

# before
layer = keras.layers.EinsumDense('aijk,jk->aik', output_dim=(None, 32))  # unrecognizable layout
model.quantize(cfg)  # ValueError: Could not determine row/column split.

# after
model.quantize(cfg, filters=[l.name for l in model.layers if l is not layer])
# or refactor the layer to 'ab,bc->ac'
Defensive patterns

Strategy: validation

Validate before calling

shape = tuple(layer.kernel.shape) if layer.built else None
if shape is None or len(shape) > 3:
    raise RuntimeError('GPTQ cannot split this kernel; exclude layer from quantization')

Prevention

When it happens

Trigger: Quantizing an EinsumDense whose kernel is higher-rank or 3D but whose einsum equation does not let Keras infer heads/head_dim/out_features (custom or unusual equations), under a quantization config whose layer structure covers this layer.

Common situations: Custom attention/MLP projection equations that do not match the expected pattern; applying model.quantize(...) too broadly so it covers an exotic EinsumDense; output_dim given as a shape tuple the splitter cannot decompose.

Related errors


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