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:
Connor Henderson
2023-02-16 11:32:32 -05:00
committed by GitHub
parent 96d4fa46ed
commit 0f96c26de6
12 changed files with 47 additions and 101 deletions

View File

@@ -13,11 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import importlib
import inspect
import os
import re
import sys
from transformers.utils import direct_transformers_import
# All paths are set with the intent you should run this script from the root of the repo with the command
@@ -26,14 +26,7 @@ PATH_TO_TRANSFORMERS = "src/transformers"
# This is to make sure the transformers module imported is the one in the repo.
spec = importlib.util.spec_from_file_location(
"transformers",
os.path.join(PATH_TO_TRANSFORMERS, "__init__.py"),
submodule_search_locations=[PATH_TO_TRANSFORMERS],
)
transformers = importlib.util.module_from_spec(spec)
spec.loader.exec_module(transformers)
transformers = sys.modules["transformers"]
transformers = direct_transformers_import(PATH_TO_TRANSFORMERS)
CONFIG_MAPPING = transformers.models.auto.configuration_auto.CONFIG_MAPPING