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
renzhc
diffusers_dcu
Commits
55d6453f
Unverified
Commit
55d6453f
authored
Sep 05, 2022
by
Suraj Patil
Committed by
GitHub
Sep 05, 2022
Browse files
[textual_inversion] use tokenizer.add_tokens to add placeholder_token (#357)
use add_tokens
parent
9ea9c6d1
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
7 deletions
+10
-7
examples/textual_inversion/textual_inversion.py
examples/textual_inversion/textual_inversion.py
+10
-7
No files found.
examples/textual_inversion/textual_inversion.py
View file @
55d6453f
...
@@ -357,15 +357,18 @@ def main():
...
@@ -357,15 +357,18 @@ def main():
# Load the tokenizer and add the placeholder token as a additional special token
# Load the tokenizer and add the placeholder token as a additional special token
if
args
.
tokenizer_name
:
if
args
.
tokenizer_name
:
tokenizer
=
CLIPTokenizer
.
from_pretrained
(
tokenizer
=
CLIPTokenizer
.
from_pretrained
(
args
.
tokenizer_name
)
args
.
tokenizer_name
,
additional_special_tokens
=
[
args
.
placeholder_token
]
)
elif
args
.
pretrained_model_name_or_path
:
elif
args
.
pretrained_model_name_or_path
:
tokenizer
=
CLIPTokenizer
.
from_pretrained
(
tokenizer
=
CLIPTokenizer
.
from_pretrained
(
args
.
pretrained_model_name_or_path
,
args
.
pretrained_model_name_or_path
,
subfolder
=
"tokenizer"
,
use_auth_token
=
args
.
use_auth_token
additional_special_tokens
=
[
args
.
placeholder_token
],
)
subfolder
=
"tokenizer"
,
use_auth_token
=
args
.
use_auth_token
,
# Add the placeholder token in tokenizer
num_added_tokens
=
tokenizer
.
add_tokens
(
args
.
placeholder_token
)
if
num_added_tokens
==
0
:
raise
ValueError
(
f
"The tokenizer already contains the token
{
args
.
placeholder_token
}
. Please pass a different"
" `placeholder_token` that is not already in the tokenizer."
)
)
# Convert the initializer_token, placeholder_token to ids
# Convert the initializer_token, placeholder_token to ids
...
...
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