transformers - ✅(Solved) Fix Six leftover dummy classes in `dummy_pt_objects.py` fail `check_repo.py` and leak into `dir(transformers)` without torch [1 pull requests, 1 comments, 2 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#45712Fetched 2026-05-01 05:33:12
View on GitHub
Comments
1
Participants
2
Timeline
12
Reactions
0
Author
Timeline (top)
mentioned ×4subscribed ×4closed ×1commented ×1

Error Message

Exception: The following objects are in the public init, but not in the docs:

  • BeamScorer
  • ConstrainedBeamSearchScorer
  • Constraint
  • ConstraintListState
  • DisjunctiveConstraint
  • PhrasalConstraint

Root Cause

This only fires without torch because src/transformers/__init__.py registers dummy_pt_objects's contents into _import_structure only inside the except OptionalDependencyNotAvailable: branch. With torch installed, that branch never runs and the six names never appear in dir(transformers), so the docs check passes. Without torch, they leak into the public namespace and the check sees them.

Fix Action

Fixed

PR fix notes

PR #45722: Remove dead beam-search dummies from dummy_pt_objects.py

Description (problem / solution / changelog)

Fixes #45712

What does this PR do?

Removes six dead dummy classes from dummy_pt_objects.py: BeamScorer, ConstrainedBeamSearchScorer, Constraint, ConstraintListState, DisjunctiveConstraint, PhrasalConstraint.

The real implementations were removed in v5 (#41223) but the dummies stayed. None of the six is referenced anywhere under src/, tests/, docs/, or in MIGRATION_GUIDE_V5.md. Without torch they leak into dir(transformers) and utils/check_repo.py fails the public-init-vs-docs invariant.

After removal, from transformers import BeamScorer raises ImportError in a no-torch env (matching the with-torch behavior) instead of returning the dummy and producing a misleading requires backend torch error on use.

DEPRECATED_OBJECTS in check_repo.py would be the alternative, but that list is for objects that still exist as aliases or shims (e.g. PretrainedConfigPreTrainedConfig). These six don't.

Tests run (no-torch venv):

$ python utils/check_repo.py
# was: "Exception: ... in the public init, but not in the docs"
# now: docs step passes (later steps fail only on torch import, unrelated to this change)

$ python utils/check_dummies.py     # exit 0
$ python utils/check_inits.py       # exit 0
$ python utils/checkers.py copies,modular_conversion   # all pass

Code Agent Policy

  • I confirm that this is not a pure code agent PR.

AI assistance (Claude) was used during investigation and patch preparation. All changes were reviewed and tested by me.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline, Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link to it if that's the case. (Six leftover dummy classes in dummy_pt_objects.py fail check_repo.py and leak into dir(transformers) without torch #45712, approved by @Rocketknight1)
  • Did you make sure to update the documentation with your changes? Here are the documentation guidelines, and here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Changed files

  • src/transformers/utils/dummy_pt_objects.py (modified, +0/-42)

Code Example

Exception: The following objects are in the public init, but not in the docs:
 - BeamScorer
 - ConstrainedBeamSearchScorer
 - Constraint
 - ConstraintListState
 - DisjunctiveConstraint
 - PhrasalConstraint

---

python -m venv .venv && source .venv/bin/activate
pip install -e ".[quality]"
python utils/check_repo.py
RAW_BUFFERClick to expand / collapse

System Info

transformers 5.7.0.dev0 (main).

utils/check_repo.py raises on a fresh install without torch:

Exception: The following objects are in the public init, but not in the docs:
 - BeamScorer
 - ConstrainedBeamSearchScorer
 - Constraint
 - ConstraintListState
 - DisjunctiveConstraint
 - PhrasalConstraint

All six are leftover entries in src/transformers/utils/dummy_pt_objects.py. The real implementations were removed in v5 (#41223) but the dummies stayed. but the dummies stayed. None of the six is referenced anywhere under src/, tests/, docs/, or in MIGRATION_GUIDE_V5.md.

This only fires without torch because src/transformers/__init__.py registers dummy_pt_objects's contents into _import_structure only inside the except OptionalDependencyNotAvailable: branch. With torch installed, that branch never runs and the six names never appear in dir(transformers), so the docs check passes. Without torch, they leak into the public namespace and the check sees them.

A side effect of the dummies still being there is that from transformers import BeamScorer returns a dummy in a no-torch env and only fails with requires backend torch on use. Installing torch wouldn't help either because the real class is gone, so the message is misleading. With torch, the import already raises ImportError.

Who can help?

@Rocketknight1 @ArthurZucker @Cyrilvallez

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

python -m venv .venv && source .venv/bin/activate
pip install -e ".[quality]"
python utils/check_repo.py

Expected behavior

check_repo.py should pass on a clean install without torch, and dir(transformers) shouldn't expose objects whose backing implementations were removed.

extent analysis

TL;DR

Remove the leftover dummy objects from src/transformers/utils/dummy_pt_objects.py to fix the issue.

Guidance

  • Identify and remove the unused dummy objects (BeamScorer, ConstrainedBeamSearchScorer, Constraint, ConstraintListState, DisjunctiveConstraint, PhrasalConstraint) from src/transformers/utils/dummy_pt_objects.py.
  • Verify that check_repo.py passes after removing the dummy objects by running the reproduction steps.
  • Check that dir(transformers) no longer exposes the removed objects.

Notes

This fix assumes that the removed implementations are not needed elsewhere in the codebase. If they are still referenced, additional changes may be required.

Recommendation

Apply workaround: Remove the leftover dummy objects, as this directly addresses the cause of the issue and allows check_repo.py to pass.

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…

FAQ

Expected behavior

check_repo.py should pass on a clean install without torch, and dir(transformers) shouldn't expose objects whose backing implementations were removed.

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 Six leftover dummy classes in `dummy_pt_objects.py` fail `check_repo.py` and leak into `dir(transformers)` without torch [1 pull requests, 1 comments, 2 participants]