Skip to content

Commit

Permalink
remove redundant init after last ref
Browse files Browse the repository at this point in the history
  • Loading branch information
papuSpartan committed May 10, 2024
1 parent 574afa4 commit 424a1c8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
61 changes: 30 additions & 31 deletions scripts/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from modules import processing
from modules import scripts
from modules.images import save_image
from modules.processing import fix_seed, Processed
from modules.processing import fix_seed
from modules.shared import opts, cmd_opts
from modules.shared import state as webui_state
from scripts.spartan.control_net import pack_control_net
Expand All @@ -31,33 +31,29 @@


# noinspection PyMissingOrEmptyDocstring
class Script(scripts.Script):

class DistributedScript(scripts.Script):
# global old_sigterm_handler, old_sigterm_handler
worker_threads: List[Thread] = []
# Whether to verify worker certificates. Can be useful if your remotes are self-signed.
verify_remotes = not cmd_opts.distributed_skip_verify_remotes
master_start = None
runs_since_init = 0
name = "distributed"
is_dropdown_handler_injected = False

if verify_remotes is False:
logger.warning(f"You have chosen to forego the verification of worker TLS certificates")
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

# build world
world = World(verify_remotes=verify_remotes)
world.load_config()
logger.info("doing initial ping sweep to see which workers are reachable")
world.ping_remotes(indiscriminate=True)

# constructed for both txt2img and img2img
def __init__(self):
super().__init__()
self.worker_threads: List[Thread] = []
# Whether to verify worker certificates. Can be useful if your remotes are self-signed.
self.verify_remotes = not cmd_opts.distributed_skip_verify_remotes
self.is_img2img = True
self.is_txt2img = True
self.alwayson = True
self.master_start = None
self.runs_since_init = 0
self.name = "distributed"
self.is_dropdown_handler_injected = False

if self.verify_remotes is False:
logger.warning(f"You have chosen to forego the verification of worker TLS certificates")
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

# build world
self.world = World(verify_remotes=self.verify_remotes)
self.world.load_config()
logger.info("doing initial ping sweep to see which workers are reachable")
self.world.ping_remotes(indiscriminate=True)

signal.signal(signal.SIGINT, self.signal_handler)
signal.signal(signal.SIGTERM, self.signal_handler)

def title(self):
return "Distribute"
Expand All @@ -67,7 +63,7 @@ def show(self, is_img2img):

def ui(self, is_img2img):
self.world.load_config()
extension_ui = UI(script=Script, world=self.world)
extension_ui = UI(world=self.world)
# root, api_exposed = extension_ui.create_ui()
components = extension_ui.create_ui()

Expand Down Expand Up @@ -203,7 +199,7 @@ def processed_inject_image(image, info_index, save_path_override=None, grid=Fals

# generate and inject grid
if opts.return_grid:
grid = processing.images.image_grid(processed.images, len(processed.images))
grid = images.image_grid(processed.images, len(processed.images))
processed_inject_image(
image=grid,
info_index=0,
Expand All @@ -219,7 +215,6 @@ def processed_inject_image(image, info_index, save_path_override=None, grid=Fals
p.batch_size = len(processed.images)
return


# p's type is
# "modules.processing.StableDiffusionProcessing*"
def before_process(self, p, *args):
Expand Down Expand Up @@ -365,10 +360,11 @@ def postprocess(self, p, processed, *args):
# restore process_images_inner if it was monkey-patched
processing.process_images_inner = self.original_process_images_inner

def signal_handler(self, sig, frame):
@staticmethod
def signal_handler(sig, frame):
logger.debug("handling interrupt signal")
# do cleanup
self.world.save_config()
DistributedScript.world.save_config()

if sig == signal.SIGINT:
if callable(old_sigint_handler):
Expand All @@ -378,3 +374,6 @@ def signal_handler(self, sig, frame):
old_sigterm_handler(sig, frame)
else:
sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
3 changes: 1 addition & 2 deletions scripts/spartan/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
class UI:
"""extension user interface related things"""

def __init__(self, script, world):
self.script = script
def __init__(self, world):
self.world = world
self.original_model_dropdown_handler = opts.data_labels.get('sd_model_checkpoint').onchange

Expand Down
2 changes: 1 addition & 1 deletion scripts/spartan/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from modules.processing import process_images, StableDiffusionProcessingTxt2Img
from . import shared as sh
from .pmodels import ConfigModel, Benchmark_Payload
from .shared import logger, warmup_samples, extension_path
from .shared import logger, extension_path
from .worker import Worker, State
from modules.call_queue import wrap_queued_call
from modules import processing
Expand Down

0 comments on commit 424a1c8

Please sign in to comment.