huggingface/transformers · error · TypeError

logit_processor_kwargs['{key}'] has type {type(value).__name

Error message

logit_processor_kwargs['{key}'] has type {type(value).__name__}, expected {expected_type.__name__}

What it means

Raised by CB logits-processor check_kwargs when a key in logit_processor_kwargs is in supported_keys but its value's Python type does not match the registered expected type. It is strict isinstance validation: e.g. passing a float where the processor registered int, or a Tensor where float is expected.

Source

Thrown at src/transformers/generation/continuous_batching/cb_logits_processors.py:162

        self.ignored_keys = set()
        for processor in self.logits_processor:
            if isinstance(processor, ContinuousBatchingLogitsProcessor):
                self.supported_keys.update(processor.supported_kwargs)
                self.ignored_keys.update(processor.ignored_kwargs)

    def check_kwargs(self, kwargs: dict) -> None:
        """Checks that the provided kwargs are compatible with the current CB processors. Warn for ignored kwargs."""
        if not kwargs:
            return None
        # Validate types for supported keys, detect unsupported keys
        problematic_keys = set()
        for key, value in kwargs.items():
            if key not in self.supported_keys:
                problematic_keys.add(key)
            else:
                expected_type = self.supported_keys[key]
                if not isinstance(value, expected_type):
                    raise TypeError(
                        f"logit_processor_kwargs['{key}'] has type {type(value).__name__}, expected {expected_type.__name__}"
                    )
        # Stop if there are only supported keys
        if not problematic_keys:
            return
        # Check if there are unknown keys
        unknown_keys = problematic_keys - self.ignored_keys
        if unknown_keys:
            raise ValueError(
                f"Unknown logit_processor_kwargs: {unknown_keys}. {self.supported_keys = } and {self.ignored_keys = }"
                "If you expect a key to not be ignored, make sure its default value (in the generation config) is not "
                "None. Eg. if temperature is None or 1.0 at creation time, no processor will be created for temperature"
            )
        # If there are none, throw a warning about the ignored keys
        logger.warning(
            f"Ignored logit_processor_kwargs: {problematic_keys}. {self.supported_keys = } and {self.ignored_keys = }"
        )

View on GitHub (pinned to a597f97485)

Solutions

  1. Cast the offending kwarg to the exact registered type (int(top_k), float(temperature))
  2. Inspect the error message: it names the key, the received type, and the expected type — fix that one key
  3. Keep sampling params in typed dataclasses/pydantic models rather than raw dicts from JSON

Example fix

# before
logit_processor_kwargs = {"top_k": 50.0, "temperature": 0.8}

# after
logit_processor_kwargs = {"top_k": 50, "temperature": 0.8}
Defensive patterns

Strategy: type-guard

Validate before calling

EXPECTED = {'temperature': float, 'top_p': float, 'top_k': int, 'min_p': float}
for k, v in logit_processor_kwargs.items():
    if k in EXPECTED and not isinstance(v, EXPECTED[k]):
        logit_processor_kwargs[k] = EXPECTED[k](v)

Type guard

def is_valid_sampling_kwargs(kwargs: dict) -> bool:
    expected = {'temperature': float, 'top_p': float, 'top_k': int}
    return all(isinstance(v, expected[k]) for k, v in kwargs.items() if k in expected)

Try / catch

try:
    manager = model.continuous_batching(logit_processor_kwargs=lpk)
except TypeError as e:
    key = e.args[0].split("'")[1]
    lpk[key] = int(lpk[key]) if isinstance(lpk[key], float) and lpk[key].is_integer() else lpk[key]
    manager = model.continuous_batching(logit_processor_kwargs=lpk)

Prevention

When it happens

Trigger: Calling generate with continuous batching and logit_processor_kwargs={'temperature': 0.8, 'top_k': 50.0} where top_k is registered as int — 50.0 (float) fails isinstance(value, int). Also bool/int mix-ups and passing numpy scalars.

Common situations: Loading sampling params from JSON/argparse where everything is str/float; passing numpy.int64 instead of int; copying configs between vLLM-style APIs (which accept floats for top_k) and transformers.

Related errors


AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14). Data as JSON: /api/errors/19705c2564bd1442. Report an issue: GitHub.