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
4c722e9e
Unverified
Commit
4c722e9e
authored
Jun 29, 2022
by
Stas Bekman
Committed by
GitHub
Jun 29, 2022
Browse files
fix regexes with escape sequence (#17943)
parent
7c4c6f60
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
5 deletions
+5
-5
src/transformers/dynamic_module_utils.py
src/transformers/dynamic_module_utils.py
+4
-4
src/transformers/modeling_utils.py
src/transformers/modeling_utils.py
+1
-1
No files found.
src/transformers/dynamic_module_utils.py
View file @
4c722e9e
...
...
@@ -78,9 +78,9 @@ def get_relative_imports(module_file):
content
=
f
.
read
()
# Imports of the form `import .xxx`
relative_imports
=
re
.
findall
(
"^\s*import\s+\.(\S+)\s*$"
,
content
,
flags
=
re
.
MULTILINE
)
relative_imports
=
re
.
findall
(
r
"^\s*import\s+\.(\S+)\s*$"
,
content
,
flags
=
re
.
MULTILINE
)
# Imports of the form `from .xxx import yyy`
relative_imports
+=
re
.
findall
(
"^\s*from\s+\.(\S+)\s+import"
,
content
,
flags
=
re
.
MULTILINE
)
relative_imports
+=
re
.
findall
(
r
"^\s*from\s+\.(\S+)\s+import"
,
content
,
flags
=
re
.
MULTILINE
)
# Unique-ify
return
list
(
set
(
relative_imports
))
...
...
@@ -122,9 +122,9 @@ def check_imports(filename):
content
=
f
.
read
()
# Imports of the form `import xxx`
imports
=
re
.
findall
(
"^\s*import\s+(\S+)\s*$"
,
content
,
flags
=
re
.
MULTILINE
)
imports
=
re
.
findall
(
r
"^\s*import\s+(\S+)\s*$"
,
content
,
flags
=
re
.
MULTILINE
)
# Imports of the form `from xxx import yyy`
imports
+=
re
.
findall
(
"^\s*from\s+(\S+)\s+import"
,
content
,
flags
=
re
.
MULTILINE
)
imports
+=
re
.
findall
(
r
"^\s*from\s+(\S+)\s+import"
,
content
,
flags
=
re
.
MULTILINE
)
# Only keep the top-level module
imports
=
[
imp
.
split
(
"."
)[
0
]
for
imp
in
imports
if
not
imp
.
startswith
(
"."
)]
...
...
src/transformers/modeling_utils.py
View file @
4c722e9e
...
...
@@ -219,7 +219,7 @@ def dtype_byte_size(dtype):
"""
if
dtype
==
torch
.
bool
:
return
1
/
8
bit_search
=
re
.
search
(
"[^\d](\d+)$"
,
str
(
dtype
))
bit_search
=
re
.
search
(
r
"[^\d](\d+)$"
,
str
(
dtype
))
if
bit_search
is
None
:
raise
ValueError
(
f
"`dtype` is not a valid dtype:
{
dtype
}
."
)
bit_size
=
int
(
bit_search
.
groups
()[
0
])
...
...
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