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:
@@ -15,16 +15,16 @@
|
||||
|
||||
import argparse
|
||||
import collections
|
||||
import importlib.util
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
import pandas as pd
|
||||
from datasets import Dataset
|
||||
from huggingface_hub import Repository
|
||||
|
||||
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
|
||||
# python utils/update_metadata.py
|
||||
@@ -32,14 +32,7 @@ TRANSFORMERS_PATH = "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(TRANSFORMERS_PATH, "__init__.py"),
|
||||
submodule_search_locations=[TRANSFORMERS_PATH],
|
||||
)
|
||||
transformers_module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(transformers_module)
|
||||
transformers_module = sys.modules["transformers"]
|
||||
transformers_module = direct_transformers_import(TRANSFORMERS_PATH)
|
||||
|
||||
|
||||
# Regexes that match TF/Flax/PT model names.
|
||||
|
||||
Reference in New Issue
Block a user