microsoft/VibeVoice · error · ValueError

Sample index {sample_idx} exceeds batch size {self.batch_siz

Error message

Sample index {sample_idx} exceeds batch size {self.batch_size}

What it means

The synchronous AudioStreamer distributes generated audio into one queue per batch element. get_stream(sample_idx) returns a single sample's iterator and validates the index against the streamer's batch size. A zero-or-greater index equal to or above batch_size fails immediately; note that negative indices are NOT caught by this check even though they will misbehave.

Source

Thrown at vibevoice/modular/streamer.py:85

                if not self.finished_flags[idx]:
                    self.audio_queues[idx].put(self.stop_signal, timeout=self.timeout)
                    self.finished_flags[idx] = True
        else:
            # End specific samples
            for sample_idx in sample_indices:
                idx = sample_idx.item() if torch.is_tensor(sample_idx) else sample_idx
                if idx < self.batch_size and not self.finished_flags[idx]:
                    self.audio_queues[idx].put(self.stop_signal, timeout=self.timeout)
                    self.finished_flags[idx] = True
    
    def __iter__(self):
        """Returns an iterator over the batch of audio streams."""
        return AudioBatchIterator(self)
    
    def get_stream(self, sample_idx: int):
        """Get the audio stream for a specific sample."""
        if sample_idx >= self.batch_size:
            raise ValueError(f"Sample index {sample_idx} exceeds batch size {self.batch_size}")
        return AudioSampleIterator(self, sample_idx)


class AudioSampleIterator:
    """Iterator for a single audio stream from the batch."""
    
    def __init__(self, streamer: AudioStreamer, sample_idx: int):
        self.streamer = streamer
        self.sample_idx = sample_idx
        
    def __iter__(self):
        return self
    
    def __next__(self):
        value = self.streamer.audio_queues[self.sample_idx].get(timeout=self.streamer.timeout)
        if value == self.streamer.stop_signal:
            raise StopIteration()
        return value

View on GitHub (pinned to 94da20d98b)

Solutions

  1. Use streamer.batch_size as the loop bound: for i in range(streamer.batch_size): stream = streamer.get_stream(i).
  2. Verify the batch dimension actually passed to the model matches the number of prompts you expect (print the input tensor's shape[0]).
  3. For a single prompt, use get_stream(0) or iterate the streamer directly (AudioBatchIterator).

Example fix

# before
for i in range(num_prompts):  # num_prompts > batch_size
    stream = streamer.get_stream(i)

# after
for i in range(streamer.batch_size):
    stream = streamer.get_stream(i)
Defensive patterns

Strategy: validation

Validate before calling

idx = int(idx)
if not (0 <= idx < streamer.batch_size):
    raise IndexError(f'stream index {idx} outside [0, {streamer.batch_size})')
stream = streamer.get_stream(idx)

Type guard

def is_valid_stream_index(streamer, idx) -> bool:
    return isinstance(idx, int) and 0 <= idx < streamer.batch_size

Try / catch

try:
    stream = streamer.get_stream(idx)
except ValueError as e:
    if 'exceeds batch size' in str(e):
        logger.warning('batch shrank; clamping to last stream')
        stream = streamer.get_stream(streamer.batch_size - 1)
    else:
        raise

Prevention

When it happens

Trigger: Calling streamer.get_stream(i) where i >= streamer.batch_size, e.g. iterating range(len(audio_files)) when the model was actually run with a smaller batch (batch dim collapsed by batching/padding logic), or hardcoding an index for a batch-1 run.

Common situations: User runs generation with batch size 1 but loops over multiple prompts calling get_stream(idx); or the batch dimension was squeezed out upstream so the streamer was constructed with batch_size=1 while the caller assumes N streams.

Related errors


AI-assisted analysis of microsoft/VibeVoice@94da20d98b (2026-08-15). Data as JSON: /api/errors/b0fc06149fe094b7. Report an issue: GitHub.