Skip to content

Commit

Permalink
Merge pull request #193 from Haidra-Org/main
Browse files Browse the repository at this point in the history
fix: attempt to reload the json on fail
  • Loading branch information
tazlin authored Feb 20, 2024
2 parents 48427e0 + bb5cc5f commit 808efd9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
17 changes: 12 additions & 5 deletions hordelib/model_manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,18 @@ def load_model_database(self) -> None:
if self.download_reference or not is_model_db_present:
raise NotImplementedError("Downloading model databases is no longer supported within hordelib.")

try:
self.model_reference = json.loads((self.models_db_path).read_text())
except json.decoder.JSONDecodeError as e:
logger.error(f"Model database {self.models_db_path} is not valid JSON: {e}")
raise
for attempt in range(3):
try:
self.model_reference = json.loads((self.models_db_path).read_text())
except json.decoder.JSONDecodeError as e:
if attempt <= 2:
logger.warning(
f"Model database {self.models_db_path} is not valid JSON: {e}. Will retry: {attempt+1}/3",
)
time.sleep(1)
continue
logger.error(f"Model database {self.models_db_path} is not valid JSON: {e}")
raise

models_available = []
for model in self.model_reference:
Expand Down
4 changes: 2 additions & 2 deletions hordelib/utils/gpuinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class GPUInfoResult(BaseModel):
product: str
pci_gen: str
pci_width: str
fan_speed: tuple[int, Unit]
fan_speed: tuple[str, Unit]
vram_total: tuple[int, Unit]
vram_used: tuple[int, Unit]
vram_free: tuple[int, Unit]
Expand All @@ -186,7 +186,7 @@ def get_empty_info(cls):
product="unknown (stats with AMD not supported)",
pci_gen="?",
pci_width="?",
fan_speed=(0, Unit.percent),
fan_speed=("0", Unit.percent),
vram_total=(0, Unit.megabytes),
vram_used=(0, Unit.megabytes),
vram_free=(0, Unit.megabytes),
Expand Down
10 changes: 8 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ def shared_model_manager(hordelib_instance: HordeLib) -> Generator[type[SharedMo
assert SharedModelManager.manager.validate_model("Deliberate")
assert SharedModelManager.manager.download_model("SDXL 1.0")
assert SharedModelManager.manager.validate_model("SDXL 1.0")
assert SharedModelManager.manager.download_model("AlbedoBase XL (SDXL)")
assert SharedModelManager.manager.validate_model("AlbedoBase XL (SDXL)")
assert SharedModelManager.manager.download_model("Rev Animated")
assert SharedModelManager.manager.validate_model("Rev Animated")

assert SharedModelManager.manager.controlnet is not None
assert SharedModelManager.manager.controlnet.download_all_models()
Expand Down Expand Up @@ -134,15 +138,17 @@ def pytest_collection_modifyitems(items):
"tests.model_managers.test_shared_model_manager",
"tests.test_mm_lora",
"tests.test_mm_ti",
"tests.test_inference",
]
MODULES_TO_RUN_LAST = [
"tests.test_inference",
"tests.test_horde_inference",
"tests.test_horde_inference_img2img",
"tests.test_horde_samplers",
"tests.test_horde_ti",
"tests.test_horde_lcm",
"tests.test_horde_lora",
"tests.test_horde_inference_controlnet",
"tests.test_horde_inference_painting",
"tests.test_horde_samplers",
]
module_mapping = {item: item.module.__name__ for item in items}

Expand Down
13 changes: 9 additions & 4 deletions tests/test_horde_samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,15 @@ def test_samplers(

for img_filename, pil_image in images_to_compare:
logger.debug(f"Checking image {img_filename}")
assert check_single_inference_image_similarity(
img_filename,
pil_image,
)
if "sde" not in img_filename and "lcm" not in img_filename:
assert check_single_inference_image_similarity(
img_filename,
pil_image,
)
else:
logger.warning(
f"Skipping image similarity check for {img_filename} due to SDE samplers being non-deterministic.",
)

def test_slow_samplers(
self,
Expand Down

0 comments on commit 808efd9

Please sign in to comment.