Skip to content

Commit

Permalink
thread safe extra network list_items AUTOMATIC1111#13014
Browse files Browse the repository at this point in the history
  • Loading branch information
CastielMa committed May 26, 2024
1 parent 0e52af4 commit 7de0a2a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
6 changes: 5 additions & 1 deletion extensions-builtin/Lora/ui_extra_networks_lora.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def refresh(self):

def create_item(self, name, index=None, enable_filter=True):
lora_on_disk = networks.available_networks.get(name)
if lora_on_disk is None:
return

path, ext = os.path.splitext(lora_on_disk.filename)

Expand Down Expand Up @@ -66,7 +68,9 @@ def create_item(self, name, index=None, enable_filter=True):
return item

def list_items(self):
for index, name in enumerate(networks.available_networks):
# instantiate a list to protect against concurrent modification
names = list(networks.available_networks)
for index, name in enumerate(names):
item = self.create_item(name, index)

if item is not None:
Expand Down
1 change: 1 addition & 0 deletions gcloud_deploy.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# install

sudo apt install nvidia-cuda-toolkit
sudo apt-get update
sudo apt -y install wget git python3

Expand Down
6 changes: 5 additions & 1 deletion modules/ui_extra_networks_checkpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def refresh(self):

def create_item(self, name, index=None, enable_filter=True):
checkpoint: sd_models.CheckpointInfo = sd_models.checkpoint_aliases.get(name)
if checkpoint is None:
return
path, ext = os.path.splitext(checkpoint.filename)
return {
"name": checkpoint.name_for_extra,
Expand All @@ -32,7 +34,9 @@ def create_item(self, name, index=None, enable_filter=True):
def list_items(self):
names = list(sd_models.checkpoints_list)
for index, name in enumerate(names):
yield self.create_item(name, index)
item = self.create_item(name, index)
if item is not None:
yield item

def allowed_directories_for_previews(self):
return [v for v in [shared.cmd_opts.ckpt_dir, sd_models.model_path] if v is not None]
Expand Down
12 changes: 9 additions & 3 deletions modules/ui_extra_networks_hypernets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def refresh(self):
shared.reload_hypernetworks()

def create_item(self, name, index=None, enable_filter=True):
full_path = shared.hypernetworks[name]
full_path = shared.hypernetworks.get(name)
if full_path is None:
return
path, ext = os.path.splitext(full_path)
sha256 = sha256_from_cache(full_path, f'hypernet/{name}')
shorthash = sha256[0:10] if sha256 else None
Expand All @@ -31,8 +33,12 @@ def create_item(self, name, index=None, enable_filter=True):
}

def list_items(self):
for index, name in enumerate(shared.hypernetworks):
yield self.create_item(name, index)
names = list(shared.hypernetworks)
for index, name in enumerate(names):
item = self.create_item(name, index)
if item is not None:
yield item


def allowed_directories_for_previews(self):
return [shared.cmd_opts.hypernetwork_dir]
Expand Down
10 changes: 7 additions & 3 deletions modules/ui_extra_networks_textual_inversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def refresh(self):

def create_item(self, name, index=None, enable_filter=True):
embedding = sd_hijack.model_hijack.embedding_db.word_embeddings.get(name)

if embedding is None:
return
path, ext = os.path.splitext(embedding.filename)
return {
"name": name,
Expand All @@ -29,8 +30,11 @@ def create_item(self, name, index=None, enable_filter=True):
}

def list_items(self):
for index, name in enumerate(sd_hijack.model_hijack.embedding_db.word_embeddings):
yield self.create_item(name, index)
names = list(sd_hijack.model_hijack.embedding_db.word_embeddings)
for index, name in enumerate(names):
item = self.create_item(name, index)
if item is not None:
yield item

def allowed_directories_for_previews(self):
return list(sd_hijack.model_hijack.embedding_db.embedding_dirs)

0 comments on commit 7de0a2a

Please sign in to comment.