Compare commits

...
2 Commits
Author SHA1 Message Date
moosecrap 2d30bd2155 Model switch fix 2026-07-27 04:47:54 -07:00
moosecrap f6f021f2a3 Forge parameter fix 2026-07-27 04:38:34 -07:00
+41 -10
View File
@@ -32,7 +32,7 @@ async def ensure_model_state(model_name: str, model_preset: Dict[str, Any]):
preset = model_preset.get("preset", "xl")
await asyncio.to_thread(
requests.post,
f"{config.SD_URL}/api/predict/checkpoint_change",
f"{config.SD_URL}/api/checkpoint_change",
json={"data": [target_ckpt, preset]},
timeout=30
)
@@ -45,7 +45,7 @@ async def ensure_model_state(model_name: str, model_preset: Dict[str, Any]):
preset = model_preset.get("preset", "xl")
await asyncio.to_thread(
requests.post,
f"{config.SD_URL}/api/predict/modules_change",
f"{config.SD_URL}/api/modules_change",
json={"data": [target_modules, preset]},
timeout=30
)
@@ -81,16 +81,47 @@ async def handle(args: Dict[str, Any]) -> List[Dict[str, Any]]:
except Exception as e:
raise ToolError(f"Failed to connect to Stable Diffusion server: {str(e)}")
# Build the label-to-index map
# Build the label-to-index map and a sparse payload
label_map = {}
label_counts = {}
payload = [p["parameter_default"] for p in params_info]
# Find the maximum param index to determine payload size
max_param_idx = 0
for p in params_info:
name = p.get("parameter_name", "")
if name.startswith("param_"):
try:
idx = int(name.replace("param_", ""))
max_param_idx = max(max_param_idx, idx)
except ValueError:
pass
# Initialize payload with Nones (size is max_idx + 1)
payload = [None] * (max_param_idx + 1)
for idx, p in enumerate(params_info):
label = p["label"]
for idx_in_list, p in enumerate(params_info):
name = p.get("parameter_name", "")
label = p.get("label")
default = p.get("parameter_default")
# Determine the absolute index in the payload
if name == "id_task":
abs_idx = 0
elif name.startswith("param_"):
try:
abs_idx = int(name.replace("param_", ""))
except ValueError:
continue
else:
# Fallback for unexpected names, though unlikely
continue
# Set the default value at the absolute index
payload[abs_idx] = default
# Handle label mapping for AI overrides
if not label or label.startswith("parameter_"):
label = p["parameter_name"]
label = name
if label in label_counts:
label_counts[label] += 1
@@ -99,7 +130,7 @@ async def handle(args: Dict[str, Any]) -> List[Dict[str, Any]]:
label_counts[label] = 0
mapped_label = label
label_map[mapped_label] = idx
label_map[mapped_label] = abs_idx
# 3. LOAD CONFIGS
models_cfg = load_toml(config.MODEL_PRESETS_PATH)
@@ -163,8 +194,8 @@ async def handle(args: Dict[str, Any]) -> List[Dict[str, Any]]:
if "Seed" in label_map:
payload[label_map["Seed"]] = -1
for _ in range(7):
payload.insert(39, None)
# The "Magic Number" splice is no longer needed as gaps are
# automatically filled by the sparse-to-dense mapping.
# 6. EXECUTE GENERATION
try: