Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
bc274a28
"vscode:/vscode.git/clone" did not exist on "5fef17f4907b4cb78685149fa03b1fbb607b3bee"
Unverified
Commit
bc274a28
authored
Apr 26, 2024
by
Xuehai Pan
Committed by
GitHub
Apr 25, 2024
Browse files
Do not use deprecated `SourceFileLoader.load_module()` in dynamic module loading (#30370)
parent
e60491ad
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
3 deletions
+10
-3
src/transformers/dynamic_module_utils.py
src/transformers/dynamic_module_utils.py
+10
-3
No files found.
src/transformers/dynamic_module_utils.py
View file @
bc274a28
...
...
@@ -15,6 +15,7 @@
"""Utilities to dynamically load objects from the Hub."""
import
filecmp
import
importlib
import
importlib.util
import
os
import
re
import
shutil
...
...
@@ -196,9 +197,15 @@ def get_class_in_module(class_name: str, module_path: Union[str, os.PathLike]) -
Returns:
`typing.Type`: The class looked for.
"""
name
=
os
.
path
.
normpath
(
module_path
).
replace
(
".py"
,
""
).
replace
(
os
.
path
.
sep
,
"."
)
module_path
=
str
(
Path
(
HF_MODULES_CACHE
)
/
module_path
)
module
=
importlib
.
machinery
.
SourceFileLoader
(
name
,
module_path
).
load_module
()
name
=
os
.
path
.
normpath
(
module_path
).
rstrip
(
".py"
).
replace
(
os
.
path
.
sep
,
"."
)
module_spec
=
importlib
.
util
.
spec_from_file_location
(
name
,
location
=
Path
(
HF_MODULES_CACHE
)
/
module_path
)
module
=
sys
.
modules
.
get
(
name
)
if
module
is
None
:
module
=
importlib
.
util
.
module_from_spec
(
module_spec
)
# insert it into sys.modules before any loading begins
sys
.
modules
[
name
]
=
module
# reload in both cases
module_spec
.
loader
.
exec_module
(
module
)
return
getattr
(
module
,
class_name
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment