Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
4635f312
Commit
4635f312
authored
May 29, 2023
by
klimaleksus
Committed by
GitHub
May 29, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor EmbeddingDatabase.register_embedding() to allow unregistering
parent
b957dcfe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
6 deletions
+19
-6
modules/textual_inversion/textual_inversion.py
modules/textual_inversion/textual_inversion.py
+19
-6
No files found.
modules/textual_inversion/textual_inversion.py
View file @
4635f312
...
@@ -120,16 +120,29 @@ class EmbeddingDatabase:
...
@@ -120,16 +120,29 @@ class EmbeddingDatabase:
self
.
embedding_dirs
.
clear
()
self
.
embedding_dirs
.
clear
()
def
register_embedding
(
self
,
embedding
,
model
):
def
register_embedding
(
self
,
embedding
,
model
):
self
.
word_embeddings
[
embedding
.
name
]
=
embedding
return
self
.
register_embedding_by_name
(
embedding
,
model
,
embedding
.
name
)
ids
=
model
.
cond_stage_model
.
tokenize
([
embedding
.
name
])[
0
]
def
register_embedding_by_name
(
self
,
embedding
,
model
,
name
):
ids
=
model
.
cond_stage_model
.
tokenize
([
name
])[
0
]
first_id
=
ids
[
0
]
first_id
=
ids
[
0
]
if
first_id
not
in
self
.
ids_lookup
:
if
first_id
not
in
self
.
ids_lookup
:
self
.
ids_lookup
[
first_id
]
=
[]
self
.
ids_lookup
[
first_id
]
=
[]
if
name
in
self
.
word_embeddings
:
self
.
ids_lookup
[
first_id
]
=
sorted
(
self
.
ids_lookup
[
first_id
]
+
[(
ids
,
embedding
)],
key
=
lambda
x
:
len
(
x
[
0
]),
reverse
=
True
)
# remove old one from the lookup list
lookup
=
[
x
for
x
in
self
.
ids_lookup
[
first_id
]
if
x
[
1
]
.
name
!=
name
]
else
:
lookup
=
self
.
ids_lookup
[
first_id
]
if
embedding
is
not
None
:
lookup
+=
[(
ids
,
embedding
)]
self
.
ids_lookup
[
first_id
]
=
sorted
(
lookup
,
key
=
lambda
x
:
len
(
x
[
0
]),
reverse
=
True
)
if
embedding
is
None
:
# unregister embedding with specified name
if
name
in
self
.
word_embeddings
:
del
self
.
word_embeddings
[
name
]
if
len
(
self
.
ids_lookup
[
first_id
])
==
0
:
del
self
.
ids_lookup
[
first_id
]
return
None
self
.
word_embeddings
[
name
]
=
embedding
return
embedding
return
embedding
def
get_expected_shape
(
self
):
def
get_expected_shape
(
self
):
...
...
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