Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
stable-diffusion-webui
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
stable-diffusion-webui
Commits
d52a80f7
Commit
d52a80f7
authored
Jan 12, 2023
by
Shondoit
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow creation of zero vectors for TI
parent
0b8911d8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
3 deletions
+6
-3
textual_inversion.py
modules/textual_inversion/textual_inversion.py
+6
-3
No files found.
modules/textual_inversion/textual_inversion.py
View file @
d52a80f7
...
...
@@ -248,11 +248,14 @@ def create_embedding(name, num_vectors_per_token, overwrite_old, init_text='*'):
with
devices
.
autocast
():
cond_model
([
""
])
# will send cond model to GPU if lowvram/medvram is active
embedded
=
cond_model
.
encode_embedding_init_text
(
init_text
,
num_vectors_per_token
)
#cond_model expects at least some text, so we provide '*' as backup.
embedded
=
cond_model
.
encode_embedding_init_text
(
init_text
or
'*'
,
num_vectors_per_token
)
vec
=
torch
.
zeros
((
num_vectors_per_token
,
embedded
.
shape
[
1
]),
device
=
devices
.
device
)
for
i
in
range
(
num_vectors_per_token
):
vec
[
i
]
=
embedded
[
i
*
int
(
embedded
.
shape
[
0
])
//
num_vectors_per_token
]
#Only copy if we provided an init_text, otherwise keep vectors as zeros
if
init_text
:
for
i
in
range
(
num_vectors_per_token
):
vec
[
i
]
=
embedded
[
i
*
int
(
embedded
.
shape
[
0
])
//
num_vectors_per_token
]
# Remove illegal characters from name.
name
=
""
.
join
(
x
for
x
in
name
if
(
x
.
isalnum
()
or
x
in
"._- "
))
...
...
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