tensorflow/models · error · ValueError

`set_quantize_activations` called on layer

Error message

`set_quantize_activations` called on layer {} with {} activation parameters, but layer expects {} values.

What it means

Cardinality check in set_quantize_activations: the number of supplied quantize activation tensors must equal the number of activation attributes declared in activation_attrs; a mismatch raises this ValueError naming the layer and both counts.

Solutions

  1. Ensure activation_attrs matches the activations tfmot collected for the layer
  2. Check the QuantizeConfig is paired with the correct layer type
  3. Update activation_attrs if the layer's activations changed
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at official/projects/qat/nlp/quantization/configs.py:350 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24). Data as JSON: /api/errors/ce73739dc2ed7ff8. Report an issue: GitHub.

Appendix: source

Thrown at official/projects/qat/nlp/quantization/configs.py:350

  def set_quantize_weights(self, layer, quantize_weights):
    if len(self.weight_attrs) != len(quantize_weights):
      raise ValueError(
          '`set_quantize_weights` called on layer {} with {} '
          'weight parameters, but layer expects {} values.'.format(
              layer.name, len(quantize_weights), len(self.weight_attrs)))

    for weight_attr, weight in zip(self.weight_attrs, quantize_weights):
      current_weight = getattr(layer, weight_attr)
      if current_weight.shape != weight.shape:
        raise ValueError('Existing layer weight shape {} is incompatible with'
                         'provided weight shape {}'.format(
                             current_weight.shape, weight.shape))

      setattr(layer, weight_attr, weight)

  def set_quantize_activations(self, layer, quantize_activations):
    if len(self.activation_attrs) != len(quantize_activations):
      raise ValueError(
          '`set_quantize_activations` called on layer {} with {} '
          'activation parameters, but layer expects {} values.'.format(
              layer.name, len(quantize_activations),
              len(self.activation_attrs)))

    for activation_attr, activation in zip(
        self.activation_attrs, quantize_activations):
      setattr(layer, activation_attr, activation)

  def get_output_quantizers(self, layer):
    if self.quantize_output:
      return [self.activation_quantizer]
    return []

  @classmethod
  def from_config(cls, config):
    """Instantiates a `Default8BitQuantizeConfig` from its config.

View on GitHub (pinned to e006f5f0d5)