Skip to content

Commit

Permalink
feat: allow setting worker name via env var or cli arg (#245)
Browse files Browse the repository at this point in the history
* fix: support setting worker name from bridge script
* fix: check for worker name not none in startup script
* fix: log dreamer name
* fix: use field validator for worker name override instead
* fix: don't use missing function
* style: fix
* fix: check worker name in type safe way
  • Loading branch information
tazlin authored Aug 4, 2024
1 parent d9a5056 commit d0b09f2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
15 changes: 14 additions & 1 deletion horde_worker_regen/bridge_data/data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from horde_sdk.ai_horde_worker.bridge_data import CombinedHordeBridgeData
from loguru import logger
from pydantic import Field, model_validator
from pydantic import Field, field_validator, model_validator
from ruamel.yaml import YAML

from horde_worker_regen.consts import TOTAL_LORA_DOWNLOAD_TIMEOUT
Expand Down Expand Up @@ -131,6 +131,19 @@ def validate_performance_modes(self) -> reGenBridgeData:

return self

@field_validator("dreamer_worker_name", mode="after")
def validate_dreamer_worker_name(cls, value: str) -> str:
"""Apply the environment variable override for the `dreamer_worker_name` field."""
AIWORKER_DREAMER_WORKER_NAME = os.getenv("AIWORKER_DREAMER_WORKER_NAME")
if AIWORKER_DREAMER_WORKER_NAME:
logger.warning(
"AIWORKER_DREAMER_WORKER_NAME environment variable is set. This will override the value for "
"`dreamer_worker_name` in the config file.",
)
return AIWORKER_DREAMER_WORKER_NAME

return value

def prepare_custom_models(self) -> None:
"""Prepare the custom models."""
if os.getenv("HORDELIB_CUSTOM_MODELS"):
Expand Down
10 changes: 10 additions & 0 deletions horde_worker_regen/run_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,21 @@ def init() -> None:
default=False,
help="Enable AMD GPU-specific optimisations",
)
parser.add_argument(
"-n",
"--worker-name",
type=str,
default=None,
help="Override the worker name from the config file, for running multiple workers on one machine",
)

args = parser.parse_args()

os.environ["HORDE_SDK_DISABLE_CUSTOM_SINKS"] = "1"

if args.worker_name:
os.environ["AIWORKER_DREAMER_WORKER_NAME"] = args.worker_name

from horde_worker_regen.load_env_vars import load_env_vars_from_config

if not args.load_config_from_env_vars:
Expand Down

0 comments on commit d0b09f2

Please sign in to comment.