huggingface/transformers · error · ValueError

Expected `eos_token_id` to be a positive integer, found {eos

Error message

Expected `eos_token_id` to be a positive integer, found {eos_token_id} instead.

What it means

Thrown by the audio codebook logits processor's __init__ when eos_token_id < 1. The processor forces EOS to be producible only on the first codebook channel, so the EOS id must be a valid positive vocab index. Note the strictness: eos_token_id=0 is also rejected, even though 0 can be a legitimate token id in some vocabularies.

Source

Thrown at src/transformers/generation/logits_process.py:3097

    <Tip warning={true}>

    This logits processor is exclusively compatible with
    [Dia](https://huggingface.co/docs/transformers/en/model_doc/dia).

    </Tip>

    Args:
        num_channels (`int`):
            Number of audio codebooks. Simplifies access to the first channel on the logits.
        eos_token_id (`int`):
            The id of *end-of-sequence* token.
    """

    def __init__(self, num_channels: int, eos_token_id: int):
        if num_channels < 1:
            raise ValueError(f"Audio codebooks need at least one channel, but found {num_channels} channels.")
        if eos_token_id < 1:
            raise ValueError(f"Expected `eos_token_id` to be a positive integer, found {eos_token_id} instead.")

        self.num_channels = num_channels
        self.eos_id = eos_token_id

    @add_start_docstrings(LOGITS_PROCESSOR_INPUTS_DOCSTRING)
    def __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor) -> torch.FloatTensor:
        # Reshape for easier channel indexing [B, C, V]
        scores = scores.reshape(-1, self.num_channels, scores.shape[-1])

        # EOS filter
        # 1. Condition: Only the first channel can generate the EOS token
        # Side condition of disabling generation of special tokens (e.g. audio pad, bos, ...)
        # (Assumes them to be greater than audio eos token position)
        scores[:, 1:, self.eos_id :] = torch.full_like(
            scores[:, 1:, self.eos_id :],
            fill_value=-float("inf"),
        )
        scores[:, 0, self.eos_id + 1 :] = torch.full_like(

View on GitHub (pinned to a597f97485)

Solutions

  1. Pass the real EOS token id from generation_config.eos_token_id (must be >= 1).
  2. If your vocabulary genuinely uses 0 as EOS, remap or pick another dedicated EOS token — the processor cannot accept 0.
  3. Guard config reads: eos = getattr(cfg, 'eos_token_id', None); validate before use.

Example fix

# before
processor = AudioEosLogitsProcessor(num_channels=4, eos_token_id=0)

# after
processor = AudioEosLogitsProcessor(num_channels=4, eos_token_id=model.generation_config.eos_token_id)
Defensive patterns

Strategy: validation

Validate before calling

eos = getattr(model.generation_config, "eos_token_id", None)
assert isinstance(eos, int) and eos >= 1, f"eos_token_id must be a positive int, got {eos!r}"

Prevention

When it happens

Trigger: Passing eos_token_id=0 or a negative value; reading eos id from a config key that does not exist and defaults to 0; using -1 as a sentinel for 'no EOS'.

Common situations: Custom audio checkpoints where EOS is token 0 (pad/bos id); configs where the field is named differently (eos_token_id vs end_of_sequence_id) and the lookup silently returns 0.

Related errors


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