diff --git a/preload.py b/preload.py index 9d1ff53..a685525 100644 --- a/preload.py +++ b/preload.py @@ -28,7 +28,7 @@ def preload(parser): help="Enable debug information", action="store_true" ) - extension_path = Path(abspath(getsourcefile(lambda: 0))).parent.parent.parent + extension_path = Path(abspath(getsourcefile(lambda: 0))).parent config_path = extension_path.joinpath('distributed-config.json') # add config file parser.add_argument( diff --git a/scripts/extension.py b/scripts/extension.py index 8f32dca..53d93b0 100644 --- a/scripts/extension.py +++ b/scripts/extension.py @@ -54,7 +54,6 @@ class Script(scripts.Script): world.add_worker(uuid=worker[0], address=worker[1], port=worker[2]) world.load_config() - assert world.has_any_workers, "No workers are available. (Try using `--distributed-remotes`?)" def title(self): return "Distribute" @@ -120,7 +119,11 @@ class Script(scripts.Script): if Script.world.thin_client_mode: p.all_negative_prompts = processed.all_negative_prompts - info_text = image_info_post['infotexts'][i] + try: + info_text = image_info_post['infotexts'][i] + except IndexError: + logger.warning(f"image '{i}' was missing info-text") + info_text = image_info_post['infotexts'][0] processed.infotexts.append(info_text) # automatically save received image to local disk if desired @@ -256,12 +259,12 @@ class Script(scripts.Script): continue else: # other scripts to pack - args_script_pack = {} - args_script_pack[title] = {"args": []} - for arg in p.script_args[script.args_from:script.args_to]: - args_script_pack[title]["args"].append(arg) - packed_script_args.append(args_script_pack) - # https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111/issues/12#issuecomment-1480382514 + # args_script_pack = {} + # args_script_pack[title] = {"args": []} + # for arg in p.script_args[script.args_from:script.args_to]: + # args_script_pack[title]["args"].append(arg) + # packed_script_args.append(args_script_pack) + # # https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111/issues/12#issuecomment-1480382514 if Script.runs_since_init < 1: logger.warning(f"Distributed doesn't yet support '{title}'") diff --git a/scripts/spartan/UI.py b/scripts/spartan/UI.py index 07fd97b..56a0cdc 100644 --- a/scripts/spartan/UI.py +++ b/scripts/spartan/UI.py @@ -230,7 +230,7 @@ class UI: thin_client_cbx = gradio.Checkbox( label='Thin-client mode (experimental)', info="Only generate images using remote workers. There will be no previews when enabled.", - value=False + value=self.world.thin_client_mode ) job_timeout = gradio.Number( label='Job timeout', value=self.world.job_timeout, diff --git a/scripts/spartan/Worker.py b/scripts/spartan/Worker.py index 0eeab43..ea5066a 100644 --- a/scripts/spartan/Worker.py +++ b/scripts/spartan/Worker.py @@ -58,11 +58,11 @@ class Worker: """ address: Union[str, None] = None - port: int = 80 + port: int = 7860 avg_ipm: Union[float, None] = None uuid: Union[str, None] = None queried: bool = False # whether this worker has been connected to yet - free_vram: Union[bytes, int] = 0 + free_vram: int = 0 verify_remotes: bool = False master: bool = False benchmarked: bool = False @@ -99,11 +99,11 @@ class Worker: "PLMS": 9.31 } - def __init__(self, address: Union[str, None] = None, port: int = 80, uuid: Union[str, None] = None, verify_remotes: bool = True, + def __init__(self, address: Union[str, None] = None, port: int = 7860, uuid: Union[str, None] = None, verify_remotes: bool = True, master: bool = False, tls: bool = False, auth: Union[str, None, Tuple, List] = None): """ Creates a new worker object. - + param address: The address of the worker node. Can be an ip or a FQDN. Defaults to None. do NOT include sdapi/v1 in the address. param port: The port number used by the worker node. Defaults to 80. (http) or 443 (https) param uuid: The unique identifier/name of the worker node. Defaults to None. @@ -157,7 +157,7 @@ class Worker: self.password = auth[1] else: raise ValueError(f"Invalid auth value: {auth}") - self.auth: Union[Tuple[str, str] , None] = (self.user, self.password) if self.user is not None else None + self.auth: Union[Tuple[str, str], None] = (self.user, self.password) if self.user is not None else None if uuid is not None: self.uuid = uuid self.session = requests.Session() @@ -173,8 +173,6 @@ class Worker: raise InvalidWorkerResponse(f"Worker '{self.uuid}' responded with status code {response.status_code}") def __str__(self): - if self.port is None or self.port == 80: - return f"{self.address}" return f"{self.address}:{self.port}" def info(self) -> dict: @@ -309,7 +307,7 @@ class Worker: option_payload (dict): The options payload. sync_options (bool): Whether to attempt to synchronize the worker's loaded models with the locals' """ - eta = 0 + eta = None # TODO detect remote out of memory exception and restart or garbage collect instance using api? try: diff --git a/scripts/spartan/World.py b/scripts/spartan/World.py index a7503a8..3a7c85b 100644 --- a/scripts/spartan/World.py +++ b/scripts/spartan/World.py @@ -82,7 +82,6 @@ class World: self.verify_remotes = verify_remotes self.initial_payload = copy.copy(initial_payload) self.thin_client_mode = False - self.has_any_workers = False # whether any workers have been added to the world def __getitem__(self, label: str) -> Worker: for worker in self._workers: @@ -173,7 +172,6 @@ class World: if original is None: self._workers.append(new) - self.has_any_workers = True return new else: original.address = address @@ -181,6 +179,7 @@ class World: original.tls = tls return original + def interrupt_remotes(self): for worker in self.get_workers(): @@ -493,14 +492,16 @@ class World: last -= 1 def config(self) -> dict: - # { - # "workers": [ - # { - # "worker1": { - # "address": "" - # } - # }, ... - #} + """ + { + "workers": [ + { + "worker1": { + "address": "" + } + }, ... + } + """ if not os.path.exists(self.config_path): logger.error(f"Config was not found at '{self.config_path}'") return @@ -539,8 +540,7 @@ class World: except InvalidWorkerResponse as e: logger.error(f"worker {w} is invalid... ignoring") continue - if not self.has_any_workers: - logger.error(f"no workers were loaded from config, please add workers to {self.config_path}") + # TODO add early warning when no workers are added else: logger.debug("loaded config")