transformers - ✅(Solved) Fix Pipeline num_workers runtime default is 0 but documentation states 8 [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
huggingface/transformers#45557Fetched 2026-04-22 07:43:25
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

The docstring for num_workers in build_pipeline_init_args() states a default of 8, but the actual runtime fallback in Pipeline.__call__() is 0.

Root Cause

The docstring for num_workers in build_pipeline_init_args() states a default of 8, but the actual runtime fallback in Pipeline.__call__() is 0.

PR fix notes

PR #45576: docs(pipeline): fix num_workers docstring default from 8 to 0

Description (problem / solution / changelog)

What does this PR do?

Fixes #45557.

The docstring for num_workers in build_pipeline_init_args() states defaults to 8, but the actual runtime fallback in Pipeline.__call__() is 0:

# Line 1210 in base.py
if self._num_workers is None:
    num_workers = 0  # actual default

This PR updates the docstring to accurately reflect the runtime behavior (defaults to 0), preventing confusion for users relying on the docs for performance tuning.

Before submitting

  • This PR fixes a typo or improves the docs (and does not need the community review, just direct merge by the author)
  • Did you read the contributor guideline?

Fixes: #45557

Changed files

  • src/transformers/pipelines/base.py (modified, +1/-1)

Code Example

num_workers (`int`, *optional*, defaults to 8):
    When the pipeline will use *DataLoader* (when passing a dataset,
    on GPU for a Pytorch model), the number of workers to be used.

---

if num_workers is None:
    if self._num_workers is None:
        num_workers = 0  # <-- should be 8 to match the documentation
    else:
        num_workers = self._num_workers

---

# Before
if num_workers is None:
    if self._num_workers is None:
        num_workers = 0
    else:
        num_workers = self._num_workers

# After
if num_workers is None:
    if self._num_workers is None:
        num_workers = 8
    else:
        num_workers = self._num_workers
RAW_BUFFERClick to expand / collapse

num_workers runtime default does not match documented default of 8

Description

The docstring for num_workers in build_pipeline_init_args() states a default of 8, but the actual runtime fallback in Pipeline.__call__() is 0.

Steps to Reproduce

Inspect src/transformers/pipelines/base.py:

Docstring (build_pipeline_init_args):

num_workers (`int`, *optional*, defaults to 8):
    When the pipeline will use *DataLoader* (when passing a dataset,
    on GPU for a Pytorch model), the number of workers to be used.

Actual runtime logic (Pipeline.__call__):

if num_workers is None:
    if self._num_workers is None:
        num_workers = 0  # <-- should be 8 to match the documentation
    else:
        num_workers = self._num_workers

Expected Behavior

The runtime default should match the documented value of 8.

Actual Behavior

The runtime default is 0, meaning no multiprocessing is used even though the documentation promises 8 workers. Users relying on the documentation for performance tuning will be surprised that DataLoader runs single-threaded by default.

Suggested Fix

Update the fallback in Pipeline.__call__() in src/transformers/pipelines/base.py:

# Before
if num_workers is None:
    if self._num_workers is None:
        num_workers = 0
    else:
        num_workers = self._num_workers

# After
if num_workers is None:
    if self._num_workers is None:
        num_workers = 8
    else:
        num_workers = self._num_workers

Environment

  • File: src/transformers/pipelines/base.py
  • Relevant functions: build_pipeline_init_args(), Pipeline.__call__()

extent analysis

TL;DR

Update the num_workers fallback in Pipeline.__call__() to match the documented default of 8.

Guidance

  • Verify the discrepancy between the documented default and the actual runtime default by inspecting the build_pipeline_init_args() docstring and the Pipeline.__call__() logic.
  • Update the num_workers fallback in Pipeline.__call__() to 8 as suggested in the issue to ensure consistency with the documentation.
  • Test the updated code to confirm that the runtime default now matches the documented value of 8.
  • Consider adding additional logging or debugging statements to help identify any potential issues related to the num_workers parameter.

Example

# Updated fallback in Pipeline.__call__()
if num_workers is None:
    if self._num_workers is None:
        num_workers = 8  # Match the documented default
    else:
        num_workers = self._num_workers

Notes

This fix assumes that the documented default of 8 is the intended behavior and that updating the runtime default will not introduce any unintended consequences.

Recommendation

Apply the suggested workaround by updating the num_workers fallback in Pipeline.__call__() to 8, as this will ensure consistency with the documentation and provide the expected behavior for users relying on the documented default.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

transformers - ✅(Solved) Fix Pipeline num_workers runtime default is 0 but documentation states 8 [1 pull requests, 1 participants]