Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
b9af152e
Unverified
Commit
b9af152e
authored
Feb 07, 2023
by
Stas Bekman
Committed by
GitHub
Feb 07, 2023
Browse files
[tokenizer] sanitize saved config (#21483)
* [tokenizer] sanitize saved config * rm config["name_or_path"] test
parent
67d07487
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
2 deletions
+4
-2
src/transformers/tokenization_utils_base.py
src/transformers/tokenization_utils_base.py
+4
-0
tests/models/auto/test_tokenization_auto.py
tests/models/auto/test_tokenization_auto.py
+0
-2
No files found.
src/transformers/tokenization_utils_base.py
View file @
b9af152e
...
...
@@ -2153,6 +2153,10 @@ class PreTrainedTokenizerBase(SpecialTokensMixin, PushToHubMixin):
if
self
.
_auto_class
is
not
None
:
custom_object_save
(
self
,
save_directory
,
config
=
tokenizer_config
)
# remove private information
if
"name_or_path"
in
tokenizer_config
:
tokenizer_config
.
pop
(
"name_or_path"
)
with
open
(
tokenizer_config_file
,
"w"
,
encoding
=
"utf-8"
)
as
f
:
out_str
=
json
.
dumps
(
tokenizer_config
,
indent
=
2
,
sort_keys
=
True
,
ensure_ascii
=
False
)
+
"
\n
"
f
.
write
(
out_str
)
...
...
tests/models/auto/test_tokenization_auto.py
View file @
b9af152e
...
...
@@ -230,8 +230,6 @@ class AutoTokenizerTest(unittest.TestCase):
# Check the class of the tokenizer was properly saved (note that it always saves the slow class).
self
.
assertEqual
(
config
[
"tokenizer_class"
],
"BertTokenizer"
)
# Check other keys just to make sure the config was properly saved /reloaded.
self
.
assertEqual
(
config
[
"name_or_path"
],
SMALL_MODEL_IDENTIFIER
)
def
test_new_tokenizer_registration
(
self
):
try
:
...
...
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