Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update deprecated load_module #21651

Merged
merged 1 commit into from
Feb 15, 2023
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
5 changes: 4 additions & 1 deletion src/transformers/processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import importlib.util
import os
import sys
from pathlib import Path

from .dynamic_module_utils import custom_object_save
Expand All @@ -31,7 +32,9 @@
spec = importlib.util.spec_from_file_location(
"transformers", Path(__file__).parent / "__init__.py", submodule_search_locations=[Path(__file__).parent]
)
transformers_module = spec.loader.load_module()
transformers_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(transformers_module)
transformers_module = sys.modules["transformers"]


AUTO_TO_BASE_CLASS_MAPPING = {
Expand Down
4 changes: 3 additions & 1 deletion tests/pipelines/test_pipelines_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
os.path.join(PATH_TO_TRANSFORMERS, "__init__.py"),
submodule_search_locations=[PATH_TO_TRANSFORMERS],
)
transformers_module = spec.loader.load_module()
transformers_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(transformers_module)
transformers_module = sys.modules["transformers"]


class ANY:
Expand Down
5 changes: 4 additions & 1 deletion utils/check_config_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import inspect
import os
import re
import sys


# All paths are set with the intent you should run this script from the root of the repo with the command
Expand All @@ -30,7 +31,9 @@
os.path.join(PATH_TO_TRANSFORMERS, "__init__.py"),
submodule_search_locations=[PATH_TO_TRANSFORMERS],
)
transformers = spec.loader.load_module()
transformers = importlib.util.module_from_spec(spec)
spec.loader.exec_module(transformers)
transformers = sys.modules["transformers"]

CONFIG_MAPPING = transformers.models.auto.configuration_auto.CONFIG_MAPPING

Expand Down
5 changes: 4 additions & 1 deletion utils/check_config_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import inspect
import os
import re
import sys


# All paths are set with the intent you should run this script from the root of the repo with the command
Expand All @@ -30,7 +31,9 @@
os.path.join(PATH_TO_TRANSFORMERS, "__init__.py"),
submodule_search_locations=[PATH_TO_TRANSFORMERS],
)
transformers = spec.loader.load_module()
transformers = importlib.util.module_from_spec(spec)
spec.loader.exec_module(transformers)
transformers = sys.modules["transformers"]

CONFIG_MAPPING = transformers.models.auto.configuration_auto.CONFIG_MAPPING

Expand Down
5 changes: 4 additions & 1 deletion utils/check_copies.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import importlib.util
import os
import re
import sys

import black
from doc_builder.style_doc import style_docstrings_in_code
Expand Down Expand Up @@ -103,7 +104,9 @@
os.path.join(TRANSFORMERS_PATH, "__init__.py"),
submodule_search_locations=[TRANSFORMERS_PATH],
)
transformers_module = spec.loader.load_module()
transformers_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(transformers_module)
transformers_module = sys.modules["transformers"]


def _should_continue(line, indent):
Expand Down
5 changes: 4 additions & 1 deletion utils/check_inits.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import importlib.util
import os
import re
import sys
from pathlib import Path


Expand Down Expand Up @@ -279,7 +280,9 @@ def check_submodules():
os.path.join(PATH_TO_TRANSFORMERS, "__init__.py"),
submodule_search_locations=[PATH_TO_TRANSFORMERS],
)
transformers = spec.loader.load_module()
transformers = importlib.util.module_from_spec(spec)
spec.loader.exec_module(transformers)
transformers = sys.modules["transformers"]

module_not_registered = [
module
Expand Down
5 changes: 4 additions & 1 deletion utils/check_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import inspect
import os
import re
import sys
import warnings
from collections import OrderedDict
from difflib import get_close_matches
Expand Down Expand Up @@ -310,7 +311,9 @@
os.path.join(PATH_TO_TRANSFORMERS, "__init__.py"),
submodule_search_locations=[PATH_TO_TRANSFORMERS],
)
transformers = spec.loader.load_module()
transformers = importlib.util.module_from_spec(spec)
spec.loader.exec_module(transformers)
transformers = sys.modules["transformers"]


def check_model_list():
Expand Down
5 changes: 4 additions & 1 deletion utils/check_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import importlib.util
import os
import re
import sys


# All paths are set with the intent you should run this script from the root of the repo with the command
Expand Down Expand Up @@ -68,7 +69,9 @@ def _find_text_in_file(filename, start_prompt, end_prompt):
os.path.join(TRANSFORMERS_PATH, "__init__.py"),
submodule_search_locations=[TRANSFORMERS_PATH],
)
transformers_module = spec.loader.load_module()
transformers_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(transformers_module)
transformers_module = sys.modules["transformers"]


# Thanks to https://stackoverflow.com/questions/29916065/how-to-do-camelcase-split-in-python
Expand Down
5 changes: 4 additions & 1 deletion utils/check_task_guides.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import argparse
import importlib.util
import os
import sys


# All paths are set with the intent you should run this script from the root of the repo with the command
Expand Down Expand Up @@ -56,7 +57,9 @@ def _find_text_in_file(filename, start_prompt, end_prompt):
os.path.join(TRANSFORMERS_PATH, "__init__.py"),
submodule_search_locations=[TRANSFORMERS_PATH],
)
transformers_module = spec.loader.load_module()
transformers_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(transformers_module)
transformers_module = sys.modules["transformers"]

TASK_GUIDE_TO_MODELS = {
"asr.mdx": transformers_module.models.auto.modeling_auto.MODEL_FOR_CTC_MAPPING_NAMES,
Expand Down
5 changes: 4 additions & 1 deletion utils/update_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import importlib.util
import os
import re
import sys
import tempfile

import pandas as pd
Expand All @@ -36,7 +37,9 @@
os.path.join(TRANSFORMERS_PATH, "__init__.py"),
submodule_search_locations=[TRANSFORMERS_PATH],
)
transformers_module = spec.loader.load_module()
transformers_module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(transformers_module)
transformers_module = sys.modules["transformers"]


# Regexes that match TF/Flax/PT model names.
Expand Down