Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,28 @@ def _get_target():
_create_module_alias(f"{__name__}.tokenization_utils", ".tokenization_utils_sentencepiece")
_create_module_alias(f"{__name__}.image_processing_utils_fast", ".image_processing_backends")

for _proc_file in sorted((Path(__file__).parent / "models").rglob("image_processing_*.py")):
_model = _proc_file.parent.name
_module = _proc_file.stem
_target = f".models.{_model}.{_module}"
_create_module_alias(f"{__name__}.models.{_model}.{_module}_fast", _target)

# Also map XImageProcessorFast -> XImageProcessor for backward compat with old class names.
def getattr_factory(target):
def _getattr(name):
new_name = name.removesuffix("Fast")
logger.warning(
"Accessing `%s` from `%s`. Returning `%s` instead. Behavior may be "
"different and this alias will be removed in future versions.",
name,
Comment on lines +835 to +838
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice ty for adding the warning! (approved offline)

target,
new_name,
)
return getattr(importlib.import_module(target, __name__), new_name)

return _getattr

sys.modules[f"{__name__}.models.{_model}.{_module}_fast"].__getattr__ = getattr_factory(_target)

if not is_torch_available():
logger.warning_advice(
Expand Down
3 changes: 3 additions & 0 deletions utils/check_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,9 @@ def ignore_undocumented(name: str) -> bool:
# BLT models are internal building blocks, tested implicitly through BltForCausalLM
if name.startswith("Blt"):
return True
# image_processing_*_fast are backward-compat module aliases, not public objects.
if name.startswith("image_processing_") and name.endswith("_fast"):
return True
if name in SHOULD_HAVE_THEIR_OWN_PAGE:
return True
return False
Expand Down
Loading