{
  "id": "huggingface/pipeline-batch-inference-mismatch",
  "signature": "ValueError: The number of outputs returned by the pipeline does not match the number of inputs. Expected 8 outputs, got 4.",
  "signature_zh": "ValueError: 管道返回的输出数量与输入数量不匹配。期望 8 个输出，但得到 4 个。",
  "regex": "ValueError: The number of outputs returned by the pipeline does not match the number of inputs. Expected \\d+ outputs, got \\d+.",
  "domain": "huggingface",
  "category": "runtime_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "使用 batch_size > 1 的管道且模型动态丢弃或合并样本（例如由于预处理中的截断或过滤）时，输出数量可能与输入数量不一致。",
  "versions": [
    {
      "version": "transformers>=4.30.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "torch>=1.13.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "python>=3.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "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.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Manually overriding `__len__` in the dataset to match filtered outputs is fragile and breaks if filtering logic changes.",
      "fail_rate": 0.3,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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.",
      "success_rate": 0.7,
      "how": "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.",
      "condition": "",
      "sources": []
    },
    {
      "action": "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`.",
      "success_rate": 0.85,
      "how": "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`.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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.",
    "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`."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://huggingface.co/docs/transformers/main_classes/pipelines#batch-inference",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2023-08-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}