refactor: Make direct_transformers_import util (#21652)
* refactor: Make direct_import util * edit direct import fn * add docstring * make import function specific to transformers only * edit doc string
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
# limitations under the License.
|
||||
|
||||
import copy
|
||||
import importlib
|
||||
import logging
|
||||
import os
|
||||
import random
|
||||
@@ -53,7 +52,7 @@ from transformers.testing_utils import (
|
||||
require_torch_or_tf,
|
||||
slow,
|
||||
)
|
||||
from transformers.utils import is_tf_available, is_torch_available
|
||||
from transformers.utils import direct_transformers_import, is_tf_available, is_torch_available
|
||||
from transformers.utils import logging as transformers_logging
|
||||
|
||||
|
||||
@@ -69,14 +68,7 @@ PATH_TO_TRANSFORMERS = os.path.join(Path(__file__).parent.parent.parent, "src/tr
|
||||
|
||||
|
||||
# Dynamically import the Transformers module to grab the attribute classes of the processor form their names.
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"transformers",
|
||||
os.path.join(PATH_TO_TRANSFORMERS, "__init__.py"),
|
||||
submodule_search_locations=[PATH_TO_TRANSFORMERS],
|
||||
)
|
||||
transformers_module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(transformers_module)
|
||||
transformers_module = sys.modules["transformers"]
|
||||
transformers_module = direct_transformers_import(PATH_TO_TRANSFORMERS)
|
||||
|
||||
|
||||
class ANY:
|
||||
|
||||
Reference in New Issue
Block a user