Ensure lora strength is always a float in API and JSON

Force float coercion in both migration paths (load_json and DB read)
and override type detection in get_sequence_keys so lora strength
keys always report as FLOAT regardless of JSON deserialization.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-18 23:02:04 +01:00
parent 08338746e2
commit 82e4ba526c
2 changed files with 14 additions and 1 deletions
+11 -1
View File
@@ -219,6 +219,9 @@ class ProjectDB:
data.setdefault(str_key, 1.0)
elif name_key in data and str_key not in data:
data[str_key] = 1.0
# Ensure strength is always a float (JSON may deserialize 1 as int)
if str_key in data:
data[str_key] = float(data[str_key])
return data
def get_sequence(self, data_file_id: int, sequence_number: int) -> dict | None:
@@ -252,6 +255,11 @@ class ProjectDB:
return 0
return self.count_sequences(df["id"])
_FLOAT_KEYS = frozenset(
f'lora {idx} {tier} strength'
for idx in range(1, 4) for tier in ('high', 'low')
)
def get_sequence_keys(self, data_file_id: int, sequence_number: int) -> tuple[list[str], list[str]]:
"""Returns (keys, types) for a sequence's data dict."""
data = self.get_sequence(data_file_id, sequence_number)
@@ -261,7 +269,9 @@ class ProjectDB:
types = []
for k, v in data.items():
keys.append(k)
if isinstance(v, bool):
if k in self._FLOAT_KEYS:
types.append("FLOAT")
elif isinstance(v, bool):
types.append("STRING")
elif isinstance(v, int):
types.append("INT")
+3
View File
@@ -168,6 +168,9 @@ def _migrate_lora_keys(data: dict) -> None:
item.setdefault(str_key, 1.0)
elif name_key in item and str_key not in item:
item[str_key] = 1.0
# Ensure strength is always a float (JSON may deserialize 1 as int)
if str_key in item:
item[str_key] = float(item[str_key])
def load_json(path: str | Path) -> tuple[dict[str, Any], float]: