{"record":{"id":"19705c2564bd1442","repo":"huggingface/transformers","slug":"logit-processor-kwargs-key-has-type-type-val","errorCode":null,"errorMessage":"logit_processor_kwargs['{key}'] has type {type(value).__name__}, expected {expected_type.__name__}","messagePattern":"logit_processor_kwargs\\['(.+?)'\\] has type (.+?), expected (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/continuous_batching/cb_logits_processors.py","lineNumber":162,"sourceCode":"        self.ignored_keys = set()\n        for processor in self.logits_processor:\n            if isinstance(processor, ContinuousBatchingLogitsProcessor):\n                self.supported_keys.update(processor.supported_kwargs)\n                self.ignored_keys.update(processor.ignored_kwargs)\n\n    def check_kwargs(self, kwargs: dict) -> None:\n        \"\"\"Checks that the provided kwargs are compatible with the current CB processors. Warn for ignored kwargs.\"\"\"\n        if not kwargs:\n            return None\n        # Validate types for supported keys, detect unsupported keys\n        problematic_keys = set()\n        for key, value in kwargs.items():\n            if key not in self.supported_keys:\n                problematic_keys.add(key)\n            else:\n                expected_type = self.supported_keys[key]\n                if not isinstance(value, expected_type):\n                    raise TypeError(\n                        f\"logit_processor_kwargs['{key}'] has type {type(value).__name__}, expected {expected_type.__name__}\"\n                    )\n        # Stop if there are only supported keys\n        if not problematic_keys:\n            return\n        # Check if there are unknown keys\n        unknown_keys = problematic_keys - self.ignored_keys\n        if unknown_keys:\n            raise ValueError(\n                f\"Unknown logit_processor_kwargs: {unknown_keys}. {self.supported_keys = } and {self.ignored_keys = }\"\n                \"If you expect a key to not be ignored, make sure its default value (in the generation config) is not \"\n                \"None. Eg. if temperature is None or 1.0 at creation time, no processor will be created for temperature\"\n            )\n        # If there are none, throw a warning about the ignored keys\n        logger.warning(\n            f\"Ignored logit_processor_kwargs: {problematic_keys}. {self.supported_keys = } and {self.ignored_keys = }\"\n        )\n","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/continuous_batching/cb_logits_processors.py#L144-L180","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Cast the offending kwarg to the exact registered type (int(top_k), float(temperature))","Inspect the error message: it names the key, the received type, and the expected type — fix that one key","Keep sampling params in typed dataclasses/pydantic models rather than raw dicts from JSON"],"exampleFix":"# before\nlogit_processor_kwargs = {\"top_k\": 50.0, \"temperature\": 0.8}\n\n# after\nlogit_processor_kwargs = {\"top_k\": 50, \"temperature\": 0.8}","handlingStrategy":"type-guard","validationCode":"EXPECTED = {'temperature': float, 'top_p': float, 'top_k': int, 'min_p': float}\nfor k, v in logit_processor_kwargs.items():\n    if k in EXPECTED and not isinstance(v, EXPECTED[k]):\n        logit_processor_kwargs[k] = EXPECTED[k](v)","typeGuard":"def is_valid_sampling_kwargs(kwargs: dict) -> bool:\n    expected = {'temperature': float, 'top_p': float, 'top_k': int}\n    return all(isinstance(v, expected[k]) for k, v in kwargs.items() if k in expected)","tryCatchPattern":"try:\n    manager = model.continuous_batching(logit_processor_kwargs=lpk)\nexcept TypeError as e:\n    key = e.args[0].split(\"'\")[1]\n    lpk[key] = int(lpk[key]) if isinstance(lpk[key], float) and lpk[key].is_integer() else lpk[key]\n    manager = model.continuous_batching(logit_processor_kwargs=lpk)","preventionTips":["Type sampling params at the boundary (argparse type=, pydantic)","int keys must be int not float even if integral","Log the kwargs dict before passing when debugging"],"tags":["validation","logits-processor","types","continuous-batching"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}