# ValueError: The number of outputs returned by the pipeline does not match the number of inputs. Expected 8 outputs, got 4.

- **ID:** `huggingface/pipeline-batch-inference-mismatch`
- **Domain:** huggingface
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

When using pipeline with batch_size > 1 and a model that dynamically drops or merges samples (e.g., due to truncation or filtering in preprocess), the output count can diverge from input count.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| transformers>=4.30.0 | active | — | — |
| torch>=1.13.0 | active | — | — |
| python>=3.8 | active | — | — |

## Workarounds

1. **Disable any sample filtering in the pipeline's preprocess step (e.g., set `truncation=False` for summarization). Alternatively, use `return_full_text=False` in text-generation pipelines to avoid output count mismatch.** (70% success)
   ```
   Disable any sample filtering in the pipeline's preprocess step (e.g., set `truncation=False` for summarization). Alternatively, use `return_full_text=False` in text-generation pipelines to avoid output count mismatch.
   ```
2. **Collect outputs in a list without batching and then manually batch inputs, ensuring each input produces exactly one output. Use `tokenizer.batch_decode` with `skip_special_tokens=True`.** (85% success)
   ```
   Collect outputs in a list without batching and then manually batch inputs, ensuring each input produces exactly one output. Use `tokenizer.batch_decode` with `skip_special_tokens=True`.
   ```

## Dead Ends

- **** — Setting `batch_size=1` avoids the mismatch but kills performance for large datasets. The error is not caused by batch size per se but by sample filtering. (40% fail)
- **** — Manually overriding `__len__` in the dataset to match filtered outputs is fragile and breaks if filtering logic changes. (30% fail)
