huggingface/transformers · error · ValueError
Logits should have twice the batch size of the input ids, th
Error message
Logits should have twice the batch size of the input ids, the first half of batches corresponding to the conditional inputs, and the second half of batches corresponding to the unconditional inputs. Got batch size {scores.shape[0]} for the logits and {input_ids.shape[0]} for the input ids. What it means
Error "Logits should have twice the batch size of the input ids, the first half of batches corresponding to the conditional inputs, and the second half of batches corresponding to the unconditional inputs. Got batch size {scores.shape[0]} for the logits and {input_ids.shape[0]} for the input ids." thrown in huggingface/transformers.
Source
Thrown at src/transformers/generation/logits_process.py:2168
>>> audio_values = model.generate(**inputs, do_sample=True, guidance_scale=3, max_new_tokens=256)
```
"""
def __init__(self, guidance_scale):
if guidance_scale > 1:
self.guidance_scale = guidance_scale
else:
raise ValueError(
"Require guidance scale >1 to use the classifier free guidance processor, got guidance scale "
f"{guidance_scale}."
)
@add_start_docstrings(LOGITS_PROCESSOR_INPUTS_DOCSTRING)
def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:
# simple check to make sure we have compatible batch sizes between our
# logits scores (cond + uncond) and input ids (cond only)
if scores.shape[0] != 2 * input_ids.shape[0]:
raise ValueError(
f"Logits should have twice the batch size of the input ids, the first half of batches corresponding to "
f"the conditional inputs, and the second half of batches corresponding to the unconditional inputs. Got "
f"batch size {scores.shape[0]} for the logits and {input_ids.shape[0]} for the input ids."
)
unguided_bsz = scores.shape[0] // 2
cond_logits, uncond_logits = scores.split(unguided_bsz, dim=0)
scores_processed = uncond_logits + (cond_logits - uncond_logits) * self.guidance_scale
return scores_processed
class AlternatingCodebooksLogitsProcessor(LogitsProcessor):
r"""
[`LogitsProcessor`] enforcing alternated generation between the two codebooks of Bark.
<Tip warning={true}>
This logits processor is exclusively compatible with
[Bark](https://huggingface.co/docs/transformers/en/model_doc/bark)'s fine submodel. See the model documentationView on GitHub (pinned to a597f97485)
Solutions
- Pass unconditional inputs so the logits batch is exactly twice the input_ids batch.
- Ensure conditional and unconditional batches are concatenated in the order [conditional, unconditional].
When it happens
Trigger: Raised in ClassifierFreeGuidanceLogitsProcessor.__call__ when scores batch size is not exactly twice the input_ids batch size.
Common situations: CFG decoding where the model did not receive duplicated conditional/unconditional inputs, so logits and input batch sizes disagree.
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/1ae62281ccb3fb94.
Report an issue: GitHub.