Release V3.8 source, illustrated manual and Spectrum workflow
This commit is contained in:
@@ -0,0 +1 @@
|
||||
"""Runtime support helpers shipped with H3 Continuum."""
|
||||
@@ -0,0 +1,230 @@
|
||||
"""Temporary GPU-canary node for the internal A2 Audio Only path."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import hashlib
|
||||
import importlib
|
||||
import json
|
||||
import sys
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
|
||||
import torch
|
||||
|
||||
|
||||
def _single(name: str, value: Any) -> Any:
|
||||
if not isinstance(value, list) or len(value) != 1:
|
||||
raise ValueError(f"{name} must contain exactly one value")
|
||||
return value[0]
|
||||
|
||||
|
||||
def _active_modules() -> SimpleNamespace:
|
||||
import nodes as comfy_nodes
|
||||
|
||||
sampler_class = comfy_nodes.NODE_CLASS_MAPPINGS.get("H3ContinuumSamplerV38")
|
||||
if sampler_class is None:
|
||||
raise RuntimeError("H3ContinuumSamplerV38 is not loaded")
|
||||
module_name = sampler_class.__module__
|
||||
base_name = (
|
||||
module_name.split(".v3.", 1)[0]
|
||||
if ".v3." in module_name
|
||||
else module_name.rsplit(".", 2)[0]
|
||||
)
|
||||
return SimpleNamespace(
|
||||
refine_schedule=importlib.import_module(f"{base_name}.v3.refine_schedule"),
|
||||
refine_target=importlib.import_module(f"{base_name}.v3.refine_target"),
|
||||
targeted_second_pass=importlib.import_module(
|
||||
f"{base_name}.v3.targeted_second_pass"
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def _samples(latent: Any, *, name: str) -> torch.Tensor:
|
||||
if not isinstance(latent, dict) or not torch.is_tensor(latent.get("samples")):
|
||||
raise ValueError(f"{name} must be a LATENT dictionary with Tensor samples")
|
||||
return latent["samples"]
|
||||
|
||||
|
||||
def _tensor_sha256(value: torch.Tensor) -> str:
|
||||
tensor = value.detach().to(device="cpu").contiguous()
|
||||
digest = hashlib.sha256()
|
||||
digest.update(str(tuple(int(item) for item in tensor.shape)).encode("ascii"))
|
||||
digest.update(str(tensor.dtype).encode("ascii"))
|
||||
digest.update(tensor.view(torch.uint8).numpy().tobytes(order="C"))
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
class H3A2AudioOnlyCanary:
|
||||
"""Non-public bridge that records the A2 GPU acceptance contract."""
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"model": ("MODEL",),
|
||||
"clip": ("CLIP",),
|
||||
"sampler": ("SAMPLER",),
|
||||
"sigmas": ("SIGMAS",),
|
||||
"video_latents": ("LATENT",),
|
||||
"audio_latents": ("LATENT",),
|
||||
"assembly_plan": ("H3_CONTINUUM_ASSEMBLY_PLAN",),
|
||||
"refine_seed": (
|
||||
"INT",
|
||||
{"default": 3802601, "min": 0, "max": 0xFFFFFFFFFFFFFFFF},
|
||||
),
|
||||
"schedule_mode": (["Tail", "External"], {"default": "Tail"}),
|
||||
"tail_evaluations": (
|
||||
"INT",
|
||||
{"default": 6, "min": 1, "max": 100},
|
||||
),
|
||||
},
|
||||
"optional": {
|
||||
"refine_context": ("H3_CONTINUUM_REFINE_CONTEXT",),
|
||||
"video_vae": ("VAE",),
|
||||
},
|
||||
}
|
||||
|
||||
INPUT_IS_LIST = True
|
||||
RETURN_TYPES = ("LATENT", "LATENT", "H3_CONTINUUM_ASSEMBLY_PLAN", "STRING")
|
||||
RETURN_NAMES = (
|
||||
"video_latents",
|
||||
"refined_audio_latents",
|
||||
"updated_assembly_plan",
|
||||
"canary_status",
|
||||
)
|
||||
OUTPUT_IS_LIST = (True, True, False, False)
|
||||
FUNCTION = "run"
|
||||
CATEGORY = "H3 Continuum Test/A2"
|
||||
|
||||
def run(
|
||||
self,
|
||||
model,
|
||||
clip,
|
||||
sampler,
|
||||
sigmas,
|
||||
video_latents,
|
||||
audio_latents,
|
||||
assembly_plan,
|
||||
refine_seed,
|
||||
schedule_mode,
|
||||
tail_evaluations,
|
||||
refine_context=None,
|
||||
video_vae=None,
|
||||
):
|
||||
modules = _active_modules()
|
||||
source_sigmas = _single("sigmas", sigmas)
|
||||
mode = str(_single("schedule_mode", schedule_mode))
|
||||
if mode == "Tail":
|
||||
schedule = modules.refine_schedule.make_tail_schedule(
|
||||
source_sigmas,
|
||||
evaluation_count=int(
|
||||
_single("tail_evaluations", tail_evaluations)
|
||||
),
|
||||
)
|
||||
else:
|
||||
schedule = None
|
||||
|
||||
input_video_samples = [
|
||||
_samples(item, name=f"video_latents[{index}]")
|
||||
for index, item in enumerate(video_latents)
|
||||
]
|
||||
input_audio_samples = [
|
||||
_samples(item, name=f"audio_latents[{index}]")
|
||||
for index, item in enumerate(audio_latents)
|
||||
]
|
||||
input_video_hashes = [_tensor_sha256(item) for item in input_video_samples]
|
||||
input_audio_hashes = [_tensor_sha256(item) for item in input_audio_samples]
|
||||
|
||||
videos, audios, plan, status = (
|
||||
modules.targeted_second_pass.run_targeted_second_pass_groups(
|
||||
model=_single("model", model),
|
||||
clip=_single("clip", clip),
|
||||
sampler=_single("sampler", sampler),
|
||||
sigmas=source_sigmas,
|
||||
video_latents=video_latents,
|
||||
audio_latents=audio_latents,
|
||||
assembly_plan=_single("assembly_plan", assembly_plan),
|
||||
refine_seed=int(_single("refine_seed", refine_seed)),
|
||||
refine_target=modules.refine_target.MODE_AUDIO_ONLY,
|
||||
refine_context=(
|
||||
None
|
||||
if refine_context is None
|
||||
else _single("refine_context", refine_context)
|
||||
),
|
||||
video_vae=(
|
||||
None if video_vae is None else _single("video_vae", video_vae)
|
||||
),
|
||||
refine_schedule=schedule,
|
||||
enable_preview=False,
|
||||
)
|
||||
)
|
||||
output_video_samples = [
|
||||
_samples(item, name=f"output_video_latents[{index}]")
|
||||
for index, item in enumerate(videos)
|
||||
]
|
||||
output_audio_samples = [
|
||||
_samples(item, name=f"output_audio_latents[{index}]")
|
||||
for index, item in enumerate(audios)
|
||||
]
|
||||
contract = plan["second_pass_contract"]
|
||||
summary = {
|
||||
"format": "h3-continuum-a2-audio-only-gpu-canary-v1",
|
||||
"target": contract["refine_target_contract"],
|
||||
"execution": contract["refine_execution_contract"],
|
||||
"second_pass_contract_version": contract.get("version"),
|
||||
"physical_groups": [
|
||||
{
|
||||
"group_id": group.get("group_id"),
|
||||
"logical_chunks": group.get("logical_chunks"),
|
||||
"terminal_merged": bool(group.get("terminal_merged")),
|
||||
"source_latent_t": group.get("source_latent_t"),
|
||||
"source_audio_shape": group.get("source_audio_shape"),
|
||||
}
|
||||
for group in contract.get("physical_groups", [])
|
||||
],
|
||||
"refine_group_seeds": contract.get("refine_group_seeds"),
|
||||
"schedule_mode": contract["refine_schedule"]["mode"],
|
||||
"schedule_evaluations": contract["refine_schedule"][
|
||||
"evaluation_count"
|
||||
],
|
||||
"schedule_sigma_hash": contract["refine_schedule"]["sigma_hash"],
|
||||
"video_object_identity": [
|
||||
output is source
|
||||
for output, source in zip(videos, video_latents, strict=True)
|
||||
],
|
||||
"video_tensor_identity": [
|
||||
output is source
|
||||
for output, source in zip(
|
||||
output_video_samples,
|
||||
input_video_samples,
|
||||
strict=True,
|
||||
)
|
||||
],
|
||||
"video_input_sha256": input_video_hashes,
|
||||
"video_output_sha256": [
|
||||
_tensor_sha256(item) for item in output_video_samples
|
||||
],
|
||||
"audio_input_sha256": input_audio_hashes,
|
||||
"audio_output_sha256": [
|
||||
_tensor_sha256(item) for item in output_audio_samples
|
||||
],
|
||||
"audio_input_shapes": [list(item.shape) for item in input_audio_samples],
|
||||
"audio_output_shapes": [list(item.shape) for item in output_audio_samples],
|
||||
"video_output_policy": contract.get("video_output"),
|
||||
"video_sampling_policy": contract.get("video_sampling"),
|
||||
"audio_output_policy": contract.get("audio_output"),
|
||||
"audio_sampling_policy": contract.get("audio_sampling"),
|
||||
}
|
||||
canary_status = status + "\nA2_CANARY_JSON=" + json.dumps(
|
||||
summary,
|
||||
sort_keys=True,
|
||||
separators=(",", ":"),
|
||||
)
|
||||
return videos, audios, plan, canary_status
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {"H3A2AudioOnlyCanary": H3A2AudioOnlyCanary}
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"H3A2AudioOnlyCanary": "H3 A2 Audio Only Canary (Temporary)"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,387 @@
|
||||
"""Temporary read-only probe for the A3c Selective Refine GPU Matrix."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import hashlib
|
||||
import json
|
||||
from typing import Any, Mapping
|
||||
|
||||
import torch
|
||||
|
||||
|
||||
def _single(name: str, value: Any) -> Any:
|
||||
if not isinstance(value, list) or len(value) != 1:
|
||||
raise ValueError(f"{name} must contain exactly one value")
|
||||
return value[0]
|
||||
|
||||
|
||||
def _samples(latent: Any, *, name: str) -> torch.Tensor:
|
||||
if not isinstance(latent, dict) or not torch.is_tensor(latent.get("samples")):
|
||||
raise ValueError(f"{name} must be a LATENT dictionary with Tensor samples")
|
||||
return latent["samples"]
|
||||
|
||||
|
||||
def _tensor_sha256(value: torch.Tensor) -> str:
|
||||
tensor = value.detach().to(device="cpu").contiguous()
|
||||
digest = hashlib.sha256()
|
||||
digest.update(str(tuple(int(item) for item in tensor.shape)).encode("ascii"))
|
||||
digest.update(str(tensor.dtype).encode("ascii"))
|
||||
digest.update(tensor.view(torch.uint8).numpy().tobytes(order="C"))
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def _json_safe(value: Any) -> Any:
|
||||
if value is None or isinstance(value, (bool, int, float, str)):
|
||||
return value
|
||||
if isinstance(value, Mapping):
|
||||
return {
|
||||
str(key): _json_safe(item)
|
||||
for key, item in sorted(value.items(), key=lambda pair: str(pair[0]))
|
||||
}
|
||||
if isinstance(value, (list, tuple)):
|
||||
return [_json_safe(item) for item in value]
|
||||
return f"<{type(value).__module__}.{type(value).__qualname__}>"
|
||||
|
||||
|
||||
def _plan_identity(plan: Any, *, omit_target_identity: bool) -> dict[str, Any]:
|
||||
normalized = copy.deepcopy(_json_safe(plan))
|
||||
if omit_target_identity and isinstance(normalized, dict):
|
||||
contract = normalized.get("second_pass_contract")
|
||||
if isinstance(contract, dict):
|
||||
contract.pop("refine_target_contract", None)
|
||||
contract.pop("refine_execution_contract", None)
|
||||
encoded = json.dumps(
|
||||
normalized,
|
||||
sort_keys=True,
|
||||
separators=(",", ":"),
|
||||
ensure_ascii=False,
|
||||
).encode("utf-8")
|
||||
return {
|
||||
"sha256": hashlib.sha256(encoded).hexdigest(),
|
||||
"normalized": normalized,
|
||||
}
|
||||
|
||||
|
||||
class H3A3cSelectiveRefineProbe:
|
||||
"""Compare first-pass and public Second Pass outputs without changing them."""
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"input_video_latents": ("LATENT",),
|
||||
"input_audio_latents": ("LATENT",),
|
||||
"output_video_latents": ("LATENT",),
|
||||
"output_audio_latents": ("LATENT",),
|
||||
"input_assembly_plan": ("H3_CONTINUUM_ASSEMBLY_PLAN",),
|
||||
"output_assembly_plan": ("H3_CONTINUUM_ASSEMBLY_PLAN",),
|
||||
"refine_status": ("STRING", {"forceInput": True}),
|
||||
"target_label": (
|
||||
["Legacy V3.5", "Video Only", "Audio Only", "Video + Audio"],
|
||||
{"default": "Video Only"},
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
INPUT_IS_LIST = True
|
||||
RETURN_TYPES = ("STRING",)
|
||||
RETURN_NAMES = ("probe_report",)
|
||||
FUNCTION = "run"
|
||||
CATEGORY = "H3 Continuum Test/A3c"
|
||||
|
||||
def run(
|
||||
self,
|
||||
input_video_latents,
|
||||
input_audio_latents,
|
||||
output_video_latents,
|
||||
output_audio_latents,
|
||||
input_assembly_plan,
|
||||
output_assembly_plan,
|
||||
refine_status,
|
||||
target_label,
|
||||
):
|
||||
if len(input_video_latents) != len(output_video_latents):
|
||||
raise ValueError("Video physical-group count changed")
|
||||
if len(input_audio_latents) != len(output_audio_latents):
|
||||
raise ValueError("Audio physical-group count changed")
|
||||
input_v = [
|
||||
_samples(item, name=f"input_video_latents[{index}]")
|
||||
for index, item in enumerate(input_video_latents)
|
||||
]
|
||||
input_a = [
|
||||
_samples(item, name=f"input_audio_latents[{index}]")
|
||||
for index, item in enumerate(input_audio_latents)
|
||||
]
|
||||
output_v = [
|
||||
_samples(item, name=f"output_video_latents[{index}]")
|
||||
for index, item in enumerate(output_video_latents)
|
||||
]
|
||||
output_a = [
|
||||
_samples(item, name=f"output_audio_latents[{index}]")
|
||||
for index, item in enumerate(output_audio_latents)
|
||||
]
|
||||
output_plan = _single("output_assembly_plan", output_assembly_plan)
|
||||
contract = output_plan.get("second_pass_contract") or {}
|
||||
status = str(_single("refine_status", refine_status))
|
||||
target_contract = contract.get("refine_target_contract") or {}
|
||||
schedule = contract.get("refine_schedule") or {}
|
||||
physical_groups = [
|
||||
{
|
||||
"group_id": group.get("group_id"),
|
||||
"logical_chunks": group.get("logical_chunks"),
|
||||
"terminal_merged": bool(group.get("terminal_merged")),
|
||||
"source_latent_t": group.get("source_latent_t"),
|
||||
"source_audio_shape": group.get("source_audio_shape"),
|
||||
}
|
||||
for group in contract.get("physical_groups", [])
|
||||
]
|
||||
summary = {
|
||||
"format": "h3-continuum-a3c-selective-refine-probe-v1",
|
||||
"target_label": str(_single("target_label", target_label)),
|
||||
"target_mode": target_contract.get("mode", "legacy_video_only"),
|
||||
"seed_namespace": target_contract.get(
|
||||
"seed_namespace", "h3-continuum-refine-v1"
|
||||
),
|
||||
"second_pass_contract_version": contract.get("version"),
|
||||
"physical_groups": physical_groups,
|
||||
"refine_group_seeds": contract.get("refine_group_seeds"),
|
||||
"schedule_mode": schedule.get("mode"),
|
||||
"schedule_evaluations": schedule.get("evaluation_count"),
|
||||
"schedule_sigma_hash": schedule.get("sigma_hash"),
|
||||
"sampling_passes_reported": status.count("sampling_passes=1"),
|
||||
"input_video_object_identity": [
|
||||
output is source
|
||||
for output, source in zip(
|
||||
output_video_latents,
|
||||
input_video_latents,
|
||||
strict=True,
|
||||
)
|
||||
],
|
||||
"input_audio_object_identity": [
|
||||
output is source
|
||||
for output, source in zip(
|
||||
output_audio_latents,
|
||||
input_audio_latents,
|
||||
strict=True,
|
||||
)
|
||||
],
|
||||
"input_video_tensor_identity": [
|
||||
output is source
|
||||
for output, source in zip(output_v, input_v, strict=True)
|
||||
],
|
||||
"input_audio_tensor_identity": [
|
||||
output is source
|
||||
for output, source in zip(output_a, input_a, strict=True)
|
||||
],
|
||||
"input_video_sha256": [_tensor_sha256(item) for item in input_v],
|
||||
"output_video_sha256": [_tensor_sha256(item) for item in output_v],
|
||||
"input_audio_sha256": [_tensor_sha256(item) for item in input_a],
|
||||
"output_audio_sha256": [_tensor_sha256(item) for item in output_a],
|
||||
"input_video_shapes": [list(item.shape) for item in input_v],
|
||||
"output_video_shapes": [list(item.shape) for item in output_v],
|
||||
"input_audio_shapes": [list(item.shape) for item in input_a],
|
||||
"output_audio_shapes": [list(item.shape) for item in output_a],
|
||||
"output_video_finite": [
|
||||
bool(torch.isfinite(item.float()).all().item()) for item in output_v
|
||||
],
|
||||
"output_audio_finite": [
|
||||
bool(torch.isfinite(item.float()).all().item()) for item in output_a
|
||||
],
|
||||
"input_plan": _plan_identity(
|
||||
_single("input_assembly_plan", input_assembly_plan),
|
||||
omit_target_identity=False,
|
||||
),
|
||||
"output_plan": _plan_identity(
|
||||
output_plan,
|
||||
omit_target_identity=False,
|
||||
),
|
||||
"output_plan_without_target_identity": _plan_identity(
|
||||
output_plan,
|
||||
omit_target_identity=True,
|
||||
),
|
||||
}
|
||||
report = status + "\nA3C_PROBE_JSON=" + json.dumps(
|
||||
summary,
|
||||
sort_keys=True,
|
||||
separators=(",", ":"),
|
||||
ensure_ascii=False,
|
||||
)
|
||||
return (report,)
|
||||
|
||||
|
||||
class H3A3cVideoOnlyParityProbe:
|
||||
"""Compare legacy and Selective Video Only outputs from one First Pass."""
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"input_audio_latents": ("LATENT",),
|
||||
"legacy_video_latents": ("LATENT",),
|
||||
"legacy_audio_latents": ("LATENT",),
|
||||
"legacy_assembly_plan": ("H3_CONTINUUM_ASSEMBLY_PLAN",),
|
||||
"legacy_status": ("STRING", {"forceInput": True}),
|
||||
"selective_video_latents": ("LATENT",),
|
||||
"selective_audio_latents": ("LATENT",),
|
||||
"selective_assembly_plan": ("H3_CONTINUUM_ASSEMBLY_PLAN",),
|
||||
"selective_status": ("STRING", {"forceInput": True}),
|
||||
}
|
||||
}
|
||||
|
||||
INPUT_IS_LIST = True
|
||||
RETURN_TYPES = ("STRING",)
|
||||
RETURN_NAMES = ("parity_report",)
|
||||
FUNCTION = "run"
|
||||
CATEGORY = "H3 Continuum Test/A3c"
|
||||
|
||||
def run(
|
||||
self,
|
||||
input_audio_latents,
|
||||
legacy_video_latents,
|
||||
legacy_audio_latents,
|
||||
legacy_assembly_plan,
|
||||
legacy_status,
|
||||
selective_video_latents,
|
||||
selective_audio_latents,
|
||||
selective_assembly_plan,
|
||||
selective_status,
|
||||
):
|
||||
counts = {
|
||||
len(input_audio_latents),
|
||||
len(legacy_video_latents),
|
||||
len(legacy_audio_latents),
|
||||
len(selective_video_latents),
|
||||
len(selective_audio_latents),
|
||||
}
|
||||
if len(counts) != 1:
|
||||
raise ValueError("Video Only parity physical-group counts differ")
|
||||
input_a = [
|
||||
_samples(item, name=f"input_audio_latents[{index}]")
|
||||
for index, item in enumerate(input_audio_latents)
|
||||
]
|
||||
legacy_v = [
|
||||
_samples(item, name=f"legacy_video_latents[{index}]")
|
||||
for index, item in enumerate(legacy_video_latents)
|
||||
]
|
||||
legacy_a = [
|
||||
_samples(item, name=f"legacy_audio_latents[{index}]")
|
||||
for index, item in enumerate(legacy_audio_latents)
|
||||
]
|
||||
selective_v = [
|
||||
_samples(item, name=f"selective_video_latents[{index}]")
|
||||
for index, item in enumerate(selective_video_latents)
|
||||
]
|
||||
selective_a = [
|
||||
_samples(item, name=f"selective_audio_latents[{index}]")
|
||||
for index, item in enumerate(selective_audio_latents)
|
||||
]
|
||||
legacy_plan = _single("legacy_assembly_plan", legacy_assembly_plan)
|
||||
selective_plan = _single("selective_assembly_plan", selective_assembly_plan)
|
||||
legacy_contract = legacy_plan.get("second_pass_contract") or {}
|
||||
selective_contract = selective_plan.get("second_pass_contract") or {}
|
||||
legacy_text = str(_single("legacy_status", legacy_status))
|
||||
selective_text = str(_single("selective_status", selective_status))
|
||||
summary = {
|
||||
"format": "h3-continuum-a3c-video-only-parity-v1",
|
||||
"physical_group_count": len(legacy_v),
|
||||
"legacy_video_sha256": [_tensor_sha256(item) for item in legacy_v],
|
||||
"selective_video_sha256": [
|
||||
_tensor_sha256(item) for item in selective_v
|
||||
],
|
||||
"legacy_audio_sha256": [_tensor_sha256(item) for item in legacy_a],
|
||||
"selective_audio_sha256": [
|
||||
_tensor_sha256(item) for item in selective_a
|
||||
],
|
||||
"legacy_video_shapes": [list(item.shape) for item in legacy_v],
|
||||
"selective_video_shapes": [list(item.shape) for item in selective_v],
|
||||
"legacy_audio_shapes": [list(item.shape) for item in legacy_a],
|
||||
"selective_audio_shapes": [list(item.shape) for item in selective_a],
|
||||
"legacy_video_finite": [
|
||||
bool(torch.isfinite(item.float()).all().item()) for item in legacy_v
|
||||
],
|
||||
"selective_video_finite": [
|
||||
bool(torch.isfinite(item.float()).all().item())
|
||||
for item in selective_v
|
||||
],
|
||||
"legacy_audio_finite": [
|
||||
bool(torch.isfinite(item.float()).all().item()) for item in legacy_a
|
||||
],
|
||||
"selective_audio_finite": [
|
||||
bool(torch.isfinite(item.float()).all().item())
|
||||
for item in selective_a
|
||||
],
|
||||
"legacy_audio_object_identity": [
|
||||
output is source
|
||||
for output, source in zip(
|
||||
legacy_audio_latents,
|
||||
input_audio_latents,
|
||||
strict=True,
|
||||
)
|
||||
],
|
||||
"selective_audio_object_identity": [
|
||||
output is source
|
||||
for output, source in zip(
|
||||
selective_audio_latents,
|
||||
input_audio_latents,
|
||||
strict=True,
|
||||
)
|
||||
],
|
||||
"legacy_audio_tensor_identity": [
|
||||
output is source
|
||||
for output, source in zip(legacy_a, input_a, strict=True)
|
||||
],
|
||||
"selective_audio_tensor_identity": [
|
||||
output is source
|
||||
for output, source in zip(selective_a, input_a, strict=True)
|
||||
],
|
||||
"legacy_refine_group_seeds": legacy_contract.get(
|
||||
"refine_group_seeds"
|
||||
),
|
||||
"selective_refine_group_seeds": selective_contract.get(
|
||||
"refine_group_seeds"
|
||||
),
|
||||
"legacy_schedule_sigma_hash": (
|
||||
legacy_contract.get("refine_schedule") or {}
|
||||
).get("sigma_hash"),
|
||||
"selective_schedule_sigma_hash": (
|
||||
selective_contract.get("refine_schedule") or {}
|
||||
).get("sigma_hash"),
|
||||
"legacy_sampling_passes_reported": legacy_text.count(
|
||||
"sampling_passes=1"
|
||||
),
|
||||
"selective_sampling_passes_reported": selective_text.count(
|
||||
"sampling_passes=1"
|
||||
),
|
||||
"legacy_plan_without_target_identity": _plan_identity(
|
||||
legacy_plan,
|
||||
omit_target_identity=True,
|
||||
)["sha256"],
|
||||
"selective_plan_without_target_identity": _plan_identity(
|
||||
selective_plan,
|
||||
omit_target_identity=True,
|
||||
)["sha256"],
|
||||
"selective_target_mode": (
|
||||
selective_contract.get("refine_target_contract") or {}
|
||||
).get("mode"),
|
||||
"selective_seed_namespace": (
|
||||
selective_contract.get("refine_target_contract") or {}
|
||||
).get("seed_namespace"),
|
||||
}
|
||||
report = "A3C_PARITY_JSON=" + json.dumps(
|
||||
summary,
|
||||
sort_keys=True,
|
||||
separators=(",", ":"),
|
||||
ensure_ascii=False,
|
||||
)
|
||||
return (report,)
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"H3A3cSelectiveRefineProbe": H3A3cSelectiveRefineProbe,
|
||||
"H3A3cVideoOnlyParityProbe": H3A3cVideoOnlyParityProbe,
|
||||
}
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"H3A3cSelectiveRefineProbe": "H3 A3c Selective Refine Probe (Temporary)",
|
||||
"H3A3cVideoOnlyParityProbe": "H3 A3c Video Only Parity Probe (Temporary)",
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
from .node import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
|
||||
|
||||
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
|
||||
@@ -0,0 +1,646 @@
|
||||
"""Observation-only Sampling boundary collector for the V3.8 G4 Gate.
|
||||
|
||||
The collector is loaded only on the dedicated diagnostic backend. It wraps the
|
||||
active Production V3.8 sampler for one node execution, returns the unchanged six
|
||||
Production outputs, and adds a seventh JSON evidence output. Every monkeypatch
|
||||
is restored in ``finally`` blocks.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping, Sequence
|
||||
from dataclasses import asdict, is_dataclass
|
||||
from enum import Enum
|
||||
import hashlib
|
||||
import importlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import time
|
||||
from types import SimpleNamespace
|
||||
from typing import Any
|
||||
import uuid
|
||||
|
||||
import torch
|
||||
|
||||
|
||||
CHECKPOINTS = ("S0", "S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8")
|
||||
MODEL_CHECKPOINTS = ("M0", "M1", "M2", "M3")
|
||||
|
||||
|
||||
def _type_name(value: Any) -> str:
|
||||
cls = value if isinstance(value, type) else type(value)
|
||||
return f"{cls.__module__}.{cls.__qualname__}"
|
||||
|
||||
|
||||
def _callable_name(value: Any) -> str:
|
||||
return (
|
||||
f"{getattr(value, '__module__', '')}."
|
||||
f"{getattr(value, '__qualname__', type(value).__qualname__)}"
|
||||
)
|
||||
|
||||
|
||||
def _tensor_fingerprint(tensor: torch.Tensor) -> dict[str, Any]:
|
||||
if bool(getattr(tensor, "is_nested", False)):
|
||||
return _nested_fingerprint(tensor)
|
||||
device_before = str(tensor.device)
|
||||
value = tensor.detach().contiguous().to("cpu")
|
||||
shape = [int(part) for part in value.shape]
|
||||
dtype = str(value.dtype)
|
||||
raw = value.view(torch.uint8).numpy().tobytes(order="C")
|
||||
digest = hashlib.sha256()
|
||||
digest.update(dtype.encode("ascii"))
|
||||
digest.update(b"\0")
|
||||
digest.update(json.dumps(shape, separators=(",", ":")).encode("ascii"))
|
||||
digest.update(b"\0")
|
||||
digest.update(raw)
|
||||
legacy_digest = hashlib.sha256()
|
||||
legacy_digest.update(dtype.encode("ascii"))
|
||||
legacy_digest.update(json.dumps(shape, separators=(",", ":")).encode("ascii"))
|
||||
legacy_digest.update(raw)
|
||||
return {
|
||||
"kind": "tensor",
|
||||
"shape": shape,
|
||||
"dtype": dtype,
|
||||
"device_before_hash": device_before,
|
||||
"numel": int(value.numel()),
|
||||
"raw_bytes": len(raw),
|
||||
"sha256": digest.hexdigest(),
|
||||
"legacy_g4_sha256": legacy_digest.hexdigest(),
|
||||
}
|
||||
|
||||
|
||||
def _nested_fingerprint(value: Any) -> dict[str, Any]:
|
||||
parts = list(value.unbind())
|
||||
fingerprints = [_tensor_fingerprint(part) for part in parts]
|
||||
payload = json.dumps(
|
||||
[item["sha256"] for item in fingerprints],
|
||||
separators=(",", ":"),
|
||||
).encode("ascii")
|
||||
return {
|
||||
"kind": "nested_tensor",
|
||||
"parts": fingerprints,
|
||||
"sha256": hashlib.sha256(payload).hexdigest(),
|
||||
}
|
||||
|
||||
|
||||
def _canonicalize(value: Any, unsupported: set[str]) -> Any:
|
||||
if torch.is_tensor(value):
|
||||
fingerprint = _tensor_fingerprint(value)
|
||||
fingerprint.pop("legacy_g4_sha256", None)
|
||||
return {"__tensor__": fingerprint}
|
||||
if hasattr(value, "unbind") and not isinstance(value, (str, bytes)):
|
||||
try:
|
||||
parts = list(value.unbind())
|
||||
except Exception:
|
||||
parts = None
|
||||
if parts is not None and parts and all(torch.is_tensor(part) for part in parts):
|
||||
fingerprint = _nested_fingerprint(value)
|
||||
for part in fingerprint.get("parts", []):
|
||||
part.pop("legacy_g4_sha256", None)
|
||||
return {"__nested_tensor__": fingerprint}
|
||||
if value is None or isinstance(value, (bool, int, float, str)):
|
||||
return value
|
||||
if isinstance(value, bytes):
|
||||
return {
|
||||
"__bytes__": {
|
||||
"length": len(value),
|
||||
"sha256": hashlib.sha256(value).hexdigest(),
|
||||
}
|
||||
}
|
||||
if isinstance(value, (torch.dtype, torch.device, uuid.UUID, Enum)):
|
||||
return {"__type__": _type_name(value), "value": str(value)}
|
||||
if is_dataclass(value) and not isinstance(value, type):
|
||||
return {
|
||||
"__dataclass__": _type_name(value),
|
||||
"value": _canonicalize(asdict(value), unsupported),
|
||||
}
|
||||
if isinstance(value, Mapping):
|
||||
return {
|
||||
str(key): _canonicalize(value[key], unsupported)
|
||||
for key in sorted(value, key=lambda item: str(item))
|
||||
}
|
||||
if isinstance(value, (list, tuple)):
|
||||
return [_canonicalize(item, unsupported) for item in value]
|
||||
if isinstance(value, (set, frozenset)):
|
||||
encoded = [_canonicalize(item, unsupported) for item in value]
|
||||
return sorted(
|
||||
encoded,
|
||||
key=lambda item: json.dumps(item, sort_keys=True, separators=(",", ":")),
|
||||
)
|
||||
if callable(value):
|
||||
return {"__callable__": _callable_name(value)}
|
||||
unsupported.add(_type_name(value))
|
||||
return {"__opaque_type__": _type_name(value)}
|
||||
|
||||
|
||||
def _structured_checkpoint(value: Any) -> dict[str, Any]:
|
||||
unsupported: set[str] = set()
|
||||
canonical = _canonicalize(value, unsupported)
|
||||
encoded = json.dumps(
|
||||
canonical,
|
||||
sort_keys=True,
|
||||
separators=(",", ":"),
|
||||
ensure_ascii=False,
|
||||
).encode("utf-8")
|
||||
return {
|
||||
"kind": "structured",
|
||||
"sha256": hashlib.sha256(encoded).hexdigest(),
|
||||
"canonical_bytes": len(encoded),
|
||||
"unsupported_types": sorted(unsupported),
|
||||
"payload": canonical,
|
||||
}
|
||||
|
||||
|
||||
def _value_checkpoint(value: Any) -> dict[str, Any]:
|
||||
if torch.is_tensor(value):
|
||||
return _tensor_fingerprint(value)
|
||||
if hasattr(value, "unbind") and not isinstance(value, (str, bytes)):
|
||||
try:
|
||||
parts = list(value.unbind())
|
||||
except Exception:
|
||||
parts = None
|
||||
if parts is not None and parts and all(torch.is_tensor(part) for part in parts):
|
||||
return _nested_fingerprint(value)
|
||||
return _structured_checkpoint(value)
|
||||
|
||||
|
||||
def _av_checkpoint(value: Any, state_module: Any) -> dict[str, Any]:
|
||||
if isinstance(value, Mapping) and "samples" in value:
|
||||
video, audio = state_module.extract_av_streams(dict(value))
|
||||
else:
|
||||
samples = value
|
||||
parts = list(samples.unbind()) if hasattr(samples, "unbind") else list(samples)
|
||||
if len(parts) < 2:
|
||||
raise RuntimeError("expected MiniMax H3 Video/Audio NestedTensor")
|
||||
video, audio = parts[0], parts[1]
|
||||
streams = {
|
||||
"video": _tensor_fingerprint(video),
|
||||
"audio": _tensor_fingerprint(audio),
|
||||
}
|
||||
combined = json.dumps(
|
||||
{name: item["sha256"] for name, item in streams.items()},
|
||||
sort_keys=True,
|
||||
separators=(",", ":"),
|
||||
).encode("ascii")
|
||||
return {
|
||||
"kind": "h3_av",
|
||||
"streams": streams,
|
||||
"sha256": hashlib.sha256(combined).hexdigest(),
|
||||
}
|
||||
|
||||
|
||||
def _runtime_descriptor(value: Any, depth: int = 0) -> Any:
|
||||
if depth > 7:
|
||||
return {"__truncated_type__": _type_name(value)}
|
||||
if value is None or isinstance(value, (bool, int, float, str)):
|
||||
return value
|
||||
if isinstance(value, (torch.dtype, torch.device, uuid.UUID, Enum)):
|
||||
return {"type": _type_name(value), "value": str(value)}
|
||||
if torch.is_tensor(value):
|
||||
return {
|
||||
"type": "tensor",
|
||||
"shape": [int(part) for part in value.shape],
|
||||
"dtype": str(value.dtype),
|
||||
"device": str(value.device),
|
||||
}
|
||||
if isinstance(value, Mapping):
|
||||
return {
|
||||
str(key): _runtime_descriptor(item, depth + 1)
|
||||
for key, item in sorted(value.items(), key=lambda item: str(item[0]))
|
||||
}
|
||||
if isinstance(value, (list, tuple)):
|
||||
return [_runtime_descriptor(item, depth + 1) for item in value]
|
||||
if isinstance(value, (set, frozenset)):
|
||||
items = [_runtime_descriptor(item, depth + 1) for item in value]
|
||||
return sorted(items, key=lambda item: json.dumps(item, sort_keys=True))
|
||||
if callable(value):
|
||||
return {"callable": _callable_name(value)}
|
||||
return {"type": _type_name(value)}
|
||||
|
||||
|
||||
def _wrapper_state(patcher: Any) -> dict[str, Any]:
|
||||
output: dict[str, Any] = {}
|
||||
for wrapper_type, keyed in sorted(
|
||||
dict(getattr(patcher, "wrappers", {}) or {}).items(),
|
||||
key=lambda item: str(item[0]),
|
||||
):
|
||||
output[str(wrapper_type)] = {
|
||||
str(key): [_callable_name(item) for item in list(items or [])]
|
||||
for key, items in sorted(
|
||||
dict(keyed or {}).items(), key=lambda item: str(item[0])
|
||||
)
|
||||
}
|
||||
return output
|
||||
|
||||
|
||||
def _patch_value_summary(value: Any) -> Any:
|
||||
if isinstance(value, (list, tuple)):
|
||||
return [_patch_value_summary(item) for item in value]
|
||||
if isinstance(value, Mapping):
|
||||
return {
|
||||
str(key): _patch_value_summary(item)
|
||||
for key, item in sorted(value.items(), key=lambda item: str(item[0]))
|
||||
}
|
||||
if callable(value):
|
||||
return {"callable": _callable_name(value)}
|
||||
return {"type": _type_name(value)}
|
||||
|
||||
|
||||
def _model_runtime_state(patcher: Any) -> dict[str, Any]:
|
||||
model = getattr(patcher, "model", None)
|
||||
current_uuid = getattr(model, "current_weight_patches_uuid", None)
|
||||
patches = dict(getattr(patcher, "patches", {}) or {})
|
||||
model_options = dict(getattr(patcher, "model_options", {}) or {})
|
||||
dtype = None
|
||||
try:
|
||||
dtype = str(patcher.model_dtype())
|
||||
except Exception:
|
||||
dtype = None
|
||||
inference_dtype = None
|
||||
try:
|
||||
inference_dtype = str(model.get_dtype_inference()) if model is not None else None
|
||||
except Exception:
|
||||
inference_dtype = None
|
||||
observed = {
|
||||
"patcher_type": _type_name(patcher),
|
||||
"model_type": None if model is None else _type_name(model),
|
||||
"diffusion_model_type": (
|
||||
None
|
||||
if model is None or getattr(model, "diffusion_model", None) is None
|
||||
else _type_name(model.diffusion_model)
|
||||
),
|
||||
"patch_uuid": str(getattr(patcher, "patches_uuid", "")),
|
||||
"current_weight_patch_uuid": (
|
||||
None if current_uuid is None else str(current_uuid)
|
||||
),
|
||||
"load_device": str(getattr(patcher, "load_device", "")),
|
||||
"offload_device": str(getattr(patcher, "offload_device", "")),
|
||||
"model_device": None if model is None else str(getattr(model, "device", "")),
|
||||
"model_dtype": dtype,
|
||||
"inference_dtype": inference_dtype,
|
||||
"hook_mode": str(getattr(patcher, "hook_mode", "")),
|
||||
"current_hook_group_type": (
|
||||
None
|
||||
if getattr(patcher, "current_hook_group", None) is None
|
||||
else _type_name(patcher.current_hook_group)
|
||||
),
|
||||
"wrappers": _wrapper_state(patcher),
|
||||
"patches": {
|
||||
str(key): _patch_value_summary(value)
|
||||
for key, value in sorted(patches.items(), key=lambda item: str(item[0]))
|
||||
},
|
||||
"object_patches": {
|
||||
str(key): _type_name(value)
|
||||
for key, value in sorted(
|
||||
dict(getattr(patcher, "object_patches", {}) or {}).items(),
|
||||
key=lambda item: str(item[0]),
|
||||
)
|
||||
},
|
||||
"model_options": _runtime_descriptor(model_options),
|
||||
"torch": {
|
||||
"deterministic_algorithms": bool(torch.are_deterministic_algorithms_enabled()),
|
||||
"cudnn_deterministic": bool(torch.backends.cudnn.deterministic),
|
||||
"cudnn_benchmark": bool(torch.backends.cudnn.benchmark),
|
||||
"cuda_matmul_allow_tf32": bool(torch.backends.cuda.matmul.allow_tf32),
|
||||
"cudnn_allow_tf32": bool(torch.backends.cudnn.allow_tf32),
|
||||
},
|
||||
}
|
||||
semantic = dict(observed)
|
||||
semantic.pop("patch_uuid", None)
|
||||
semantic.pop("current_weight_patch_uuid", None)
|
||||
semantic["patch_uuid_present"] = bool(observed["patch_uuid"])
|
||||
semantic["current_weight_patch_uuid_present"] = (
|
||||
observed["current_weight_patch_uuid"] is not None
|
||||
)
|
||||
checkpoint = _structured_checkpoint(semantic)
|
||||
checkpoint["observed_state"] = observed
|
||||
return checkpoint
|
||||
|
||||
|
||||
def _sampler_signature(sampler: Any) -> dict[str, Any]:
|
||||
value = {
|
||||
"sampler_type": _type_name(sampler),
|
||||
"sampler_function": (
|
||||
None
|
||||
if getattr(sampler, "sampler_function", None) is None
|
||||
else _callable_name(sampler.sampler_function)
|
||||
),
|
||||
"extra_options": _runtime_descriptor(
|
||||
dict(getattr(sampler, "extra_options", {}) or {})
|
||||
),
|
||||
"inpaint_options": _runtime_descriptor(
|
||||
dict(getattr(sampler, "inpaint_options", {}) or {})
|
||||
),
|
||||
}
|
||||
return _structured_checkpoint(value)
|
||||
|
||||
|
||||
def _resolve_modules() -> SimpleNamespace:
|
||||
import nodes as comfy_nodes
|
||||
|
||||
sampler_class = comfy_nodes.NODE_CLASS_MAPPINGS.get("H3ContinuumSamplerV38")
|
||||
if sampler_class is None:
|
||||
raise RuntimeError("H3ContinuumSamplerV38 is not loaded")
|
||||
owner = sys.modules.get(sampler_class.__module__)
|
||||
source = getattr(owner, "__file__", None)
|
||||
if source is None:
|
||||
raise RuntimeError("cannot resolve active H3 Continuum package")
|
||||
module_name = sampler_class.__module__
|
||||
base_name = (
|
||||
module_name.split(".v3.", 1)[0]
|
||||
if ".v3." in module_name
|
||||
else module_name.rsplit(".", 2)[0]
|
||||
)
|
||||
return SimpleNamespace(
|
||||
sampler_class=sampler_class,
|
||||
production_root=str(Path(source).resolve().parent.parent),
|
||||
sequence=importlib.import_module(f"{base_name}.v2.sequence"),
|
||||
state=importlib.import_module(f"{base_name}.state"),
|
||||
)
|
||||
|
||||
|
||||
class SamplingCollector:
|
||||
def __init__(self, modules: SimpleNamespace, *, trace_steps: bool):
|
||||
self.modules = modules
|
||||
self.trace_steps = bool(trace_steps)
|
||||
self.records: list[dict[str, Any]] = []
|
||||
self.hooks_restored = True
|
||||
|
||||
def _capture_model_payload(
|
||||
self,
|
||||
record: dict[str, Any],
|
||||
*,
|
||||
x: Any,
|
||||
t: Any,
|
||||
c_concat: Any,
|
||||
c_crossattn: Any,
|
||||
control: Any,
|
||||
transformer_options: Any,
|
||||
kwargs: Mapping[str, Any],
|
||||
output: Any,
|
||||
) -> None:
|
||||
record["model"] = {
|
||||
"M0": _value_checkpoint(x),
|
||||
"M1": _value_checkpoint(t),
|
||||
"M2": _structured_checkpoint(
|
||||
{
|
||||
"c_concat": c_concat,
|
||||
"c_crossattn": c_crossattn,
|
||||
"control": control,
|
||||
"transformer_options": transformer_options,
|
||||
"kwargs": dict(kwargs),
|
||||
}
|
||||
),
|
||||
"M3": _value_checkpoint(output),
|
||||
}
|
||||
|
||||
def wrap(self, original_sample):
|
||||
def observed_sample_chunk(**kwargs):
|
||||
import comfy.model_base
|
||||
import comfy.sample
|
||||
import comfy.samplers
|
||||
|
||||
record: dict[str, Any] = {
|
||||
"physical_call_index": len(self.records) + 1,
|
||||
"seed": int(kwargs["seed"]),
|
||||
"checkpoints": {},
|
||||
"model": {},
|
||||
"steps": [],
|
||||
}
|
||||
checkpoints = record["checkpoints"]
|
||||
checkpoints["S0"] = _av_checkpoint(kwargs["latent"], self.modules.state)
|
||||
checkpoints["S3"] = _value_checkpoint(kwargs["latent"].get("noise_mask"))
|
||||
checkpoints["S4"] = _tensor_fingerprint(kwargs["sigmas"])
|
||||
checkpoints["S5"] = _structured_checkpoint(int(kwargs["seed"]))
|
||||
checkpoints["S6"] = _sampler_signature(kwargs["sampler"])
|
||||
checkpoints["S7"] = _structured_checkpoint(kwargs["conditioning"])
|
||||
checkpoints["S8"] = _model_runtime_state(kwargs["model"])
|
||||
|
||||
original_fix = comfy.sample.fix_empty_latent_channels
|
||||
original_noise = comfy.sample.prepare_noise
|
||||
original_apply = comfy.model_base.BaseModel._apply_model
|
||||
original_guider_sample = comfy.samplers.CFGGuider.sample
|
||||
fixed_seen = False
|
||||
noise_seen = False
|
||||
model_seen = False
|
||||
pending_model_payload = None
|
||||
|
||||
def fix_empty(*args, **inner_kwargs):
|
||||
nonlocal fixed_seen
|
||||
result = original_fix(*args, **inner_kwargs)
|
||||
if not fixed_seen:
|
||||
fixed_seen = True
|
||||
checkpoints["S1"] = _av_checkpoint(result, self.modules.state)
|
||||
return result
|
||||
|
||||
def prepare_noise(*args, **inner_kwargs):
|
||||
nonlocal noise_seen
|
||||
result = original_noise(*args, **inner_kwargs)
|
||||
if not noise_seen:
|
||||
noise_seen = True
|
||||
checkpoints["S2"] = _av_checkpoint(result, self.modules.state)
|
||||
return result
|
||||
|
||||
def apply_model(
|
||||
model_self,
|
||||
x,
|
||||
t,
|
||||
c_concat=None,
|
||||
c_crossattn=None,
|
||||
control=None,
|
||||
transformer_options={},
|
||||
**inner_kwargs,
|
||||
):
|
||||
nonlocal model_seen, pending_model_payload
|
||||
result = original_apply(
|
||||
model_self,
|
||||
x,
|
||||
t,
|
||||
c_concat,
|
||||
c_crossattn,
|
||||
control,
|
||||
transformer_options,
|
||||
**inner_kwargs,
|
||||
)
|
||||
if not model_seen and model_self.__class__.__name__ == "MiniMaxH3":
|
||||
model_seen = True
|
||||
# Retain references only. Hashing CUDA tensors here forces a
|
||||
# host synchronization between sampler steps and masks the
|
||||
# ordering defect this Gate is intended to observe.
|
||||
pending_model_payload = {
|
||||
"x": x,
|
||||
"t": t,
|
||||
"c_concat": c_concat,
|
||||
"c_crossattn": c_crossattn,
|
||||
"control": control,
|
||||
"transformer_options": transformer_options,
|
||||
"kwargs": dict(inner_kwargs),
|
||||
"output": result,
|
||||
}
|
||||
return result
|
||||
|
||||
def guider_sample(guider_self, *args, **inner_kwargs):
|
||||
existing_callback = inner_kwargs.get("callback")
|
||||
|
||||
def chained_callback(step, x0, x, total_steps):
|
||||
if existing_callback is not None:
|
||||
existing_callback(step, x0, x, total_steps)
|
||||
record["steps"].append(
|
||||
{
|
||||
"step": int(step),
|
||||
"total_steps": int(total_steps),
|
||||
"x0": _value_checkpoint(x0),
|
||||
"x": _value_checkpoint(x),
|
||||
}
|
||||
)
|
||||
|
||||
if self.trace_steps:
|
||||
inner_kwargs["callback"] = chained_callback
|
||||
record["step_callback_chained"] = existing_callback is not None
|
||||
return original_guider_sample(guider_self, *args, **inner_kwargs)
|
||||
|
||||
comfy.sample.fix_empty_latent_channels = fix_empty
|
||||
comfy.sample.prepare_noise = prepare_noise
|
||||
comfy.model_base.BaseModel._apply_model = apply_model
|
||||
if self.trace_steps:
|
||||
comfy.samplers.CFGGuider.sample = guider_sample
|
||||
started = time.perf_counter()
|
||||
self.records.append(record)
|
||||
try:
|
||||
result = original_sample(**kwargs)
|
||||
if pending_model_payload is not None:
|
||||
self._capture_model_payload(record, **pending_model_payload)
|
||||
record["output"] = _av_checkpoint(result, self.modules.state)
|
||||
record["sampling_elapsed_seconds"] = time.perf_counter() - started
|
||||
record["model_runtime_after"] = _model_runtime_state(kwargs["model"])
|
||||
return result
|
||||
finally:
|
||||
comfy.sample.fix_empty_latent_channels = original_fix
|
||||
comfy.sample.prepare_noise = original_noise
|
||||
comfy.model_base.BaseModel._apply_model = original_apply
|
||||
comfy.samplers.CFGGuider.sample = original_guider_sample
|
||||
restored = (
|
||||
comfy.sample.fix_empty_latent_channels is original_fix
|
||||
and comfy.sample.prepare_noise is original_noise
|
||||
and comfy.model_base.BaseModel._apply_model is original_apply
|
||||
and comfy.samplers.CFGGuider.sample is original_guider_sample
|
||||
)
|
||||
record["hooks_restored"] = bool(restored)
|
||||
record["capture_complete"] = {
|
||||
"fixed_latent": fixed_seen,
|
||||
"noise": noise_seen,
|
||||
"first_model_call": model_seen,
|
||||
"all_sampling_checkpoints": all(
|
||||
name in checkpoints for name in CHECKPOINTS
|
||||
),
|
||||
"all_model_checkpoints": all(
|
||||
name in record["model"] for name in MODEL_CHECKPOINTS
|
||||
),
|
||||
}
|
||||
self.hooks_restored = self.hooks_restored and bool(restored)
|
||||
|
||||
return observed_sample_chunk
|
||||
|
||||
|
||||
class H3G4SamplingDeterminismDiagnostic:
|
||||
RETURN_TYPES = (
|
||||
"LATENT",
|
||||
"LATENT",
|
||||
"H3_CONTINUUM_ASSEMBLY_PLAN",
|
||||
"STRING",
|
||||
"AUDIO",
|
||||
"H3_CONTINUUM_REFINE_CONTEXT",
|
||||
"STRING",
|
||||
)
|
||||
RETURN_NAMES = (
|
||||
"video_latents",
|
||||
"audio_latents",
|
||||
"assembly_plan",
|
||||
"status",
|
||||
"driving_audio",
|
||||
"refine_context",
|
||||
"diagnostic_json",
|
||||
)
|
||||
OUTPUT_IS_LIST = (True, True, False, False, False, False, False)
|
||||
FUNCTION = "run"
|
||||
CATEGORY = "H3 Continuum/Diagnostics"
|
||||
OUTPUT_NODE = True
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
modules = _resolve_modules()
|
||||
schema = modules.sampler_class.INPUT_TYPES()
|
||||
required = dict(schema.get("required", {}))
|
||||
required["diagnostic_label"] = (
|
||||
"STRING",
|
||||
{"default": "sampling_diagnostic"},
|
||||
)
|
||||
required["diagnostic_nonce"] = (
|
||||
"INT",
|
||||
{"default": 0, "min": 0, "max": 0x7FFFFFFF},
|
||||
)
|
||||
required["trace_steps"] = ("BOOLEAN", {"default": False})
|
||||
schema["required"] = required
|
||||
return schema
|
||||
|
||||
@classmethod
|
||||
def IS_CHANGED(cls, generation_mode="Full Run", **kwargs):
|
||||
# Preserve the public V3.8 cache contract exactly: Full Run is stable,
|
||||
# while Review Each Chunk is intentionally non-cacheable.
|
||||
modules = _resolve_modules()
|
||||
return modules.sampler_class.IS_CHANGED(generation_mode=generation_mode)
|
||||
|
||||
def run(
|
||||
self,
|
||||
diagnostic_label,
|
||||
diagnostic_nonce,
|
||||
trace_steps,
|
||||
**kwargs,
|
||||
):
|
||||
modules = _resolve_modules()
|
||||
sequence = modules.sequence
|
||||
collector = SamplingCollector(modules, trace_steps=bool(trace_steps))
|
||||
original_sample = sequence.sample_chunk
|
||||
model = kwargs.get("model")
|
||||
state_before = _model_runtime_state(model)
|
||||
sequence.sample_chunk = collector.wrap(original_sample)
|
||||
started = time.perf_counter()
|
||||
try:
|
||||
outputs = modules.sampler_class().run(**kwargs)
|
||||
state_after = _model_runtime_state(model)
|
||||
finally:
|
||||
sequence.sample_chunk = original_sample
|
||||
restored = sequence.sample_chunk is original_sample and collector.hooks_restored
|
||||
result = {
|
||||
"format": "h3-v38-g4-sampling-determinism-v1",
|
||||
"diagnostic_label": str(diagnostic_label),
|
||||
"diagnostic_nonce": int(diagnostic_nonce),
|
||||
"trace_steps": bool(trace_steps),
|
||||
"production_root": modules.production_root,
|
||||
"sampler_node_elapsed_seconds": time.perf_counter() - started,
|
||||
"sampler_model_state_before": state_before,
|
||||
"sampler_model_state_after": state_after,
|
||||
"physical_samples": collector.records,
|
||||
"physical_sample_count": len(collector.records),
|
||||
"hooks_restored": bool(restored),
|
||||
}
|
||||
payload = json.dumps(
|
||||
result,
|
||||
sort_keys=True,
|
||||
separators=(",", ":"),
|
||||
ensure_ascii=False,
|
||||
)
|
||||
return {
|
||||
"ui": {"text": [payload]},
|
||||
"result": (*outputs, payload),
|
||||
}
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"H3G4SamplingDeterminismDiagnostic": H3G4SamplingDeterminismDiagnostic,
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"H3G4SamplingDeterminismDiagnostic": "H3 G4 Sampling Determinism Diagnostic",
|
||||
}
|
||||
@@ -1,32 +1,32 @@
|
||||
# H3 Core vs Continuum GPU Diagnostic
|
||||
|
||||
This is a standalone diagnostic node. It does not change or register through the
|
||||
production H3 Continuum package.
|
||||
|
||||
## Install for ComfyUI_W
|
||||
|
||||
Run from the repository root:
|
||||
|
||||
```powershell
|
||||
.\tools\install_gpu_diagnostic_node.ps1
|
||||
```
|
||||
|
||||
Restart ComfyUI and search for `H3 Core vs Continuum GPU Diagnostic`.
|
||||
|
||||
## Connections
|
||||
|
||||
- Connect the same direct MODEL used by both tests. Keep Spectrum off.
|
||||
- Connect the same CLIP, Video VAE, Audio VAE, sampler, and sigmas.
|
||||
- Connect the exact same First Frame and Last Frame.
|
||||
- Use 640x640, seed 42, 8 steps, Euler/simple for the baseline comparison.
|
||||
- Run Storage and Session are not used by this node.
|
||||
|
||||
One queue executes Core FL2VA at 243 frames, then Continuum Terminal Merge 2x5s.
|
||||
Results are written below:
|
||||
|
||||
```text
|
||||
ComfyUI/output/h3_continuum/diagnostics/<timestamp>/
|
||||
```
|
||||
|
||||
The report identifies the first difference across pre-sampler data, first H3
|
||||
MODEL call, sampled physical latent, split/recombine, and decode/assembly.
|
||||
# H3 Core vs Continuum GPU Diagnostic
|
||||
|
||||
This is a standalone diagnostic node. It does not change or register through the
|
||||
production H3 Continuum package.
|
||||
|
||||
## Install for ComfyUI_W
|
||||
|
||||
Run from the repository root:
|
||||
|
||||
```powershell
|
||||
.\tools\install_gpu_diagnostic_node.ps1
|
||||
```
|
||||
|
||||
Restart ComfyUI and search for `H3 Core vs Continuum GPU Diagnostic`.
|
||||
|
||||
## Connections
|
||||
|
||||
- Connect the same direct MODEL used by both tests. Keep Spectrum off.
|
||||
- Connect the same CLIP, Video VAE, Audio VAE, sampler, and sigmas.
|
||||
- Connect the exact same First Frame and Last Frame.
|
||||
- Use 640x640, seed 42, 8 steps, Euler/simple for the baseline comparison.
|
||||
- Run Storage and Session are not used by this node.
|
||||
|
||||
One queue executes Core FL2VA at 243 frames, then Continuum Terminal Merge 2x5s.
|
||||
Results are written below:
|
||||
|
||||
```text
|
||||
ComfyUI/output/h3_continuum/diagnostics/<timestamp>/
|
||||
```
|
||||
|
||||
The report identifies the first difference across pre-sampler data, first H3
|
||||
MODEL call, sampled physical latent, split/recombine, and decode/assembly.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"""Standalone GPU diagnostics for H3 Continuum.
|
||||
|
||||
This package is intentionally separate from the production node package. Copy the
|
||||
directory into ComfyUI/custom_nodes only while diagnostics are needed.
|
||||
"""
|
||||
|
||||
from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
|
||||
|
||||
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
|
||||
"""Standalone GPU diagnostics for H3 Continuum.
|
||||
|
||||
This package is intentionally separate from the production node package. Copy the
|
||||
directory into ComfyUI/custom_nodes only while diagnostics are needed.
|
||||
"""
|
||||
|
||||
from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
|
||||
|
||||
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
|
||||
|
||||
@@ -1,302 +1,302 @@
|
||||
"""Deterministic tensor capture and comparison helpers for the GPU runner."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping, Sequence
|
||||
from dataclasses import asdict, dataclass
|
||||
from hashlib import sha256
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
import torch
|
||||
|
||||
|
||||
STAGE_ORDER = (
|
||||
"A_pre_sampler",
|
||||
"B_first_model_call",
|
||||
"C_physical_sample",
|
||||
"D_split_recombine",
|
||||
"E1_decode_243",
|
||||
"E2_final_240",
|
||||
)
|
||||
|
||||
|
||||
def _dense_cpu(tensor: torch.Tensor) -> torch.Tensor:
|
||||
return tensor.detach().to("cpu").contiguous()
|
||||
|
||||
|
||||
def _raw_sha256(tensor: torch.Tensor) -> str:
|
||||
value = _dense_cpu(tensor)
|
||||
raw = value.view(torch.uint8).numpy().tobytes()
|
||||
return sha256(raw).hexdigest()
|
||||
|
||||
|
||||
def tensor_fingerprint(tensor: torch.Tensor) -> dict[str, Any]:
|
||||
value = _dense_cpu(tensor)
|
||||
return {
|
||||
"shape": list(value.shape),
|
||||
"dtype": str(value.dtype),
|
||||
"sha256": _raw_sha256(value),
|
||||
"numel": int(value.numel()),
|
||||
}
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TensorDifference:
|
||||
comparable: bool
|
||||
bit_exact: bool
|
||||
allclose: bool
|
||||
max_abs_diff: float | None
|
||||
mean_abs_diff: float | None
|
||||
reason: str | None = None
|
||||
|
||||
@property
|
||||
def matches(self) -> bool:
|
||||
return self.comparable and (self.bit_exact or self.allclose)
|
||||
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
value = asdict(self)
|
||||
value["matches"] = self.matches
|
||||
return value
|
||||
|
||||
|
||||
def compare_tensors(
|
||||
left: torch.Tensor,
|
||||
right: torch.Tensor,
|
||||
*,
|
||||
rtol: float = 1.0e-4,
|
||||
atol: float = 1.0e-5,
|
||||
) -> TensorDifference:
|
||||
a = _dense_cpu(left)
|
||||
b = _dense_cpu(right)
|
||||
if tuple(a.shape) != tuple(b.shape):
|
||||
return TensorDifference(False, False, False, None, None, "shape mismatch")
|
||||
if a.dtype != b.dtype:
|
||||
return TensorDifference(False, False, False, None, None, "dtype mismatch")
|
||||
bit_exact = bool(torch.equal(a, b))
|
||||
if not (a.is_floating_point() or a.is_complex()):
|
||||
return TensorDifference(True, bit_exact, bit_exact, 0.0 if bit_exact else None, 0.0 if bit_exact else None)
|
||||
af = a.to(torch.float64)
|
||||
bf = b.to(torch.float64)
|
||||
delta = (af - bf).abs()
|
||||
max_abs = float(delta.max().item()) if delta.numel() else 0.0
|
||||
mean_abs = float(delta.mean().item()) if delta.numel() else 0.0
|
||||
close = bool(torch.allclose(af, bf, rtol=rtol, atol=atol, equal_nan=True))
|
||||
return TensorDifference(True, bit_exact, close, max_abs, mean_abs)
|
||||
|
||||
|
||||
def _safe_tensor_key(value: str) -> str:
|
||||
return re.sub(r"[^A-Za-z0-9_.-]+", "_", value).strip("_") or "tensor"
|
||||
|
||||
|
||||
def _is_primitive(value: Any) -> bool:
|
||||
return value is None or isinstance(value, (bool, int, float, str))
|
||||
|
||||
|
||||
def _primitive_sequence(value: Any) -> bool:
|
||||
return isinstance(value, (list, tuple)) and all(_is_primitive(item) for item in value)
|
||||
|
||||
|
||||
class DiagnosticCapture:
|
||||
def __init__(self, side: str):
|
||||
self.side = side
|
||||
self.manifest: dict[str, Any] = {
|
||||
"format": "h3-core-continuum-gpu-diagnostic-v1",
|
||||
"side": side,
|
||||
"stages": {},
|
||||
}
|
||||
self.tensors: dict[str, torch.Tensor] = {}
|
||||
self.runtime: dict[str, Any] = {}
|
||||
|
||||
def _stage(self, stage: str) -> dict[str, Any]:
|
||||
return self.manifest["stages"].setdefault(stage, {"values": {}, "tensors": {}})
|
||||
|
||||
def add_value(self, stage: str, field: str, value: Any) -> None:
|
||||
if not (_is_primitive(value) or _primitive_sequence(value)):
|
||||
value = json.loads(json.dumps(value, default=str))
|
||||
self._stage(stage)["values"][field] = value
|
||||
|
||||
def add_tensor(self, stage: str, field: str, tensor: torch.Tensor, *, persist: bool = True) -> None:
|
||||
if not torch.is_tensor(tensor):
|
||||
raise TypeError(f"{field} is not a tensor")
|
||||
if getattr(tensor, "is_nested", False):
|
||||
parts = list(tensor.unbind())
|
||||
self.add_value(stage, f"{field}.components", len(parts))
|
||||
for index, part in enumerate(parts):
|
||||
self.add_tensor(stage, f"{field}.component_{index}", part, persist=persist)
|
||||
return
|
||||
value = _dense_cpu(tensor)
|
||||
key = _safe_tensor_key(f"{stage}.{field}")
|
||||
self._stage(stage)["tensors"][field] = {
|
||||
**tensor_fingerprint(value),
|
||||
"stored_as": key if persist else None,
|
||||
}
|
||||
if persist:
|
||||
self.tensors[key] = value.clone()
|
||||
|
||||
def capture_value(
|
||||
self,
|
||||
stage: str,
|
||||
field: str,
|
||||
value: Any,
|
||||
*,
|
||||
persist_tensors: bool = True,
|
||||
depth: int = 0,
|
||||
) -> None:
|
||||
if depth > 7:
|
||||
self.add_value(stage, f"{field}.truncated", True)
|
||||
return
|
||||
if torch.is_tensor(value):
|
||||
self.add_tensor(stage, field, value, persist=persist_tensors)
|
||||
return
|
||||
if _is_primitive(value):
|
||||
self.add_value(stage, field, value)
|
||||
return
|
||||
if _primitive_sequence(value):
|
||||
self.add_value(stage, field, list(value))
|
||||
return
|
||||
if isinstance(value, Mapping):
|
||||
keys = sorted(str(key) for key in value.keys())
|
||||
self.add_value(stage, f"{field}.keys", keys)
|
||||
for key in keys[:256]:
|
||||
try:
|
||||
child = value[key]
|
||||
except (KeyError, TypeError):
|
||||
child = next((item for raw, item in value.items() if str(raw) == key), None)
|
||||
self.capture_value(
|
||||
stage,
|
||||
f"{field}.{key}",
|
||||
child,
|
||||
persist_tensors=persist_tensors,
|
||||
depth=depth + 1,
|
||||
)
|
||||
return
|
||||
if isinstance(value, Sequence) and not isinstance(value, (str, bytes, bytearray)):
|
||||
self.add_value(stage, f"{field}.length", len(value))
|
||||
for index, child in enumerate(value[:256]):
|
||||
self.capture_value(
|
||||
stage,
|
||||
f"{field}.{index}",
|
||||
child,
|
||||
persist_tensors=persist_tensors,
|
||||
depth=depth + 1,
|
||||
)
|
||||
return
|
||||
if hasattr(value, "unbind") and value.__class__.__name__ == "NestedTensor":
|
||||
parts = list(value.unbind())
|
||||
self.add_value(stage, f"{field}.components", len(parts))
|
||||
for index, child in enumerate(parts):
|
||||
label = ("video", "audio")[index] if index < 2 else f"component_{index}"
|
||||
self.capture_value(
|
||||
stage,
|
||||
f"{field}.{label}",
|
||||
child,
|
||||
persist_tensors=persist_tensors,
|
||||
depth=depth + 1,
|
||||
)
|
||||
return
|
||||
if all(hasattr(value, name) for name in ("signature", "segments", "position_ids")):
|
||||
self.add_value(stage, f"{field}.type", value.__class__.__name__)
|
||||
self.add_value(stage, f"{field}.signature", list(value.signature))
|
||||
self.add_value(stage, f"{field}.segments", [list(item) for item in value.segments])
|
||||
for name in ("position_ids", "img_pos", "img_update", "audio_pos", "audio_update"):
|
||||
child = getattr(value, name, None)
|
||||
if torch.is_tensor(child):
|
||||
self.add_tensor(stage, f"{field}.{name}", child, persist=persist_tensors)
|
||||
return
|
||||
self.add_value(stage, f"{field}.type", value.__class__.__name__)
|
||||
|
||||
def save(self, directory: Path) -> None:
|
||||
directory.mkdir(parents=True, exist_ok=True)
|
||||
from safetensors.torch import save_file
|
||||
|
||||
save_file(self.tensors, str(directory / "tensors.safetensors"))
|
||||
(directory / "manifest.json").write_text(
|
||||
json.dumps(self.manifest, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
def compare_stage(
|
||||
left: DiagnosticCapture,
|
||||
right: DiagnosticCapture,
|
||||
stage: str,
|
||||
) -> dict[str, Any]:
|
||||
a = left.manifest["stages"].get(stage, {"values": {}, "tensors": {}})
|
||||
b = right.manifest["stages"].get(stage, {"values": {}, "tensors": {}})
|
||||
details: dict[str, Any] = {}
|
||||
first_field: str | None = None
|
||||
|
||||
value_fields = list(a["values"].keys()) + [key for key in b["values"] if key not in a["values"]]
|
||||
for field in value_fields:
|
||||
av = a["values"].get(field, {"missing": True})
|
||||
bv = b["values"].get(field, {"missing": True})
|
||||
matches = av == bv
|
||||
details[field] = {"kind": "value", "matches": matches, "left": av, "right": bv}
|
||||
if not matches and first_field is None:
|
||||
first_field = field
|
||||
|
||||
tensor_fields = list(a["tensors"].keys()) + [key for key in b["tensors"] if key not in a["tensors"]]
|
||||
for field in tensor_fields:
|
||||
a_meta = a["tensors"].get(field)
|
||||
b_meta = b["tensors"].get(field)
|
||||
if a_meta is None or b_meta is None:
|
||||
result = {"kind": "tensor", "matches": False, "reason": "missing tensor"}
|
||||
else:
|
||||
a_key = a_meta.get("stored_as")
|
||||
b_key = b_meta.get("stored_as")
|
||||
if a_key in left.tensors and b_key in right.tensors:
|
||||
result = {"kind": "tensor", **compare_tensors(left.tensors[a_key], right.tensors[b_key]).to_dict()}
|
||||
else:
|
||||
matches = a_meta == b_meta
|
||||
result = {"kind": "fingerprint", "matches": matches, "left": a_meta, "right": b_meta}
|
||||
details[field] = result
|
||||
if not result["matches"] and first_field is None:
|
||||
first_field = field
|
||||
|
||||
return {
|
||||
"status": "MATCH" if first_field is None else "DIFFER",
|
||||
"first_field": first_field,
|
||||
"fields": details,
|
||||
}
|
||||
|
||||
|
||||
def recombine_terminal_streams(
|
||||
first: torch.Tensor,
|
||||
second: torch.Tensor,
|
||||
*,
|
||||
first_range: tuple[int, int] | list[int],
|
||||
second_range: tuple[int, int] | list[int],
|
||||
dim: int,
|
||||
) -> torch.Tensor:
|
||||
first_start, first_stop = (int(value) for value in first_range)
|
||||
second_start, second_stop = (int(value) for value in second_range)
|
||||
overlap = first_stop - second_start
|
||||
if first_start != 0 or overlap < 0:
|
||||
raise ValueError("terminal split ranges do not form an overlapping sequence")
|
||||
if first.shape[dim] != first_stop - first_start:
|
||||
raise ValueError("first logical stream length does not match its range")
|
||||
if second.shape[dim] != second_stop - second_start:
|
||||
raise ValueError("second logical stream length does not match its range")
|
||||
if overlap > second.shape[dim]:
|
||||
raise ValueError("terminal overlap exceeds the second logical stream")
|
||||
slices = [slice(None)] * second.ndim
|
||||
slices[dim] = slice(overlap, None)
|
||||
return torch.cat((first, second[tuple(slices)]), dim=dim).contiguous()
|
||||
|
||||
|
||||
def format_comparison(comparison: Mapping[str, Any], output_directory: Path) -> str:
|
||||
lines = []
|
||||
first_divergence = None
|
||||
for stage in STAGE_ORDER:
|
||||
result = comparison.get(stage, {"status": "NOT_RUN", "first_field": None})
|
||||
lines.append(f"{stage}: {result['status']}")
|
||||
if first_divergence is None and result["status"] == "DIFFER":
|
||||
field = result.get("first_field")
|
||||
first_divergence = f"{stage}.{field}" if field else stage
|
||||
lines.append("")
|
||||
lines.append(f"First divergence: {first_divergence or 'none'}")
|
||||
lines.append(f"Output: {output_directory}")
|
||||
return "\n".join(lines)
|
||||
"""Deterministic tensor capture and comparison helpers for the GPU runner."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping, Sequence
|
||||
from dataclasses import asdict, dataclass
|
||||
from hashlib import sha256
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
import torch
|
||||
|
||||
|
||||
STAGE_ORDER = (
|
||||
"A_pre_sampler",
|
||||
"B_first_model_call",
|
||||
"C_physical_sample",
|
||||
"D_split_recombine",
|
||||
"E1_decode_243",
|
||||
"E2_final_240",
|
||||
)
|
||||
|
||||
|
||||
def _dense_cpu(tensor: torch.Tensor) -> torch.Tensor:
|
||||
return tensor.detach().to("cpu").contiguous()
|
||||
|
||||
|
||||
def _raw_sha256(tensor: torch.Tensor) -> str:
|
||||
value = _dense_cpu(tensor)
|
||||
raw = value.view(torch.uint8).numpy().tobytes()
|
||||
return sha256(raw).hexdigest()
|
||||
|
||||
|
||||
def tensor_fingerprint(tensor: torch.Tensor) -> dict[str, Any]:
|
||||
value = _dense_cpu(tensor)
|
||||
return {
|
||||
"shape": list(value.shape),
|
||||
"dtype": str(value.dtype),
|
||||
"sha256": _raw_sha256(value),
|
||||
"numel": int(value.numel()),
|
||||
}
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class TensorDifference:
|
||||
comparable: bool
|
||||
bit_exact: bool
|
||||
allclose: bool
|
||||
max_abs_diff: float | None
|
||||
mean_abs_diff: float | None
|
||||
reason: str | None = None
|
||||
|
||||
@property
|
||||
def matches(self) -> bool:
|
||||
return self.comparable and (self.bit_exact or self.allclose)
|
||||
|
||||
def to_dict(self) -> dict[str, Any]:
|
||||
value = asdict(self)
|
||||
value["matches"] = self.matches
|
||||
return value
|
||||
|
||||
|
||||
def compare_tensors(
|
||||
left: torch.Tensor,
|
||||
right: torch.Tensor,
|
||||
*,
|
||||
rtol: float = 1.0e-4,
|
||||
atol: float = 1.0e-5,
|
||||
) -> TensorDifference:
|
||||
a = _dense_cpu(left)
|
||||
b = _dense_cpu(right)
|
||||
if tuple(a.shape) != tuple(b.shape):
|
||||
return TensorDifference(False, False, False, None, None, "shape mismatch")
|
||||
if a.dtype != b.dtype:
|
||||
return TensorDifference(False, False, False, None, None, "dtype mismatch")
|
||||
bit_exact = bool(torch.equal(a, b))
|
||||
if not (a.is_floating_point() or a.is_complex()):
|
||||
return TensorDifference(True, bit_exact, bit_exact, 0.0 if bit_exact else None, 0.0 if bit_exact else None)
|
||||
af = a.to(torch.float64)
|
||||
bf = b.to(torch.float64)
|
||||
delta = (af - bf).abs()
|
||||
max_abs = float(delta.max().item()) if delta.numel() else 0.0
|
||||
mean_abs = float(delta.mean().item()) if delta.numel() else 0.0
|
||||
close = bool(torch.allclose(af, bf, rtol=rtol, atol=atol, equal_nan=True))
|
||||
return TensorDifference(True, bit_exact, close, max_abs, mean_abs)
|
||||
|
||||
|
||||
def _safe_tensor_key(value: str) -> str:
|
||||
return re.sub(r"[^A-Za-z0-9_.-]+", "_", value).strip("_") or "tensor"
|
||||
|
||||
|
||||
def _is_primitive(value: Any) -> bool:
|
||||
return value is None or isinstance(value, (bool, int, float, str))
|
||||
|
||||
|
||||
def _primitive_sequence(value: Any) -> bool:
|
||||
return isinstance(value, (list, tuple)) and all(_is_primitive(item) for item in value)
|
||||
|
||||
|
||||
class DiagnosticCapture:
|
||||
def __init__(self, side: str):
|
||||
self.side = side
|
||||
self.manifest: dict[str, Any] = {
|
||||
"format": "h3-core-continuum-gpu-diagnostic-v1",
|
||||
"side": side,
|
||||
"stages": {},
|
||||
}
|
||||
self.tensors: dict[str, torch.Tensor] = {}
|
||||
self.runtime: dict[str, Any] = {}
|
||||
|
||||
def _stage(self, stage: str) -> dict[str, Any]:
|
||||
return self.manifest["stages"].setdefault(stage, {"values": {}, "tensors": {}})
|
||||
|
||||
def add_value(self, stage: str, field: str, value: Any) -> None:
|
||||
if not (_is_primitive(value) or _primitive_sequence(value)):
|
||||
value = json.loads(json.dumps(value, default=str))
|
||||
self._stage(stage)["values"][field] = value
|
||||
|
||||
def add_tensor(self, stage: str, field: str, tensor: torch.Tensor, *, persist: bool = True) -> None:
|
||||
if not torch.is_tensor(tensor):
|
||||
raise TypeError(f"{field} is not a tensor")
|
||||
if getattr(tensor, "is_nested", False):
|
||||
parts = list(tensor.unbind())
|
||||
self.add_value(stage, f"{field}.components", len(parts))
|
||||
for index, part in enumerate(parts):
|
||||
self.add_tensor(stage, f"{field}.component_{index}", part, persist=persist)
|
||||
return
|
||||
value = _dense_cpu(tensor)
|
||||
key = _safe_tensor_key(f"{stage}.{field}")
|
||||
self._stage(stage)["tensors"][field] = {
|
||||
**tensor_fingerprint(value),
|
||||
"stored_as": key if persist else None,
|
||||
}
|
||||
if persist:
|
||||
self.tensors[key] = value.clone()
|
||||
|
||||
def capture_value(
|
||||
self,
|
||||
stage: str,
|
||||
field: str,
|
||||
value: Any,
|
||||
*,
|
||||
persist_tensors: bool = True,
|
||||
depth: int = 0,
|
||||
) -> None:
|
||||
if depth > 7:
|
||||
self.add_value(stage, f"{field}.truncated", True)
|
||||
return
|
||||
if torch.is_tensor(value):
|
||||
self.add_tensor(stage, field, value, persist=persist_tensors)
|
||||
return
|
||||
if _is_primitive(value):
|
||||
self.add_value(stage, field, value)
|
||||
return
|
||||
if _primitive_sequence(value):
|
||||
self.add_value(stage, field, list(value))
|
||||
return
|
||||
if isinstance(value, Mapping):
|
||||
keys = sorted(str(key) for key in value.keys())
|
||||
self.add_value(stage, f"{field}.keys", keys)
|
||||
for key in keys[:256]:
|
||||
try:
|
||||
child = value[key]
|
||||
except (KeyError, TypeError):
|
||||
child = next((item for raw, item in value.items() if str(raw) == key), None)
|
||||
self.capture_value(
|
||||
stage,
|
||||
f"{field}.{key}",
|
||||
child,
|
||||
persist_tensors=persist_tensors,
|
||||
depth=depth + 1,
|
||||
)
|
||||
return
|
||||
if isinstance(value, Sequence) and not isinstance(value, (str, bytes, bytearray)):
|
||||
self.add_value(stage, f"{field}.length", len(value))
|
||||
for index, child in enumerate(value[:256]):
|
||||
self.capture_value(
|
||||
stage,
|
||||
f"{field}.{index}",
|
||||
child,
|
||||
persist_tensors=persist_tensors,
|
||||
depth=depth + 1,
|
||||
)
|
||||
return
|
||||
if hasattr(value, "unbind") and value.__class__.__name__ == "NestedTensor":
|
||||
parts = list(value.unbind())
|
||||
self.add_value(stage, f"{field}.components", len(parts))
|
||||
for index, child in enumerate(parts):
|
||||
label = ("video", "audio")[index] if index < 2 else f"component_{index}"
|
||||
self.capture_value(
|
||||
stage,
|
||||
f"{field}.{label}",
|
||||
child,
|
||||
persist_tensors=persist_tensors,
|
||||
depth=depth + 1,
|
||||
)
|
||||
return
|
||||
if all(hasattr(value, name) for name in ("signature", "segments", "position_ids")):
|
||||
self.add_value(stage, f"{field}.type", value.__class__.__name__)
|
||||
self.add_value(stage, f"{field}.signature", list(value.signature))
|
||||
self.add_value(stage, f"{field}.segments", [list(item) for item in value.segments])
|
||||
for name in ("position_ids", "img_pos", "img_update", "audio_pos", "audio_update"):
|
||||
child = getattr(value, name, None)
|
||||
if torch.is_tensor(child):
|
||||
self.add_tensor(stage, f"{field}.{name}", child, persist=persist_tensors)
|
||||
return
|
||||
self.add_value(stage, f"{field}.type", value.__class__.__name__)
|
||||
|
||||
def save(self, directory: Path) -> None:
|
||||
directory.mkdir(parents=True, exist_ok=True)
|
||||
from safetensors.torch import save_file
|
||||
|
||||
save_file(self.tensors, str(directory / "tensors.safetensors"))
|
||||
(directory / "manifest.json").write_text(
|
||||
json.dumps(self.manifest, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
def compare_stage(
|
||||
left: DiagnosticCapture,
|
||||
right: DiagnosticCapture,
|
||||
stage: str,
|
||||
) -> dict[str, Any]:
|
||||
a = left.manifest["stages"].get(stage, {"values": {}, "tensors": {}})
|
||||
b = right.manifest["stages"].get(stage, {"values": {}, "tensors": {}})
|
||||
details: dict[str, Any] = {}
|
||||
first_field: str | None = None
|
||||
|
||||
value_fields = list(a["values"].keys()) + [key for key in b["values"] if key not in a["values"]]
|
||||
for field in value_fields:
|
||||
av = a["values"].get(field, {"missing": True})
|
||||
bv = b["values"].get(field, {"missing": True})
|
||||
matches = av == bv
|
||||
details[field] = {"kind": "value", "matches": matches, "left": av, "right": bv}
|
||||
if not matches and first_field is None:
|
||||
first_field = field
|
||||
|
||||
tensor_fields = list(a["tensors"].keys()) + [key for key in b["tensors"] if key not in a["tensors"]]
|
||||
for field in tensor_fields:
|
||||
a_meta = a["tensors"].get(field)
|
||||
b_meta = b["tensors"].get(field)
|
||||
if a_meta is None or b_meta is None:
|
||||
result = {"kind": "tensor", "matches": False, "reason": "missing tensor"}
|
||||
else:
|
||||
a_key = a_meta.get("stored_as")
|
||||
b_key = b_meta.get("stored_as")
|
||||
if a_key in left.tensors and b_key in right.tensors:
|
||||
result = {"kind": "tensor", **compare_tensors(left.tensors[a_key], right.tensors[b_key]).to_dict()}
|
||||
else:
|
||||
matches = a_meta == b_meta
|
||||
result = {"kind": "fingerprint", "matches": matches, "left": a_meta, "right": b_meta}
|
||||
details[field] = result
|
||||
if not result["matches"] and first_field is None:
|
||||
first_field = field
|
||||
|
||||
return {
|
||||
"status": "MATCH" if first_field is None else "DIFFER",
|
||||
"first_field": first_field,
|
||||
"fields": details,
|
||||
}
|
||||
|
||||
|
||||
def recombine_terminal_streams(
|
||||
first: torch.Tensor,
|
||||
second: torch.Tensor,
|
||||
*,
|
||||
first_range: tuple[int, int] | list[int],
|
||||
second_range: tuple[int, int] | list[int],
|
||||
dim: int,
|
||||
) -> torch.Tensor:
|
||||
first_start, first_stop = (int(value) for value in first_range)
|
||||
second_start, second_stop = (int(value) for value in second_range)
|
||||
overlap = first_stop - second_start
|
||||
if first_start != 0 or overlap < 0:
|
||||
raise ValueError("terminal split ranges do not form an overlapping sequence")
|
||||
if first.shape[dim] != first_stop - first_start:
|
||||
raise ValueError("first logical stream length does not match its range")
|
||||
if second.shape[dim] != second_stop - second_start:
|
||||
raise ValueError("second logical stream length does not match its range")
|
||||
if overlap > second.shape[dim]:
|
||||
raise ValueError("terminal overlap exceeds the second logical stream")
|
||||
slices = [slice(None)] * second.ndim
|
||||
slices[dim] = slice(overlap, None)
|
||||
return torch.cat((first, second[tuple(slices)]), dim=dim).contiguous()
|
||||
|
||||
|
||||
def format_comparison(comparison: Mapping[str, Any], output_directory: Path) -> str:
|
||||
lines = []
|
||||
first_divergence = None
|
||||
for stage in STAGE_ORDER:
|
||||
result = comparison.get(stage, {"status": "NOT_RUN", "first_field": None})
|
||||
lines.append(f"{stage}: {result['status']}")
|
||||
if first_divergence is None and result["status"] == "DIFFER":
|
||||
field = result.get("first_field")
|
||||
first_divergence = f"{stage}.{field}" if field else stage
|
||||
lines.append("")
|
||||
lines.append(f"First divergence: {first_divergence or 'none'}")
|
||||
lines.append(f"Output: {output_directory}")
|
||||
return "\n".join(lines)
|
||||
|
||||
@@ -0,0 +1,222 @@
|
||||
"""Diagnostic-only continuation depth and mask-strength policies for Issue #13."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
from typing import Any, Callable
|
||||
|
||||
import torch
|
||||
|
||||
|
||||
MODE_BASELINE_22 = "Baseline 22f"
|
||||
MODE_DEPTH_13 = "Video Depth 13f"
|
||||
MODE_DEPTH_9 = "Video Depth 9f"
|
||||
MODE_STRENGTH_75 = "Video Strength 75%"
|
||||
MODE_DEPTH_13_STRENGTH_75 = "Video Depth 13f + Strength 75%"
|
||||
MODE_OPTIONS = (
|
||||
MODE_BASELINE_22,
|
||||
MODE_DEPTH_13,
|
||||
MODE_DEPTH_9,
|
||||
MODE_STRENGTH_75,
|
||||
MODE_DEPTH_13_STRENGTH_75,
|
||||
)
|
||||
|
||||
_PREFIX_SLOTS = 7
|
||||
_AUDIO_PREFIX_STEPS = 37
|
||||
_ACTIVE_SLOT_CONTRACT = {
|
||||
MODE_BASELINE_22: (_PREFIX_SLOTS, 22),
|
||||
MODE_DEPTH_13: (4, 13),
|
||||
MODE_DEPTH_9: (3, 9),
|
||||
MODE_STRENGTH_75: (_PREFIX_SLOTS, 22),
|
||||
MODE_DEPTH_13_STRENGTH_75: (4, 13),
|
||||
}
|
||||
|
||||
|
||||
def _mask_values(tensor: torch.Tensor) -> list[float]:
|
||||
return [float(value) for value in torch.unique(tensor.detach().float()).tolist()]
|
||||
|
||||
|
||||
class R28ContinuationPolicy:
|
||||
"""Scoped callback used only by the external R2.8 diagnostic node."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
mode: str,
|
||||
*,
|
||||
tensor_summary: Callable[[torch.Tensor], dict[str, Any]],
|
||||
) -> None:
|
||||
if mode not in MODE_OPTIONS:
|
||||
raise ValueError(f"unknown R2.8 continuation policy: {mode!r}")
|
||||
self.mode = str(mode)
|
||||
self.tensor_summary = tensor_summary
|
||||
self._prepared: dict[int, dict[str, Any]] = {}
|
||||
self.sample_calls: list[dict[str, Any]] = []
|
||||
|
||||
@property
|
||||
def active_video_slots(self) -> int:
|
||||
return int(_ACTIVE_SLOT_CONTRACT[self.mode][0])
|
||||
|
||||
@property
|
||||
def active_video_frames(self) -> int:
|
||||
return int(_ACTIVE_SLOT_CONTRACT[self.mode][1])
|
||||
|
||||
@property
|
||||
def prefix_denoise_mask_value(self) -> float:
|
||||
if self.mode in (MODE_STRENGTH_75, MODE_DEPTH_13_STRENGTH_75):
|
||||
return 0.25
|
||||
return 0.0
|
||||
|
||||
def prepare_masked_latent(
|
||||
self,
|
||||
*,
|
||||
latent: dict[str, Any],
|
||||
physical_group: int,
|
||||
logical_chunks: tuple[int, ...],
|
||||
context_frames: int,
|
||||
video_context: torch.Tensor,
|
||||
audio_context: torch.Tensor | None,
|
||||
) -> dict[str, Any]:
|
||||
if int(context_frames) != 22:
|
||||
raise ValueError("R2.8 policy requires the unchanged Balanced 22-frame transport")
|
||||
mask = latent.get("noise_mask")
|
||||
if mask is None or not hasattr(mask, "unbind"):
|
||||
raise ValueError("R2.8 policy requires the native nested AV noise mask")
|
||||
parts = list(mask.unbind())
|
||||
if len(parts) < 2:
|
||||
raise ValueError("R2.8 policy requires Video and Audio masks")
|
||||
video_mask, audio_mask = parts[0], parts[1]
|
||||
if int(video_mask.shape[2]) <= _PREFIX_SLOTS:
|
||||
raise ValueError("R2.8 Video target has no generated region after the prefix")
|
||||
if int(audio_mask.shape[-1]) <= _AUDIO_PREFIX_STEPS:
|
||||
raise ValueError("R2.8 Audio target has no generated region after the prefix")
|
||||
|
||||
original_video_mask = video_mask.detach().clone()
|
||||
original_audio_mask = audio_mask.detach().clone()
|
||||
transformed = latent
|
||||
if self.mode != MODE_BASELINE_22:
|
||||
video_mask = video_mask.clone()
|
||||
oldest_inactive = _PREFIX_SLOTS - self.active_video_slots
|
||||
if oldest_inactive:
|
||||
video_mask[:, :, :oldest_inactive] = 1.0
|
||||
video_mask[
|
||||
:, :, oldest_inactive:_PREFIX_SLOTS
|
||||
] = self.prefix_denoise_mask_value
|
||||
transformed = dict(latent)
|
||||
transformed["noise_mask"] = mask.__class__((video_mask, audio_mask.clone()))
|
||||
|
||||
effective_mask = list(transformed["noise_mask"].unbind())
|
||||
effective_video_mask, effective_audio_mask = effective_mask[0], effective_mask[1]
|
||||
self._prepared[int(physical_group)] = {
|
||||
"physical_group": int(physical_group),
|
||||
"logical_chunks": [int(value) for value in logical_chunks],
|
||||
"transport_context_frames": int(context_frames),
|
||||
"transport_video_prefix_slots": _PREFIX_SLOTS,
|
||||
"transport_audio_prefix_steps": _AUDIO_PREFIX_STEPS,
|
||||
"active_video_slots": self.active_video_slots,
|
||||
"active_video_frames": self.active_video_frames,
|
||||
"video_prefix_denoise_mask_value": self.prefix_denoise_mask_value,
|
||||
"video_context": self.tensor_summary(video_context),
|
||||
"audio_context": self.tensor_summary(audio_context)
|
||||
if audio_context is not None
|
||||
else None,
|
||||
"source_samples_object_passthrough": transformed.get("samples")
|
||||
is latent.get("samples"),
|
||||
"input_video_mask_unchanged": bool(
|
||||
torch.equal(original_video_mask, list(mask.unbind())[0])
|
||||
),
|
||||
"input_audio_mask_unchanged": bool(
|
||||
torch.equal(original_audio_mask, list(mask.unbind())[1])
|
||||
),
|
||||
"effective_video_prefix_mask_values": _mask_values(
|
||||
effective_video_mask[:, :, :_PREFIX_SLOTS]
|
||||
),
|
||||
"effective_video_generated_mask_values": _mask_values(
|
||||
effective_video_mask[:, :, _PREFIX_SLOTS:]
|
||||
),
|
||||
"effective_audio_prefix_mask_values": _mask_values(
|
||||
effective_audio_mask[..., :_AUDIO_PREFIX_STEPS]
|
||||
),
|
||||
"effective_audio_generated_mask_values": _mask_values(
|
||||
effective_audio_mask[..., _AUDIO_PREFIX_STEPS:]
|
||||
),
|
||||
}
|
||||
return transformed
|
||||
|
||||
def before_sampling(
|
||||
self,
|
||||
*,
|
||||
physical_group: int,
|
||||
logical_chunks: tuple[int, ...],
|
||||
context_frames: int,
|
||||
latent: dict[str, Any],
|
||||
conditioning: Any,
|
||||
seed: int,
|
||||
sigmas: torch.Tensor,
|
||||
) -> dict[str, Any]:
|
||||
samples = list(latent["samples"].unbind())
|
||||
metadata = conditioning[0][1] if conditioning else {}
|
||||
record = {
|
||||
"physical_group": int(physical_group),
|
||||
"logical_chunks": [int(value) for value in logical_chunks],
|
||||
"context_frames": int(context_frames),
|
||||
"seed": int(seed),
|
||||
"sigmas": self.tensor_summary(sigmas),
|
||||
"input_video": self.tensor_summary(samples[0]),
|
||||
"input_audio": self.tensor_summary(samples[1]),
|
||||
"prompt_embedding": self.tensor_summary(conditioning[0][0])
|
||||
if conditioning and torch.is_tensor(conditioning[0][0])
|
||||
else None,
|
||||
"minimax_frame_count": metadata.get("minimax_frame_count"),
|
||||
"policy": self._prepared.get(int(physical_group)),
|
||||
}
|
||||
return {"started": time.perf_counter(), "record": record}
|
||||
|
||||
def after_sampling(
|
||||
self,
|
||||
*,
|
||||
token: dict[str, Any],
|
||||
physical_group: int,
|
||||
logical_chunks: tuple[int, ...],
|
||||
context_frames: int,
|
||||
latent: dict[str, Any],
|
||||
sampled: dict[str, Any],
|
||||
seed: int,
|
||||
sigmas: torch.Tensor,
|
||||
) -> None:
|
||||
record = dict(token["record"])
|
||||
record["sample_host_elapsed_seconds"] = float(
|
||||
time.perf_counter() - float(token["started"])
|
||||
)
|
||||
source_video, source_audio = list(latent["samples"].unbind())[:2]
|
||||
output_video, output_audio = list(sampled["samples"].unbind())[:2]
|
||||
record["output_video"] = self.tensor_summary(output_video)
|
||||
record["output_audio"] = self.tensor_summary(output_audio)
|
||||
if int(context_frames) == 22:
|
||||
source_video_prefix = source_video[:, :, :_PREFIX_SLOTS]
|
||||
output_video_prefix = output_video[:, :, :_PREFIX_SLOTS]
|
||||
source_audio_prefix = source_audio[..., :_AUDIO_PREFIX_STEPS]
|
||||
output_audio_prefix = output_audio[..., :_AUDIO_PREFIX_STEPS]
|
||||
record["restored_video_prefix_bit_exact"] = bool(
|
||||
torch.equal(source_video_prefix, output_video_prefix)
|
||||
)
|
||||
record["restored_audio_prefix_bit_exact"] = bool(
|
||||
torch.equal(source_audio_prefix, output_audio_prefix)
|
||||
)
|
||||
record["restored_video_prefix"] = self.tensor_summary(output_video_prefix)
|
||||
record["restored_audio_prefix"] = self.tensor_summary(output_audio_prefix)
|
||||
self.sample_calls.append(record)
|
||||
|
||||
def finalize(self) -> dict[str, Any]:
|
||||
return {
|
||||
"format": "h3-continuum-issue13-r28-policy-v1",
|
||||
"mode": self.mode,
|
||||
"transport_context_frames": 22,
|
||||
"transport_video_prefix_slots": _PREFIX_SLOTS,
|
||||
"transport_audio_prefix_steps": _AUDIO_PREFIX_STEPS,
|
||||
"active_video_slots": self.active_video_slots,
|
||||
"active_video_frames": self.active_video_frames,
|
||||
"video_prefix_denoise_mask_value": self.prefix_denoise_mask_value,
|
||||
"audio_contract": "unchanged 37T protected prefix",
|
||||
"sample_calls": list(self.sample_calls),
|
||||
"sampling_count": len(self.sample_calls),
|
||||
}
|
||||
+1105
-692
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,164 @@
|
||||
"""Diagnostic-only one-shot appearance re-anchor for Issue #13 R2.7."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
import torch
|
||||
|
||||
|
||||
SOFT_REANCHOR_STRENGTH = 0.5
|
||||
_EPSILON = 1.0e-6
|
||||
|
||||
|
||||
def _validate_pixels(value: torch.Tensor, *, label: str) -> torch.Tensor:
|
||||
if not torch.is_tensor(value) or value.ndim != 5 or int(value.shape[-1]) != 3:
|
||||
raise ValueError(f"{label} must be [B,F,H,W,3] RGB pixels")
|
||||
measured = value.detach().float()
|
||||
if not bool(torch.isfinite(measured).all().item()):
|
||||
raise ValueError(f"{label} contains NaN or Inf")
|
||||
return measured
|
||||
|
||||
|
||||
def rgb_appearance_summary(value: torch.Tensor) -> dict[str, float]:
|
||||
"""Return global low-frequency RGB appearance statistics."""
|
||||
|
||||
rgb = _validate_pixels(value, label="pixels")
|
||||
red, green, blue = rgb.unbind(dim=-1)
|
||||
luma = 0.2126 * red + 0.7152 * green + 0.0722 * blue
|
||||
maximum = rgb.amax(dim=-1)
|
||||
minimum = rgb.amin(dim=-1)
|
||||
saturation = (maximum - minimum) / maximum.clamp_min(_EPSILON)
|
||||
return {
|
||||
"luma_mean": float(luma.mean().item()),
|
||||
"luma_std": float(luma.std(unbiased=False).item()),
|
||||
"saturation_mean": float(saturation.mean().item()),
|
||||
"chroma_u_mean": float((blue - luma).mean().item()),
|
||||
"chroma_u_std": float((blue - luma).std(unbiased=False).item()),
|
||||
"chroma_v_mean": float((red - luma).mean().item()),
|
||||
"chroma_v_std": float((red - luma).std(unbiased=False).item()),
|
||||
"highlight_fraction": float((luma >= (250.0 / 255.0)).float().mean().item()),
|
||||
}
|
||||
|
||||
|
||||
def _matched_channel(
|
||||
current: torch.Tensor,
|
||||
reference: torch.Tensor,
|
||||
) -> tuple[torch.Tensor, float]:
|
||||
current_mean = current.mean()
|
||||
current_std = current.std(unbiased=False).clamp_min(_EPSILON)
|
||||
reference_mean = reference.mean()
|
||||
reference_std = reference.std(unbiased=False).clamp_min(_EPSILON)
|
||||
scale = (reference_std / current_std).clamp(0.5, 2.0)
|
||||
return (current - current_mean) * scale + reference_mean, float(scale.item())
|
||||
|
||||
|
||||
def soft_match_rgb_appearance(
|
||||
current_pixels: torch.Tensor,
|
||||
reference_pixels: torch.Tensor,
|
||||
*,
|
||||
strength: float = SOFT_REANCHOR_STRENGTH,
|
||||
) -> tuple[torch.Tensor, dict[str, Any]]:
|
||||
"""Match only global luma/chroma statistics; preserve spatial coordinates."""
|
||||
|
||||
amount = float(strength)
|
||||
if not 0.0 <= amount <= 1.0:
|
||||
raise ValueError("soft re-anchor strength must be in [0,1]")
|
||||
current = _validate_pixels(current_pixels, label="current_pixels")
|
||||
reference = _validate_pixels(reference_pixels, label="reference_pixels")
|
||||
if tuple(current.shape[-3:]) != tuple(reference.shape[-3:]):
|
||||
raise ValueError("current/reference pixel geometry must match")
|
||||
|
||||
current_r, current_g, current_b = current.unbind(dim=-1)
|
||||
reference_r, reference_g, reference_b = reference.unbind(dim=-1)
|
||||
current_y = 0.2126 * current_r + 0.7152 * current_g + 0.0722 * current_b
|
||||
reference_y = (
|
||||
0.2126 * reference_r + 0.7152 * reference_g + 0.0722 * reference_b
|
||||
)
|
||||
current_u = current_b - current_y
|
||||
current_v = current_r - current_y
|
||||
reference_u = reference_b - reference_y
|
||||
reference_v = reference_r - reference_y
|
||||
|
||||
matched_y, luma_scale = _matched_channel(current_y, reference_y)
|
||||
matched_u, chroma_u_scale = _matched_channel(current_u, reference_u)
|
||||
matched_v, chroma_v_scale = _matched_channel(current_v, reference_v)
|
||||
matched_r = matched_y + matched_v
|
||||
matched_b = matched_y + matched_u
|
||||
matched_g = (matched_y - 0.2126 * matched_r - 0.0722 * matched_b) / 0.7152
|
||||
fully_matched = torch.stack((matched_r, matched_g, matched_b), dim=-1).clamp(0.0, 1.0)
|
||||
adjusted = (current + amount * (fully_matched - current)).clamp(0.0, 1.0)
|
||||
delta = adjusted - current
|
||||
report = {
|
||||
"strength": amount,
|
||||
"method": "global Y/U/V mean+std match; 50% blend; no blur/warp/resize",
|
||||
"scales": {
|
||||
"luma": luma_scale,
|
||||
"chroma_u": chroma_u_scale,
|
||||
"chroma_v": chroma_v_scale,
|
||||
},
|
||||
"reference": rgb_appearance_summary(reference),
|
||||
"before": rgb_appearance_summary(current),
|
||||
"fully_matched": rgb_appearance_summary(fully_matched),
|
||||
"after": rgb_appearance_summary(adjusted),
|
||||
"pixel_delta_rms": float(delta.square().mean().sqrt().item()),
|
||||
"pixel_delta_max_abs": float(delta.abs().max().item()),
|
||||
"geometry_unchanged": tuple(adjusted.shape) == tuple(current.shape),
|
||||
}
|
||||
return adjusted.to(dtype=current_pixels.dtype), report
|
||||
|
||||
|
||||
def soft_reanchor_context(
|
||||
current_context: torch.Tensor,
|
||||
reference_context: torch.Tensor,
|
||||
*,
|
||||
video_vae: Any,
|
||||
strength: float = SOFT_REANCHOR_STRENGTH,
|
||||
) -> tuple[torch.Tensor, dict[str, Any]]:
|
||||
"""Decode/adjust/encode one temporary context copy without mutating inputs."""
|
||||
|
||||
if not torch.is_tensor(current_context) or current_context.ndim != 5:
|
||||
raise ValueError("current_context must be [B,C,T,H,W]")
|
||||
if not torch.is_tensor(reference_context) or reference_context.ndim != 5:
|
||||
raise ValueError("reference_context must be [B,C,T,H,W]")
|
||||
if tuple(current_context.shape) != tuple(reference_context.shape):
|
||||
raise ValueError("current/reference latent context shapes must match")
|
||||
if int(current_context.shape[0]) != 1:
|
||||
raise ValueError("R2.7 diagnostic expects a single context batch")
|
||||
if not callable(getattr(video_vae, "decode", None)) or not callable(
|
||||
getattr(video_vae, "encode", None)
|
||||
):
|
||||
raise ValueError("R2.7 Soft Re-anchor requires the connected Video VAE")
|
||||
|
||||
current_guard = current_context.detach().clone()
|
||||
reference_guard = reference_context.detach().clone()
|
||||
reference_pixels = video_vae.decode(reference_context)
|
||||
current_pixels = video_vae.decode(current_context)
|
||||
adjusted_pixels, appearance = soft_match_rgb_appearance(
|
||||
current_pixels,
|
||||
reference_pixels,
|
||||
strength=strength,
|
||||
)
|
||||
encoded = video_vae.encode(adjusted_pixels[0])
|
||||
if not torch.is_tensor(encoded) or tuple(encoded.shape) != tuple(current_context.shape):
|
||||
raise ValueError(
|
||||
"Soft Re-anchor VAE roundtrip changed the continuation latent shape: "
|
||||
f"{getattr(encoded, 'shape', None)} vs {tuple(current_context.shape)}"
|
||||
)
|
||||
encoded = encoded.to(
|
||||
device=current_context.device,
|
||||
dtype=current_context.dtype,
|
||||
).contiguous()
|
||||
if not bool(torch.isfinite(encoded.float()).all().item()):
|
||||
raise ValueError("Soft Re-anchor encoded context contains NaN or Inf")
|
||||
appearance.update(
|
||||
{
|
||||
"current_context_unchanged": bool(torch.equal(current_context, current_guard)),
|
||||
"reference_context_unchanged": bool(
|
||||
torch.equal(reference_context, reference_guard)
|
||||
),
|
||||
"latent_shape_unchanged": tuple(encoded.shape)
|
||||
== tuple(current_context.shape),
|
||||
}
|
||||
)
|
||||
return encoded, appearance
|
||||
@@ -1,29 +1,29 @@
|
||||
param(
|
||||
[string]$ComfyUIRoot = 'D:\StabilityMatrix\Data\Packages\ComfyUI_W'
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$source = Join-Path $PSScriptRoot 'gpu_diagnostic_node'
|
||||
$customNodes = Join-Path $ComfyUIRoot 'custom_nodes'
|
||||
$destination = Join-Path $customNodes 'H3_Continuum_GPU_Diagnostics'
|
||||
|
||||
if (-not (Test-Path -LiteralPath $source -PathType Container)) {
|
||||
throw "Diagnostic source was not found: $source"
|
||||
}
|
||||
if (-not (Test-Path -LiteralPath $customNodes -PathType Container)) {
|
||||
throw "ComfyUI custom_nodes directory was not found: $customNodes"
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Path $destination -Force | Out-Null
|
||||
foreach ($name in @('__init__.py', 'capture.py', 'nodes.py', 'README.md')) {
|
||||
Copy-Item -LiteralPath (Join-Path $source $name) -Destination (Join-Path $destination $name) -Force
|
||||
}
|
||||
|
||||
$sourceCount = (Get-ChildItem -LiteralPath $source -File).Count
|
||||
$destinationCount = (Get-ChildItem -LiteralPath $destination -File).Count
|
||||
if ($destinationCount -lt $sourceCount) {
|
||||
throw "Diagnostic install verification failed: $destinationCount < $sourceCount"
|
||||
}
|
||||
|
||||
Write-Output "Installed standalone diagnostics: $destination"
|
||||
Write-Output 'Restart ComfyUI before using the diagnostic node.'
|
||||
param(
|
||||
[string]$ComfyUIRoot = 'D:\StabilityMatrix\Data\Packages\ComfyUI_W'
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$source = Join-Path $PSScriptRoot 'gpu_diagnostic_node'
|
||||
$customNodes = Join-Path $ComfyUIRoot 'custom_nodes'
|
||||
$destination = Join-Path $customNodes 'H3_Continuum_GPU_Diagnostics'
|
||||
|
||||
if (-not (Test-Path -LiteralPath $source -PathType Container)) {
|
||||
throw "Diagnostic source was not found: $source"
|
||||
}
|
||||
if (-not (Test-Path -LiteralPath $customNodes -PathType Container)) {
|
||||
throw "ComfyUI custom_nodes directory was not found: $customNodes"
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Path $destination -Force | Out-Null
|
||||
foreach ($name in @('__init__.py', 'capture.py', 'nodes.py', 'README.md')) {
|
||||
Copy-Item -LiteralPath (Join-Path $source $name) -Destination (Join-Path $destination $name) -Force
|
||||
}
|
||||
|
||||
$sourceCount = (Get-ChildItem -LiteralPath $source -File).Count
|
||||
$destinationCount = (Get-ChildItem -LiteralPath $destination -File).Count
|
||||
if ($destinationCount -lt $sourceCount) {
|
||||
throw "Diagnostic install verification failed: $destinationCount < $sourceCount"
|
||||
}
|
||||
|
||||
Write-Output "Installed standalone diagnostics: $destination"
|
||||
Write-Output 'Restart ComfyUI before using the diagnostic node.'
|
||||
|
||||
@@ -0,0 +1,408 @@
|
||||
"""Run the staged Issue #13 R2.5 cause-isolation GPU gate.
|
||||
|
||||
This is evidence tooling only. It uses the external diagnostic node and keeps
|
||||
the Production sampler, conditioning, Run Storage, and assembly code intact.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
from p32_api_runner import submit_and_wait
|
||||
|
||||
|
||||
TURBO_LORA = "minimax\\minimax_h3_fl2v_turbo_4step_v1.0_768p_comfyui_bf16.safetensors"
|
||||
MOTION_BOOSTER_LORA = "minimax\\H3_Motion_BoosterV2.safetensors"
|
||||
MOTION_REPAIR_LORA = "minimax\\Motion_Repair.safetensors"
|
||||
|
||||
CASE_SPECS = {
|
||||
"screen_3x5_turbo": {"chunks": 3, "chunk_seconds": 5.0, "steps": 8, "profile": "turbo"},
|
||||
"screen_3x10_turbo": {"chunks": 3, "chunk_seconds": 10.0, "steps": 8, "profile": "turbo"},
|
||||
"screen_6x5_turbo": {"chunks": 6, "chunk_seconds": 5.0, "steps": 8, "profile": "turbo"},
|
||||
"screen_6x5_turbo_fixed_prompt": {
|
||||
"chunks": 6,
|
||||
"chunk_seconds": 5.0,
|
||||
"steps": 8,
|
||||
"profile": "turbo",
|
||||
"fixed_prompt": True,
|
||||
},
|
||||
"screen_6x5_turbo_fixed_prefix": {
|
||||
"chunks": 6,
|
||||
"chunk_seconds": 5.0,
|
||||
"steps": 8,
|
||||
"profile": "turbo",
|
||||
"fixed_prompt": True,
|
||||
"continuation_source_mode": "Fixed Group 1 Tail",
|
||||
},
|
||||
"screen_6x5_turbo_soft_reanchor": {
|
||||
"chunks": 6,
|
||||
"chunk_seconds": 5.0,
|
||||
"steps": 8,
|
||||
"profile": "turbo",
|
||||
"fixed_prompt": True,
|
||||
"continuation_source_mode": "Soft Re-anchor Group 4",
|
||||
},
|
||||
"extend_4x10_turbo": {"chunks": 4, "chunk_seconds": 10.0, "steps": 8, "profile": "turbo"},
|
||||
"extend_5x10_turbo": {"chunks": 5, "chunk_seconds": 10.0, "steps": 8, "profile": "turbo"},
|
||||
"extend_6x10_turbo": {"chunks": 6, "chunk_seconds": 10.0, "steps": 8, "profile": "turbo"},
|
||||
"motion_off_3x5_normal": {"chunks": 3, "chunk_seconds": 5.0, "steps": 20, "profile": "motion_off"},
|
||||
"motion_both_3x5_normal": {"chunks": 3, "chunk_seconds": 5.0, "steps": 20, "profile": "motion_both"},
|
||||
"motion_booster_3x5_normal": {"chunks": 3, "chunk_seconds": 5.0, "steps": 20, "profile": "motion_booster"},
|
||||
"motion_repair_3x5_normal": {"chunks": 3, "chunk_seconds": 5.0, "steps": 20, "profile": "motion_repair"},
|
||||
}
|
||||
|
||||
PROMPT_ACTIONS = (
|
||||
"She holds a calm gaze while a light breeze moves a few strands of hair and a thin curl of smoke rises.",
|
||||
"Her eyes shift gently toward the camera as her cigarette hand lifts slightly and her hair moves in the breeze.",
|
||||
"She blinks and turns her head a little while a strand of hair brushes her cheek and the smoke curls upward.",
|
||||
"Her shoulders settle into a subtly different pose as the cigarette lowers slightly and her bangs move softly.",
|
||||
"She looks just past the camera and then back while the smoke disperses and the movement of her hair continues.",
|
||||
"She returns to a steady gaze with her cigarette hand near her shoulder and her hair settling naturally.",
|
||||
)
|
||||
|
||||
DIAGNOSTIC_MARKER = "V3.6-R1 diagnostic: "
|
||||
|
||||
|
||||
def _prompt(action: str, *, motion_trigger: bool) -> str:
|
||||
trigger = "dynv2, " if motion_trigger else ""
|
||||
return (
|
||||
"integrated_multimodal_description: [Shot 1] "
|
||||
f"{trigger}Live-action close-up of the same blonde woman at a Route 66 gas station, "
|
||||
"wearing the same white lace camisole and holding the same cigarette. "
|
||||
"The camera remains static, the daylight exposure stays stable, and her natural skin texture, facial features, clothing, and background remain consistent. "
|
||||
f"{action}\n\n"
|
||||
"overall_soundscape: A soft outdoor breeze, distant road ambience, and faint fabric and hair movement remain audible.\n\n"
|
||||
"non_diegetic_music: N/A"
|
||||
)
|
||||
|
||||
|
||||
def _prompt_list(
|
||||
chunks: int, *, motion_trigger: bool, fixed_prompt: bool = False
|
||||
) -> str:
|
||||
if fixed_prompt:
|
||||
return "\n---\n".join(
|
||||
_prompt(PROMPT_ACTIONS[0], motion_trigger=motion_trigger)
|
||||
for _ in range(int(chunks))
|
||||
)
|
||||
indices = (0, 2, 4) if int(chunks) == 3 else tuple(range(int(chunks)))
|
||||
return "\n---\n".join(
|
||||
_prompt(PROMPT_ACTIONS[index], motion_trigger=motion_trigger)
|
||||
for index in indices
|
||||
)
|
||||
|
||||
|
||||
def _configure_loras(loader_inputs: dict, profile: str) -> list[dict]:
|
||||
for name, value in list(loader_inputs.items()):
|
||||
if name.startswith("lora_") and isinstance(value, dict):
|
||||
value["on"] = False
|
||||
|
||||
selected: list[dict] = []
|
||||
|
||||
def set_slot(slot: int, name: str, strength: float = 1.0) -> None:
|
||||
loader_inputs[f"lora_{slot}"] = {
|
||||
"on": True,
|
||||
"lora": name,
|
||||
"strength": float(strength),
|
||||
}
|
||||
selected.append({"name": name, "strength": float(strength)})
|
||||
|
||||
if profile == "turbo":
|
||||
set_slot(1, TURBO_LORA)
|
||||
elif profile == "motion_both":
|
||||
set_slot(1, MOTION_BOOSTER_LORA)
|
||||
set_slot(2, MOTION_REPAIR_LORA)
|
||||
elif profile == "motion_booster":
|
||||
set_slot(1, MOTION_BOOSTER_LORA)
|
||||
elif profile == "motion_repair":
|
||||
set_slot(1, MOTION_REPAIR_LORA)
|
||||
elif profile != "motion_off":
|
||||
raise ValueError(f"unknown LoRA profile: {profile}")
|
||||
return selected
|
||||
|
||||
|
||||
def configure_prompt(
|
||||
source: dict,
|
||||
*,
|
||||
case: str,
|
||||
output_prefix: str,
|
||||
image_name: str,
|
||||
seed: int,
|
||||
width: int,
|
||||
height: int,
|
||||
diagnostic_nonce: int,
|
||||
) -> tuple[dict, list[dict]]:
|
||||
if case not in CASE_SPECS:
|
||||
raise ValueError(f"unknown Issue #13 R2.5 case: {case}")
|
||||
spec = CASE_SPECS[case]
|
||||
chunks = int(spec["chunks"])
|
||||
chunk_seconds = float(spec["chunk_seconds"])
|
||||
profile = str(spec["profile"])
|
||||
prompt = copy.deepcopy(source)
|
||||
|
||||
sampler = prompt["305"]
|
||||
sampler["class_type"] = "H3ContinuumMaskedPrefixR1Diagnostic"
|
||||
sampler["_meta"] = {"title": f"Issue #13 R2.5 Diagnostic — {case}"}
|
||||
inputs = sampler["inputs"]
|
||||
inputs.update(
|
||||
{
|
||||
"prompt_mode": "List",
|
||||
"chunks": chunks,
|
||||
"chunk_seconds": chunk_seconds,
|
||||
"width": int(width),
|
||||
"height": int(height),
|
||||
"continuity": "Balanced — 22 frames",
|
||||
"base_seed": int(seed),
|
||||
"audio_continuity": True,
|
||||
"diagnostics": "Detailed Report",
|
||||
"reroll_from_chunk": "Auto",
|
||||
"reroll_nonce": 0,
|
||||
"strict_compatibility": False,
|
||||
"debug": False,
|
||||
"show_preview": False,
|
||||
"run_storage": "Off",
|
||||
"run_name": "",
|
||||
"project_id": "",
|
||||
"continuation_transport": "masked_av_prefix_22_v1",
|
||||
"synchronize_sampling": True,
|
||||
"diagnostic_nonce": int(diagnostic_nonce),
|
||||
"continuation_source_mode": str(
|
||||
spec.get("continuation_source_mode", "Recursive")
|
||||
),
|
||||
"first_frame": ["119", 0],
|
||||
}
|
||||
)
|
||||
for key in (
|
||||
"continuation_backend",
|
||||
"generation_mode",
|
||||
"review_action",
|
||||
"max_new_physical_groups",
|
||||
"aspect",
|
||||
"preset",
|
||||
"custom_mp",
|
||||
"guide",
|
||||
"last_frame",
|
||||
):
|
||||
inputs.pop(key, None)
|
||||
|
||||
motion_profile = profile.startswith("motion_")
|
||||
prompt["188"]["inputs"]["value"] = _prompt_list(
|
||||
chunks,
|
||||
motion_trigger=motion_profile,
|
||||
fixed_prompt=bool(spec.get("fixed_prompt", False)),
|
||||
)
|
||||
prompt["114"]["inputs"]["image"] = str(image_name)
|
||||
prompt["139"]["inputs"]["sampler_name"] = "euler"
|
||||
prompt["153"]["inputs"].update(
|
||||
{"scheduler": "simple", "steps": int(spec["steps"]), "denoise": 1.0}
|
||||
)
|
||||
prompt["297"]["inputs"]["value"] = max(
|
||||
0.05, (float(width) * float(height)) / 1_000_000.0
|
||||
)
|
||||
prompt["306"]["inputs"].update(
|
||||
{
|
||||
"exact_total_duration": True,
|
||||
"audio_seam": "Off",
|
||||
"video_seam": "Off",
|
||||
"buffer_backend": "Auto",
|
||||
"diagnostics": "Detailed Report",
|
||||
}
|
||||
)
|
||||
prompt["191"]["inputs"]["filename_prefix"] = str(output_prefix)
|
||||
prompt["249"]["inputs"]["source"] = ["305", 3]
|
||||
|
||||
spectrum = prompt.get("150", {}).get("inputs", {})
|
||||
if spectrum:
|
||||
spectrum["enabled"] = False
|
||||
selected_loras = _configure_loras(prompt["286"]["inputs"], profile)
|
||||
return prompt, selected_loras
|
||||
|
||||
|
||||
def _relative_lora_path(name: str) -> Path:
|
||||
return Path(*str(name).replace("\\", "/").split("/"))
|
||||
|
||||
|
||||
def _inventory_loras(lora_root: Path, selected: list[dict]) -> list[dict]:
|
||||
inventory = []
|
||||
for item in selected:
|
||||
path = lora_root / _relative_lora_path(str(item["name"]))
|
||||
if not path.is_file():
|
||||
raise FileNotFoundError(f"required LoRA is missing: {path}")
|
||||
inventory.append(
|
||||
{
|
||||
**item,
|
||||
"path": str(path),
|
||||
"bytes": path.stat().st_size,
|
||||
"sha256": hashlib.sha256(path.read_bytes()).hexdigest(),
|
||||
}
|
||||
)
|
||||
return inventory
|
||||
|
||||
|
||||
def _output_video(history: dict, prompt_id: str) -> dict | None:
|
||||
entry = history.get(str(prompt_id), {})
|
||||
outputs = entry.get("outputs", {}) if isinstance(entry, dict) else {}
|
||||
save = outputs.get("191", {}) if isinstance(outputs, dict) else {}
|
||||
images = save.get("images", []) if isinstance(save, dict) else []
|
||||
return images[0] if images else None
|
||||
|
||||
|
||||
def _status_text(history: dict, prompt_id: str) -> str:
|
||||
entry = history.get(str(prompt_id), {})
|
||||
outputs = entry.get("outputs", {}) if isinstance(entry, dict) else {}
|
||||
preview = outputs.get("249", {}) if isinstance(outputs, dict) else {}
|
||||
values = preview.get("text", []) if isinstance(preview, dict) else []
|
||||
return str(values[0]) if values else ""
|
||||
|
||||
|
||||
def _diagnostic_from_status(status: str) -> dict:
|
||||
if DIAGNOSTIC_MARKER not in status:
|
||||
raise RuntimeError("Issue #13 R2.5 diagnostic marker is missing")
|
||||
value = json.loads(status.rsplit(DIAGNOSTIC_MARKER, 1)[1].strip())
|
||||
if not isinstance(value, dict):
|
||||
raise RuntimeError("Issue #13 R2.5 diagnostic payload is not an object")
|
||||
return value
|
||||
|
||||
|
||||
def run(args: argparse.Namespace) -> dict:
|
||||
source = json.loads(args.prompt.read_text(encoding="utf-8"))
|
||||
cases = list(
|
||||
args.cases
|
||||
or ("screen_3x5_turbo", "screen_3x10_turbo", "screen_6x5_turbo")
|
||||
)
|
||||
image_sha256 = hashlib.sha256(args.image_source.read_bytes()).hexdigest()
|
||||
args.output_root.mkdir(parents=True, exist_ok=True)
|
||||
summary_path = args.output_root / "summary.json"
|
||||
results = []
|
||||
if summary_path.exists():
|
||||
results = list(
|
||||
json.loads(summary_path.read_text(encoding="utf-8")).get("cases") or []
|
||||
)
|
||||
completed_cases = {str(item.get("case")) for item in results}
|
||||
|
||||
for offset, case in enumerate(cases):
|
||||
if case in completed_cases:
|
||||
print(f"ISSUE13-R25 SKIP completed case={case}", flush=True)
|
||||
continue
|
||||
configured, selected = configure_prompt(
|
||||
source,
|
||||
case=case,
|
||||
output_prefix=f"video/issue13_r25/Issue13_R25_{case}_seed{args.seed}",
|
||||
image_name=args.image_name,
|
||||
seed=args.seed,
|
||||
width=args.width,
|
||||
height=args.height,
|
||||
diagnostic_nonce=args.diagnostic_nonce + offset,
|
||||
)
|
||||
lora_inventory = _inventory_loras(args.lora_root, selected)
|
||||
case_root = args.output_root / case
|
||||
case_root.mkdir(parents=True, exist_ok=True)
|
||||
prompt_path = case_root / "prompt.json"
|
||||
prompt_path.write_text(
|
||||
json.dumps(configured, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
print(f"ISSUE13-R25 START case={case}", flush=True)
|
||||
prompt_id, history, elapsed = submit_and_wait(
|
||||
server=args.server,
|
||||
prompt=configured,
|
||||
client_id=f"issue13-r25-{uuid.uuid4().hex}",
|
||||
timeout_seconds=args.timeout_seconds,
|
||||
poll_seconds=3.0,
|
||||
)
|
||||
history_path = case_root / "history.json"
|
||||
history_path.write_text(
|
||||
json.dumps(history, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
status = _status_text(history, prompt_id)
|
||||
spec = CASE_SPECS[case]
|
||||
result = {
|
||||
"case": case,
|
||||
"chunks": int(spec["chunks"]),
|
||||
"chunk_seconds": float(spec["chunk_seconds"]),
|
||||
"profile": str(spec["profile"]),
|
||||
"steps": int(spec["steps"]),
|
||||
"sampler": "euler",
|
||||
"scheduler": "simple",
|
||||
"prompt_id": prompt_id,
|
||||
"api_elapsed_seconds": elapsed,
|
||||
"prompt": str(prompt_path),
|
||||
"history": str(history_path),
|
||||
"output_video": _output_video(history, prompt_id),
|
||||
"status_sha256": hashlib.sha256(status.encode("utf-8")).hexdigest(),
|
||||
"lora_inventory": lora_inventory,
|
||||
"diagnostic": _diagnostic_from_status(status),
|
||||
}
|
||||
(case_root / "summary.json").write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
results.append(result)
|
||||
summary = {
|
||||
"format": "h3-continuum-issue13-r25-gate-v1",
|
||||
"server": args.server,
|
||||
"source_prompt": str(args.prompt),
|
||||
"input_image": {
|
||||
"source": str(args.image_source),
|
||||
"runtime_name": args.image_name,
|
||||
"sha256": image_sha256,
|
||||
},
|
||||
"seed": int(args.seed),
|
||||
"width": int(args.width),
|
||||
"height": int(args.height),
|
||||
"sampler": "euler",
|
||||
"scheduler": "simple",
|
||||
"continuity": "Balanced — 22 frames",
|
||||
"audio_continuity": True,
|
||||
"transport": "masked_av_prefix_22_v1",
|
||||
"spectrum": False,
|
||||
"video_seam": "Off",
|
||||
"audio_seam": "Off",
|
||||
"cases": results,
|
||||
}
|
||||
summary_path.write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
print(
|
||||
f"ISSUE13-R25 COMPLETE case={case} prompt_id={prompt_id} elapsed={elapsed:.3f}s",
|
||||
flush=True,
|
||||
)
|
||||
return json.loads(summary_path.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def _parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8190")
|
||||
parser.add_argument("--prompt", type=Path, required=True)
|
||||
parser.add_argument("--output-root", type=Path, required=True)
|
||||
parser.add_argument("--image-source", type=Path, required=True)
|
||||
parser.add_argument("--image-name", required=True)
|
||||
parser.add_argument(
|
||||
"--lora-root",
|
||||
type=Path,
|
||||
default=Path(r"D:\StabilityMatrix\Data\Packages\ComfyUI_W\models\loras"),
|
||||
)
|
||||
parser.add_argument("--seed", type=int, default=131325)
|
||||
parser.add_argument("--width", type=int, default=576)
|
||||
parser.add_argument("--height", type=int, default=864)
|
||||
parser.add_argument("--diagnostic-nonce", type=int, default=132500)
|
||||
parser.add_argument("--timeout-seconds", type=float, default=7200.0)
|
||||
parser.add_argument("--cases", nargs="*", choices=tuple(CASE_SPECS))
|
||||
return parser
|
||||
|
||||
|
||||
def main() -> int:
|
||||
print(json.dumps(run(_parser().parse_args()), ensure_ascii=False))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,292 @@
|
||||
"""Compare Issue #13 R2.8 candidates with the accepted recursive 22f baseline."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import csv
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
import issue13_r2_analyze as base
|
||||
|
||||
|
||||
DRIFT_KEYS = (
|
||||
"saturation_mean",
|
||||
"contrast_p95_p05",
|
||||
"sharpness_laplacian_variance",
|
||||
"gradient_mean",
|
||||
"highlight_clip_fraction",
|
||||
"skin_highlight_proxy_fraction",
|
||||
)
|
||||
|
||||
|
||||
def _case_video(record: dict, video_root: Path) -> Path:
|
||||
value = record.get("output_video") or {}
|
||||
return video_root / str(value.get("subfolder", "")) / str(value.get("filename", ""))
|
||||
|
||||
|
||||
def _end_metrics(frames: list[np.ndarray], *, chunks: int, radius: int) -> list[dict]:
|
||||
rows = []
|
||||
for index in range(int(chunks)):
|
||||
stop = min(len(frames), int(round((index + 1) * len(frames) / chunks)))
|
||||
start = max(0, stop - int(radius))
|
||||
values = [base._frame_metrics(frame) for frame in frames[start:stop]]
|
||||
merged = {
|
||||
key: float(np.mean([item[key] for item in values])) for key in values[0]
|
||||
}
|
||||
merged.update(
|
||||
{
|
||||
"group": index + 1,
|
||||
"sample_start": start,
|
||||
"sample_end_exclusive": stop,
|
||||
"sample_count": stop - start,
|
||||
}
|
||||
)
|
||||
rows.append(merged)
|
||||
return rows
|
||||
|
||||
|
||||
def _face_crop(frame: np.ndarray) -> tuple[np.ndarray, str]:
|
||||
gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
|
||||
cascade = cv2.CascadeClassifier(
|
||||
cv2.data.haarcascades + "haarcascade_frontalface_default.xml"
|
||||
)
|
||||
faces = cascade.detectMultiScale(gray, scaleFactor=1.08, minNeighbors=5)
|
||||
if len(faces):
|
||||
x, y, width, height = max(faces, key=lambda box: int(box[2]) * int(box[3]))
|
||||
margin_x = int(round(width * 0.12))
|
||||
margin_y = int(round(height * 0.12))
|
||||
x0, y0 = max(0, x - margin_x), max(0, y - margin_y)
|
||||
x1 = min(frame.shape[1], x + width + margin_x)
|
||||
y1 = min(frame.shape[0], y + height + margin_y)
|
||||
return frame[y0:y1, x0:x1], "haar"
|
||||
height, width = frame.shape[:2]
|
||||
return frame[
|
||||
int(height * 0.08) : int(height * 0.68),
|
||||
int(width * 0.18) : int(width * 0.82),
|
||||
], "center_fallback"
|
||||
|
||||
|
||||
def _face_descriptor(frame: np.ndarray) -> tuple[np.ndarray, str]:
|
||||
crop, method = _face_crop(frame)
|
||||
gray = cv2.cvtColor(crop, cv2.COLOR_RGB2GRAY)
|
||||
gray = cv2.resize(gray, (64, 64), interpolation=cv2.INTER_AREA).astype(np.float32)
|
||||
gray = (gray - gray.mean()) / max(float(gray.std()), 1.0e-6)
|
||||
descriptor = cv2.dct(gray)[:16, :16].reshape(-1)[1:]
|
||||
descriptor /= max(float(np.linalg.norm(descriptor)), 1.0e-6)
|
||||
return descriptor, method
|
||||
|
||||
|
||||
def _identity_and_frame_difference(representatives: list[np.ndarray]) -> dict:
|
||||
descriptors = []
|
||||
methods = []
|
||||
crops = []
|
||||
for frame in representatives:
|
||||
descriptor, method = _face_descriptor(frame)
|
||||
crop, _ = _face_crop(frame)
|
||||
descriptors.append(descriptor)
|
||||
methods.append(method)
|
||||
crops.append(
|
||||
cv2.resize(crop, (128, 128), interpolation=cv2.INTER_AREA).astype(np.float32)
|
||||
/ 255.0
|
||||
)
|
||||
reference = descriptors[0]
|
||||
similarities = [float((np.dot(reference, value) + 1.0) * 0.5) for value in descriptors]
|
||||
adjacent_mae = [
|
||||
float(np.abs(crops[index] - crops[index - 1]).mean())
|
||||
for index in range(1, len(crops))
|
||||
]
|
||||
return {
|
||||
"contract": "face-structure DCT similarity proxy; not a biometric identity score",
|
||||
"crop_methods": methods,
|
||||
"group1_similarity": similarities,
|
||||
"group1_to_group6_similarity": similarities[-1],
|
||||
"adjacent_face_frame_mae": adjacent_mae,
|
||||
"mean_adjacent_face_frame_mae": float(np.mean(adjacent_mae)),
|
||||
}
|
||||
|
||||
|
||||
def _metric_comparison(baseline: dict, candidate: dict) -> dict:
|
||||
metrics = {}
|
||||
reductions = []
|
||||
for key in DRIFT_KEYS:
|
||||
baseline_trend = baseline["end_trend"][key]
|
||||
candidate_trend = candidate["end_trend"][key]
|
||||
baseline_delta = float(baseline_trend["last_minus_first"])
|
||||
candidate_delta = float(candidate_trend["last_minus_first"])
|
||||
baseline_slope = float(baseline_trend["linear_slope_per_chunk"])
|
||||
candidate_slope = float(candidate_trend["linear_slope_per_chunk"])
|
||||
reduction = None
|
||||
slope_reduction = None
|
||||
if baseline_delta > 0.0:
|
||||
reduction = (baseline_delta - candidate_delta) / baseline_delta * 100.0
|
||||
reductions.append(reduction)
|
||||
if baseline_slope > 0.0:
|
||||
slope_reduction = (
|
||||
(baseline_slope - candidate_slope) / baseline_slope * 100.0
|
||||
)
|
||||
metrics[key] = {
|
||||
"baseline_delta": baseline_delta,
|
||||
"candidate_delta": candidate_delta,
|
||||
"reduction_percent": reduction,
|
||||
"baseline_slope_per_continuation": baseline_slope,
|
||||
"candidate_slope_per_continuation": candidate_slope,
|
||||
"slope_reduction_percent": slope_reduction,
|
||||
"scored": baseline_delta > 0.0,
|
||||
}
|
||||
baseline_flow = float(
|
||||
np.mean(
|
||||
[
|
||||
row["trajectory_flow_discontinuity"]
|
||||
for row in baseline["boundary_metrics"]
|
||||
]
|
||||
)
|
||||
)
|
||||
candidate_flow = float(
|
||||
np.mean(
|
||||
[
|
||||
row["trajectory_flow_discontinuity"]
|
||||
for row in candidate["boundary_metrics"]
|
||||
]
|
||||
)
|
||||
)
|
||||
mean_reduction = float(np.mean(reductions)) if reductions else None
|
||||
sharpness_ok = (
|
||||
metrics["sharpness_laplacian_variance"]["candidate_delta"]
|
||||
<= metrics["sharpness_laplacian_variance"]["baseline_delta"]
|
||||
)
|
||||
gradient_ok = (
|
||||
metrics["gradient_mean"]["candidate_delta"]
|
||||
<= metrics["gradient_mean"]["baseline_delta"]
|
||||
)
|
||||
flow_ratio = candidate_flow / max(baseline_flow, 1.0e-9)
|
||||
numeric_promising = bool(
|
||||
mean_reduction is not None
|
||||
and mean_reduction >= 30.0
|
||||
and sharpness_ok
|
||||
and gradient_ok
|
||||
and flow_ratio <= 1.15
|
||||
)
|
||||
return {
|
||||
"metrics": metrics,
|
||||
"screening_mean_reduction_percent": mean_reduction,
|
||||
"screening_mean_contract": (
|
||||
"mean of baseline-positive drift indicators only; visual review remains required"
|
||||
),
|
||||
"sharpness_not_worse": sharpness_ok,
|
||||
"gradient_not_worse": gradient_ok,
|
||||
"baseline_mean_flow_discontinuity": baseline_flow,
|
||||
"candidate_mean_flow_discontinuity": candidate_flow,
|
||||
"flow_ratio": flow_ratio,
|
||||
"numeric_promising": numeric_promising,
|
||||
}
|
||||
|
||||
|
||||
def run(args: argparse.Namespace) -> dict:
|
||||
summary = json.loads((args.output_root / "summary.json").read_text(encoding="utf-8"))
|
||||
baseline_analysis = json.loads(args.baseline_analysis.read_text(encoding="utf-8"))
|
||||
baseline_key = args.baseline_case
|
||||
baseline_record = baseline_analysis["videos"][baseline_key]
|
||||
baseline_path = Path(baseline_record["path"])
|
||||
baseline_frames, baseline_fps = base._read_frames(baseline_path)
|
||||
baseline_center, baseline_representatives = base._chunk_metrics(
|
||||
baseline_frames, chunks=6, radius=args.radius
|
||||
)
|
||||
baseline_end = _end_metrics(baseline_frames, chunks=6, radius=args.end_radius)
|
||||
cases = {
|
||||
"baseline_22f_accepted": {
|
||||
"path": str(baseline_path),
|
||||
"fps": baseline_fps,
|
||||
"frame_count": len(baseline_frames),
|
||||
"center_metrics": baseline_center,
|
||||
"end_metrics": baseline_end,
|
||||
"end_trend": base._trend(baseline_end, base.METRIC_KEYS),
|
||||
"boundary_metrics": base._boundary_metrics(baseline_frames, chunks=6),
|
||||
"identity_and_frame_difference": _identity_and_frame_difference(
|
||||
baseline_representatives
|
||||
),
|
||||
}
|
||||
}
|
||||
sheet_rows = [("A accepted 22f", baseline_representatives)]
|
||||
end_csv_rows = []
|
||||
for row in baseline_end:
|
||||
end_csv_rows.append({"case": "baseline_22f_accepted", **row})
|
||||
|
||||
for record in summary["cases"]:
|
||||
case = str(record["case"])
|
||||
path = _case_video(record, args.video_root)
|
||||
frames, fps = base._read_frames(path)
|
||||
center, representatives = base._chunk_metrics(
|
||||
frames, chunks=6, radius=args.radius
|
||||
)
|
||||
end = _end_metrics(frames, chunks=6, radius=args.end_radius)
|
||||
cases[case] = {
|
||||
"path": str(path),
|
||||
"fps": fps,
|
||||
"frame_count": len(frames),
|
||||
"center_metrics": center,
|
||||
"end_metrics": end,
|
||||
"end_trend": base._trend(end, base.METRIC_KEYS),
|
||||
"boundary_metrics": base._boundary_metrics(frames, chunks=6),
|
||||
"identity_and_frame_difference": _identity_and_frame_difference(
|
||||
representatives
|
||||
),
|
||||
}
|
||||
sheet_rows.append((case, representatives))
|
||||
for row in end:
|
||||
end_csv_rows.append({"case": case, **row})
|
||||
|
||||
baseline = cases["baseline_22f_accepted"]
|
||||
comparisons = {
|
||||
case: _metric_comparison(baseline, value)
|
||||
for case, value in cases.items()
|
||||
if case != "baseline_22f_accepted"
|
||||
}
|
||||
csv_path = args.output_root / "group_end_metrics.csv"
|
||||
with csv_path.open("w", encoding="utf-8", newline="") as handle:
|
||||
writer = csv.DictWriter(handle, fieldnames=list(end_csv_rows[0]))
|
||||
writer.writeheader()
|
||||
writer.writerows(end_csv_rows)
|
||||
contact_path = args.output_root / "contact_sheet.png"
|
||||
base._contact_sheet(sheet_rows, contact_path)
|
||||
result = {
|
||||
"format": "h3-continuum-issue13-r28-analysis-v1",
|
||||
"baseline_analysis": str(args.baseline_analysis),
|
||||
"baseline_case": baseline_key,
|
||||
"cases": cases,
|
||||
"comparisons": comparisons,
|
||||
"group_end_metrics_csv": str(csv_path),
|
||||
"contact_sheet": str(contact_path),
|
||||
}
|
||||
output = args.output_root / "analysis.json"
|
||||
output.write_text(json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8")
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
return result
|
||||
|
||||
|
||||
def _parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--output-root", type=Path, required=True)
|
||||
parser.add_argument("--baseline-analysis", type=Path, required=True)
|
||||
parser.add_argument(
|
||||
"--baseline-case", default="screen_6x5_turbo_fixed_prompt"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--video-root", type=Path, default=Path(r"D:\output\video\comfy_video")
|
||||
)
|
||||
parser.add_argument("--radius", type=int, default=12)
|
||||
parser.add_argument("--end-radius", type=int, default=12)
|
||||
return parser
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run(_parser().parse_args())
|
||||
@@ -0,0 +1,258 @@
|
||||
"""Run the staged Issue #13 R2.8 continuation depth/strength GPU gate."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
import issue13_r25_gate_runner as r25
|
||||
from p32_api_runner import submit_and_wait
|
||||
|
||||
|
||||
CASE_SPECS = {
|
||||
"baseline_22f": {"experiment": "Baseline 22f"},
|
||||
"depth_13f": {"experiment": "Video Depth 13f"},
|
||||
"depth_9f": {"experiment": "Video Depth 9f"},
|
||||
"strength_75": {"experiment": "Video Strength 75%"},
|
||||
"depth_13f_strength_75": {
|
||||
"experiment": "Video Depth 13f + Strength 75%"
|
||||
},
|
||||
}
|
||||
|
||||
DIAGNOSTIC_MARKER = "R2.8 diagnostic: "
|
||||
|
||||
|
||||
def configure_prompt(
|
||||
source: dict,
|
||||
*,
|
||||
case: str,
|
||||
output_prefix: str,
|
||||
image_name: str,
|
||||
seed: int,
|
||||
width: int,
|
||||
height: int,
|
||||
diagnostic_nonce: int,
|
||||
) -> tuple[dict, list[dict]]:
|
||||
if case not in CASE_SPECS:
|
||||
raise ValueError(f"unknown Issue #13 R2.8 case: {case}")
|
||||
prompt = copy.deepcopy(source)
|
||||
sampler = prompt["305"]
|
||||
sampler["class_type"] = "H3ContinuumContinuationR28Diagnostic"
|
||||
sampler["_meta"] = {"title": f"Issue #13 R2.8 Diagnostic — {case}"}
|
||||
inputs = sampler["inputs"]
|
||||
inputs.update(
|
||||
{
|
||||
"prompt_mode": "List",
|
||||
"chunks": 6,
|
||||
"chunk_seconds": 5.0,
|
||||
"width": int(width),
|
||||
"height": int(height),
|
||||
"continuity": "Balanced — 22 frames",
|
||||
"base_seed": int(seed),
|
||||
"audio_continuity": True,
|
||||
"diagnostics": "Detailed Report",
|
||||
"reroll_from_chunk": "Auto",
|
||||
"reroll_nonce": 0,
|
||||
"strict_compatibility": False,
|
||||
"debug": False,
|
||||
"show_preview": False,
|
||||
"run_storage": "Off",
|
||||
"run_name": "",
|
||||
"project_id": "",
|
||||
"continuation_transport": "masked_av_prefix_22_v1",
|
||||
"continuation_experiment": CASE_SPECS[case]["experiment"],
|
||||
"diagnostic_nonce": int(diagnostic_nonce),
|
||||
"first_frame": ["119", 0],
|
||||
}
|
||||
)
|
||||
for key in (
|
||||
"continuation_backend",
|
||||
"continuation_source_mode",
|
||||
"synchronize_sampling",
|
||||
"generation_mode",
|
||||
"review_action",
|
||||
"max_new_physical_groups",
|
||||
"aspect",
|
||||
"preset",
|
||||
"custom_mp",
|
||||
"guide",
|
||||
"last_frame",
|
||||
):
|
||||
inputs.pop(key, None)
|
||||
|
||||
prompt["188"]["inputs"]["value"] = r25._prompt_list(
|
||||
6, motion_trigger=False, fixed_prompt=True
|
||||
)
|
||||
prompt["114"]["inputs"]["image"] = str(image_name)
|
||||
prompt["139"]["inputs"]["sampler_name"] = "euler"
|
||||
prompt["153"]["inputs"].update(
|
||||
{"scheduler": "simple", "steps": 8, "denoise": 1.0}
|
||||
)
|
||||
prompt["297"]["inputs"]["value"] = max(
|
||||
0.05, (float(width) * float(height)) / 1_000_000.0
|
||||
)
|
||||
prompt["306"]["inputs"].update(
|
||||
{
|
||||
"exact_total_duration": True,
|
||||
"audio_seam": "Off",
|
||||
"video_seam": "Off",
|
||||
"buffer_backend": "Auto",
|
||||
"diagnostics": "Detailed Report",
|
||||
}
|
||||
)
|
||||
prompt["191"]["inputs"]["filename_prefix"] = str(output_prefix)
|
||||
prompt["249"]["inputs"]["source"] = ["305", 3]
|
||||
spectrum = prompt.get("150", {}).get("inputs", {})
|
||||
if spectrum:
|
||||
spectrum["enabled"] = False
|
||||
selected = r25._configure_loras(prompt["286"]["inputs"], "turbo")
|
||||
return prompt, selected
|
||||
|
||||
|
||||
def _diagnostic_from_status(status: str) -> dict:
|
||||
if DIAGNOSTIC_MARKER not in status:
|
||||
raise RuntimeError("Issue #13 R2.8 diagnostic marker is missing")
|
||||
value = json.loads(status.rsplit(DIAGNOSTIC_MARKER, 1)[1].strip())
|
||||
if not isinstance(value, dict):
|
||||
raise RuntimeError("Issue #13 R2.8 diagnostic payload is not an object")
|
||||
return value
|
||||
|
||||
|
||||
def run(args: argparse.Namespace) -> dict:
|
||||
source = json.loads(args.prompt.read_text(encoding="utf-8"))
|
||||
cases = list(args.cases or ("depth_13f",))
|
||||
image_sha256 = hashlib.sha256(args.image_source.read_bytes()).hexdigest()
|
||||
args.output_root.mkdir(parents=True, exist_ok=True)
|
||||
summary_path = args.output_root / "summary.json"
|
||||
results = []
|
||||
if summary_path.exists():
|
||||
results = list(
|
||||
json.loads(summary_path.read_text(encoding="utf-8")).get("cases") or []
|
||||
)
|
||||
completed = {str(item.get("case")) for item in results}
|
||||
|
||||
for offset, case in enumerate(cases):
|
||||
if case in completed:
|
||||
print(f"ISSUE13-R28 SKIP completed case={case}", flush=True)
|
||||
continue
|
||||
configured, selected = configure_prompt(
|
||||
source,
|
||||
case=case,
|
||||
output_prefix=f"video/issue13_r28/Issue13_R28_{case}_seed{args.seed}",
|
||||
image_name=args.image_name,
|
||||
seed=args.seed,
|
||||
width=args.width,
|
||||
height=args.height,
|
||||
diagnostic_nonce=args.diagnostic_nonce + offset,
|
||||
)
|
||||
inventory = r25._inventory_loras(args.lora_root, selected)
|
||||
case_root = args.output_root / case
|
||||
case_root.mkdir(parents=True, exist_ok=True)
|
||||
prompt_path = case_root / "prompt.json"
|
||||
prompt_path.write_text(
|
||||
json.dumps(configured, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
print(f"ISSUE13-R28 START case={case}", flush=True)
|
||||
prompt_id, history, elapsed = submit_and_wait(
|
||||
server=args.server,
|
||||
prompt=configured,
|
||||
client_id=f"issue13-r28-{uuid.uuid4().hex}",
|
||||
timeout_seconds=args.timeout_seconds,
|
||||
poll_seconds=3.0,
|
||||
)
|
||||
history_path = case_root / "history.json"
|
||||
history_path.write_text(
|
||||
json.dumps(history, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
status = r25._status_text(history, prompt_id)
|
||||
result = {
|
||||
"case": case,
|
||||
"chunks": 6,
|
||||
"chunk_seconds": 5.0,
|
||||
"profile": "turbo",
|
||||
"steps": 8,
|
||||
"sampler": "euler",
|
||||
"scheduler": "simple",
|
||||
"prompt_id": prompt_id,
|
||||
"api_elapsed_seconds": float(elapsed),
|
||||
"prompt": str(prompt_path),
|
||||
"history": str(history_path),
|
||||
"output_video": r25._output_video(history, prompt_id),
|
||||
"status_sha256": hashlib.sha256(status.encode("utf-8")).hexdigest(),
|
||||
"lora_inventory": inventory,
|
||||
"diagnostic": _diagnostic_from_status(status),
|
||||
}
|
||||
(case_root / "summary.json").write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
results.append(result)
|
||||
summary = {
|
||||
"format": "h3-continuum-issue13-r28-gate-v1",
|
||||
"server": args.server,
|
||||
"source_prompt": str(args.prompt),
|
||||
"baseline_summary": str(args.baseline_summary)
|
||||
if args.baseline_summary
|
||||
else None,
|
||||
"input_image": {
|
||||
"source": str(args.image_source),
|
||||
"runtime_name": args.image_name,
|
||||
"sha256": image_sha256,
|
||||
},
|
||||
"seed": int(args.seed),
|
||||
"width": int(args.width),
|
||||
"height": int(args.height),
|
||||
"sampler": "euler",
|
||||
"scheduler": "simple",
|
||||
"continuity_transport": "Balanced 22f / masked_av_prefix_22_v1",
|
||||
"audio_continuity": True,
|
||||
"cases": results,
|
||||
}
|
||||
summary_path.write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
print(
|
||||
f"ISSUE13-R28 COMPLETE case={case} prompt_id={prompt_id} elapsed={elapsed:.3f}s",
|
||||
flush=True,
|
||||
)
|
||||
return json.loads(summary_path.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def _parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8190")
|
||||
parser.add_argument("--prompt", type=Path, required=True)
|
||||
parser.add_argument("--output-root", type=Path, required=True)
|
||||
parser.add_argument("--image-source", type=Path, required=True)
|
||||
parser.add_argument("--image-name", required=True)
|
||||
parser.add_argument("--baseline-summary", type=Path)
|
||||
parser.add_argument(
|
||||
"--lora-root",
|
||||
type=Path,
|
||||
default=Path(r"D:\StabilityMatrix\Data\Packages\ComfyUI_W\models\loras"),
|
||||
)
|
||||
parser.add_argument("--seed", type=int, default=131325)
|
||||
parser.add_argument("--width", type=int, default=576)
|
||||
parser.add_argument("--height", type=int, default=864)
|
||||
parser.add_argument("--diagnostic-nonce", type=int, default=132800)
|
||||
parser.add_argument("--timeout-seconds", type=float, default=7200.0)
|
||||
parser.add_argument("--cases", nargs="*", choices=tuple(CASE_SPECS))
|
||||
return parser
|
||||
|
||||
|
||||
def main() -> int:
|
||||
print(json.dumps(run(_parser().parse_args()), ensure_ascii=False))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,462 @@
|
||||
"""Analyze Issue #13 R2 decoded video and continuation-latent trends."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import csv
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
|
||||
METRIC_KEYS = (
|
||||
"luma_mean",
|
||||
"luma_std",
|
||||
"saturation_mean",
|
||||
"saturation_p95",
|
||||
"contrast_p95_p05",
|
||||
"sharpness_laplacian_variance",
|
||||
"gradient_mean",
|
||||
"highlight_clip_fraction",
|
||||
"skin_highlight_proxy_fraction",
|
||||
"shadow_clip_fraction",
|
||||
)
|
||||
|
||||
LATENT_KEYS = (
|
||||
"mean",
|
||||
"std",
|
||||
"rms",
|
||||
"minimum",
|
||||
"maximum",
|
||||
"temporal_delta_rms",
|
||||
)
|
||||
|
||||
|
||||
def _video_path(record: dict, video_root: Path) -> Path:
|
||||
item = record.get("output_video") or {}
|
||||
return video_root / str(item.get("subfolder", "")) / str(item.get("filename", ""))
|
||||
|
||||
|
||||
def _read_frames(path: Path) -> tuple[list[np.ndarray], float]:
|
||||
capture = cv2.VideoCapture(str(path))
|
||||
if not capture.isOpened():
|
||||
raise RuntimeError(f"cannot open video: {path}")
|
||||
fps = float(capture.get(cv2.CAP_PROP_FPS) or 24.0)
|
||||
frames = []
|
||||
while True:
|
||||
ok, frame = capture.read()
|
||||
if not ok:
|
||||
break
|
||||
frames.append(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
|
||||
capture.release()
|
||||
if not frames:
|
||||
raise RuntimeError(f"video contains no frames: {path}")
|
||||
return frames, fps
|
||||
|
||||
|
||||
def _frame_metrics(frame: np.ndarray) -> dict[str, float]:
|
||||
rgb = frame.astype(np.float32) / 255.0
|
||||
y = 0.2126 * rgb[..., 0] + 0.7152 * rgb[..., 1] + 0.0722 * rgb[..., 2]
|
||||
hsv = cv2.cvtColor(frame, cv2.COLOR_RGB2HSV).astype(np.float32)
|
||||
saturation = hsv[..., 1] / 255.0
|
||||
gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
|
||||
laplacian = cv2.Laplacian(gray, cv2.CV_64F)
|
||||
sobel_x = cv2.Sobel(gray, cv2.CV_32F, 1, 0, ksize=3)
|
||||
sobel_y = cv2.Sobel(gray, cv2.CV_32F, 0, 1, ksize=3)
|
||||
gradient = cv2.magnitude(sobel_x, sobel_y) / 255.0
|
||||
ycrcb = cv2.cvtColor(frame, cv2.COLOR_RGB2YCrCb)
|
||||
skin_mask = (
|
||||
(ycrcb[..., 1] >= 133)
|
||||
& (ycrcb[..., 1] <= 173)
|
||||
& (ycrcb[..., 2] >= 77)
|
||||
& (ycrcb[..., 2] <= 127)
|
||||
)
|
||||
skin_count = int(np.count_nonzero(skin_mask))
|
||||
skin_highlight = (
|
||||
float(np.count_nonzero(skin_mask & (y >= (220.0 / 255.0))))
|
||||
/ float(skin_count)
|
||||
if skin_count
|
||||
else 0.0
|
||||
)
|
||||
return {
|
||||
"luma_mean": float(np.mean(y)),
|
||||
"luma_std": float(np.std(y)),
|
||||
"red_mean": float(np.mean(rgb[..., 0])),
|
||||
"green_mean": float(np.mean(rgb[..., 1])),
|
||||
"blue_mean": float(np.mean(rgb[..., 2])),
|
||||
"saturation_mean": float(np.mean(saturation)),
|
||||
"saturation_p95": float(np.percentile(saturation, 95)),
|
||||
"contrast_p95_p05": float(np.percentile(y, 95) - np.percentile(y, 5)),
|
||||
"sharpness_laplacian_variance": float(np.var(laplacian)),
|
||||
"gradient_mean": float(np.mean(gradient)),
|
||||
"highlight_clip_fraction": float(np.mean(y >= (250.0 / 255.0))),
|
||||
"skin_highlight_proxy_fraction": skin_highlight,
|
||||
"shadow_clip_fraction": float(np.mean(y <= (5.0 / 255.0))),
|
||||
}
|
||||
|
||||
|
||||
def _chunk_metrics(
|
||||
frames: list[np.ndarray], *, chunks: int, radius: int
|
||||
) -> tuple[list[dict], list[np.ndarray]]:
|
||||
frame_count = len(frames)
|
||||
rows = []
|
||||
representatives = []
|
||||
for index in range(chunks):
|
||||
center = int(round((index + 0.5) * frame_count / chunks))
|
||||
center = min(max(center, 0), frame_count - 1)
|
||||
start = max(0, center - radius)
|
||||
end = min(frame_count, center + radius + 1)
|
||||
values = [_frame_metrics(frame) for frame in frames[start:end]]
|
||||
merged = {
|
||||
key: float(np.mean([item[key] for item in values])) for key in values[0]
|
||||
}
|
||||
merged.update(
|
||||
{
|
||||
"chunk": index + 1,
|
||||
"center_frame": center,
|
||||
"sample_start": start,
|
||||
"sample_end_exclusive": end,
|
||||
"sample_count": end - start,
|
||||
}
|
||||
)
|
||||
rows.append(merged)
|
||||
representatives.append(frames[center])
|
||||
return rows, representatives
|
||||
|
||||
|
||||
def _normalized_histogram(values: np.ndarray, *, bins: int = 16) -> list[float]:
|
||||
counts, _ = np.histogram(values, bins=bins, range=(0.0, 1.0))
|
||||
total = int(counts.sum())
|
||||
if total <= 0:
|
||||
return [0.0] * int(bins)
|
||||
return [float(value) / float(total) for value in counts]
|
||||
|
||||
|
||||
def _continuation_input_rgb_proxy(
|
||||
frames: list[np.ndarray], *, chunks: int, context_frames: int
|
||||
) -> dict:
|
||||
"""Measure decoded source frames immediately before each chunk boundary.
|
||||
|
||||
The R2 diagnostic separately proves that each source latent tail is copied
|
||||
bit-exactly into the following target prefix. This read-only decoded window
|
||||
is therefore a visual proxy; it does not add a VAE decode to Sampling.
|
||||
"""
|
||||
|
||||
boundaries = []
|
||||
frame_count = len(frames)
|
||||
for target_index in range(1, int(chunks)):
|
||||
boundary = int(round(target_index * frame_count / int(chunks)))
|
||||
boundary = min(max(boundary, 1), frame_count)
|
||||
start = max(0, boundary - int(context_frames))
|
||||
window = frames[start:boundary]
|
||||
values = [_frame_metrics(frame) for frame in window]
|
||||
merged = {
|
||||
key: float(np.mean([item[key] for item in values])) for key in values[0]
|
||||
}
|
||||
rgb = np.concatenate(
|
||||
[frame.astype(np.float32).reshape(-1, 3) / 255.0 for frame in window],
|
||||
axis=0,
|
||||
)
|
||||
luma = 0.2126 * rgb[:, 0] + 0.7152 * rgb[:, 1] + 0.0722 * rgb[:, 2]
|
||||
saturation = np.concatenate(
|
||||
[
|
||||
cv2.cvtColor(frame, cv2.COLOR_RGB2HSV)[..., 1]
|
||||
.reshape(-1)
|
||||
.astype(np.float32)
|
||||
/ 255.0
|
||||
for frame in window
|
||||
]
|
||||
)
|
||||
merged.update(
|
||||
{
|
||||
"source_group": target_index,
|
||||
"target_group": target_index + 1,
|
||||
"boundary_frame": boundary,
|
||||
"window_start": start,
|
||||
"window_end_exclusive": boundary,
|
||||
"window_frames": len(window),
|
||||
"histogram_bins": 16,
|
||||
"red_histogram": _normalized_histogram(rgb[:, 0]),
|
||||
"green_histogram": _normalized_histogram(rgb[:, 1]),
|
||||
"blue_histogram": _normalized_histogram(rgb[:, 2]),
|
||||
"luma_histogram": _normalized_histogram(luma),
|
||||
"saturation_histogram": _normalized_histogram(saturation),
|
||||
}
|
||||
)
|
||||
boundaries.append(merged)
|
||||
return {
|
||||
"contract": "decoded source-tail proxy; no extra VAE decode during Sampling",
|
||||
"context_frames": int(context_frames),
|
||||
"boundaries": boundaries,
|
||||
"trend": _trend(boundaries, METRIC_KEYS) if boundaries else {},
|
||||
}
|
||||
|
||||
|
||||
def _trend(rows: list[dict], keys: tuple[str, ...]) -> dict:
|
||||
x = np.arange(1, len(rows) + 1, dtype=np.float64)
|
||||
result = {}
|
||||
for key in keys:
|
||||
values = np.asarray([float(row[key]) for row in rows], dtype=np.float64)
|
||||
result[key] = {
|
||||
"first": float(values[0]),
|
||||
"last": float(values[-1]),
|
||||
"last_minus_first": float(values[-1] - values[0]),
|
||||
"linear_slope_per_chunk": float(np.polyfit(x, values, 1)[0])
|
||||
if len(values) > 1
|
||||
else 0.0,
|
||||
"increase_steps": int(np.count_nonzero(np.diff(values) > 0.0)),
|
||||
"decrease_steps": int(np.count_nonzero(np.diff(values) < 0.0)),
|
||||
}
|
||||
return result
|
||||
|
||||
|
||||
def _flow_mean(first: np.ndarray, second: np.ndarray) -> float:
|
||||
first_gray = cv2.cvtColor(first, cv2.COLOR_RGB2GRAY)
|
||||
second_gray = cv2.cvtColor(second, cv2.COLOR_RGB2GRAY)
|
||||
flow = cv2.calcOpticalFlowFarneback(
|
||||
first_gray,
|
||||
second_gray,
|
||||
None,
|
||||
0.5,
|
||||
3,
|
||||
15,
|
||||
3,
|
||||
5,
|
||||
1.2,
|
||||
0,
|
||||
)
|
||||
return float(np.linalg.norm(flow, axis=-1).mean())
|
||||
|
||||
|
||||
def _boundary_metrics(frames: list[np.ndarray], *, chunks: int) -> list[dict]:
|
||||
rows = []
|
||||
frame_count = len(frames)
|
||||
for target_index in range(1, int(chunks)):
|
||||
boundary = int(round(target_index * frame_count / int(chunks)))
|
||||
boundary = min(max(boundary, 2), frame_count - 2)
|
||||
before2, before, after, after2 = frames[
|
||||
boundary - 2
|
||||
], frames[boundary - 1], frames[boundary], frames[boundary + 1]
|
||||
before_float = before.astype(np.float32) / 255.0
|
||||
after_float = after.astype(np.float32) / 255.0
|
||||
before_metrics = _frame_metrics(before)
|
||||
after_metrics = _frame_metrics(after)
|
||||
flow_before = _flow_mean(before2, before)
|
||||
flow_boundary = _flow_mean(before, after)
|
||||
flow_after = _flow_mean(after, after2)
|
||||
local_flow = 0.5 * (flow_before + flow_after)
|
||||
rows.append(
|
||||
{
|
||||
"source_group": target_index,
|
||||
"target_group": target_index + 1,
|
||||
"boundary_frame": boundary,
|
||||
"frame_mae": float(np.abs(after_float - before_float).mean()),
|
||||
"luma_jump_abs": abs(
|
||||
after_metrics["luma_mean"] - before_metrics["luma_mean"]
|
||||
),
|
||||
"saturation_jump_abs": abs(
|
||||
after_metrics["saturation_mean"]
|
||||
- before_metrics["saturation_mean"]
|
||||
),
|
||||
"gradient_jump_abs": abs(
|
||||
after_metrics["gradient_mean"]
|
||||
- before_metrics["gradient_mean"]
|
||||
),
|
||||
"flow_before": flow_before,
|
||||
"flow_boundary": flow_boundary,
|
||||
"flow_after": flow_after,
|
||||
"trajectory_flow_discontinuity": abs(flow_boundary - local_flow)
|
||||
/ max(local_flow, 1.0e-6),
|
||||
}
|
||||
)
|
||||
return rows
|
||||
|
||||
|
||||
def _latent_trend(diagnostic: dict) -> dict:
|
||||
calls = list(diagnostic.get("sample_calls") or [])
|
||||
|
||||
def rows_for(name: str) -> list[dict]:
|
||||
rows = []
|
||||
for call in calls:
|
||||
value = call.get(name)
|
||||
if not isinstance(value, dict):
|
||||
continue
|
||||
row = {"sample_number": int(call.get("sample_number", len(rows) + 1))}
|
||||
for key in LATENT_KEYS:
|
||||
if value.get(key) is not None:
|
||||
row[key] = float(value[key])
|
||||
rows.append(row)
|
||||
return rows
|
||||
|
||||
streams = {}
|
||||
for name in ("input_video", "output_video", "output_tail", "source_tail"):
|
||||
rows = rows_for(name)
|
||||
available = tuple(key for key in LATENT_KEYS if rows and key in rows[0])
|
||||
streams[name] = {
|
||||
"rows": rows,
|
||||
"trend": _trend(rows, available) if rows and available else {},
|
||||
}
|
||||
prefix_pairs = list(diagnostic.get("final_prefix_pairs") or [])
|
||||
return {
|
||||
"streams": streams,
|
||||
"prefix_pair_count": len(prefix_pairs),
|
||||
"all_video_prefix_pairs_bit_exact": bool(prefix_pairs)
|
||||
and all(bool(pair.get("bit_exact")) for pair in prefix_pairs),
|
||||
"all_audio_prefix_pairs_bit_exact": bool(prefix_pairs)
|
||||
and all(bool(pair.get("audio_bit_exact")) for pair in prefix_pairs),
|
||||
"maximum_video_prefix_abs_diff": max(
|
||||
(float(pair.get("max_abs_diff", 0.0)) for pair in prefix_pairs),
|
||||
default=0.0,
|
||||
),
|
||||
"maximum_audio_prefix_abs_diff": max(
|
||||
(float(pair.get("audio_max_abs_diff", 0.0)) for pair in prefix_pairs),
|
||||
default=0.0,
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def _contact_sheet(
|
||||
rows: list[tuple[str, list[np.ndarray]]],
|
||||
output: Path,
|
||||
*,
|
||||
column_labels: list[str] | None = None,
|
||||
) -> None:
|
||||
thumb_w, thumb_h = 224, 224
|
||||
label_w, top_h = 240, 42
|
||||
columns = max((len(frames) for _, frames in rows), default=0)
|
||||
width = label_w + thumb_w * columns
|
||||
height = top_h + thumb_h * len(rows)
|
||||
sheet = Image.new("RGB", (width, height), (9, 15, 25))
|
||||
draw = ImageDraw.Draw(sheet)
|
||||
font = ImageFont.load_default()
|
||||
for column in range(columns):
|
||||
draw.text(
|
||||
(label_w + column * thumb_w + 8, 14),
|
||||
column_labels[column]
|
||||
if column_labels is not None and column < len(column_labels)
|
||||
else f"Chunk {column + 1}",
|
||||
fill=(210, 225, 245),
|
||||
font=font,
|
||||
)
|
||||
for row_index, (label, frames) in enumerate(rows):
|
||||
y = top_h + row_index * thumb_h
|
||||
draw.text((10, y + 16), label, fill=(115, 210, 255), font=font)
|
||||
for column, frame in enumerate(frames):
|
||||
image = Image.fromarray(frame).resize(
|
||||
(thumb_w, thumb_h), Image.Resampling.LANCZOS
|
||||
)
|
||||
sheet.paste(image, (label_w + column * thumb_w, y))
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
sheet.save(output)
|
||||
|
||||
|
||||
def _milestone_frames(
|
||||
frames: list[np.ndarray], *, chunks: int
|
||||
) -> tuple[list[str], list[np.ndarray]]:
|
||||
frame_count = len(frames)
|
||||
chunk_frames = frame_count / float(chunks)
|
||||
indices = [
|
||||
min(frame_count - 1, 12),
|
||||
min(frame_count - 1, max(0, int(round(3 * chunk_frames)) - 1)),
|
||||
min(frame_count - 1, int(round(3 * chunk_frames)) + 12),
|
||||
min(frame_count - 1, int(round(4.5 * chunk_frames))),
|
||||
frame_count - 1,
|
||||
]
|
||||
return (
|
||||
["Near 0s", "G3 end", "G4 post", "G5", "G6 end"],
|
||||
[frames[index] for index in indices],
|
||||
)
|
||||
|
||||
|
||||
def run(args: argparse.Namespace) -> dict:
|
||||
summary = json.loads((args.output_root / "summary.json").read_text(encoding="utf-8"))
|
||||
all_rows = []
|
||||
sheets = []
|
||||
milestone_sheets = []
|
||||
milestone_labels = None
|
||||
videos = {}
|
||||
for record in summary["cases"]:
|
||||
case = str(record["case"])
|
||||
chunks = int(record["chunks"])
|
||||
path = _video_path(record, args.video_root)
|
||||
frames, fps = _read_frames(path)
|
||||
metrics, representatives = _chunk_metrics(
|
||||
frames, chunks=chunks, radius=args.radius
|
||||
)
|
||||
for row in metrics:
|
||||
row["case"] = case
|
||||
row["video"] = str(path)
|
||||
row["fps"] = fps
|
||||
row["frame_count"] = len(frames)
|
||||
all_rows.append(row)
|
||||
sheets.append((case, representatives))
|
||||
labels, milestones = _milestone_frames(frames, chunks=chunks)
|
||||
milestone_labels = labels
|
||||
milestone_sheets.append((case, milestones))
|
||||
videos[case] = {
|
||||
"path": str(path),
|
||||
"sha256": hashlib.sha256(path.read_bytes()).hexdigest(),
|
||||
"fps": fps,
|
||||
"frame_count": len(frames),
|
||||
"duration_seconds": len(frames) / fps,
|
||||
"chunks": chunks,
|
||||
"chunk_seconds": float(record["chunk_seconds"]),
|
||||
"metrics": metrics,
|
||||
"decoded_trend": _trend(metrics, METRIC_KEYS),
|
||||
"continuation_input_rgb_proxy": _continuation_input_rgb_proxy(
|
||||
frames,
|
||||
chunks=chunks,
|
||||
context_frames=int(
|
||||
(record.get("diagnostic") or {}).get("context_frames", 22)
|
||||
),
|
||||
),
|
||||
"boundary_metrics": _boundary_metrics(frames, chunks=chunks),
|
||||
"latent_trend": _latent_trend(record.get("diagnostic") or {}),
|
||||
}
|
||||
|
||||
if not all_rows:
|
||||
raise RuntimeError("Issue #13 R2 summary contains no completed cases")
|
||||
csv_path = args.output_root / "chunk_metrics.csv"
|
||||
with csv_path.open("w", encoding="utf-8", newline="") as handle:
|
||||
writer = csv.DictWriter(handle, fieldnames=list(all_rows[0]))
|
||||
writer.writeheader()
|
||||
writer.writerows(all_rows)
|
||||
contact_path = args.output_root / "contact_sheet.png"
|
||||
_contact_sheet(sheets, contact_path)
|
||||
milestone_contact_path = args.output_root / "milestone_contact_sheet.png"
|
||||
_contact_sheet(
|
||||
milestone_sheets,
|
||||
milestone_contact_path,
|
||||
column_labels=milestone_labels,
|
||||
)
|
||||
result = {
|
||||
"format": "h3-continuum-issue13-r2-analysis-v2",
|
||||
"sample_radius_frames": args.radius,
|
||||
"videos": videos,
|
||||
"csv": str(csv_path),
|
||||
"contact_sheet": str(contact_path),
|
||||
"milestone_contact_sheet": str(milestone_contact_path),
|
||||
}
|
||||
(args.output_root / "analysis.json").write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
print(json.dumps(result, ensure_ascii=False))
|
||||
return result
|
||||
|
||||
|
||||
def _parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--output-root", type=Path, required=True)
|
||||
parser.add_argument(
|
||||
"--video-root", type=Path, default=Path(r"D:\output\video\comfy_video")
|
||||
)
|
||||
parser.add_argument("--radius", type=int, default=12)
|
||||
return parser
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run(_parser().parse_args())
|
||||
@@ -0,0 +1,282 @@
|
||||
"""Run the Issue #13 R2 long-duration continuation diagnostic.
|
||||
|
||||
This is evidence tooling only. It selects the already accepted Masked AV
|
||||
transport explicitly through the external GPU diagnostic node and does not
|
||||
modify the Production sampler, conditioning, or assembly path.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
from p32_api_runner import submit_and_wait
|
||||
|
||||
|
||||
BASE_PROMPT = (
|
||||
"A continuous cinematic live-action tracking shot of one woman in an "
|
||||
"orange jacket riding a skateboard steadily forward along a waterfront "
|
||||
"promenade. The camera follows her in one smooth direction. Preserve her "
|
||||
"face, clothing, skateboard, warm sunlight, detailed texture, rich color, "
|
||||
"and continuous forward motion. Natural skateboard wheels, wind, and "
|
||||
"distant city ambience are audible."
|
||||
)
|
||||
|
||||
CASE_SPECS = {
|
||||
"g1_standard_6x10": {"chunks": 6, "chunk_seconds": 10.0},
|
||||
"g2_standard_5x5": {"chunks": 5, "chunk_seconds": 5.0},
|
||||
}
|
||||
|
||||
DIAGNOSTIC_MARKER = "V3.6-R1 diagnostic: "
|
||||
|
||||
|
||||
def _same_prompt_list(chunks: int) -> str:
|
||||
return "\n---\n".join([BASE_PROMPT] * int(chunks))
|
||||
|
||||
|
||||
def configure_prompt(
|
||||
source: dict,
|
||||
*,
|
||||
case: str,
|
||||
output_prefix: str,
|
||||
seed: int,
|
||||
steps: int,
|
||||
size: int,
|
||||
diagnostic_nonce: int,
|
||||
) -> dict:
|
||||
if case not in CASE_SPECS:
|
||||
raise ValueError(f"unknown Issue #13 R2 case: {case}")
|
||||
spec = CASE_SPECS[case]
|
||||
chunks = int(spec["chunks"])
|
||||
chunk_seconds = float(spec["chunk_seconds"])
|
||||
prompt = copy.deepcopy(source)
|
||||
|
||||
sampler = prompt["305"]
|
||||
sampler["class_type"] = "H3ContinuumMaskedPrefixR1Diagnostic"
|
||||
sampler["_meta"] = {"title": f"Issue #13 R2 Diagnostic — {case}"}
|
||||
inputs = sampler["inputs"]
|
||||
inputs.update(
|
||||
{
|
||||
"prompt_mode": "List",
|
||||
"chunks": chunks,
|
||||
"chunk_seconds": chunk_seconds,
|
||||
"width": int(size),
|
||||
"height": int(size),
|
||||
"continuity": "Balanced — 22 frames",
|
||||
"base_seed": int(seed),
|
||||
"audio_continuity": True,
|
||||
"diagnostics": "Detailed Report",
|
||||
"reroll_from_chunk": "Auto",
|
||||
"reroll_nonce": 0,
|
||||
"strict_compatibility": False,
|
||||
"debug": False,
|
||||
"show_preview": False,
|
||||
"run_storage": "Off",
|
||||
"run_name": "",
|
||||
"project_id": "",
|
||||
"continuation_transport": "masked_av_prefix_22_v1",
|
||||
"synchronize_sampling": True,
|
||||
"diagnostic_nonce": int(diagnostic_nonce),
|
||||
"first_frame": ["119", 0],
|
||||
}
|
||||
)
|
||||
for key in (
|
||||
"continuation_backend",
|
||||
"generation_mode",
|
||||
"review_action",
|
||||
"max_new_physical_groups",
|
||||
"aspect",
|
||||
"preset",
|
||||
"custom_mp",
|
||||
"guide",
|
||||
"last_frame",
|
||||
):
|
||||
inputs.pop(key, None)
|
||||
|
||||
prompt["188"]["inputs"]["value"] = _same_prompt_list(chunks)
|
||||
prompt["153"]["inputs"].update(
|
||||
{"scheduler": "simple", "steps": int(steps), "denoise": 1.0}
|
||||
)
|
||||
prompt["297"]["inputs"]["value"] = max(
|
||||
0.05, (float(size) * float(size)) / 1_000_000.0
|
||||
)
|
||||
prompt["306"]["inputs"].update(
|
||||
{
|
||||
"exact_total_duration": True,
|
||||
"audio_seam": "Off",
|
||||
"video_seam": "Off",
|
||||
"buffer_backend": "Auto",
|
||||
"diagnostics": "Detailed Report",
|
||||
}
|
||||
)
|
||||
prompt["191"]["inputs"]["filename_prefix"] = str(output_prefix)
|
||||
prompt["249"]["inputs"]["source"] = ["305", 3]
|
||||
|
||||
spectrum = prompt.get("150", {}).get("inputs", {})
|
||||
if spectrum:
|
||||
spectrum["enabled"] = False
|
||||
lora_loader = prompt.get("286", {}).get("inputs", {})
|
||||
for name, value in lora_loader.items():
|
||||
if name.startswith("lora_") and isinstance(value, dict):
|
||||
value["on"] = False
|
||||
return prompt
|
||||
|
||||
|
||||
def _output_video(history: dict, prompt_id: str) -> dict | None:
|
||||
entry = history.get(str(prompt_id), {})
|
||||
outputs = entry.get("outputs", {}) if isinstance(entry, dict) else {}
|
||||
save = outputs.get("191", {}) if isinstance(outputs, dict) else {}
|
||||
images = save.get("images", []) if isinstance(save, dict) else []
|
||||
return images[0] if images else None
|
||||
|
||||
|
||||
def _status_text(history: dict, prompt_id: str) -> str:
|
||||
entry = history.get(str(prompt_id), {})
|
||||
outputs = entry.get("outputs", {}) if isinstance(entry, dict) else {}
|
||||
preview = outputs.get("249", {}) if isinstance(outputs, dict) else {}
|
||||
values = preview.get("text", []) if isinstance(preview, dict) else []
|
||||
return str(values[0]) if values else ""
|
||||
|
||||
|
||||
def _diagnostic_from_status(status: str) -> dict:
|
||||
if DIAGNOSTIC_MARKER not in status:
|
||||
raise RuntimeError("Issue #13 R2 diagnostic marker is missing from status")
|
||||
payload = status.rsplit(DIAGNOSTIC_MARKER, 1)[1].strip()
|
||||
value = json.loads(payload)
|
||||
if not isinstance(value, dict):
|
||||
raise RuntimeError("Issue #13 R2 diagnostic payload is not an object")
|
||||
return value
|
||||
|
||||
|
||||
def run(args: argparse.Namespace) -> dict:
|
||||
source = json.loads(args.prompt.read_text(encoding="utf-8"))
|
||||
cases = list(args.cases or CASE_SPECS)
|
||||
unknown = [case for case in cases if case not in CASE_SPECS]
|
||||
if unknown:
|
||||
raise SystemExit(f"unknown --cases: {', '.join(unknown)}")
|
||||
|
||||
args.output_root.mkdir(parents=True, exist_ok=True)
|
||||
summary_path = args.output_root / "summary.json"
|
||||
results = []
|
||||
if summary_path.exists():
|
||||
existing = json.loads(summary_path.read_text(encoding="utf-8"))
|
||||
results = list(existing.get("cases") or [])
|
||||
completed_cases = {str(item.get("case")) for item in results}
|
||||
|
||||
for offset, case in enumerate(cases):
|
||||
if case in completed_cases:
|
||||
print(f"ISSUE13-R2 SKIP completed case={case}", flush=True)
|
||||
continue
|
||||
spec = CASE_SPECS[case]
|
||||
configured = configure_prompt(
|
||||
source,
|
||||
case=case,
|
||||
output_prefix=f"video/issue13_r2/Issue13_R2_{case}_seed{args.seed}",
|
||||
seed=args.seed,
|
||||
steps=args.steps,
|
||||
size=args.size,
|
||||
diagnostic_nonce=args.diagnostic_nonce + offset,
|
||||
)
|
||||
case_root = args.output_root / case
|
||||
case_root.mkdir(parents=True, exist_ok=True)
|
||||
prompt_path = case_root / "prompt.json"
|
||||
prompt_path.write_text(
|
||||
json.dumps(configured, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
print(f"ISSUE13-R2 START case={case}", flush=True)
|
||||
prompt_id, history, elapsed = submit_and_wait(
|
||||
server=args.server,
|
||||
prompt=configured,
|
||||
client_id=f"issue13-r2-{uuid.uuid4().hex}",
|
||||
timeout_seconds=args.timeout_seconds,
|
||||
poll_seconds=3.0,
|
||||
)
|
||||
history_path = case_root / "history.json"
|
||||
history_path.write_text(
|
||||
json.dumps(history, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
status = _status_text(history, prompt_id)
|
||||
diagnostic = _diagnostic_from_status(status)
|
||||
result = {
|
||||
"case": case,
|
||||
"chunks": int(spec["chunks"]),
|
||||
"chunk_seconds": float(spec["chunk_seconds"]),
|
||||
"prompt_id": prompt_id,
|
||||
"api_elapsed_seconds": elapsed,
|
||||
"prompt": str(prompt_path),
|
||||
"history": str(history_path),
|
||||
"output_video": _output_video(history, prompt_id),
|
||||
"status_sha256": hashlib.sha256(status.encode("utf-8")).hexdigest(),
|
||||
"diagnostic": diagnostic,
|
||||
}
|
||||
(case_root / "summary.json").write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
results.append(result)
|
||||
print(
|
||||
f"ISSUE13-R2 COMPLETE case={case} prompt_id={prompt_id} "
|
||||
f"elapsed={elapsed:.3f}s",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
summary = {
|
||||
"format": "h3-continuum-issue13-r2-gate-v1",
|
||||
"server": args.server,
|
||||
"source_prompt": str(args.prompt),
|
||||
"seed": int(args.seed),
|
||||
"steps": int(args.steps),
|
||||
"size": int(args.size),
|
||||
"sampler": "res_multistep",
|
||||
"scheduler": "simple",
|
||||
"continuity": "Balanced — 22 frames",
|
||||
"audio_continuity": True,
|
||||
"transport": "masked_av_prefix_22_v1",
|
||||
"spectrum": False,
|
||||
"lora": False,
|
||||
"video_seam": "Off",
|
||||
"audio_seam": "Off",
|
||||
"cases": results,
|
||||
}
|
||||
summary_path.write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
return json.loads(summary_path.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def _parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8190")
|
||||
parser.add_argument("--prompt", type=Path, required=True)
|
||||
parser.add_argument("--output-root", type=Path, required=True)
|
||||
parser.add_argument("--seed", type=int, default=130013)
|
||||
parser.add_argument("--steps", type=int, default=8)
|
||||
parser.add_argument("--size", type=int, default=384)
|
||||
parser.add_argument("--diagnostic-nonce", type=int, default=131300)
|
||||
parser.add_argument("--timeout-seconds", type=float, default=7200.0)
|
||||
parser.add_argument("--cases", nargs="*", choices=tuple(CASE_SPECS))
|
||||
return parser
|
||||
|
||||
|
||||
def main() -> int:
|
||||
summary = run(_parser().parse_args())
|
||||
print(json.dumps(summary, ensure_ascii=False))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
+37
-37
@@ -1,37 +1,37 @@
|
||||
param(
|
||||
[string]$Source = (Split-Path -Parent $PSScriptRoot),
|
||||
[string]$SnapshotRoot = 'D:\Codex\_snapshots\ComfyUI-H3-Continuum',
|
||||
[string]$Label = 'pre-change'
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$sourcePath = (Resolve-Path -LiteralPath $Source).Path
|
||||
$stamp = Get-Date -Format 'yyyyMMdd_HHmmss'
|
||||
$safeLabel = $Label -replace '[^A-Za-z0-9._-]', '-'
|
||||
$destination = Join-Path $SnapshotRoot "$safeLabel-$stamp"
|
||||
$rootFull = [IO.Path]::GetFullPath($SnapshotRoot)
|
||||
$destinationFull = [IO.Path]::GetFullPath($destination)
|
||||
|
||||
if (-not $destinationFull.StartsWith($rootFull, [StringComparison]::OrdinalIgnoreCase)) {
|
||||
throw 'Snapshot destination escaped the configured snapshot root.'
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Path $destination -Force | Out-Null
|
||||
Get-ChildItem -LiteralPath $sourcePath -Force |
|
||||
Where-Object { $_.Name -ne '.git' } |
|
||||
ForEach-Object { Copy-Item -LiteralPath $_.FullName -Destination $destination -Recurse -Force }
|
||||
|
||||
$sourceCount = (Get-ChildItem -LiteralPath $sourcePath -Recurse -Force -File |
|
||||
Where-Object { $_.FullName -notmatch '[\\/]\.git[\\/]' } |
|
||||
Measure-Object).Count
|
||||
$destinationCount = (Get-ChildItem -LiteralPath $destination -Recurse -Force -File | Measure-Object).Count
|
||||
|
||||
if ($sourceCount -ne $destinationCount) {
|
||||
throw "Snapshot verification failed: source=$sourceCount destination=$destinationCount"
|
||||
}
|
||||
|
||||
[pscustomobject]@{
|
||||
Source = $sourcePath
|
||||
Snapshot = $destination
|
||||
Files = $destinationCount
|
||||
}
|
||||
param(
|
||||
[string]$Source = (Split-Path -Parent $PSScriptRoot),
|
||||
[string]$SnapshotRoot = 'D:\Codex\_snapshots\ComfyUI-H3-Continuum',
|
||||
[string]$Label = 'pre-change'
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$sourcePath = (Resolve-Path -LiteralPath $Source).Path
|
||||
$stamp = Get-Date -Format 'yyyyMMdd_HHmmss'
|
||||
$safeLabel = $Label -replace '[^A-Za-z0-9._-]', '-'
|
||||
$destination = Join-Path $SnapshotRoot "$safeLabel-$stamp"
|
||||
$rootFull = [IO.Path]::GetFullPath($SnapshotRoot)
|
||||
$destinationFull = [IO.Path]::GetFullPath($destination)
|
||||
|
||||
if (-not $destinationFull.StartsWith($rootFull, [StringComparison]::OrdinalIgnoreCase)) {
|
||||
throw 'Snapshot destination escaped the configured snapshot root.'
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Path $destination -Force | Out-Null
|
||||
Get-ChildItem -LiteralPath $sourcePath -Force |
|
||||
Where-Object { $_.Name -ne '.git' } |
|
||||
ForEach-Object { Copy-Item -LiteralPath $_.FullName -Destination $destination -Recurse -Force }
|
||||
|
||||
$sourceCount = (Get-ChildItem -LiteralPath $sourcePath -Recurse -Force -File |
|
||||
Where-Object { $_.FullName -notmatch '[\\/]\.git[\\/]' } |
|
||||
Measure-Object).Count
|
||||
$destinationCount = (Get-ChildItem -LiteralPath $destination -Recurse -Force -File | Measure-Object).Count
|
||||
|
||||
if ($sourceCount -ne $destinationCount) {
|
||||
throw "Snapshot verification failed: source=$sourceCount destination=$destinationCount"
|
||||
}
|
||||
|
||||
[pscustomobject]@{
|
||||
Source = $sourcePath
|
||||
Snapshot = $destination
|
||||
Files = $destinationCount
|
||||
}
|
||||
|
||||
@@ -0,0 +1,619 @@
|
||||
"""Run the three-case V3.8 A2 Audio Only GPU Canary."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
from dataclasses import asdict, dataclass
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import Any, Mapping
|
||||
import uuid
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
from safetensors.torch import load_file
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
from p32_api_runner import submit_and_wait
|
||||
from v36_r1_stress_gate_runner import ResourceMonitor
|
||||
from v38_easy_gpu_gate_runner import _output_media, _probe_media
|
||||
|
||||
|
||||
class GateFailure(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class GateCase:
|
||||
name: str
|
||||
chunks: int
|
||||
terminal_merge: bool
|
||||
expected_physical_groups: int
|
||||
boundary_seconds: tuple[float, ...]
|
||||
|
||||
|
||||
CASES = (
|
||||
GateCase("g1_1x5_tail6", 1, False, 1, ()),
|
||||
GateCase("g2_3x5_balanced22", 3, False, 3, (5.0, 10.0)),
|
||||
GateCase("g3_terminal_merge", 3, True, 2, (5.0, 10.0)),
|
||||
)
|
||||
|
||||
|
||||
PROMPT = (
|
||||
"A continuous cinematic shot follows a woman walking through a modern plaza. "
|
||||
"Natural footsteps, clothing movement, wind, and steady city ambience remain "
|
||||
"audible throughout without cuts or silence."
|
||||
)
|
||||
FIRST_PASS_SEED = 3802701
|
||||
REFINE_SEED = 3802702
|
||||
|
||||
|
||||
def _sha256_file(path: Path) -> str:
|
||||
digest = hashlib.sha256()
|
||||
with path.open("rb") as stream:
|
||||
for block in iter(lambda: stream.read(1024 * 1024), b""):
|
||||
digest.update(block)
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def _sha256_tensor(value: torch.Tensor) -> str:
|
||||
tensor = value.detach().to(device="cpu").contiguous()
|
||||
digest = hashlib.sha256()
|
||||
digest.update(str(tuple(int(item) for item in tensor.shape)).encode("ascii"))
|
||||
digest.update(str(tensor.dtype).encode("ascii"))
|
||||
digest.update(tensor.view(torch.uint8).numpy().tobytes(order="C"))
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def _find_one(prompt: Mapping[str, Any], class_type: str) -> tuple[str, dict[str, Any]]:
|
||||
matches = [
|
||||
(str(node_id), node)
|
||||
for node_id, node in prompt.items()
|
||||
if str(node.get("class_type")) == class_type
|
||||
]
|
||||
if len(matches) != 1:
|
||||
raise GateFailure(f"expected one {class_type}, found {len(matches)}")
|
||||
return matches[0]
|
||||
|
||||
|
||||
def _remove_class(prompt: dict[str, Any], class_type: str) -> None:
|
||||
for node_id in [
|
||||
str(key)
|
||||
for key, node in prompt.items()
|
||||
if str(node.get("class_type")) == class_type
|
||||
]:
|
||||
prompt.pop(node_id, None)
|
||||
|
||||
|
||||
def _configure_prompt(
|
||||
template: Mapping[str, Any],
|
||||
*,
|
||||
case: GateCase,
|
||||
output_prefix: str,
|
||||
) -> dict[str, Any]:
|
||||
prompt = copy.deepcopy(dict(template))
|
||||
sampler_id, continuum = _find_one(prompt, "H3ContinuumSamplerV38")
|
||||
inputs = continuum["inputs"]
|
||||
inputs.update(
|
||||
{
|
||||
"prompt_mode": "Fixed",
|
||||
"chunks": int(case.chunks),
|
||||
"chunk_seconds": 5.0,
|
||||
"continuity": "Balanced — 22 frames",
|
||||
"base_seed": FIRST_PASS_SEED,
|
||||
"audio_continuity": True,
|
||||
"diagnostics": "Detailed Report",
|
||||
"reroll_from_chunk": "Auto",
|
||||
"reroll_nonce": 0,
|
||||
"strict_compatibility": False,
|
||||
"debug": True,
|
||||
"show_preview": False,
|
||||
"run_storage": "Off",
|
||||
"run_name": "",
|
||||
"project_id": "",
|
||||
"generation_mode": "Full Run",
|
||||
"review_action": "Continue / Next",
|
||||
"aspect": "Square 1:1",
|
||||
"preset": "Custom",
|
||||
"custom_mp": 0.331776,
|
||||
}
|
||||
)
|
||||
for name in (
|
||||
"reference_video_1",
|
||||
"reference_video_2",
|
||||
"reference_video_3",
|
||||
"driving_audio",
|
||||
):
|
||||
inputs.pop(name, None)
|
||||
if not case.terminal_merge:
|
||||
inputs.pop("first_frame", None)
|
||||
inputs.pop("last_frame", None)
|
||||
_remove_class(prompt, "LoadImage")
|
||||
_remove_class(prompt, "H3ContinuumLoadVideo")
|
||||
|
||||
prompt_id = str(inputs["sequence_prompt"][0])
|
||||
prompt[prompt_id]["inputs"]["value"] = PROMPT
|
||||
first_scheduler_id = str(inputs["sigmas"][0])
|
||||
prompt[first_scheduler_id]["inputs"].update(
|
||||
{"scheduler": "simple", "steps": 8, "denoise": 1.0}
|
||||
)
|
||||
scheduler_matches = [
|
||||
(str(node_id), node)
|
||||
for node_id, node in prompt.items()
|
||||
if str(node.get("class_type")) == "BasicScheduler"
|
||||
and str(node_id) != first_scheduler_id
|
||||
]
|
||||
if len(scheduler_matches) != 1:
|
||||
raise GateFailure(
|
||||
"expected one refine BasicScheduler, "
|
||||
f"found {len(scheduler_matches)}"
|
||||
)
|
||||
refine_scheduler_id, refine_scheduler = scheduler_matches[0]
|
||||
refine_scheduler["inputs"].update(
|
||||
{"scheduler": "simple", "steps": 10, "denoise": 0.35}
|
||||
)
|
||||
|
||||
prompt["302"] = {
|
||||
"class_type": "H3A2AudioOnlyCanary",
|
||||
"inputs": {
|
||||
"model": inputs["model"],
|
||||
"clip": inputs["clip"],
|
||||
"sampler": inputs["sampler"],
|
||||
"sigmas": [refine_scheduler_id, 0],
|
||||
"video_latents": [sampler_id, 0],
|
||||
"audio_latents": [sampler_id, 1],
|
||||
"assembly_plan": [sampler_id, 2],
|
||||
"refine_context": [sampler_id, 5],
|
||||
"video_vae": inputs["video_vae"],
|
||||
"refine_seed": REFINE_SEED,
|
||||
"schedule_mode": "Tail",
|
||||
"tail_evaluations": 6,
|
||||
},
|
||||
"_meta": {"title": "A2 Audio Only Canary"},
|
||||
}
|
||||
for node_id in ("900", "901", "902", "903", "904", "905", "906"):
|
||||
prompt.pop(node_id, None)
|
||||
prompt["900"] = {
|
||||
"class_type": "PreviewAny",
|
||||
"inputs": {"source": [sampler_id, 3]},
|
||||
}
|
||||
prompt["901"] = {
|
||||
"class_type": "PreviewAny",
|
||||
"inputs": {"source": ["302", 3]},
|
||||
}
|
||||
prompt["902"] = {
|
||||
"class_type": "SaveLatent",
|
||||
"inputs": {
|
||||
"samples": [sampler_id, 0],
|
||||
"filename_prefix": f"{output_prefix}_first_video",
|
||||
},
|
||||
}
|
||||
prompt["903"] = {
|
||||
"class_type": "SaveLatent",
|
||||
"inputs": {
|
||||
"samples": [sampler_id, 1],
|
||||
"filename_prefix": f"{output_prefix}_first_audio",
|
||||
},
|
||||
}
|
||||
prompt["904"] = {
|
||||
"class_type": "SaveLatent",
|
||||
"inputs": {
|
||||
"samples": ["302", 0],
|
||||
"filename_prefix": f"{output_prefix}_refined_video",
|
||||
},
|
||||
}
|
||||
prompt["905"] = {
|
||||
"class_type": "SaveLatent",
|
||||
"inputs": {
|
||||
"samples": ["302", 1],
|
||||
"filename_prefix": f"{output_prefix}_refined_audio",
|
||||
},
|
||||
}
|
||||
prompt["906"] = {
|
||||
"class_type": "PreviewAny",
|
||||
"inputs": {"source": ["302", 2]},
|
||||
}
|
||||
_save_id, save_video = _find_one(prompt, "SaveVideo")
|
||||
save_video["inputs"]["filename_prefix"] = output_prefix
|
||||
return prompt
|
||||
|
||||
|
||||
def _history_entry(history: Mapping[str, Any], prompt_id: str) -> Mapping[str, Any]:
|
||||
entry = history.get(prompt_id)
|
||||
if not isinstance(entry, Mapping):
|
||||
raise GateFailure(f"history is missing prompt {prompt_id}")
|
||||
return entry
|
||||
|
||||
|
||||
def _output_text(entry: Mapping[str, Any], node_id: str) -> str:
|
||||
value = (entry.get("outputs") or {}).get(node_id) or {}
|
||||
items = value.get("text")
|
||||
if isinstance(items, list):
|
||||
return "\n".join(str(item) for item in items)
|
||||
if isinstance(items, str):
|
||||
return items
|
||||
return json.dumps(value, ensure_ascii=False, sort_keys=True)
|
||||
|
||||
|
||||
def _output_latents(
|
||||
entry: Mapping[str, Any],
|
||||
node_id: str,
|
||||
output_root: Path,
|
||||
) -> list[dict[str, Any]]:
|
||||
output = (entry.get("outputs") or {}).get(node_id) or {}
|
||||
records = []
|
||||
for value in output.get("latents") or []:
|
||||
path = output_root / str(value.get("subfolder") or "") / str(
|
||||
value["filename"]
|
||||
)
|
||||
latent = load_file(str(path), device="cpu")["latent_tensor"]
|
||||
records.append(
|
||||
{
|
||||
"path": str(path),
|
||||
"shape": [int(item) for item in latent.shape],
|
||||
"dtype": str(latent.dtype),
|
||||
"tensor_sha256": _sha256_tensor(latent),
|
||||
}
|
||||
)
|
||||
return records
|
||||
|
||||
|
||||
def _canary_json(status: str) -> dict[str, Any]:
|
||||
line = next(
|
||||
(item for item in status.splitlines() if item.startswith("A2_CANARY_JSON=")),
|
||||
"",
|
||||
)
|
||||
if not line:
|
||||
raise GateFailure("A2 canary status JSON is missing")
|
||||
return json.loads(line.split("=", 1)[1])
|
||||
|
||||
|
||||
def _decode_audio(path: Path, ffmpeg: str) -> np.ndarray:
|
||||
process = subprocess.run(
|
||||
[
|
||||
ffmpeg,
|
||||
"-v",
|
||||
"error",
|
||||
"-i",
|
||||
str(path),
|
||||
"-map",
|
||||
"0:a:0",
|
||||
"-ac",
|
||||
"2",
|
||||
"-ar",
|
||||
"32000",
|
||||
"-c:a",
|
||||
"pcm_f32le",
|
||||
"-f",
|
||||
"f32le",
|
||||
"-",
|
||||
],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
check=False,
|
||||
)
|
||||
if process.returncode:
|
||||
raise GateFailure(
|
||||
"ffmpeg audio decode failed: "
|
||||
+ process.stderr.decode("utf-8", errors="replace")[-2000:]
|
||||
)
|
||||
audio = np.frombuffer(process.stdout, dtype="<f4")
|
||||
if audio.size == 0 or audio.size % 2:
|
||||
raise GateFailure("decoded stereo PCM is empty or malformed")
|
||||
return audio.reshape(-1, 2)
|
||||
|
||||
|
||||
def _rms(value: np.ndarray) -> float:
|
||||
if value.size == 0:
|
||||
return 0.0
|
||||
return float(np.sqrt(np.mean(np.square(value.astype(np.float64)))))
|
||||
|
||||
|
||||
def _audio_health(
|
||||
media_path: Path,
|
||||
*,
|
||||
ffmpeg: str,
|
||||
expected_seconds: float,
|
||||
boundaries: tuple[float, ...],
|
||||
) -> dict[str, Any]:
|
||||
audio = _decode_audio(media_path, ffmpeg)
|
||||
sample_rate = 32000
|
||||
global_rms = _rms(audio)
|
||||
channel_rms = [_rms(audio[:, channel]) for channel in range(2)]
|
||||
window = max(1, int(round(0.5 * sample_rate)))
|
||||
window_rms = [
|
||||
_rms(audio[start : start + window])
|
||||
for start in range(0, len(audio), window)
|
||||
if len(audio[start : start + window]) >= window // 2
|
||||
]
|
||||
boundary_metrics = []
|
||||
for seconds in boundaries:
|
||||
index = int(round(seconds * sample_rate))
|
||||
if not 1 <= index < len(audio):
|
||||
raise GateFailure(f"audio boundary {seconds}s is outside decoded PCM")
|
||||
radius = int(round(0.1 * sample_rate))
|
||||
local = audio[max(0, index - radius) : min(len(audio), index + radius)]
|
||||
local_diff = np.abs(np.diff(local, axis=0))
|
||||
q999 = float(np.quantile(local_diff, 0.999)) if local_diff.size else 0.0
|
||||
sample_jump = float(np.max(np.abs(audio[index] - audio[index - 1])))
|
||||
threshold = max(0.25, q999 * 8.0)
|
||||
before_rms = _rms(audio[max(0, index - radius) : index])
|
||||
after_rms = _rms(audio[index : min(len(audio), index + radius)])
|
||||
boundary_metrics.append(
|
||||
{
|
||||
"seconds": seconds,
|
||||
"sample_index": index,
|
||||
"sample_jump": sample_jump,
|
||||
"local_diff_q999": q999,
|
||||
"click_threshold": threshold,
|
||||
"no_click_advisory": sample_jump <= threshold,
|
||||
"rms_before_100ms": before_rms,
|
||||
"rms_after_100ms": after_rms,
|
||||
"no_boundary_silence": before_rms > 1e-7 and after_rms > 1e-7,
|
||||
}
|
||||
)
|
||||
expected_samples = int(round(expected_seconds * sample_rate))
|
||||
checks = {
|
||||
"finite": bool(np.isfinite(audio).all()),
|
||||
"not_silent": global_rms > 1e-7,
|
||||
"channels_not_collapsed": all(value > 1e-7 for value in channel_rms),
|
||||
"windows_not_collapsed": bool(window_rms)
|
||||
and min(window_rms) > 1e-8,
|
||||
"duration_no_drift": abs(len(audio) - expected_samples) <= 1024,
|
||||
"boundaries_no_click": all(
|
||||
item["no_click_advisory"] for item in boundary_metrics
|
||||
),
|
||||
"boundaries_not_silent": all(
|
||||
item["no_boundary_silence"] for item in boundary_metrics
|
||||
),
|
||||
}
|
||||
return {
|
||||
"sample_rate": sample_rate,
|
||||
"channels": 2,
|
||||
"samples_per_channel": int(len(audio)),
|
||||
"duration_seconds": float(len(audio) / sample_rate),
|
||||
"expected_samples_per_channel": expected_samples,
|
||||
"global_rms": global_rms,
|
||||
"channel_rms": channel_rms,
|
||||
"peak": float(np.max(np.abs(audio))),
|
||||
"minimum_window_rms": min(window_rms) if window_rms else 0.0,
|
||||
"boundaries": boundary_metrics,
|
||||
"checks": checks,
|
||||
"pass": all(checks.values()),
|
||||
}
|
||||
|
||||
|
||||
def _run_case(
|
||||
args: argparse.Namespace,
|
||||
*,
|
||||
case: GateCase,
|
||||
template: Mapping[str, Any],
|
||||
) -> dict[str, Any]:
|
||||
case_root = args.evidence_root / case.name
|
||||
case_root.mkdir(parents=True, exist_ok=True)
|
||||
output_prefix = f"v38_a2_audio_only/{args.run_tag}/{case.name}"
|
||||
prompt = _configure_prompt(template, case=case, output_prefix=output_prefix)
|
||||
prompt_path = case_root / "prompt.json"
|
||||
prompt_path.write_text(
|
||||
json.dumps(prompt, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
print(f"A2 GPU Canary start: {case.name}", flush=True)
|
||||
with ResourceMonitor(args.backend_pid, interval_seconds=0.5) as monitor:
|
||||
prompt_id, history, elapsed = submit_and_wait(
|
||||
server=args.server,
|
||||
prompt=prompt,
|
||||
client_id=f"v38-a2-{uuid.uuid4().hex}",
|
||||
timeout_seconds=args.timeout_seconds,
|
||||
poll_seconds=2.0,
|
||||
)
|
||||
history_path = case_root / "history.json"
|
||||
history_path.write_text(
|
||||
json.dumps(history, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
entry = _history_entry(history, prompt_id)
|
||||
first_status = _output_text(entry, "900")
|
||||
canary_status = _output_text(entry, "901")
|
||||
canary = _canary_json(canary_status)
|
||||
first_videos = _output_latents(entry, "902", args.output_root)
|
||||
first_audios = _output_latents(entry, "903", args.output_root)
|
||||
refined_videos = _output_latents(entry, "904", args.output_root)
|
||||
refined_audios = _output_latents(entry, "905", args.output_root)
|
||||
media_path = _output_media(history, args.output_root)
|
||||
media = _probe_media(media_path, args.ffprobe)
|
||||
audio_health = _audio_health(
|
||||
media_path,
|
||||
ffmpeg=args.ffmpeg,
|
||||
expected_seconds=case.chunks * 5.0,
|
||||
boundaries=case.boundary_seconds,
|
||||
)
|
||||
first_video_hashes = [item["tensor_sha256"] for item in first_videos]
|
||||
refined_video_hashes = [item["tensor_sha256"] for item in refined_videos]
|
||||
first_audio_hashes = [item["tensor_sha256"] for item in first_audios]
|
||||
refined_audio_hashes = [item["tensor_sha256"] for item in refined_audios]
|
||||
groups = canary.get("physical_groups") or []
|
||||
terminal_check = True
|
||||
if case.terminal_merge:
|
||||
terminal_check = (
|
||||
len(groups) == 2
|
||||
and groups[-1].get("logical_chunks") == [2, 3]
|
||||
and groups[-1].get("terminal_merged") is True
|
||||
)
|
||||
checks = {
|
||||
"physical_group_count": len(groups) == case.expected_physical_groups,
|
||||
"first_video_count": len(first_videos) == case.expected_physical_groups,
|
||||
"refined_video_count": len(refined_videos) == case.expected_physical_groups,
|
||||
"first_audio_count": len(first_audios) == case.expected_physical_groups,
|
||||
"refined_audio_count": len(refined_audios) == case.expected_physical_groups,
|
||||
"video_sha_exact": first_video_hashes == refined_video_hashes,
|
||||
"video_object_identity": len(canary.get("video_object_identity") or [])
|
||||
== case.expected_physical_groups
|
||||
and all(canary.get("video_object_identity") or []),
|
||||
"video_tensor_identity": len(canary.get("video_tensor_identity") or [])
|
||||
== case.expected_physical_groups
|
||||
and all(canary.get("video_tensor_identity") or []),
|
||||
"audio_changed": len(first_audio_hashes) == len(refined_audio_hashes)
|
||||
and all(
|
||||
before != after
|
||||
for before, after in zip(
|
||||
first_audio_hashes,
|
||||
refined_audio_hashes,
|
||||
strict=True,
|
||||
)
|
||||
),
|
||||
"audio_shape_preserved": canary.get("audio_input_shapes")
|
||||
== canary.get("audio_output_shapes"),
|
||||
"audio_seed_namespace": (
|
||||
(canary.get("target") or {}).get("seed_namespace")
|
||||
== "h3-continuum-refine-audio-v1"
|
||||
),
|
||||
"tail_6": canary.get("schedule_mode") == "tail"
|
||||
and canary.get("schedule_evaluations") == 6,
|
||||
"second_pass_contract_v1": canary.get("second_pass_contract_version") == 1,
|
||||
"terminal_atomic_group": terminal_check,
|
||||
"media_duration": abs(float(media["format_duration"]) - case.chunks * 5.0)
|
||||
<= 0.05,
|
||||
"media_frames": int(media["frames"]) == case.chunks * 5 * 24,
|
||||
"media_audio_contract": int(media["audio_sample_rate"]) == 32000
|
||||
and int(media["audio_channels"]) == 2,
|
||||
"audio_health": bool(audio_health["pass"]),
|
||||
"temporary_video_discarded": (
|
||||
canary_status.count("temporary_video_discarded=true")
|
||||
== case.expected_physical_groups
|
||||
),
|
||||
}
|
||||
result = {
|
||||
"case": asdict(case),
|
||||
"prompt_id": prompt_id,
|
||||
"api_elapsed_seconds": float(elapsed),
|
||||
"prompt": str(prompt_path),
|
||||
"history": str(history_path),
|
||||
"first_status": first_status,
|
||||
"canary_status": canary_status,
|
||||
"canary": canary,
|
||||
"first_video_latents": first_videos,
|
||||
"refined_video_latents": refined_videos,
|
||||
"first_audio_latents": first_audios,
|
||||
"refined_audio_latents": refined_audios,
|
||||
"media_path": str(media_path),
|
||||
"media_sha256": _sha256_file(media_path),
|
||||
"media": media,
|
||||
"audio_health": audio_health,
|
||||
"resources": monitor.as_dict(),
|
||||
"checks": checks,
|
||||
"pass": all(checks.values()),
|
||||
}
|
||||
(case_root / "result.json").write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
(case_root / "canary_status.txt").write_text(
|
||||
canary_status,
|
||||
encoding="utf-8",
|
||||
)
|
||||
print(
|
||||
f"A2 GPU Canary end: {case.name}; pass={result['pass']}; "
|
||||
f"elapsed={elapsed:.3f}s; video_exact={checks['video_sha_exact']}; "
|
||||
f"audio_changed={checks['audio_changed']}",
|
||||
flush=True,
|
||||
)
|
||||
if not result["pass"]:
|
||||
failed = [name for name, value in checks.items() if not value]
|
||||
raise GateFailure(f"{case.name} failed checks: {failed}")
|
||||
return result
|
||||
|
||||
|
||||
def run(args: argparse.Namespace) -> dict[str, Any]:
|
||||
args.evidence_root.mkdir(parents=True, exist_ok=True)
|
||||
t2_template = json.loads(args.t2_template.read_text(encoding="utf-8"))
|
||||
terminal_template = json.loads(
|
||||
args.terminal_template.read_text(encoding="utf-8")
|
||||
)
|
||||
summary = {
|
||||
"format": "h3-continuum-v38-a2-audio-only-gpu-canary-v1",
|
||||
"server": args.server,
|
||||
"backend_pid": args.backend_pid,
|
||||
"run_tag": args.run_tag,
|
||||
"first_pass_seed": FIRST_PASS_SEED,
|
||||
"refine_seed": REFINE_SEED,
|
||||
"settings": {
|
||||
"resolution": "576x576",
|
||||
"first_pass_steps": 8,
|
||||
"refine_source_steps": 10,
|
||||
"refine_denoise": 0.35,
|
||||
"refine_schedule": "Tail 6",
|
||||
"continuity": "Balanced — 22 frames",
|
||||
"audio_continuity": True,
|
||||
"run_storage": "Off",
|
||||
"sampler": "res_multistep",
|
||||
"scheduler": "simple",
|
||||
"sage": True,
|
||||
},
|
||||
"templates": {
|
||||
"t2": str(args.t2_template),
|
||||
"terminal": str(args.terminal_template),
|
||||
},
|
||||
"results": {},
|
||||
"pass": False,
|
||||
"production_status": "HOLD",
|
||||
}
|
||||
summary_path = args.evidence_root / "summary.json"
|
||||
try:
|
||||
for case in CASES:
|
||||
template = terminal_template if case.terminal_merge else t2_template
|
||||
summary["results"][case.name] = _run_case(
|
||||
args,
|
||||
case=case,
|
||||
template=template,
|
||||
)
|
||||
summary["pass"] = True
|
||||
summary["status"] = "GPU Experimental PASS / Production HOLD"
|
||||
return summary
|
||||
except Exception as exc:
|
||||
summary["failure_type"] = type(exc).__name__
|
||||
summary["failure"] = str(exc)
|
||||
summary["status"] = "GPU Canary STOP / Production HOLD"
|
||||
return summary
|
||||
finally:
|
||||
summary_path.write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8190")
|
||||
parser.add_argument("--backend-pid", type=int, required=True)
|
||||
parser.add_argument("--run-tag", required=True)
|
||||
parser.add_argument("--evidence-root", type=Path, required=True)
|
||||
parser.add_argument("--t2-template", type=Path, required=True)
|
||||
parser.add_argument("--terminal-template", type=Path, required=True)
|
||||
parser.add_argument(
|
||||
"--output-root",
|
||||
type=Path,
|
||||
default=Path(r"D:\output\video\comfy_video"),
|
||||
)
|
||||
parser.add_argument("--ffmpeg", default=shutil.which("ffmpeg"))
|
||||
parser.add_argument("--ffprobe", default=shutil.which("ffprobe"))
|
||||
parser.add_argument("--timeout-seconds", type=float, default=3600.0)
|
||||
args = parser.parse_args()
|
||||
if not args.ffmpeg or not args.ffprobe:
|
||||
raise SystemExit("ffmpeg and ffprobe are required")
|
||||
summary = run(args)
|
||||
print(json.dumps(summary, indent=2, ensure_ascii=False), flush=True)
|
||||
return 0 if summary["pass"] else 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,751 @@
|
||||
"""Run the A3c Selective Refine public-node GPU Matrix."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
from dataclasses import asdict, dataclass
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import Any, Mapping
|
||||
import uuid
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
from p32_api_runner import submit_and_wait
|
||||
from v36_r1_stress_gate_runner import ResourceMonitor
|
||||
from v38_a2_audio_only_gpu_canary import (
|
||||
_audio_health,
|
||||
_history_entry,
|
||||
_output_latents,
|
||||
_output_text,
|
||||
)
|
||||
from v38_easy_gpu_gate_runner import _output_media, _probe_media
|
||||
|
||||
|
||||
class GateFailure(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class MatrixCase:
|
||||
name: str
|
||||
target: str
|
||||
chunks: int
|
||||
terminal_merge: bool
|
||||
expected_physical_groups: int
|
||||
boundary_seconds: tuple[float, ...]
|
||||
|
||||
|
||||
G2_TO_G5 = (
|
||||
MatrixCase("g2_audio_only_1x5", "Audio Only", 1, False, 1, ()),
|
||||
MatrixCase("g3_video_audio_1x5", "Video + Audio", 1, False, 1, ()),
|
||||
MatrixCase(
|
||||
"g4_video_audio_3x5",
|
||||
"Video + Audio",
|
||||
3,
|
||||
False,
|
||||
3,
|
||||
(5.0, 10.0),
|
||||
),
|
||||
MatrixCase(
|
||||
"g5_video_audio_terminal",
|
||||
"Video + Audio",
|
||||
3,
|
||||
True,
|
||||
2,
|
||||
(5.0, 10.0),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
PROMPT = (
|
||||
"A continuous cinematic shot follows a woman walking through a modern plaza. "
|
||||
"Natural footsteps, clothing movement, wind, and steady city ambience remain "
|
||||
"audible throughout without cuts or silence."
|
||||
)
|
||||
FIRST_PASS_SEED = 3802801
|
||||
REFINE_SEED = 3802802
|
||||
SELECTIVE_CLASS = "H3ContinuumSelectiveSecondPassExperimental"
|
||||
LEGACY_CLASS = "H3ContinuumSecondPassV35"
|
||||
|
||||
|
||||
def _find_one(prompt: Mapping[str, Any], class_type: str) -> tuple[str, dict[str, Any]]:
|
||||
values = [
|
||||
(str(node_id), node)
|
||||
for node_id, node in prompt.items()
|
||||
if str(node.get("class_type")) == class_type
|
||||
]
|
||||
if len(values) != 1:
|
||||
raise GateFailure(f"expected one {class_type}, found {len(values)}")
|
||||
return values[0]
|
||||
|
||||
|
||||
def _remove_class(prompt: dict[str, Any], class_type: str) -> None:
|
||||
for node_id in [
|
||||
str(value)
|
||||
for value, node in prompt.items()
|
||||
if str(node.get("class_type")) == class_type
|
||||
]:
|
||||
prompt.pop(node_id, None)
|
||||
|
||||
|
||||
def _second_pass_inputs(prompt: Mapping[str, Any], *, target: str | None) -> dict[str, Any]:
|
||||
sampler_id, continuum = _find_one(prompt, "H3ContinuumSamplerV38")
|
||||
inputs = continuum["inputs"]
|
||||
scheduler_matches = [
|
||||
(str(node_id), node)
|
||||
for node_id, node in prompt.items()
|
||||
if str(node.get("class_type")) == "BasicScheduler"
|
||||
and str(node_id) != str(inputs["sigmas"][0])
|
||||
]
|
||||
if len(scheduler_matches) != 1:
|
||||
raise GateFailure(
|
||||
f"expected one refine BasicScheduler, found {len(scheduler_matches)}"
|
||||
)
|
||||
refine_scheduler_id, _scheduler = scheduler_matches[0]
|
||||
result = {
|
||||
"model": inputs["model"],
|
||||
"clip": inputs["clip"],
|
||||
"sampler": inputs["sampler"],
|
||||
"sigmas": [refine_scheduler_id, 0],
|
||||
"video_latents": [sampler_id, 0],
|
||||
"audio_latents": [sampler_id, 1],
|
||||
"assembly_plan": [sampler_id, 2],
|
||||
"refine_context": [sampler_id, 5],
|
||||
"video_vae": inputs["video_vae"],
|
||||
"refine_seed": REFINE_SEED,
|
||||
}
|
||||
if target is not None:
|
||||
result["refine_target"] = target
|
||||
return result
|
||||
|
||||
|
||||
def _configure_base(
|
||||
template: Mapping[str, Any],
|
||||
*,
|
||||
chunks: int,
|
||||
terminal_merge: bool,
|
||||
output_prefix: str,
|
||||
) -> dict[str, Any]:
|
||||
prompt = copy.deepcopy(dict(template))
|
||||
sampler_id, continuum = _find_one(prompt, "H3ContinuumSamplerV38")
|
||||
inputs = continuum["inputs"]
|
||||
inputs.update(
|
||||
{
|
||||
"prompt_mode": "Fixed",
|
||||
"chunks": int(chunks),
|
||||
"chunk_seconds": 5.0,
|
||||
"continuity": "Balanced — 22 frames",
|
||||
"base_seed": FIRST_PASS_SEED,
|
||||
"audio_continuity": True,
|
||||
"diagnostics": "Detailed Report",
|
||||
"reroll_from_chunk": "Auto",
|
||||
"reroll_nonce": 0,
|
||||
"strict_compatibility": False,
|
||||
"debug": True,
|
||||
"show_preview": False,
|
||||
"run_storage": "Off",
|
||||
"run_name": "",
|
||||
"project_id": "",
|
||||
"generation_mode": "Full Run",
|
||||
"review_action": "Continue / Next",
|
||||
"aspect": "Square 1:1",
|
||||
"preset": "Custom",
|
||||
"custom_mp": 0.331776,
|
||||
}
|
||||
)
|
||||
for name in (
|
||||
"reference_video_1",
|
||||
"reference_video_2",
|
||||
"reference_video_3",
|
||||
"driving_audio",
|
||||
):
|
||||
inputs.pop(name, None)
|
||||
if not terminal_merge:
|
||||
inputs.pop("first_frame", None)
|
||||
inputs.pop("last_frame", None)
|
||||
_remove_class(prompt, "LoadImage")
|
||||
_remove_class(prompt, "H3ContinuumLoadVideo")
|
||||
|
||||
prompt_id = str(inputs["sequence_prompt"][0])
|
||||
prompt[prompt_id]["inputs"]["value"] = PROMPT
|
||||
first_scheduler_id = str(inputs["sigmas"][0])
|
||||
prompt[first_scheduler_id]["inputs"].update(
|
||||
{"scheduler": "simple", "steps": 8, "denoise": 1.0}
|
||||
)
|
||||
refine_schedulers = [
|
||||
node
|
||||
for node_id, node in prompt.items()
|
||||
if str(node.get("class_type")) == "BasicScheduler"
|
||||
and str(node_id) != first_scheduler_id
|
||||
]
|
||||
if len(refine_schedulers) != 1:
|
||||
raise GateFailure(
|
||||
f"expected one refine BasicScheduler, found {len(refine_schedulers)}"
|
||||
)
|
||||
refine_schedulers[0]["inputs"].update(
|
||||
{"scheduler": "simple", "steps": 10, "denoise": 0.35}
|
||||
)
|
||||
|
||||
for node_id in ("907", "908", "909", "910", "911"):
|
||||
prompt.pop(node_id, None)
|
||||
_save_id, save_video = _find_one(prompt, "SaveVideo")
|
||||
save_video["inputs"]["filename_prefix"] = output_prefix
|
||||
return prompt
|
||||
|
||||
|
||||
def _redirect_refined_media(prompt: dict[str, Any], node_id: str) -> None:
|
||||
_video_id, video_decode = _find_one(prompt, "VAEDecode")
|
||||
_audio_id, audio_decode = _find_one(prompt, "VAEDecodeAudio")
|
||||
_assemble_id, assemble = _find_one(prompt, "H3ContinuumAssembleSeamV35")
|
||||
video_decode["inputs"]["samples"] = [node_id, 0]
|
||||
audio_decode["inputs"]["samples"] = [node_id, 1]
|
||||
assemble["inputs"]["assembly_plan"] = [node_id, 2]
|
||||
|
||||
|
||||
def _configure_g1(template: Mapping[str, Any], *, output_prefix: str) -> dict[str, Any]:
|
||||
prompt = _configure_base(
|
||||
template,
|
||||
chunks=1,
|
||||
terminal_merge=False,
|
||||
output_prefix=output_prefix,
|
||||
)
|
||||
sampler_id, _continuum = _find_one(prompt, "H3ContinuumSamplerV38")
|
||||
prompt["302"] = {
|
||||
"class_type": LEGACY_CLASS,
|
||||
"inputs": _second_pass_inputs(prompt, target=None),
|
||||
"_meta": {"title": "Legacy V3.5 Video Only"},
|
||||
}
|
||||
prompt["303"] = {
|
||||
"class_type": SELECTIVE_CLASS,
|
||||
"inputs": _second_pass_inputs(prompt, target="Video Only"),
|
||||
"_meta": {"title": "Selective Video Only"},
|
||||
}
|
||||
_redirect_refined_media(prompt, "303")
|
||||
prompt["904"]["inputs"].update(
|
||||
{"samples": ["303", 0], "filename_prefix": f"{output_prefix}_selective_video"}
|
||||
)
|
||||
prompt["905"]["inputs"].update(
|
||||
{"samples": ["303", 1], "filename_prefix": f"{output_prefix}_selective_audio"}
|
||||
)
|
||||
prompt["909"] = {
|
||||
"class_type": "SaveLatent",
|
||||
"inputs": {
|
||||
"samples": ["302", 0],
|
||||
"filename_prefix": f"{output_prefix}_legacy_video",
|
||||
},
|
||||
}
|
||||
prompt["910"] = {
|
||||
"class_type": "SaveLatent",
|
||||
"inputs": {
|
||||
"samples": ["302", 1],
|
||||
"filename_prefix": f"{output_prefix}_legacy_audio",
|
||||
},
|
||||
}
|
||||
prompt["907"] = {
|
||||
"class_type": "H3A3cVideoOnlyParityProbe",
|
||||
"inputs": {
|
||||
"input_audio_latents": [sampler_id, 1],
|
||||
"legacy_video_latents": ["302", 0],
|
||||
"legacy_audio_latents": ["302", 1],
|
||||
"legacy_assembly_plan": ["302", 2],
|
||||
"legacy_status": ["302", 3],
|
||||
"selective_video_latents": ["303", 0],
|
||||
"selective_audio_latents": ["303", 1],
|
||||
"selective_assembly_plan": ["303", 2],
|
||||
"selective_status": ["303", 3],
|
||||
},
|
||||
}
|
||||
prompt["908"] = {
|
||||
"class_type": "PreviewAny",
|
||||
"inputs": {"source": ["907", 0]},
|
||||
}
|
||||
prompt["911"] = {
|
||||
"class_type": "PreviewAny",
|
||||
"inputs": {"source": ["303", 3]},
|
||||
}
|
||||
return prompt
|
||||
|
||||
|
||||
def _configure_selective(
|
||||
template: Mapping[str, Any],
|
||||
*,
|
||||
case: MatrixCase,
|
||||
output_prefix: str,
|
||||
) -> dict[str, Any]:
|
||||
prompt = _configure_base(
|
||||
template,
|
||||
chunks=case.chunks,
|
||||
terminal_merge=case.terminal_merge,
|
||||
output_prefix=output_prefix,
|
||||
)
|
||||
sampler_id, _continuum = _find_one(prompt, "H3ContinuumSamplerV38")
|
||||
prompt["302"] = {
|
||||
"class_type": SELECTIVE_CLASS,
|
||||
"inputs": _second_pass_inputs(prompt, target=case.target),
|
||||
"_meta": {"title": f"Selective {case.target}"},
|
||||
}
|
||||
_redirect_refined_media(prompt, "302")
|
||||
prompt["904"]["inputs"].update(
|
||||
{"samples": ["302", 0], "filename_prefix": f"{output_prefix}_refined_video"}
|
||||
)
|
||||
prompt["905"]["inputs"].update(
|
||||
{"samples": ["302", 1], "filename_prefix": f"{output_prefix}_refined_audio"}
|
||||
)
|
||||
prompt["907"] = {
|
||||
"class_type": "H3A3cSelectiveRefineProbe",
|
||||
"inputs": {
|
||||
"input_video_latents": [sampler_id, 0],
|
||||
"input_audio_latents": [sampler_id, 1],
|
||||
"output_video_latents": ["302", 0],
|
||||
"output_audio_latents": ["302", 1],
|
||||
"input_assembly_plan": [sampler_id, 2],
|
||||
"output_assembly_plan": ["302", 2],
|
||||
"refine_status": ["302", 3],
|
||||
"target_label": case.target,
|
||||
},
|
||||
}
|
||||
prompt["908"] = {
|
||||
"class_type": "PreviewAny",
|
||||
"inputs": {"source": ["907", 0]},
|
||||
}
|
||||
return prompt
|
||||
|
||||
|
||||
def _marker_json(text: str, marker: str) -> dict[str, Any]:
|
||||
line = next((value for value in text.splitlines() if value.startswith(marker)), "")
|
||||
if not line:
|
||||
raise GateFailure(f"status marker is missing: {marker}")
|
||||
return json.loads(line.split("=", 1)[1])
|
||||
|
||||
|
||||
def _decoded_stream_hash(media_path: Path, *, ffmpeg: str, stream: str) -> str:
|
||||
if stream == "video":
|
||||
arguments = ["-map", "0:v:0", "-pix_fmt", "rgb24", "-f", "rawvideo"]
|
||||
elif stream == "audio":
|
||||
arguments = [
|
||||
"-map",
|
||||
"0:a:0",
|
||||
"-ac",
|
||||
"2",
|
||||
"-ar",
|
||||
"32000",
|
||||
"-c:a",
|
||||
"pcm_f32le",
|
||||
"-f",
|
||||
"f32le",
|
||||
]
|
||||
else:
|
||||
raise ValueError(f"unsupported stream {stream!r}")
|
||||
process = subprocess.Popen(
|
||||
[ffmpeg, "-v", "error", "-i", str(media_path), *arguments, "-"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
)
|
||||
if process.stdout is None or process.stderr is None:
|
||||
raise GateFailure("ffmpeg pipe creation failed")
|
||||
digest = hashlib.sha256()
|
||||
while True:
|
||||
block = process.stdout.read(1024 * 1024)
|
||||
if not block:
|
||||
break
|
||||
digest.update(block)
|
||||
stderr = process.stderr.read()
|
||||
returncode = process.wait()
|
||||
if returncode:
|
||||
raise GateFailure(
|
||||
f"ffmpeg {stream} decode failed: "
|
||||
+ stderr.decode("utf-8", errors="replace")[-2000:]
|
||||
)
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def _execute(
|
||||
args: argparse.Namespace,
|
||||
*,
|
||||
name: str,
|
||||
prompt: dict[str, Any],
|
||||
expected_seconds: float,
|
||||
boundaries: tuple[float, ...],
|
||||
) -> tuple[dict[str, Any], Mapping[str, Any]]:
|
||||
case_root = args.evidence_root / name
|
||||
case_root.mkdir(parents=True, exist_ok=True)
|
||||
prompt_path = case_root / "prompt.json"
|
||||
prompt_path.write_text(
|
||||
json.dumps(prompt, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
print(f"A3c start: {name}", flush=True)
|
||||
with ResourceMonitor(args.backend_pid, interval_seconds=0.5) as monitor:
|
||||
prompt_id, history, elapsed = submit_and_wait(
|
||||
server=args.server,
|
||||
prompt=prompt,
|
||||
client_id=f"v38-a3c-{uuid.uuid4().hex}",
|
||||
timeout_seconds=args.timeout_seconds,
|
||||
poll_seconds=2.0,
|
||||
)
|
||||
history_path = case_root / "history.json"
|
||||
history_path.write_text(
|
||||
json.dumps(history, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
entry = _history_entry(history, prompt_id)
|
||||
media_path = _output_media(history, args.output_root)
|
||||
media = _probe_media(media_path, args.ffprobe)
|
||||
audio_health = _audio_health(
|
||||
media_path,
|
||||
ffmpeg=args.ffmpeg,
|
||||
expected_seconds=expected_seconds,
|
||||
boundaries=boundaries,
|
||||
)
|
||||
decoded = {
|
||||
"video_sha256": _decoded_stream_hash(
|
||||
media_path,
|
||||
ffmpeg=args.ffmpeg,
|
||||
stream="video",
|
||||
),
|
||||
"audio_pcm_sha256": _decoded_stream_hash(
|
||||
media_path,
|
||||
ffmpeg=args.ffmpeg,
|
||||
stream="audio",
|
||||
),
|
||||
}
|
||||
result = {
|
||||
"name": name,
|
||||
"prompt_id": prompt_id,
|
||||
"api_elapsed_seconds": float(elapsed),
|
||||
"prompt": str(prompt_path),
|
||||
"history": str(history_path),
|
||||
"media_path": str(media_path),
|
||||
"media": media,
|
||||
"decoded": decoded,
|
||||
"audio_health": audio_health,
|
||||
"resources": monitor.as_dict(),
|
||||
}
|
||||
return result, entry
|
||||
|
||||
|
||||
def _run_g1(
|
||||
args: argparse.Namespace,
|
||||
*,
|
||||
template: Mapping[str, Any],
|
||||
) -> dict[str, Any]:
|
||||
output_prefix = f"v38_a3c/{args.run_tag}/g1_video_only_parity"
|
||||
prompt = _configure_g1(template, output_prefix=output_prefix)
|
||||
result, entry = _execute(
|
||||
args,
|
||||
name="g1_video_only_parity",
|
||||
prompt=prompt,
|
||||
expected_seconds=5.0,
|
||||
boundaries=(),
|
||||
)
|
||||
parity_status = _output_text(entry, "908")
|
||||
parity = _marker_json(parity_status, "A3C_PARITY_JSON=")
|
||||
first_videos = _output_latents(entry, "902", args.output_root)
|
||||
first_audios = _output_latents(entry, "903", args.output_root)
|
||||
selective_videos = _output_latents(entry, "904", args.output_root)
|
||||
selective_audios = _output_latents(entry, "905", args.output_root)
|
||||
legacy_videos = _output_latents(entry, "909", args.output_root)
|
||||
legacy_audios = _output_latents(entry, "910", args.output_root)
|
||||
group_count = int(parity.get("physical_group_count") or 0)
|
||||
checks = {
|
||||
"one_physical_group": group_count == 1,
|
||||
"first_output_counts": len(first_videos) == len(first_audios) == 1,
|
||||
"legacy_output_counts": len(legacy_videos) == len(legacy_audios) == 1,
|
||||
"selective_output_counts": len(selective_videos)
|
||||
== len(selective_audios)
|
||||
== 1,
|
||||
"video_latent_sha_parity": parity.get("legacy_video_sha256")
|
||||
== parity.get("selective_video_sha256"),
|
||||
"audio_latent_sha_parity": parity.get("legacy_audio_sha256")
|
||||
== parity.get("selective_audio_sha256"),
|
||||
"legacy_audio_passthrough": all(
|
||||
parity.get("legacy_audio_object_identity") or []
|
||||
)
|
||||
and all(parity.get("legacy_audio_tensor_identity") or []),
|
||||
"selective_audio_passthrough": all(
|
||||
parity.get("selective_audio_object_identity") or []
|
||||
)
|
||||
and all(parity.get("selective_audio_tensor_identity") or []),
|
||||
"audio_matches_first_pass": parity.get("legacy_audio_sha256")
|
||||
== [item["tensor_sha256"] for item in first_audios]
|
||||
== parity.get("selective_audio_sha256"),
|
||||
"refine_seed_parity": parity.get("legacy_refine_group_seeds")
|
||||
== parity.get("selective_refine_group_seeds"),
|
||||
"sigmas_parity": parity.get("legacy_schedule_sigma_hash")
|
||||
== parity.get("selective_schedule_sigma_hash"),
|
||||
"sampling_count_parity": parity.get("legacy_sampling_passes_reported")
|
||||
== parity.get("selective_sampling_passes_reported")
|
||||
== group_count,
|
||||
"assembly_plan_parity": parity.get("legacy_plan_without_target_identity")
|
||||
== parity.get("selective_plan_without_target_identity"),
|
||||
"target_contract": parity.get("selective_target_mode") == "video_only"
|
||||
and parity.get("selective_seed_namespace")
|
||||
== "h3-continuum-refine-v1",
|
||||
"shape_parity": parity.get("legacy_video_shapes")
|
||||
== parity.get("selective_video_shapes")
|
||||
and parity.get("legacy_audio_shapes")
|
||||
== parity.get("selective_audio_shapes"),
|
||||
"finite": all(parity.get("legacy_video_finite") or [])
|
||||
and all(parity.get("selective_video_finite") or [])
|
||||
and all(parity.get("legacy_audio_finite") or [])
|
||||
and all(parity.get("selective_audio_finite") or []),
|
||||
"media": int(result["media"]["frames"]) == 120
|
||||
and abs(float(result["media"]["format_duration"]) - 5.0) <= 0.05
|
||||
and int(result["media"]["audio_sample_rate"]) == 32000
|
||||
and int(result["media"]["audio_channels"]) == 2,
|
||||
"audio_health": bool(result["audio_health"]["pass"]),
|
||||
}
|
||||
result.update(
|
||||
{
|
||||
"parity_status": parity_status,
|
||||
"parity": parity,
|
||||
"first_video_latents": first_videos,
|
||||
"first_audio_latents": first_audios,
|
||||
"legacy_video_latents": legacy_videos,
|
||||
"legacy_audio_latents": legacy_audios,
|
||||
"selective_video_latents": selective_videos,
|
||||
"selective_audio_latents": selective_audios,
|
||||
"checks": checks,
|
||||
"pass": all(checks.values()),
|
||||
}
|
||||
)
|
||||
case_root = args.evidence_root / "g1_video_only_parity"
|
||||
(case_root / "result.json").write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
print(f"A3c end: g1_video_only_parity; pass={result['pass']}", flush=True)
|
||||
if not result["pass"]:
|
||||
failed = [name for name, value in checks.items() if not value]
|
||||
raise GateFailure(f"G1 Video Only parity failed: {failed}")
|
||||
return result
|
||||
|
||||
|
||||
def _run_selective_case(
|
||||
args: argparse.Namespace,
|
||||
*,
|
||||
case: MatrixCase,
|
||||
template: Mapping[str, Any],
|
||||
) -> dict[str, Any]:
|
||||
output_prefix = f"v38_a3c/{args.run_tag}/{case.name}"
|
||||
prompt = _configure_selective(
|
||||
template,
|
||||
case=case,
|
||||
output_prefix=output_prefix,
|
||||
)
|
||||
result, entry = _execute(
|
||||
args,
|
||||
name=case.name,
|
||||
prompt=prompt,
|
||||
expected_seconds=case.chunks * 5.0,
|
||||
boundaries=case.boundary_seconds,
|
||||
)
|
||||
probe_status = _output_text(entry, "908")
|
||||
probe = _marker_json(probe_status, "A3C_PROBE_JSON=")
|
||||
first_videos = _output_latents(entry, "902", args.output_root)
|
||||
first_audios = _output_latents(entry, "903", args.output_root)
|
||||
refined_videos = _output_latents(entry, "904", args.output_root)
|
||||
refined_audios = _output_latents(entry, "905", args.output_root)
|
||||
groups = list(probe.get("physical_groups") or [])
|
||||
expected_mode = "audio_only" if case.target == "Audio Only" else "video_audio"
|
||||
expected_namespace = (
|
||||
"h3-continuum-refine-audio-v1"
|
||||
if case.target == "Audio Only"
|
||||
else "h3-continuum-refine-av-v1"
|
||||
)
|
||||
terminal_atomic = True
|
||||
if case.terminal_merge:
|
||||
terminal_atomic = (
|
||||
len(groups) == 2
|
||||
and groups[-1].get("logical_chunks") == [2, 3]
|
||||
and groups[-1].get("terminal_merged") is True
|
||||
)
|
||||
common = {
|
||||
"physical_group_count": len(groups) == case.expected_physical_groups,
|
||||
"latent_counts": len(first_videos)
|
||||
== len(first_audios)
|
||||
== len(refined_videos)
|
||||
== len(refined_audios)
|
||||
== case.expected_physical_groups,
|
||||
"target_contract": probe.get("target_mode") == expected_mode
|
||||
and probe.get("seed_namespace") == expected_namespace,
|
||||
"contract_version": probe.get("second_pass_contract_version") == 1,
|
||||
"seed_count": len(probe.get("refine_group_seeds") or [])
|
||||
== case.expected_physical_groups,
|
||||
"sigmas_recorded": bool(probe.get("schedule_sigma_hash")),
|
||||
"sampling_count": probe.get("sampling_passes_reported")
|
||||
== case.expected_physical_groups,
|
||||
"video_shape": probe.get("input_video_shapes")
|
||||
== probe.get("output_video_shapes"),
|
||||
"audio_shape": probe.get("input_audio_shapes")
|
||||
== probe.get("output_audio_shapes"),
|
||||
"finite": all(probe.get("output_video_finite") or [])
|
||||
and all(probe.get("output_audio_finite") or []),
|
||||
"terminal_atomic": terminal_atomic,
|
||||
"media_frames": int(result["media"]["frames"]) == case.chunks * 5 * 24,
|
||||
"media_duration": abs(
|
||||
float(result["media"]["format_duration"]) - case.chunks * 5.0
|
||||
)
|
||||
<= 0.05,
|
||||
"media_audio": int(result["media"]["audio_sample_rate"]) == 32000
|
||||
and int(result["media"]["audio_channels"]) == 2,
|
||||
"audio_health": bool(result["audio_health"]["pass"]),
|
||||
}
|
||||
if case.target == "Audio Only":
|
||||
target_checks = {
|
||||
"video_object_passthrough": all(
|
||||
probe.get("input_video_object_identity") or []
|
||||
)
|
||||
and all(probe.get("input_video_tensor_identity") or []),
|
||||
"video_sha_passthrough": probe.get("input_video_sha256")
|
||||
== probe.get("output_video_sha256"),
|
||||
"audio_changed": all(
|
||||
before != after
|
||||
for before, after in zip(
|
||||
probe.get("input_audio_sha256") or [],
|
||||
probe.get("output_audio_sha256") or [],
|
||||
strict=True,
|
||||
)
|
||||
),
|
||||
}
|
||||
else:
|
||||
target_checks = {
|
||||
"video_changed": all(
|
||||
before != after
|
||||
for before, after in zip(
|
||||
probe.get("input_video_sha256") or [],
|
||||
probe.get("output_video_sha256") or [],
|
||||
strict=True,
|
||||
)
|
||||
),
|
||||
"audio_changed": all(
|
||||
before != after
|
||||
for before, after in zip(
|
||||
probe.get("input_audio_sha256") or [],
|
||||
probe.get("output_audio_sha256") or [],
|
||||
strict=True,
|
||||
)
|
||||
),
|
||||
}
|
||||
checks = {**common, **target_checks}
|
||||
result.update(
|
||||
{
|
||||
"case": asdict(case),
|
||||
"probe_status": probe_status,
|
||||
"probe": probe,
|
||||
"first_video_latents": first_videos,
|
||||
"first_audio_latents": first_audios,
|
||||
"refined_video_latents": refined_videos,
|
||||
"refined_audio_latents": refined_audios,
|
||||
"checks": checks,
|
||||
"pass": all(checks.values()),
|
||||
}
|
||||
)
|
||||
case_root = args.evidence_root / case.name
|
||||
(case_root / "result.json").write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
print(f"A3c end: {case.name}; pass={result['pass']}", flush=True)
|
||||
if not result["pass"]:
|
||||
failed = [name for name, value in checks.items() if not value]
|
||||
raise GateFailure(f"{case.name} failed: {failed}")
|
||||
return result
|
||||
|
||||
|
||||
def run(args: argparse.Namespace) -> dict[str, Any]:
|
||||
args.evidence_root.mkdir(parents=True, exist_ok=True)
|
||||
t2_template = json.loads(args.t2_template.read_text(encoding="utf-8"))
|
||||
terminal_template = json.loads(
|
||||
args.terminal_template.read_text(encoding="utf-8")
|
||||
)
|
||||
summary = {
|
||||
"format": "h3-continuum-v38-a3c-selective-refine-gpu-matrix-v1",
|
||||
"server": args.server,
|
||||
"backend_pid": args.backend_pid,
|
||||
"run_tag": args.run_tag,
|
||||
"first_pass_seed": FIRST_PASS_SEED,
|
||||
"refine_seed": REFINE_SEED,
|
||||
"settings": {
|
||||
"resolution": "576x576",
|
||||
"first_pass_steps": 8,
|
||||
"refine_steps": 10,
|
||||
"refine_denoise": 0.35,
|
||||
"continuity": "Balanced — 22 frames",
|
||||
"audio_continuity": True,
|
||||
"run_storage": "Off",
|
||||
"sampler": "res_multistep",
|
||||
"scheduler": "simple",
|
||||
"sage": True,
|
||||
},
|
||||
"templates": {
|
||||
"t2": str(args.t2_template),
|
||||
"terminal": str(args.terminal_template),
|
||||
},
|
||||
"results": {},
|
||||
"pass": False,
|
||||
"production_status": "HOLD for audio-targeted modes",
|
||||
}
|
||||
summary_path = args.evidence_root / "summary.json"
|
||||
try:
|
||||
summary["results"]["g1_video_only_parity"] = _run_g1(
|
||||
args,
|
||||
template=t2_template,
|
||||
)
|
||||
for case in G2_TO_G5:
|
||||
template = terminal_template if case.terminal_merge else t2_template
|
||||
summary["results"][case.name] = _run_selective_case(
|
||||
args,
|
||||
case=case,
|
||||
template=template,
|
||||
)
|
||||
summary["pass"] = True
|
||||
summary["status"] = "Selective Refine GPU Experimental PASS"
|
||||
return summary
|
||||
except Exception as exc:
|
||||
summary["failure_type"] = type(exc).__name__
|
||||
summary["failure"] = str(exc)
|
||||
summary["status"] = "A3c STOP / Production HOLD"
|
||||
return summary
|
||||
finally:
|
||||
summary_path.write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8190")
|
||||
parser.add_argument("--backend-pid", type=int, required=True)
|
||||
parser.add_argument("--run-tag", required=True)
|
||||
parser.add_argument("--evidence-root", type=Path, required=True)
|
||||
parser.add_argument("--t2-template", type=Path, required=True)
|
||||
parser.add_argument("--terminal-template", type=Path, required=True)
|
||||
parser.add_argument(
|
||||
"--output-root",
|
||||
type=Path,
|
||||
default=Path(r"D:\output\video\comfy_video"),
|
||||
)
|
||||
parser.add_argument("--ffmpeg", default=shutil.which("ffmpeg"))
|
||||
parser.add_argument("--ffprobe", default=shutil.which("ffprobe"))
|
||||
parser.add_argument("--timeout-seconds", type=float, default=3600.0)
|
||||
args = parser.parse_args()
|
||||
if not args.ffmpeg or not args.ffprobe:
|
||||
raise SystemExit("ffmpeg and ffprobe are required")
|
||||
summary = run(args)
|
||||
print(json.dumps(summary, indent=2, ensure_ascii=False), flush=True)
|
||||
return 0 if summary["pass"] else 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,524 @@
|
||||
"""Run the A4 Chunk-scoped Refine GPU Matrix against the public node."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
from dataclasses import asdict, dataclass
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import sys
|
||||
from typing import Any, Mapping
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
from v38_a2_audio_only_gpu_canary import _output_latents, _output_text
|
||||
from v38_a3c_selective_refine_gpu_matrix import (
|
||||
GateFailure,
|
||||
MatrixCase,
|
||||
_configure_selective,
|
||||
_execute,
|
||||
_marker_json,
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ScopeCase:
|
||||
name: str
|
||||
scope: str
|
||||
scope_index: int
|
||||
terminal_merge: bool
|
||||
selected_group_index: int | None
|
||||
selected_logical_chunks: tuple[int, ...]
|
||||
|
||||
|
||||
CASES = (
|
||||
ScopeCase("g1_all_video_audio_3x5", "All", 1, False, None, (1, 2, 3)),
|
||||
ScopeCase("g2_physical_group_2", "Physical Group", 2, False, 1, (2,)),
|
||||
ScopeCase("g3_logical_chunk_2", "Logical Chunk", 2, False, 1, (2,)),
|
||||
ScopeCase("g4_terminal_logical_chunk_2", "Logical Chunk", 2, True, 1, (2, 3)),
|
||||
ScopeCase("g5_terminal_logical_chunk_3", "Logical Chunk", 3, True, 1, (2, 3)),
|
||||
)
|
||||
|
||||
|
||||
def _key_paths(value: Any, prefix: str = "$") -> list[str]:
|
||||
paths: list[str] = []
|
||||
if isinstance(value, Mapping):
|
||||
for key, item in sorted(value.items(), key=lambda pair: str(pair[0])):
|
||||
path = f"{prefix}.{key}"
|
||||
paths.append(path)
|
||||
paths.extend(_key_paths(item, path))
|
||||
elif isinstance(value, list):
|
||||
for index, item in enumerate(value):
|
||||
paths.extend(_key_paths(item, f"{prefix}[]"))
|
||||
return paths
|
||||
|
||||
|
||||
def _cross_run_plan_identity(value: Any) -> Any:
|
||||
"""Ignore only the pre-existing per-execution monotonic start marker."""
|
||||
|
||||
normalized = copy.deepcopy(value)
|
||||
if isinstance(normalized, dict):
|
||||
normalized.pop("_runtime_started_at", None)
|
||||
return normalized
|
||||
|
||||
|
||||
def _configure(
|
||||
template: Mapping[str, Any],
|
||||
*,
|
||||
case: ScopeCase,
|
||||
output_prefix: str,
|
||||
) -> dict[str, Any]:
|
||||
base_case = MatrixCase(
|
||||
name=case.name,
|
||||
target="Video + Audio",
|
||||
chunks=3,
|
||||
terminal_merge=case.terminal_merge,
|
||||
expected_physical_groups=2 if case.terminal_merge else 3,
|
||||
boundary_seconds=(5.0, 10.0),
|
||||
)
|
||||
prompt = _configure_selective(
|
||||
template,
|
||||
case=base_case,
|
||||
output_prefix=output_prefix,
|
||||
)
|
||||
selective = prompt["302"]["inputs"]
|
||||
selective["refine_scope"] = case.scope
|
||||
selective["refine_scope_index"] = int(case.scope_index)
|
||||
prompt["302"]["_meta"]["title"] = (
|
||||
f"Selective Video + Audio / {case.scope} {case.scope_index}"
|
||||
)
|
||||
return prompt
|
||||
|
||||
|
||||
def _load_a3c_baseline(path: Path, result_name: str) -> dict[str, Any]:
|
||||
summary = json.loads(path.read_text(encoding="utf-8"))
|
||||
if not bool(summary.get("pass")):
|
||||
raise GateFailure("A3c baseline summary is not PASS")
|
||||
result = (summary.get("results") or {}).get(result_name)
|
||||
if not isinstance(result, dict) or not bool(result.get("pass")):
|
||||
raise GateFailure(f"A3c baseline {result_name!r} is missing or not PASS")
|
||||
return result
|
||||
|
||||
|
||||
def _identity_checks(
|
||||
probe: Mapping[str, Any],
|
||||
*,
|
||||
selected_group_index: int,
|
||||
) -> dict[str, bool]:
|
||||
count = len(probe.get("physical_groups") or [])
|
||||
expected_selected = [index == selected_group_index for index in range(count)]
|
||||
video_object = list(probe.get("input_video_object_identity") or [])
|
||||
video_tensor = list(probe.get("input_video_tensor_identity") or [])
|
||||
audio_object = list(probe.get("input_audio_object_identity") or [])
|
||||
audio_tensor = list(probe.get("input_audio_tensor_identity") or [])
|
||||
input_video = list(probe.get("input_video_sha256") or [])
|
||||
output_video = list(probe.get("output_video_sha256") or [])
|
||||
input_audio = list(probe.get("input_audio_sha256") or [])
|
||||
output_audio = list(probe.get("output_audio_sha256") or [])
|
||||
return {
|
||||
"identity_vector_lengths": all(
|
||||
len(values) == count
|
||||
for values in (
|
||||
video_object,
|
||||
video_tensor,
|
||||
audio_object,
|
||||
audio_tensor,
|
||||
input_video,
|
||||
output_video,
|
||||
input_audio,
|
||||
output_audio,
|
||||
)
|
||||
),
|
||||
"video_object_passthrough": all(
|
||||
identity == (not selected)
|
||||
for identity, selected in zip(
|
||||
video_object,
|
||||
expected_selected,
|
||||
strict=True,
|
||||
)
|
||||
),
|
||||
"video_tensor_passthrough": all(
|
||||
identity == (not selected)
|
||||
for identity, selected in zip(
|
||||
video_tensor,
|
||||
expected_selected,
|
||||
strict=True,
|
||||
)
|
||||
),
|
||||
"audio_object_passthrough": all(
|
||||
identity == (not selected)
|
||||
for identity, selected in zip(
|
||||
audio_object,
|
||||
expected_selected,
|
||||
strict=True,
|
||||
)
|
||||
),
|
||||
"audio_tensor_passthrough": all(
|
||||
identity == (not selected)
|
||||
for identity, selected in zip(
|
||||
audio_tensor,
|
||||
expected_selected,
|
||||
strict=True,
|
||||
)
|
||||
),
|
||||
"video_sha_selection": all(
|
||||
(before != after) is selected
|
||||
for before, after, selected in zip(
|
||||
input_video,
|
||||
output_video,
|
||||
expected_selected,
|
||||
strict=True,
|
||||
)
|
||||
),
|
||||
"audio_sha_selection": all(
|
||||
(before != after) is selected
|
||||
for before, after, selected in zip(
|
||||
input_audio,
|
||||
output_audio,
|
||||
expected_selected,
|
||||
strict=True,
|
||||
)
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def _run_case(
|
||||
args: argparse.Namespace,
|
||||
*,
|
||||
case: ScopeCase,
|
||||
template: Mapping[str, Any],
|
||||
baseline_probe: Mapping[str, Any],
|
||||
all_result: Mapping[str, Any] | None,
|
||||
) -> dict[str, Any]:
|
||||
output_prefix = f"v38_a4/{args.run_tag}/{case.name}"
|
||||
prompt = _configure(template, case=case, output_prefix=output_prefix)
|
||||
result, entry = _execute(
|
||||
args,
|
||||
name=case.name,
|
||||
prompt=prompt,
|
||||
expected_seconds=15.0,
|
||||
boundaries=(5.0, 10.0),
|
||||
)
|
||||
probe_status = _output_text(entry, "908")
|
||||
probe = _marker_json(probe_status, "A3C_PROBE_JSON=")
|
||||
first_videos = _output_latents(entry, "902", args.output_root)
|
||||
first_audios = _output_latents(entry, "903", args.output_root)
|
||||
refined_videos = _output_latents(entry, "904", args.output_root)
|
||||
refined_audios = _output_latents(entry, "905", args.output_root)
|
||||
groups = list(probe.get("physical_groups") or [])
|
||||
expected_groups = 2 if case.terminal_merge else 3
|
||||
contract = (probe.get("output_plan") or {}).get("normalized", {}).get(
|
||||
"second_pass_contract",
|
||||
{},
|
||||
)
|
||||
checks = {
|
||||
"physical_group_count": len(groups) == expected_groups,
|
||||
"latent_counts": len(first_videos)
|
||||
== len(first_audios)
|
||||
== len(refined_videos)
|
||||
== len(refined_audios)
|
||||
== expected_groups,
|
||||
"target_contract": probe.get("target_mode") == "video_audio"
|
||||
and probe.get("seed_namespace") == "h3-continuum-refine-av-v1",
|
||||
"contract_version": probe.get("second_pass_contract_version") == 1,
|
||||
"schedule_hash": probe.get("schedule_sigma_hash")
|
||||
== baseline_probe.get("schedule_sigma_hash"),
|
||||
"plan_scope_field_absent": "refine_scope_contract" not in contract,
|
||||
"media": int(result["media"]["frames"]) == 360
|
||||
and abs(float(result["media"]["format_duration"]) - 15.0) <= 0.05
|
||||
and int(result["media"]["audio_sample_rate"]) == 32000
|
||||
and int(result["media"]["audio_channels"]) == 2,
|
||||
"audio_health": bool(result["audio_health"]["pass"]),
|
||||
}
|
||||
if case.selected_group_index is None:
|
||||
current_plan = (probe.get("output_plan") or {}).get("normalized")
|
||||
baseline_plan = (baseline_probe.get("output_plan") or {}).get("normalized")
|
||||
checks.update(
|
||||
{
|
||||
"all_video_input_parity": probe.get("input_video_sha256")
|
||||
== baseline_probe.get("input_video_sha256"),
|
||||
"all_audio_input_parity": probe.get("input_audio_sha256")
|
||||
== baseline_probe.get("input_audio_sha256"),
|
||||
"all_video_output_parity": probe.get("output_video_sha256")
|
||||
== baseline_probe.get("output_video_sha256"),
|
||||
"all_audio_output_parity": probe.get("output_audio_sha256")
|
||||
== baseline_probe.get("output_audio_sha256"),
|
||||
"all_seed_parity": probe.get("refine_group_seeds")
|
||||
== baseline_probe.get("refine_group_seeds"),
|
||||
"all_sampling_parity": probe.get("sampling_passes_reported")
|
||||
== baseline_probe.get("sampling_passes_reported")
|
||||
== expected_groups,
|
||||
"all_plan_field_set": _key_paths(current_plan)
|
||||
== _key_paths(baseline_plan),
|
||||
"all_plan_parity": _cross_run_plan_identity(current_plan)
|
||||
== _cross_run_plan_identity(baseline_plan),
|
||||
"all_decoded_video_parity": result["decoded"]["video_sha256"]
|
||||
== args.a3c_decoded_video_sha,
|
||||
"all_decoded_audio_parity": result["decoded"]["audio_pcm_sha256"]
|
||||
== args.a3c_decoded_audio_sha,
|
||||
"all_scope_status": "scope=All." in probe_status,
|
||||
}
|
||||
)
|
||||
else:
|
||||
selected_index = int(case.selected_group_index)
|
||||
expected_seed = list(baseline_probe.get("refine_group_seeds") or [])[selected_index]
|
||||
checks.update(
|
||||
{
|
||||
"one_sampling": probe.get("sampling_passes_reported") == 1,
|
||||
"one_seed": probe.get("refine_group_seeds") == [expected_seed],
|
||||
"scope_status": f"scope={case.scope} {case.scope_index}." in probe_status,
|
||||
"resolved_groups_status": f"selected_physical_groups=[{selected_index + 1}]"
|
||||
in probe_status,
|
||||
"resolved_logical_status": (
|
||||
"selected_logical_chunks="
|
||||
+ str(list(case.selected_logical_chunks))
|
||||
)
|
||||
in probe_status,
|
||||
**_identity_checks(
|
||||
probe,
|
||||
selected_group_index=selected_index,
|
||||
),
|
||||
}
|
||||
)
|
||||
if all_result is not None:
|
||||
all_plan = (all_result.get("probe") or {}).get("output_plan") or {}
|
||||
checks["assembly_field_set_parity"] = _key_paths(
|
||||
(probe.get("output_plan") or {}).get("normalized")
|
||||
) == _key_paths(all_plan.get("normalized"))
|
||||
result.update(
|
||||
{
|
||||
"case": asdict(case),
|
||||
"probe_status": probe_status,
|
||||
"probe": probe,
|
||||
"first_video_latents": first_videos,
|
||||
"first_audio_latents": first_audios,
|
||||
"refined_video_latents": refined_videos,
|
||||
"refined_audio_latents": refined_audios,
|
||||
"checks": checks,
|
||||
"pass": all(checks.values()),
|
||||
}
|
||||
)
|
||||
case_root = args.evidence_root / case.name
|
||||
(case_root / "result.json").write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
print(f"A4 end: {case.name}; pass={result['pass']}", flush=True)
|
||||
if not result["pass"]:
|
||||
failed = [name for name, passed in checks.items() if not passed]
|
||||
raise GateFailure(f"{case.name} failed: {failed}")
|
||||
return result
|
||||
|
||||
|
||||
def _load_resumed_all_result(
|
||||
path: Path,
|
||||
*,
|
||||
baseline_probe: Mapping[str, Any],
|
||||
) -> dict[str, Any]:
|
||||
"""Revalidate one completed G1 without repeating its GPU Sampling."""
|
||||
|
||||
result = json.loads(path.read_text(encoding="utf-8"))
|
||||
probe = result.get("probe") or {}
|
||||
checks = dict(result.get("checks") or {})
|
||||
current_plan = (probe.get("output_plan") or {}).get("normalized")
|
||||
baseline_plan = (baseline_probe.get("output_plan") or {}).get("normalized")
|
||||
checks["all_plan_field_set"] = _key_paths(current_plan) == _key_paths(
|
||||
baseline_plan
|
||||
)
|
||||
checks["all_plan_parity"] = _cross_run_plan_identity(
|
||||
current_plan
|
||||
) == _cross_run_plan_identity(baseline_plan)
|
||||
result["checks"] = checks
|
||||
result["pass"] = all(checks.values())
|
||||
result["resumed_without_resampling"] = True
|
||||
if not result["pass"]:
|
||||
failed = [name for name, passed in checks.items() if not passed]
|
||||
raise GateFailure(f"resumed G1 validation failed: {failed}")
|
||||
path.with_name("result.revalidated.json").write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
def _load_resumed_scoped_result(
|
||||
path: Path,
|
||||
*,
|
||||
assembly_reference_probe: Mapping[str, Any],
|
||||
) -> dict[str, Any]:
|
||||
"""Revalidate one completed scoped case without repeating GPU Sampling."""
|
||||
|
||||
result = json.loads(path.read_text(encoding="utf-8"))
|
||||
probe = result.get("probe") or {}
|
||||
checks = dict(result.get("checks") or {})
|
||||
current_plan = (probe.get("output_plan") or {}).get("normalized")
|
||||
reference_plan = (assembly_reference_probe.get("output_plan") or {}).get(
|
||||
"normalized"
|
||||
)
|
||||
checks["assembly_field_set_parity"] = _key_paths(current_plan) == _key_paths(
|
||||
reference_plan
|
||||
)
|
||||
result["checks"] = checks
|
||||
result["pass"] = all(checks.values())
|
||||
result["resumed_without_resampling"] = True
|
||||
if not result["pass"]:
|
||||
failed = [name for name, passed in checks.items() if not passed]
|
||||
raise GateFailure(f"resumed scoped validation failed: {failed}")
|
||||
path.with_name("result.revalidated.json").write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
def _cross_case_checks(results: Mapping[str, Mapping[str, Any]]) -> dict[str, bool]:
|
||||
g2 = results[CASES[1].name]
|
||||
g3 = results[CASES[2].name]
|
||||
g4 = results[CASES[3].name]
|
||||
g5 = results[CASES[4].name]
|
||||
return {
|
||||
"physical_vs_logical_nonterminal_video": g2["probe"]["output_video_sha256"]
|
||||
== g3["probe"]["output_video_sha256"],
|
||||
"physical_vs_logical_nonterminal_audio": g2["probe"]["output_audio_sha256"]
|
||||
== g3["probe"]["output_audio_sha256"],
|
||||
"physical_vs_logical_nonterminal_seed": g2["probe"]["refine_group_seeds"]
|
||||
== g3["probe"]["refine_group_seeds"],
|
||||
"terminal_2_vs_3_video": g4["probe"]["output_video_sha256"]
|
||||
== g5["probe"]["output_video_sha256"],
|
||||
"terminal_2_vs_3_audio": g4["probe"]["output_audio_sha256"]
|
||||
== g5["probe"]["output_audio_sha256"],
|
||||
"terminal_2_vs_3_seed": g4["probe"]["refine_group_seeds"]
|
||||
== g5["probe"]["refine_group_seeds"],
|
||||
"terminal_2_vs_3_plan": g4["probe"]["output_plan"]["sha256"]
|
||||
== g5["probe"]["output_plan"]["sha256"],
|
||||
"terminal_2_vs_3_decoded_video": g4["decoded"]["video_sha256"]
|
||||
== g5["decoded"]["video_sha256"],
|
||||
"terminal_2_vs_3_decoded_audio": g4["decoded"]["audio_pcm_sha256"]
|
||||
== g5["decoded"]["audio_pcm_sha256"],
|
||||
}
|
||||
|
||||
|
||||
def run(args: argparse.Namespace) -> dict[str, Any]:
|
||||
args.evidence_root.mkdir(parents=True, exist_ok=True)
|
||||
t2_template = json.loads(args.t2_template.read_text(encoding="utf-8"))
|
||||
terminal_template = json.loads(args.terminal_template.read_text(encoding="utf-8"))
|
||||
baseline_result = _load_a3c_baseline(
|
||||
args.a3c_baseline,
|
||||
"g4_video_audio_3x5",
|
||||
)
|
||||
terminal_baseline_result = _load_a3c_baseline(
|
||||
args.a3c_baseline,
|
||||
"g5_video_audio_terminal",
|
||||
)
|
||||
baseline_probe = baseline_result["probe"]
|
||||
args.a3c_decoded_video_sha = baseline_result["decoded"]["video_sha256"]
|
||||
args.a3c_decoded_audio_sha = baseline_result["decoded"]["audio_pcm_sha256"]
|
||||
summary: dict[str, Any] = {
|
||||
"format": "h3-continuum-v38-a4-chunk-scoped-refine-gpu-matrix-v1",
|
||||
"server": args.server,
|
||||
"backend_pid": args.backend_pid,
|
||||
"run_tag": args.run_tag,
|
||||
"a3c_baseline": str(args.a3c_baseline),
|
||||
"results": {},
|
||||
"pass": False,
|
||||
"production_status": "HOLD for audio-targeted modes",
|
||||
}
|
||||
summary_path = args.evidence_root / "summary.json"
|
||||
try:
|
||||
resume_results: dict[str, Path] = {}
|
||||
for path in args.resume_result or ():
|
||||
payload = json.loads(path.read_text(encoding="utf-8"))
|
||||
name = str((payload.get("case") or {}).get("name") or "")
|
||||
if not name or name in resume_results:
|
||||
raise GateFailure(f"invalid or duplicate resumed result: {path}")
|
||||
resume_results[name] = path
|
||||
all_result: Mapping[str, Any] | None = None
|
||||
for case in CASES:
|
||||
assembly_reference_result = (
|
||||
terminal_baseline_result if case.terminal_merge else all_result
|
||||
)
|
||||
if case.name in resume_results:
|
||||
if case.selected_group_index is None:
|
||||
result = _load_resumed_all_result(
|
||||
resume_results[case.name],
|
||||
baseline_probe=baseline_probe,
|
||||
)
|
||||
else:
|
||||
if assembly_reference_result is None:
|
||||
raise GateFailure("scoped resume has no Assembly reference")
|
||||
result = _load_resumed_scoped_result(
|
||||
resume_results[case.name],
|
||||
assembly_reference_probe=assembly_reference_result["probe"],
|
||||
)
|
||||
else:
|
||||
template = terminal_template if case.terminal_merge else t2_template
|
||||
result = _run_case(
|
||||
args,
|
||||
case=case,
|
||||
template=template,
|
||||
baseline_probe=(
|
||||
terminal_baseline_result["probe"]
|
||||
if case.terminal_merge
|
||||
else baseline_probe
|
||||
),
|
||||
all_result=assembly_reference_result,
|
||||
)
|
||||
summary["results"][case.name] = result
|
||||
if case.selected_group_index is None:
|
||||
all_result = result
|
||||
summary["cross_case_checks"] = _cross_case_checks(summary["results"])
|
||||
if not all(summary["cross_case_checks"].values()):
|
||||
failed = [
|
||||
name
|
||||
for name, passed in summary["cross_case_checks"].items()
|
||||
if not passed
|
||||
]
|
||||
raise GateFailure(f"cross-case parity failed: {failed}")
|
||||
summary["pass"] = True
|
||||
summary["status"] = "A4 Chunk-scoped Refine GPU Experimental PASS"
|
||||
return summary
|
||||
except Exception as exc:
|
||||
summary["failure_type"] = type(exc).__name__
|
||||
summary["failure"] = str(exc)
|
||||
summary["status"] = "A4 STOP / Production HOLD"
|
||||
return summary
|
||||
finally:
|
||||
summary_path.write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8190")
|
||||
parser.add_argument("--backend-pid", type=int, required=True)
|
||||
parser.add_argument("--run-tag", required=True)
|
||||
parser.add_argument("--evidence-root", type=Path, required=True)
|
||||
parser.add_argument("--t2-template", type=Path, required=True)
|
||||
parser.add_argument("--terminal-template", type=Path, required=True)
|
||||
parser.add_argument("--a3c-baseline", type=Path, required=True)
|
||||
parser.add_argument("--resume-result", type=Path, action="append")
|
||||
parser.add_argument(
|
||||
"--output-root",
|
||||
type=Path,
|
||||
default=Path(r"D:\output\video\comfy_video"),
|
||||
)
|
||||
parser.add_argument("--ffmpeg", default=shutil.which("ffmpeg"))
|
||||
parser.add_argument("--ffprobe", default=shutil.which("ffprobe"))
|
||||
parser.add_argument("--timeout-seconds", type=float, default=3600.0)
|
||||
args = parser.parse_args()
|
||||
if not args.ffmpeg or not args.ffprobe:
|
||||
raise SystemExit("ffmpeg and ffprobe are required")
|
||||
summary = run(args)
|
||||
print(json.dumps(summary, indent=2, ensure_ascii=False), flush=True)
|
||||
return 0 if summary["pass"] else 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,698 @@
|
||||
"""Run the A6 Temporal Window Refine GPU Matrix against the public node."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
from dataclasses import asdict, dataclass
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import sys
|
||||
import types
|
||||
from typing import Any, Mapping, Sequence
|
||||
|
||||
from safetensors.torch import load_file
|
||||
import torch
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
SOURCE_ROOT = TOOLS_ROOT.parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
from v38_a2_audio_only_gpu_canary import _output_latents, _output_text
|
||||
from v38_a3c_selective_refine_gpu_matrix import (
|
||||
GateFailure,
|
||||
MatrixCase,
|
||||
_configure_g1,
|
||||
_configure_selective,
|
||||
_execute,
|
||||
_marker_json,
|
||||
)
|
||||
from v38_a4_chunk_scoped_refine_gpu_matrix import (
|
||||
_cross_run_plan_identity,
|
||||
_key_paths,
|
||||
_load_a3c_baseline,
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class WindowCase:
|
||||
name: str
|
||||
target: str
|
||||
chunks: int
|
||||
terminal_merge: bool
|
||||
start_sec: float
|
||||
end_sec: float
|
||||
selected_group_indices: tuple[int, ...]
|
||||
boundary_seconds: tuple[float, ...]
|
||||
|
||||
|
||||
WINDOW_CASES = (
|
||||
WindowCase(
|
||||
"g2_video_only_partial",
|
||||
"Video Only",
|
||||
1,
|
||||
False,
|
||||
1.0,
|
||||
3.0,
|
||||
(0,),
|
||||
(),
|
||||
),
|
||||
WindowCase(
|
||||
"g3_video_audio_partial",
|
||||
"Video + Audio",
|
||||
1,
|
||||
False,
|
||||
1.0,
|
||||
3.0,
|
||||
(0,),
|
||||
(),
|
||||
),
|
||||
WindowCase(
|
||||
"g4_video_audio_cross_group",
|
||||
"Video + Audio",
|
||||
3,
|
||||
False,
|
||||
4.0,
|
||||
6.0,
|
||||
(0, 1),
|
||||
(5.0, 10.0),
|
||||
),
|
||||
WindowCase(
|
||||
"g5_terminal_one_logical_side",
|
||||
"Video + Audio",
|
||||
3,
|
||||
True,
|
||||
5.5,
|
||||
8.0,
|
||||
(1,),
|
||||
(5.0, 10.0),
|
||||
),
|
||||
)
|
||||
|
||||
VIDEO_ONLY_CONTRACT_FIELDS = {
|
||||
"audio_output",
|
||||
"audio_sampling",
|
||||
"conditioning_sources",
|
||||
"execution",
|
||||
"physical_groups",
|
||||
"refine_execution_contract",
|
||||
"refine_group_seeds",
|
||||
"refine_schedule",
|
||||
"refine_schedule_identity",
|
||||
"refine_seed_base",
|
||||
"refine_target_contract",
|
||||
"target_height",
|
||||
"target_width",
|
||||
"version",
|
||||
}
|
||||
|
||||
|
||||
def _load_source_contract():
|
||||
"""Load only constants/temporal/refine_window under an isolated package."""
|
||||
|
||||
package_name = "h3_a6_gate_source"
|
||||
package = types.ModuleType(package_name)
|
||||
package.__path__ = [str(SOURCE_ROOT)]
|
||||
sys.modules[package_name] = package
|
||||
v3_package = types.ModuleType(f"{package_name}.v3")
|
||||
v3_package.__path__ = [str(SOURCE_ROOT / "v3")]
|
||||
sys.modules[f"{package_name}.v3"] = v3_package
|
||||
|
||||
def load(name: str, path: Path):
|
||||
spec = importlib.util.spec_from_file_location(name, path)
|
||||
if spec is None or spec.loader is None:
|
||||
raise GateFailure(f"cannot load source module {path}")
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
sys.modules[name] = module
|
||||
spec.loader.exec_module(module)
|
||||
return module
|
||||
|
||||
load(f"{package_name}.constants", SOURCE_ROOT / "constants.py")
|
||||
temporal = load(f"{package_name}.temporal", SOURCE_ROOT / "temporal.py")
|
||||
refine_window = load(
|
||||
f"{package_name}.v3.refine_window",
|
||||
SOURCE_ROOT / "v3" / "refine_window.py",
|
||||
)
|
||||
return temporal, refine_window
|
||||
|
||||
|
||||
TEMPORAL, REFINE_WINDOW = _load_source_contract()
|
||||
|
||||
|
||||
def _load_tensor(record: Mapping[str, Any]) -> torch.Tensor:
|
||||
return load_file(str(record["path"]), device="cpu")["latent_tensor"]
|
||||
|
||||
|
||||
def _temporal_selection(
|
||||
tensor: torch.Tensor,
|
||||
ranges: Sequence[Sequence[int]],
|
||||
*,
|
||||
time_dim: int,
|
||||
) -> tuple[torch.Tensor, torch.Tensor]:
|
||||
dimension = int(time_dim)
|
||||
if dimension < 0:
|
||||
dimension += tensor.ndim
|
||||
mask = torch.zeros(int(tensor.shape[dimension]), dtype=torch.bool)
|
||||
for start, stop in ranges:
|
||||
mask[int(start) : int(stop)] = True
|
||||
moved = tensor.movedim(dimension, 0)
|
||||
return moved[mask], moved[~mask]
|
||||
|
||||
|
||||
def _temporal_checks(
|
||||
before: torch.Tensor,
|
||||
after: torch.Tensor,
|
||||
ranges: Sequence[Sequence[int]],
|
||||
*,
|
||||
time_dim: int,
|
||||
expect_inside_change: bool,
|
||||
) -> dict[str, bool]:
|
||||
if tuple(before.shape) != tuple(after.shape) or before.dtype != after.dtype:
|
||||
return {
|
||||
"shape_dtype": False,
|
||||
"inside_expected": False,
|
||||
"outside_exact": False,
|
||||
}
|
||||
before_inside, before_outside = _temporal_selection(
|
||||
before,
|
||||
ranges,
|
||||
time_dim=time_dim,
|
||||
)
|
||||
after_inside, after_outside = _temporal_selection(
|
||||
after,
|
||||
ranges,
|
||||
time_dim=time_dim,
|
||||
)
|
||||
inside_equal = torch.equal(before_inside, after_inside)
|
||||
return {
|
||||
"shape_dtype": True,
|
||||
"inside_expected": (not inside_equal) if expect_inside_change else inside_equal,
|
||||
"outside_exact": torch.equal(before_outside, after_outside),
|
||||
}
|
||||
|
||||
|
||||
def _field_set(value: Any) -> set[str]:
|
||||
return set(_key_paths(value))
|
||||
|
||||
|
||||
def _contains_window_key(value: Any) -> bool:
|
||||
if isinstance(value, Mapping):
|
||||
return any(
|
||||
"window" in str(key).lower() or _contains_window_key(item)
|
||||
for key, item in value.items()
|
||||
)
|
||||
if isinstance(value, list):
|
||||
return any(_contains_window_key(item) for item in value)
|
||||
return False
|
||||
|
||||
|
||||
def _configure_parity(template: Mapping[str, Any], *, output_prefix: str) -> dict[str, Any]:
|
||||
prompt = _configure_g1(template, output_prefix=output_prefix)
|
||||
prompt["303"]["inputs"].update(
|
||||
{
|
||||
"refine_scope": "All",
|
||||
"refine_scope_index": 1,
|
||||
"window_start_sec": 0.0,
|
||||
"window_end_sec": 5.0,
|
||||
}
|
||||
)
|
||||
return prompt
|
||||
|
||||
|
||||
def _configure_window(
|
||||
template: Mapping[str, Any],
|
||||
*,
|
||||
case: WindowCase,
|
||||
output_prefix: str,
|
||||
) -> dict[str, Any]:
|
||||
matrix_case = MatrixCase(
|
||||
name=case.name,
|
||||
target=case.target,
|
||||
chunks=case.chunks,
|
||||
terminal_merge=case.terminal_merge,
|
||||
expected_physical_groups=2 if case.terminal_merge else case.chunks,
|
||||
boundary_seconds=case.boundary_seconds,
|
||||
)
|
||||
prompt = _configure_selective(
|
||||
template,
|
||||
case=matrix_case,
|
||||
output_prefix=output_prefix,
|
||||
)
|
||||
prompt["302"]["inputs"].update(
|
||||
{
|
||||
"refine_scope": "Time Window",
|
||||
"refine_scope_index": 1,
|
||||
"window_start_sec": float(case.start_sec),
|
||||
"window_end_sec": float(case.end_sec),
|
||||
}
|
||||
)
|
||||
prompt["302"]["_meta"]["title"] = (
|
||||
f"Selective {case.target} / Time Window "
|
||||
f"[{case.start_sec:g}, {case.end_sec:g})"
|
||||
)
|
||||
return prompt
|
||||
|
||||
|
||||
def _run_g1(args: argparse.Namespace, template: Mapping[str, Any]) -> dict[str, Any]:
|
||||
output_prefix = f"v38_a6/{args.run_tag}/g1_no_window_all_video_only"
|
||||
prompt = _configure_parity(template, output_prefix=output_prefix)
|
||||
result, entry = _execute(
|
||||
args,
|
||||
name="g1_no_window_all_video_only",
|
||||
prompt=prompt,
|
||||
expected_seconds=5.0,
|
||||
boundaries=(),
|
||||
)
|
||||
parity_status = _output_text(entry, "908")
|
||||
parity = _marker_json(parity_status, "A3C_PARITY_JSON=")
|
||||
checks = {
|
||||
"one_physical_group": parity.get("physical_group_count") == 1,
|
||||
"video_latent_sha_parity": parity.get("legacy_video_sha256")
|
||||
== parity.get("selective_video_sha256"),
|
||||
"audio_latent_sha_parity": parity.get("legacy_audio_sha256")
|
||||
== parity.get("selective_audio_sha256"),
|
||||
"audio_object_passthrough": all(
|
||||
parity.get("legacy_audio_object_identity") or []
|
||||
)
|
||||
and all(parity.get("selective_audio_object_identity") or []),
|
||||
"audio_tensor_passthrough": all(
|
||||
parity.get("legacy_audio_tensor_identity") or []
|
||||
)
|
||||
and all(parity.get("selective_audio_tensor_identity") or []),
|
||||
"seed_parity": parity.get("legacy_refine_group_seeds")
|
||||
== parity.get("selective_refine_group_seeds"),
|
||||
"sigmas_parity": parity.get("legacy_schedule_sigma_hash")
|
||||
== parity.get("selective_schedule_sigma_hash"),
|
||||
"sampling_parity": parity.get("legacy_sampling_passes_reported")
|
||||
== parity.get("selective_sampling_passes_reported")
|
||||
== 1,
|
||||
"assembly_plan_parity": parity.get("legacy_plan_without_target_identity")
|
||||
== parity.get("selective_plan_without_target_identity"),
|
||||
"target_contract": parity.get("selective_target_mode") == "video_only",
|
||||
"finite": all(parity.get("legacy_video_finite") or [])
|
||||
and all(parity.get("selective_video_finite") or [])
|
||||
and all(parity.get("legacy_audio_finite") or [])
|
||||
and all(parity.get("selective_audio_finite") or []),
|
||||
"media": int(result["media"]["frames"]) == 120
|
||||
and abs(float(result["media"]["format_duration"]) - 5.0) <= 0.05
|
||||
and int(result["media"]["audio_sample_rate"]) == 32000
|
||||
and int(result["media"]["audio_channels"]) == 2,
|
||||
"audio_health": bool(result["audio_health"]["pass"]),
|
||||
}
|
||||
result.update(
|
||||
{
|
||||
"parity_status": parity_status,
|
||||
"parity": parity,
|
||||
"checks": checks,
|
||||
"pass": all(checks.values()),
|
||||
}
|
||||
)
|
||||
case_root = args.evidence_root / "g1_no_window_all_video_only"
|
||||
(case_root / "result.json").write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
if not result["pass"]:
|
||||
failed = [name for name, passed in checks.items() if not passed]
|
||||
raise GateFailure(f"A6 G1 parity failed: {failed}")
|
||||
return result
|
||||
|
||||
|
||||
def _run_window_case(
|
||||
args: argparse.Namespace,
|
||||
*,
|
||||
case: WindowCase,
|
||||
template: Mapping[str, Any],
|
||||
baseline_probe: Mapping[str, Any],
|
||||
expected_seeds: Sequence[int],
|
||||
expected_contract_fields: set[str],
|
||||
) -> dict[str, Any]:
|
||||
output_prefix = f"v38_a6/{args.run_tag}/{case.name}"
|
||||
prompt = _configure_window(template, case=case, output_prefix=output_prefix)
|
||||
result, entry = _execute(
|
||||
args,
|
||||
name=case.name,
|
||||
prompt=prompt,
|
||||
expected_seconds=case.chunks * 5.0,
|
||||
boundaries=case.boundary_seconds,
|
||||
)
|
||||
status = _output_text(entry, "908")
|
||||
probe = _marker_json(status, "A3C_PROBE_JSON=")
|
||||
input_video_records = _output_latents(entry, "902", args.output_root)
|
||||
input_audio_records = _output_latents(entry, "903", args.output_root)
|
||||
output_video_records = _output_latents(entry, "904", args.output_root)
|
||||
output_audio_records = _output_latents(entry, "905", args.output_root)
|
||||
input_videos = [_load_tensor(record) for record in input_video_records]
|
||||
input_audios = [_load_tensor(record) for record in input_audio_records]
|
||||
output_videos = [_load_tensor(record) for record in output_video_records]
|
||||
output_audios = [_load_tensor(record) for record in output_audio_records]
|
||||
normalized_plan = (probe.get("output_plan") or {}).get("normalized") or {}
|
||||
window = REFINE_WINDOW.resolve_refine_window(
|
||||
case.start_sec,
|
||||
case.end_sec,
|
||||
normalized_plan,
|
||||
)
|
||||
selected = tuple(window.selected_group_indices)
|
||||
expected_selected = tuple(case.selected_group_indices)
|
||||
contract = normalized_plan.get("second_pass_contract") or {}
|
||||
baseline_plan = (baseline_probe.get("output_plan") or {}).get("normalized") or {}
|
||||
baseline_contract = baseline_plan.get("second_pass_contract") or {}
|
||||
checks: dict[str, bool] = {
|
||||
"selected_groups": selected == expected_selected,
|
||||
"physical_group_count": len(input_videos)
|
||||
== len(input_audios)
|
||||
== len(output_videos)
|
||||
== len(output_audios)
|
||||
== (2 if case.terminal_merge else case.chunks),
|
||||
"sampling_count": probe.get("sampling_passes_reported")
|
||||
== len(expected_selected),
|
||||
"absolute_seed_parity": probe.get("refine_group_seeds")
|
||||
== list(expected_seeds),
|
||||
"sigmas_parity": probe.get("schedule_sigma_hash")
|
||||
== baseline_probe.get("schedule_sigma_hash"),
|
||||
"contract_version": probe.get("second_pass_contract_version") == 1,
|
||||
"window_status": "scope=Time Window" in status
|
||||
and "timeline=final_visible_output" in status
|
||||
and "continuation_prefix=protected" in status,
|
||||
"window_not_in_plan": not _contains_window_key(contract),
|
||||
"assembly_field_set": set(contract) == set(expected_contract_fields),
|
||||
"refine_schedule_v1_unchanged": contract.get("refine_schedule")
|
||||
== baseline_contract.get("refine_schedule"),
|
||||
"media": int(result["media"]["frames"]) == case.chunks * 120
|
||||
and abs(
|
||||
float(result["media"]["format_duration"]) - case.chunks * 5.0
|
||||
)
|
||||
<= 0.05
|
||||
and int(result["media"]["audio_sample_rate"]) == 32000
|
||||
and int(result["media"]["audio_channels"]) == 2,
|
||||
"audio_health": bool(result["audio_health"]["pass"]),
|
||||
"finite": all(probe.get("output_video_finite") or [])
|
||||
and all(probe.get("output_audio_finite") or []),
|
||||
}
|
||||
group_checks: dict[str, dict[str, bool]] = {}
|
||||
for group_index, (before_v, before_a, after_v, after_a) in enumerate(
|
||||
zip(input_videos, input_audios, output_videos, output_audios, strict=True)
|
||||
):
|
||||
group_window = window.group(group_index)
|
||||
selected_group = group_index in expected_selected
|
||||
current: dict[str, bool] = {}
|
||||
if not selected_group:
|
||||
current.update(
|
||||
{
|
||||
"video_whole_exact": torch.equal(before_v, after_v),
|
||||
"audio_whole_exact": torch.equal(before_a, after_a),
|
||||
"video_object_passthrough": bool(
|
||||
(probe.get("input_video_object_identity") or [])[group_index]
|
||||
),
|
||||
"video_tensor_passthrough": bool(
|
||||
(probe.get("input_video_tensor_identity") or [])[group_index]
|
||||
),
|
||||
"audio_object_passthrough": bool(
|
||||
(probe.get("input_audio_object_identity") or [])[group_index]
|
||||
),
|
||||
"audio_tensor_passthrough": bool(
|
||||
(probe.get("input_audio_tensor_identity") or [])[group_index]
|
||||
),
|
||||
}
|
||||
)
|
||||
else:
|
||||
if group_window is None:
|
||||
raise GateFailure(f"selected group {group_index + 1} has no window")
|
||||
video_expect_change = case.target in ("Video Only", "Video + Audio")
|
||||
audio_expect_change = case.target in ("Audio Only", "Video + Audio")
|
||||
for name, passed in _temporal_checks(
|
||||
before_v,
|
||||
after_v,
|
||||
group_window.video_slot_ranges,
|
||||
time_dim=2,
|
||||
expect_inside_change=video_expect_change,
|
||||
).items():
|
||||
current[f"video_{name}"] = passed
|
||||
for name, passed in _temporal_checks(
|
||||
before_a,
|
||||
after_a,
|
||||
group_window.audio_tick_ranges,
|
||||
time_dim=-1,
|
||||
expect_inside_change=audio_expect_change,
|
||||
).items():
|
||||
current[f"audio_{name}"] = passed
|
||||
physical_group = contract["physical_groups"][group_index]
|
||||
trim_frames = int(physical_group.get("trim_prefix_frames", 0))
|
||||
offsets = TEMPORAL.latent_slot_offsets(int(before_v.shape[2]))
|
||||
first_video_slot = int(group_window.video_slot_ranges[0][0])
|
||||
first_audio_tick = int(group_window.audio_tick_ranges[0][0])
|
||||
current["video_prefix_excluded"] = offsets[first_video_slot] >= trim_frames
|
||||
current["audio_prefix_excluded"] = (
|
||||
first_audio_tick >= TEMPORAL.audio_latent_t(trim_frames)
|
||||
)
|
||||
group_checks[str(group_index + 1)] = current
|
||||
checks[f"group_{group_index + 1}"] = all(current.values())
|
||||
if case.terminal_merge:
|
||||
terminal = list(probe.get("physical_groups") or [])[-1]
|
||||
checks["terminal_atomic"] = (
|
||||
terminal.get("logical_chunks") == [2, 3]
|
||||
and terminal.get("terminal_merged") is True
|
||||
and probe.get("sampling_passes_reported") == 1
|
||||
and selected == (1,)
|
||||
)
|
||||
result.update(
|
||||
{
|
||||
"case": asdict(case),
|
||||
"probe_status": status,
|
||||
"probe": probe,
|
||||
"window_contract": REFINE_WINDOW.serializable_window_contract(window),
|
||||
"input_video_latents": input_video_records,
|
||||
"input_audio_latents": input_audio_records,
|
||||
"output_video_latents": output_video_records,
|
||||
"output_audio_latents": output_audio_records,
|
||||
"group_checks": group_checks,
|
||||
"checks": checks,
|
||||
"pass": all(checks.values()),
|
||||
}
|
||||
)
|
||||
case_root = args.evidence_root / case.name
|
||||
(case_root / "result.json").write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
if not result["pass"]:
|
||||
failed = [name for name, passed in checks.items() if not passed]
|
||||
raise GateFailure(f"{case.name} failed: {failed}")
|
||||
return result
|
||||
|
||||
|
||||
def _load_resumed_g1(path: Path) -> dict[str, Any]:
|
||||
result = json.loads(path.read_text(encoding="utf-8"))
|
||||
if not bool(result.get("pass")) or not all((result.get("checks") or {}).values()):
|
||||
raise GateFailure(f"resumed G1 is not PASS: {path}")
|
||||
result["resumed_without_resampling"] = True
|
||||
path.with_name("result.revalidated.json").write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
def _load_resumed_window_result(
|
||||
path: Path,
|
||||
*,
|
||||
expected_seeds: Sequence[int],
|
||||
expected_contract_fields: set[str],
|
||||
) -> dict[str, Any]:
|
||||
result = json.loads(path.read_text(encoding="utf-8"))
|
||||
probe = result.get("probe") or {}
|
||||
contract = (
|
||||
((probe.get("output_plan") or {}).get("normalized") or {}).get(
|
||||
"second_pass_contract"
|
||||
)
|
||||
or {}
|
||||
)
|
||||
checks = dict(result.get("checks") or {})
|
||||
checks["absolute_seed_parity"] = probe.get("refine_group_seeds") == list(
|
||||
expected_seeds
|
||||
)
|
||||
checks["assembly_field_set"] = set(contract) == set(expected_contract_fields)
|
||||
result["checks"] = checks
|
||||
result["pass"] = all(checks.values())
|
||||
result["resumed_without_resampling"] = True
|
||||
if not result["pass"]:
|
||||
failed = [name for name, passed in checks.items() if not passed]
|
||||
raise GateFailure(f"resumed window validation failed: {failed}")
|
||||
path.with_name("result.revalidated.json").write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
def run(args: argparse.Namespace) -> dict[str, Any]:
|
||||
args.evidence_root.mkdir(parents=True, exist_ok=True)
|
||||
t2_template = json.loads(args.t2_template.read_text(encoding="utf-8"))
|
||||
terminal_template = json.loads(args.terminal_template.read_text(encoding="utf-8"))
|
||||
baseline_summary = json.loads(args.a3c_baseline.read_text(encoding="utf-8"))
|
||||
nonterminal_baseline = _load_a3c_baseline(
|
||||
args.a3c_baseline,
|
||||
"g4_video_audio_3x5",
|
||||
)["probe"]
|
||||
one_group_av_baseline = _load_a3c_baseline(
|
||||
args.a3c_baseline,
|
||||
"g3_video_audio_1x5",
|
||||
)["probe"]
|
||||
terminal_baseline = _load_a3c_baseline(
|
||||
args.a3c_baseline,
|
||||
"g5_video_audio_terminal",
|
||||
)["probe"]
|
||||
summary: dict[str, Any] = {
|
||||
"format": "h3-continuum-v38-a6-temporal-window-refine-gpu-matrix-v1",
|
||||
"server": args.server,
|
||||
"backend_pid": args.backend_pid,
|
||||
"run_tag": args.run_tag,
|
||||
"a3c_baseline": str(args.a3c_baseline),
|
||||
"settings": {
|
||||
"resolution": "576x576",
|
||||
"first_pass_steps": 8,
|
||||
"refine_steps": 10,
|
||||
"refine_denoise": 0.35,
|
||||
"continuity": "Balanced — 22 frames",
|
||||
"audio_continuity": True,
|
||||
"run_storage": "Off",
|
||||
"sampler": "res_multistep",
|
||||
"scheduler": "simple",
|
||||
"sage": True,
|
||||
},
|
||||
"results": {},
|
||||
"pass": False,
|
||||
"production_status": "Experimental; audio-targeted modes remain HOLD",
|
||||
}
|
||||
summary_path = args.evidence_root / "summary.json"
|
||||
try:
|
||||
if args.resume_g1 is not None:
|
||||
summary["results"]["g1_no_window_all_video_only"] = _load_resumed_g1(
|
||||
args.resume_g1
|
||||
)
|
||||
else:
|
||||
summary["results"]["g1_no_window_all_video_only"] = _run_g1(
|
||||
args,
|
||||
t2_template,
|
||||
)
|
||||
video_only_seeds = list(
|
||||
(((baseline_summary.get("results") or {}).get("g1_video_only_parity") or {})
|
||||
.get("parity", {})
|
||||
.get("selective_refine_group_seeds")
|
||||
or [])
|
||||
)
|
||||
resume_results: dict[str, Path] = {}
|
||||
for path in args.resume_result or ():
|
||||
payload = json.loads(path.read_text(encoding="utf-8"))
|
||||
name = str((payload.get("case") or {}).get("name") or "")
|
||||
if not name or name in resume_results:
|
||||
raise GateFailure(f"invalid or duplicate resumed result: {path}")
|
||||
resume_results[name] = path
|
||||
for case in WINDOW_CASES:
|
||||
template = terminal_template if case.terminal_merge else t2_template
|
||||
if case.target == "Video Only":
|
||||
baseline = one_group_av_baseline
|
||||
expected_seeds = video_only_seeds
|
||||
expected_fields = VIDEO_ONLY_CONTRACT_FIELDS
|
||||
elif case.terminal_merge:
|
||||
baseline = terminal_baseline
|
||||
expected_seeds = [
|
||||
list(terminal_baseline.get("refine_group_seeds") or [])[index]
|
||||
for index in case.selected_group_indices
|
||||
]
|
||||
expected_fields = set(
|
||||
(
|
||||
(terminal_baseline.get("output_plan") or {})
|
||||
.get("normalized", {})
|
||||
.get("second_pass_contract", {})
|
||||
)
|
||||
)
|
||||
elif case.chunks == 1:
|
||||
baseline = one_group_av_baseline
|
||||
expected_seeds = list(
|
||||
one_group_av_baseline.get("refine_group_seeds") or []
|
||||
)
|
||||
expected_fields = set(
|
||||
(
|
||||
(one_group_av_baseline.get("output_plan") or {})
|
||||
.get("normalized", {})
|
||||
.get("second_pass_contract", {})
|
||||
)
|
||||
)
|
||||
else:
|
||||
baseline = nonterminal_baseline
|
||||
expected_seeds = [
|
||||
list(nonterminal_baseline.get("refine_group_seeds") or [])[index]
|
||||
for index in case.selected_group_indices
|
||||
]
|
||||
expected_fields = set(
|
||||
(
|
||||
(nonterminal_baseline.get("output_plan") or {})
|
||||
.get("normalized", {})
|
||||
.get("second_pass_contract", {})
|
||||
)
|
||||
)
|
||||
if case.name in resume_results:
|
||||
result = _load_resumed_window_result(
|
||||
resume_results[case.name],
|
||||
expected_seeds=expected_seeds,
|
||||
expected_contract_fields=expected_fields,
|
||||
)
|
||||
else:
|
||||
result = _run_window_case(
|
||||
args,
|
||||
case=case,
|
||||
template=template,
|
||||
baseline_probe=baseline,
|
||||
expected_seeds=expected_seeds,
|
||||
expected_contract_fields=expected_fields,
|
||||
)
|
||||
summary["results"][case.name] = result
|
||||
summary["pass"] = True
|
||||
summary["status"] = "A6 Temporal Window Refine GPU Experimental PASS"
|
||||
return summary
|
||||
except Exception as exc:
|
||||
summary["failure_type"] = type(exc).__name__
|
||||
summary["failure"] = str(exc)
|
||||
summary["status"] = "A6 STOP / Production unchanged"
|
||||
return summary
|
||||
finally:
|
||||
summary_path.write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8190")
|
||||
parser.add_argument("--backend-pid", type=int, required=True)
|
||||
parser.add_argument("--run-tag", required=True)
|
||||
parser.add_argument("--evidence-root", type=Path, required=True)
|
||||
parser.add_argument("--t2-template", type=Path, required=True)
|
||||
parser.add_argument("--terminal-template", type=Path, required=True)
|
||||
parser.add_argument("--a3c-baseline", type=Path, required=True)
|
||||
parser.add_argument("--resume-g1", type=Path)
|
||||
parser.add_argument("--resume-result", type=Path, action="append")
|
||||
parser.add_argument(
|
||||
"--output-root",
|
||||
type=Path,
|
||||
default=Path(r"D:\output\video\comfy_video"),
|
||||
)
|
||||
parser.add_argument("--ffmpeg", default=shutil.which("ffmpeg"))
|
||||
parser.add_argument("--ffprobe", default=shutil.which("ffprobe"))
|
||||
parser.add_argument("--timeout-seconds", type=float, default=3600.0)
|
||||
args = parser.parse_args()
|
||||
if not args.ffmpeg or not args.ffprobe:
|
||||
raise SystemExit("ffmpeg and ffprobe are required")
|
||||
summary = run(args)
|
||||
print(json.dumps(summary, indent=2, ensure_ascii=False), flush=True)
|
||||
return 0 if summary["pass"] else 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,632 @@
|
||||
"""Run the A7a read-only Packed-row Observability GPU Matrix."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
from dataclasses import dataclass
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
from typing import Any, Mapping
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
from v38_a2_audio_only_gpu_canary import (
|
||||
_history_entry,
|
||||
_output_latents,
|
||||
_output_text,
|
||||
)
|
||||
from v38_a3c_selective_refine_gpu_matrix import (
|
||||
GateFailure,
|
||||
PROMPT,
|
||||
_configure_base,
|
||||
_execute,
|
||||
_find_one,
|
||||
_marker_json,
|
||||
_remove_class,
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class FirstPassCase:
|
||||
name: str
|
||||
chunks: int
|
||||
terminal_merge: bool
|
||||
conditioning: str
|
||||
baseline_kind: str
|
||||
baseline_history: Path | None = None
|
||||
|
||||
@property
|
||||
def expected_groups(self) -> int:
|
||||
return 2 if self.terminal_merge else self.chunks
|
||||
|
||||
@property
|
||||
def expected_seconds(self) -> float:
|
||||
return float(self.chunks * 5)
|
||||
|
||||
|
||||
PLAN_PATTERN = re.compile(
|
||||
r"execution_order=(\[[^\]]*\]),\s*"
|
||||
r"max_concurrent_physical_groups=(\d+),\s*"
|
||||
r"observed_groups=(\d+)/(\d+),\s*"
|
||||
r"peak_candidate=(\d+|unavailable),\s*"
|
||||
r"peak_total_rows=(\d+|unavailable)"
|
||||
)
|
||||
GROUP_PATTERN = re.compile(
|
||||
r"physical_group=(\d+),\s*logical_chunks=(\[[^\]]*\]),\s*"
|
||||
r"terminal_atomic=(true|false),\s*total=(\d+),\s*text=(\d+),\s*"
|
||||
r"condition_video=(\d+),\s*condition_audio=(\d+),\s*"
|
||||
r"target_video=(\d+),\s*target_audio=(\d+),\s*unknown=(\d+)"
|
||||
)
|
||||
|
||||
|
||||
def _history_only_entry(path: Path) -> Mapping[str, Any]:
|
||||
history = json.loads(path.read_text(encoding="utf-8"))
|
||||
if not isinstance(history, Mapping) or len(history) != 1:
|
||||
raise GateFailure(f"baseline history must contain one prompt: {path}")
|
||||
return _history_entry(history, str(next(iter(history))))
|
||||
|
||||
|
||||
def _baseline_from_a6(path: Path) -> dict[str, Any]:
|
||||
entry = _history_only_entry(path)
|
||||
probe_status = _output_text(entry, "908")
|
||||
probe = _marker_json(probe_status, "A3C_PROBE_JSON=")
|
||||
return {
|
||||
"origin": str(path),
|
||||
"video_sha256": list(probe.get("input_video_sha256") or []),
|
||||
"audio_sha256": list(probe.get("input_audio_sha256") or []),
|
||||
"assembly_sha256": str((probe.get("input_plan") or {}).get("sha256") or ""),
|
||||
"assembly_normalized": copy.deepcopy(
|
||||
(probe.get("input_plan") or {}).get("normalized")
|
||||
),
|
||||
"decoded": None,
|
||||
}
|
||||
|
||||
|
||||
def _cross_run_plan_identity(value: Any) -> Any:
|
||||
"""Ignore only the pre-existing per-execution monotonic start marker."""
|
||||
|
||||
normalized = copy.deepcopy(value)
|
||||
if isinstance(normalized, dict):
|
||||
normalized.pop("_runtime_started_at", None)
|
||||
return normalized
|
||||
|
||||
|
||||
def _parse_packed_rows(status: str) -> dict[str, Any]:
|
||||
plan_line = next(
|
||||
(line for line in status.splitlines() if line.startswith("Packed-row plan [A7a v1]:")),
|
||||
"",
|
||||
)
|
||||
if not plan_line:
|
||||
raise GateFailure("A7a packed-row plan is missing from Detailed status")
|
||||
match = PLAN_PATTERN.search(plan_line)
|
||||
if match is None:
|
||||
raise GateFailure("A7a packed-row plan could not be parsed")
|
||||
groups = []
|
||||
for line in status.splitlines():
|
||||
if not line.startswith("Packed-row group [A7a v1]:"):
|
||||
continue
|
||||
current = GROUP_PATTERN.search(line)
|
||||
if current is None:
|
||||
raise GateFailure(f"A7a packed-row group could not be parsed: {line}")
|
||||
group = {
|
||||
"physical_group": int(current.group(1)),
|
||||
"logical_chunks": json.loads(current.group(2)),
|
||||
"terminal_atomic": current.group(3) == "true",
|
||||
"total": int(current.group(4)),
|
||||
"text": int(current.group(5)),
|
||||
"condition_video": int(current.group(6)),
|
||||
"condition_audio": int(current.group(7)),
|
||||
"target_video": int(current.group(8)),
|
||||
"target_audio": int(current.group(9)),
|
||||
"unknown": int(current.group(10)),
|
||||
"point_in_time_memory_observation": (
|
||||
"pre_system_available=" in line
|
||||
and "post_system_available=" in line
|
||||
and "pre_CUDA_allocated=" in line
|
||||
and "post_CUDA_allocated=" in line
|
||||
and "pre_Core_free=" in line
|
||||
and "post_Core_free=" in line
|
||||
),
|
||||
}
|
||||
group["component_sum"] = sum(
|
||||
group[key]
|
||||
for key in (
|
||||
"text",
|
||||
"condition_video",
|
||||
"condition_audio",
|
||||
"target_video",
|
||||
"target_audio",
|
||||
"unknown",
|
||||
)
|
||||
)
|
||||
groups.append(group)
|
||||
peak_candidate = None if match.group(5) == "unavailable" else int(match.group(5))
|
||||
peak_rows = None if match.group(6) == "unavailable" else int(match.group(6))
|
||||
return {
|
||||
"execution_order": json.loads(match.group(1)),
|
||||
"max_concurrent_physical_groups": int(match.group(2)),
|
||||
"observed_groups": int(match.group(3)),
|
||||
"recorded_groups": int(match.group(4)),
|
||||
"peak_row_candidate": peak_candidate,
|
||||
"peak_total_rows": peak_rows,
|
||||
"groups": groups,
|
||||
"report_contract": {
|
||||
"actual_core_rows_only": "actual Core rows only" in plan_line,
|
||||
"no_vram_time_prediction": "VRAM/time prediction=not provided" in plan_line,
|
||||
"execution_policy_unchanged": "execution policy=unchanged" in plan_line,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def _configure_first_pass(
|
||||
template: Mapping[str, Any],
|
||||
*,
|
||||
case: FirstPassCase,
|
||||
diagnostics: str,
|
||||
output_prefix: str,
|
||||
reference_image: str,
|
||||
reference_video: str,
|
||||
) -> dict[str, Any]:
|
||||
prompt = _configure_base(
|
||||
template,
|
||||
chunks=case.chunks,
|
||||
terminal_merge=case.terminal_merge,
|
||||
output_prefix=output_prefix,
|
||||
)
|
||||
_remove_class(prompt, "H3ContinuumSecondPassV35")
|
||||
_remove_class(prompt, "H3ContinuumSelectiveSecondPassExperimental")
|
||||
sampler_id, sampler_node = _find_one(prompt, "H3ContinuumSamplerV38")
|
||||
inputs = sampler_node["inputs"]
|
||||
inputs["diagnostics"] = diagnostics
|
||||
inputs["run_storage"] = "Off"
|
||||
prompt_id = str(inputs["sequence_prompt"][0])
|
||||
prompt[prompt_id]["inputs"]["value"] = PROMPT
|
||||
|
||||
for node_id in ("900", "901", "902", "903", "904", "905", "906", "907", "908", "909", "910", "911"):
|
||||
prompt.pop(node_id, None)
|
||||
|
||||
if case.conditioning == "reference_images_3":
|
||||
prompt[prompt_id]["inputs"]["value"] = (
|
||||
PROMPT
|
||||
+ " Preserve the identities and natural appearance from <Picture 1>, "
|
||||
"<Picture 2>, and <Picture 3>."
|
||||
)
|
||||
for offset, input_name in enumerate(
|
||||
("reference_image_1", "reference_image_2", "reference_image_3"),
|
||||
start=950,
|
||||
):
|
||||
prompt[str(offset)] = {
|
||||
"class_type": "LoadImage",
|
||||
"inputs": {"image": reference_image},
|
||||
"_meta": {"title": f"A7a Reference Image {offset - 949}"},
|
||||
}
|
||||
inputs[input_name] = [str(offset), 0]
|
||||
elif case.conditioning == "reference_video":
|
||||
prompt[prompt_id]["inputs"]["value"] = (
|
||||
PROMPT
|
||||
+ " Follow the motion and appearance guidance from <Video 1> while preserving continuity."
|
||||
)
|
||||
prompt["950"] = {
|
||||
"class_type": "H3ContinuumLoadVideo",
|
||||
"inputs": {
|
||||
"enable_video": True,
|
||||
"file": reference_video,
|
||||
"force_rate": 24.0,
|
||||
},
|
||||
"_meta": {"title": "A7a High-row Video Guide"},
|
||||
}
|
||||
inputs["reference_video_1"] = ["950", 0]
|
||||
inputs["video_reference_size"] = "Efficient - 0.4 MP"
|
||||
|
||||
_video_decode_id, video_decode = _find_one(prompt, "VAEDecode")
|
||||
_audio_decode_id, audio_decode = _find_one(prompt, "VAEDecodeAudio")
|
||||
_assemble_id, assemble = _find_one(prompt, "H3ContinuumAssembleSeamV35")
|
||||
video_decode["inputs"]["samples"] = [sampler_id, 0]
|
||||
audio_decode["inputs"]["samples"] = [sampler_id, 1]
|
||||
assemble["inputs"]["assembly_plan"] = [sampler_id, 2]
|
||||
prompt["900"] = {
|
||||
"class_type": "PreviewAny",
|
||||
"inputs": {"source": [sampler_id, 3]},
|
||||
}
|
||||
prompt["902"] = {
|
||||
"class_type": "SaveLatent",
|
||||
"inputs": {
|
||||
"samples": [sampler_id, 0],
|
||||
"filename_prefix": f"{output_prefix}_video",
|
||||
},
|
||||
}
|
||||
prompt["903"] = {
|
||||
"class_type": "SaveLatent",
|
||||
"inputs": {
|
||||
"samples": [sampler_id, 1],
|
||||
"filename_prefix": f"{output_prefix}_audio",
|
||||
},
|
||||
}
|
||||
prompt["907"] = {
|
||||
"class_type": "H3A3cSelectiveRefineProbe",
|
||||
"inputs": {
|
||||
"input_video_latents": [sampler_id, 0],
|
||||
"input_audio_latents": [sampler_id, 1],
|
||||
"output_video_latents": [sampler_id, 0],
|
||||
"output_audio_latents": [sampler_id, 1],
|
||||
"input_assembly_plan": [sampler_id, 2],
|
||||
"output_assembly_plan": [sampler_id, 2],
|
||||
"refine_status": [sampler_id, 3],
|
||||
"target_label": "Video Only",
|
||||
},
|
||||
}
|
||||
prompt["908"] = {
|
||||
"class_type": "PreviewAny",
|
||||
"inputs": {"source": ["907", 0]},
|
||||
}
|
||||
return prompt
|
||||
|
||||
|
||||
def _run_once(
|
||||
args: argparse.Namespace,
|
||||
*,
|
||||
case: FirstPassCase,
|
||||
template: Mapping[str, Any],
|
||||
diagnostics: str,
|
||||
) -> dict[str, Any]:
|
||||
variant = "basic" if diagnostics == "Basic" else "detailed"
|
||||
name = f"{case.name}_{variant}"
|
||||
output_prefix = f"v38_a7a/{args.run_tag}/{name}"
|
||||
prompt = _configure_first_pass(
|
||||
template,
|
||||
case=case,
|
||||
diagnostics=diagnostics,
|
||||
output_prefix=output_prefix,
|
||||
reference_image=args.reference_image,
|
||||
reference_video=args.reference_video,
|
||||
)
|
||||
result, entry = _execute(
|
||||
args,
|
||||
name=name,
|
||||
prompt=prompt,
|
||||
expected_seconds=case.expected_seconds,
|
||||
boundaries=tuple(float(index * 5) for index in range(1, case.chunks)),
|
||||
)
|
||||
sampler_status = _output_text(entry, "900")
|
||||
probe_status = _output_text(entry, "908")
|
||||
probe = _marker_json(probe_status, "A3C_PROBE_JSON=")
|
||||
video_records = _output_latents(entry, "902", args.output_root)
|
||||
audio_records = _output_latents(entry, "903", args.output_root)
|
||||
result.update(
|
||||
{
|
||||
"diagnostics": diagnostics,
|
||||
"sampler_status": sampler_status,
|
||||
"probe": probe,
|
||||
"video_latents": video_records,
|
||||
"audio_latents": audio_records,
|
||||
"packed_rows": (
|
||||
_parse_packed_rows(sampler_status)
|
||||
if diagnostics == "Detailed Report"
|
||||
else None
|
||||
),
|
||||
}
|
||||
)
|
||||
checks = {
|
||||
"latent_count": len(video_records)
|
||||
== len(audio_records)
|
||||
== case.expected_groups,
|
||||
"saved_video_sha_matches_probe": [item["tensor_sha256"] for item in video_records]
|
||||
== list(probe.get("input_video_sha256") or []),
|
||||
"saved_audio_sha_matches_probe": [item["tensor_sha256"] for item in audio_records]
|
||||
== list(probe.get("input_audio_sha256") or []),
|
||||
"finite": all(probe.get("output_video_finite") or [])
|
||||
and all(probe.get("output_audio_finite") or []),
|
||||
"media_frames": int(result["media"]["frames"])
|
||||
== int(case.expected_seconds * 24),
|
||||
"media_duration": abs(
|
||||
float(result["media"]["format_duration"]) - case.expected_seconds
|
||||
)
|
||||
<= 0.05,
|
||||
"media_audio": int(result["media"]["audio_sample_rate"]) == 32000
|
||||
and int(result["media"]["audio_channels"]) == 2,
|
||||
"audio_health": bool(result["audio_health"]["pass"]),
|
||||
"run_storage_off": prompt[_find_one(prompt, "H3ContinuumSamplerV38")[0]][
|
||||
"inputs"
|
||||
]["run_storage"]
|
||||
== "Off",
|
||||
}
|
||||
if diagnostics == "Basic":
|
||||
checks["planner_absent_in_basic"] = "Packed-row plan [A7a" not in sampler_status
|
||||
else:
|
||||
packed = result["packed_rows"]
|
||||
rows = list(packed["groups"])
|
||||
expected_order = list(range(1, case.expected_groups + 1))
|
||||
actual_peak = min(
|
||||
(group["physical_group"] for group in rows if group["total"] == max(item["total"] for item in rows)),
|
||||
default=None,
|
||||
)
|
||||
checks.update(
|
||||
{
|
||||
"execution_order": packed["execution_order"] == expected_order,
|
||||
"max_concurrent_one": packed["max_concurrent_physical_groups"] == 1,
|
||||
"all_groups_observed": packed["observed_groups"]
|
||||
== packed["recorded_groups"]
|
||||
== len(rows)
|
||||
== case.expected_groups,
|
||||
"component_sum_equals_seq_len": all(
|
||||
group["component_sum"] == group["total"] for group in rows
|
||||
),
|
||||
"one_valid_target_pair_per_observed_layout": all(
|
||||
group["target_video"] > 0 and group["target_audio"] > 0
|
||||
for group in rows
|
||||
),
|
||||
"peak_row_candidate": packed["peak_row_candidate"] == actual_peak,
|
||||
"peak_row_count": packed["peak_total_rows"]
|
||||
== max((group["total"] for group in rows), default=None),
|
||||
"memory_observation_only": all(
|
||||
group["point_in_time_memory_observation"] for group in rows
|
||||
),
|
||||
"report_contract": all(packed["report_contract"].values()),
|
||||
"terminal_atomic": (
|
||||
not case.terminal_merge
|
||||
or (
|
||||
rows[-1]["logical_chunks"] == [2, 3]
|
||||
and rows[-1]["terminal_atomic"] is True
|
||||
)
|
||||
),
|
||||
}
|
||||
)
|
||||
result["checks"] = checks
|
||||
result["pass"] = all(checks.values())
|
||||
result_path = args.evidence_root / name / "result.json"
|
||||
result_path.write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
if not result["pass"]:
|
||||
failed = [key for key, value in checks.items() if not value]
|
||||
raise GateFailure(f"{name} failed: {failed}")
|
||||
return result
|
||||
|
||||
|
||||
def _baseline_from_result(result: Mapping[str, Any]) -> dict[str, Any]:
|
||||
probe = result["probe"]
|
||||
return {
|
||||
"origin": str(result["history"]),
|
||||
"video_sha256": list(probe.get("input_video_sha256") or []),
|
||||
"audio_sha256": list(probe.get("input_audio_sha256") or []),
|
||||
"assembly_sha256": str((probe.get("input_plan") or {}).get("sha256") or ""),
|
||||
"assembly_normalized": copy.deepcopy(
|
||||
(probe.get("input_plan") or {}).get("normalized")
|
||||
),
|
||||
"decoded": copy.deepcopy(result.get("decoded")),
|
||||
}
|
||||
|
||||
|
||||
def _load_completed_result(path: Path) -> dict[str, Any]:
|
||||
result = json.loads(path.read_text(encoding="utf-8"))
|
||||
checks = result.get("checks") or {}
|
||||
if not bool(result.get("pass")) or not checks or not all(checks.values()):
|
||||
raise GateFailure(f"existing result is not a completed run-level PASS: {path}")
|
||||
result["resumed_without_resampling"] = True
|
||||
return result
|
||||
|
||||
|
||||
def _parity_checks(
|
||||
detailed: Mapping[str, Any], baseline: Mapping[str, Any]
|
||||
) -> dict[str, bool]:
|
||||
probe = detailed["probe"]
|
||||
checks = {
|
||||
"video_latent_sha_parity": list(probe.get("input_video_sha256") or [])
|
||||
== list(baseline["video_sha256"]),
|
||||
"audio_latent_sha_parity": list(probe.get("input_audio_sha256") or [])
|
||||
== list(baseline["audio_sha256"]),
|
||||
"assembly_plan_identity": _cross_run_plan_identity(
|
||||
(probe.get("input_plan") or {}).get("normalized")
|
||||
)
|
||||
== _cross_run_plan_identity(baseline.get("assembly_normalized")),
|
||||
}
|
||||
if baseline.get("decoded") is not None:
|
||||
checks["decoded_video_parity"] = (
|
||||
detailed.get("decoded") or {}
|
||||
).get("video_sha256") == baseline["decoded"].get("video_sha256")
|
||||
checks["decoded_audio_parity"] = (
|
||||
detailed.get("decoded") or {}
|
||||
).get("audio_pcm_sha256") == baseline["decoded"].get("audio_pcm_sha256")
|
||||
return checks
|
||||
|
||||
|
||||
def run(args: argparse.Namespace) -> dict[str, Any]:
|
||||
args.evidence_root.mkdir(parents=True, exist_ok=True)
|
||||
t2_template = json.loads(args.t2_template.read_text(encoding="utf-8"))
|
||||
terminal_template = json.loads(args.terminal_template.read_text(encoding="utf-8"))
|
||||
cases = (
|
||||
FirstPassCase("g1_1x5_t2va", 1, False, "none", "same_runtime_basic"),
|
||||
FirstPassCase(
|
||||
"g2_3x5_continuation",
|
||||
3,
|
||||
False,
|
||||
"none",
|
||||
"accepted_a6",
|
||||
args.a6_g2_history,
|
||||
),
|
||||
FirstPassCase(
|
||||
"g3_fl2va_terminal",
|
||||
3,
|
||||
True,
|
||||
"none",
|
||||
"accepted_a6",
|
||||
args.a6_g3_history,
|
||||
),
|
||||
FirstPassCase(
|
||||
"g4_reference_images_3",
|
||||
1,
|
||||
False,
|
||||
"reference_images_3",
|
||||
"same_runtime_basic",
|
||||
),
|
||||
FirstPassCase(
|
||||
"g5_reference_video_high_row",
|
||||
1,
|
||||
False,
|
||||
"reference_video",
|
||||
"same_runtime_basic",
|
||||
),
|
||||
)
|
||||
summary: dict[str, Any] = {
|
||||
"format": "h3-continuum-v38-a7a-packed-row-gpu-matrix-v1",
|
||||
"server": args.server,
|
||||
"backend_pid": args.backend_pid,
|
||||
"run_tag": args.run_tag,
|
||||
"settings": {
|
||||
"resolution": "576x576",
|
||||
"steps": 8,
|
||||
"continuity": "Balanced - 22 frames",
|
||||
"audio_continuity": True,
|
||||
"run_storage": "Off",
|
||||
"sampler": "res_multistep",
|
||||
"scheduler": "simple",
|
||||
"sage": True,
|
||||
},
|
||||
"baseline_policy": {
|
||||
"g1_g4_g5": "same-runtime Basic vs Detailed",
|
||||
"g2_g3": "accepted pre-A7 A6 First Pass latent/Assembly evidence",
|
||||
"decoded_parity": "required where same-runtime Basic baseline exists",
|
||||
},
|
||||
"results": {},
|
||||
"pass": False,
|
||||
"production_status": "read-only Experimental; A7b execution policy HOLD",
|
||||
}
|
||||
summary_path = args.evidence_root / "summary.json"
|
||||
try:
|
||||
g1_rows = None
|
||||
for case in cases:
|
||||
template = terminal_template if case.terminal_merge else t2_template
|
||||
basic = None
|
||||
if case.baseline_kind == "same_runtime_basic":
|
||||
basic_path = args.evidence_root / f"{case.name}_basic" / "result.json"
|
||||
basic = (
|
||||
_load_completed_result(basic_path)
|
||||
if args.resume_existing and basic_path.exists()
|
||||
else _run_once(
|
||||
args,
|
||||
case=case,
|
||||
template=template,
|
||||
diagnostics="Basic",
|
||||
)
|
||||
)
|
||||
baseline = _baseline_from_result(basic)
|
||||
else:
|
||||
if case.baseline_history is None:
|
||||
raise GateFailure(f"accepted baseline path missing for {case.name}")
|
||||
baseline = _baseline_from_a6(case.baseline_history)
|
||||
detailed_path = (
|
||||
args.evidence_root / f"{case.name}_detailed" / "result.json"
|
||||
)
|
||||
detailed = (
|
||||
_load_completed_result(detailed_path)
|
||||
if args.resume_existing and detailed_path.exists()
|
||||
else _run_once(
|
||||
args,
|
||||
case=case,
|
||||
template=template,
|
||||
diagnostics="Detailed Report",
|
||||
)
|
||||
)
|
||||
parity = _parity_checks(detailed, baseline)
|
||||
extra: dict[str, bool] = {}
|
||||
current_rows = detailed["packed_rows"]["groups"]
|
||||
if case.name == "g1_1x5_t2va":
|
||||
g1_rows = current_rows[0]
|
||||
elif case.conditioning in {"reference_images_3", "reference_video"}:
|
||||
if g1_rows is None:
|
||||
raise GateFailure("G1 row baseline is unavailable")
|
||||
extra["condition_video_rows_increased_vs_g1"] = (
|
||||
current_rows[0]["condition_video"] > g1_rows["condition_video"]
|
||||
)
|
||||
all_checks = {**parity, **extra}
|
||||
case_result = {
|
||||
"case": {
|
||||
"name": case.name,
|
||||
"chunks": case.chunks,
|
||||
"terminal_merge": case.terminal_merge,
|
||||
"conditioning": case.conditioning,
|
||||
"baseline_kind": case.baseline_kind,
|
||||
},
|
||||
"baseline": baseline,
|
||||
"basic": basic,
|
||||
"detailed": detailed,
|
||||
"parity_checks": parity,
|
||||
"conditioning_checks": extra,
|
||||
"pass": all(all_checks.values()),
|
||||
}
|
||||
summary["results"][case.name] = case_result
|
||||
summary_path.write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
print(
|
||||
f"A7a {case.name}: pass={case_result['pass']} "
|
||||
f"peak-row-candidate={detailed['packed_rows']['peak_row_candidate']} "
|
||||
f"rows={detailed['packed_rows']['peak_total_rows']}",
|
||||
flush=True,
|
||||
)
|
||||
if not case_result["pass"]:
|
||||
failed = [key for key, value in all_checks.items() if not value]
|
||||
raise GateFailure(f"{case.name} parity failed: {failed}")
|
||||
summary["pass"] = True
|
||||
summary["status"] = "A7a Packed-row Observability GPU Experimental PASS"
|
||||
return summary
|
||||
except Exception as exc:
|
||||
summary["failure_type"] = type(exc).__name__
|
||||
summary["failure"] = str(exc)
|
||||
summary["status"] = "A7a STOP / Production unchanged"
|
||||
return summary
|
||||
finally:
|
||||
summary_path.write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8190")
|
||||
parser.add_argument("--backend-pid", type=int, required=True)
|
||||
parser.add_argument("--run-tag", required=True)
|
||||
parser.add_argument("--evidence-root", type=Path, required=True)
|
||||
parser.add_argument("--t2-template", type=Path, required=True)
|
||||
parser.add_argument("--terminal-template", type=Path, required=True)
|
||||
parser.add_argument("--a6-g2-history", type=Path, required=True)
|
||||
parser.add_argument("--a6-g3-history", type=Path, required=True)
|
||||
parser.add_argument("--reference-image", required=True)
|
||||
parser.add_argument("--reference-video", required=True)
|
||||
parser.add_argument("--resume-existing", action="store_true")
|
||||
parser.add_argument(
|
||||
"--output-root",
|
||||
type=Path,
|
||||
default=Path(r"D:\output\video\comfy_video"),
|
||||
)
|
||||
parser.add_argument("--ffmpeg", default=shutil.which("ffmpeg"))
|
||||
parser.add_argument("--ffprobe", default=shutil.which("ffprobe"))
|
||||
parser.add_argument("--timeout-seconds", type=float, default=3600.0)
|
||||
args = parser.parse_args()
|
||||
if not args.ffmpeg or not args.ffprobe:
|
||||
raise SystemExit("ffmpeg and ffprobe are required")
|
||||
summary = run(args)
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"status": summary.get("status"),
|
||||
"pass": summary.get("pass"),
|
||||
"failure": summary.get("failure"),
|
||||
"summary": str(args.evidence_root / "summary.json"),
|
||||
},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
flush=True,
|
||||
)
|
||||
return 0 if summary["pass"] else 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,571 @@
|
||||
"""Run the A7b explicit Reference downgrade GPU Matrix."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
from dataclasses import dataclass
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
from typing import Any, Mapping
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
from v38_a2_audio_only_gpu_canary import _output_latents, _output_text
|
||||
from v38_a3c_selective_refine_gpu_matrix import (
|
||||
GateFailure,
|
||||
PROMPT,
|
||||
_execute,
|
||||
_find_one,
|
||||
_marker_json,
|
||||
)
|
||||
from v38_a7a_packed_row_gpu_matrix import (
|
||||
_cross_run_plan_identity,
|
||||
_parse_packed_rows,
|
||||
)
|
||||
|
||||
|
||||
ACTION_DISABLED = "Disabled"
|
||||
ACTION_REDUCE = "Reduce References One Step"
|
||||
IMAGE_MAX = "Max Identity"
|
||||
IMAGE_MATCH = "Match Output"
|
||||
VIDEO_BALANCED = "Balanced - 0.6 MP"
|
||||
VIDEO_EFFICIENT = "Efficient - 0.4 MP"
|
||||
POLICY_STATUS = "Memory Action Policy [Experimental A7b v1]"
|
||||
SEED_PATTERN = re.compile(r"chunk 1/1: seed=(\d+)")
|
||||
IMAGE_GEOMETRY_PATTERN = re.compile(r"Ref1=(\d+)x(\d+)")
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class A7bCase:
|
||||
name: str
|
||||
conditioning: str
|
||||
reference_count: int = 0
|
||||
video_file: str = ""
|
||||
|
||||
@property
|
||||
def is_image(self) -> bool:
|
||||
return self.conditioning == "image"
|
||||
|
||||
@property
|
||||
def is_video(self) -> bool:
|
||||
return self.conditioning == "video"
|
||||
|
||||
|
||||
def _sha256_json(value: Any) -> str:
|
||||
payload = json.dumps(
|
||||
value,
|
||||
sort_keys=True,
|
||||
separators=(",", ":"),
|
||||
ensure_ascii=True,
|
||||
).encode("utf-8")
|
||||
return hashlib.sha256(payload).hexdigest()
|
||||
|
||||
|
||||
def _configure_prompt(
|
||||
template: Mapping[str, Any],
|
||||
*,
|
||||
case: A7bCase,
|
||||
action: str,
|
||||
output_prefix: str,
|
||||
run_name: str,
|
||||
reference_image: str,
|
||||
) -> dict[str, Any]:
|
||||
prompt = copy.deepcopy(dict(template))
|
||||
sampler_id, sampler = _find_one(prompt, "H3ContinuumSamplerV38")
|
||||
sampler["class_type"] = "H3ContinuumSamplerV38MemoryPolicyExperimental"
|
||||
inputs = sampler["inputs"]
|
||||
inputs["diagnostics"] = "Detailed Report"
|
||||
inputs["run_storage"] = "Save + Auto Resume"
|
||||
inputs["run_name"] = run_name
|
||||
inputs["project_id"] = ""
|
||||
inputs["reference_size"] = IMAGE_MAX
|
||||
inputs["video_reference_size"] = VIDEO_BALANCED
|
||||
for name in (
|
||||
"reference_image_1",
|
||||
"reference_image_2",
|
||||
"reference_image_3",
|
||||
"reference_video_1",
|
||||
):
|
||||
inputs.pop(name, None)
|
||||
|
||||
prompt["949"] = {
|
||||
"class_type": "H3ContinuumMemoryActionPolicyExperimental",
|
||||
"inputs": {"reference_action": action},
|
||||
"_meta": {"title": "A7b Explicit Memory Action Policy"},
|
||||
}
|
||||
inputs["memory_action_policy"] = ["949", 0]
|
||||
prompt_id = str(inputs["sequence_prompt"][0])
|
||||
prompt[prompt_id]["inputs"]["value"] = PROMPT
|
||||
|
||||
if case.is_image:
|
||||
labels = []
|
||||
for index in range(1, case.reference_count + 1):
|
||||
node_id = str(949 + index)
|
||||
input_name = f"reference_image_{index}"
|
||||
prompt[node_id] = {
|
||||
"class_type": "LoadImage",
|
||||
"inputs": {"image": reference_image},
|
||||
"_meta": {"title": f"A7b Reference Image {index}"},
|
||||
}
|
||||
inputs[input_name] = [node_id, 0]
|
||||
labels.append(f"<Picture {index}>")
|
||||
prompt[prompt_id]["inputs"]["value"] = (
|
||||
PROMPT
|
||||
+ " Preserve the identity and natural appearance from "
|
||||
+ ", ".join(labels)
|
||||
+ "."
|
||||
)
|
||||
elif case.is_video:
|
||||
prompt["950"] = {
|
||||
"class_type": "H3ContinuumLoadVideo",
|
||||
"inputs": {
|
||||
"enable_video": True,
|
||||
"file": case.video_file,
|
||||
"force_rate": 24.0,
|
||||
},
|
||||
"_meta": {"title": "A7b Video Guide"},
|
||||
}
|
||||
inputs["reference_video_1"] = ["950", 0]
|
||||
prompt[prompt_id]["inputs"]["value"] = (
|
||||
PROMPT
|
||||
+ " Follow the appearance and motion guidance from <Video 1> while "
|
||||
"preserving continuity."
|
||||
)
|
||||
|
||||
_save_video_id, save_video = _find_one(prompt, "SaveVideo")
|
||||
save_video["inputs"]["filename_prefix"] = output_prefix
|
||||
prompt["902"]["inputs"]["filename_prefix"] = output_prefix + "_video"
|
||||
prompt["903"]["inputs"]["filename_prefix"] = output_prefix + "_audio"
|
||||
# The accepted A7a template already routes sampler outputs through Core
|
||||
# decode, assemble, SaveLatent, and the read-only A3c evidence probe.
|
||||
for node_id in ("900", "902", "903", "907", "908"):
|
||||
if node_id not in prompt:
|
||||
raise GateFailure(f"accepted A7a evidence node {node_id} is missing")
|
||||
prompt["900"]["inputs"]["source"] = [sampler_id, 3]
|
||||
prompt["902"]["inputs"]["samples"] = [sampler_id, 0]
|
||||
prompt["903"]["inputs"]["samples"] = [sampler_id, 1]
|
||||
for name, slot in (
|
||||
("input_video_latents", 0),
|
||||
("output_video_latents", 0),
|
||||
("input_audio_latents", 1),
|
||||
("output_audio_latents", 1),
|
||||
("input_assembly_plan", 2),
|
||||
("output_assembly_plan", 2),
|
||||
("refine_status", 3),
|
||||
):
|
||||
prompt["907"]["inputs"][name] = [sampler_id, slot]
|
||||
return prompt
|
||||
|
||||
|
||||
def _latest_manifest(output_root: Path, run_name: str) -> dict[str, Any]:
|
||||
revision_root = output_root / "h3_continuum" / "runs" / run_name / "revisions"
|
||||
manifests = sorted(
|
||||
revision_root.glob("*/manifest.json"),
|
||||
key=lambda path: path.stat().st_mtime_ns,
|
||||
)
|
||||
if not manifests:
|
||||
raise GateFailure(f"Run Storage manifest is missing for {run_name}")
|
||||
path = manifests[-1]
|
||||
manifest = json.loads(path.read_text(encoding="utf-8"))
|
||||
return {"path": str(path), "manifest": manifest}
|
||||
|
||||
|
||||
def _one_seed(status: str) -> int:
|
||||
match = SEED_PATTERN.search(status)
|
||||
if match is None:
|
||||
raise GateFailure("effective chunk seed is missing from sampler status")
|
||||
return int(match.group(1))
|
||||
|
||||
|
||||
def _image_geometry(status: str) -> tuple[int, int] | None:
|
||||
match = IMAGE_GEOMETRY_PATTERN.search(status)
|
||||
return None if match is None else (int(match.group(1)), int(match.group(2)))
|
||||
|
||||
|
||||
def _run_variant(
|
||||
args: argparse.Namespace,
|
||||
*,
|
||||
template: Mapping[str, Any],
|
||||
case: A7bCase,
|
||||
action: str,
|
||||
) -> dict[str, Any]:
|
||||
variant = "disabled" if action == ACTION_DISABLED else "reduce"
|
||||
name = f"{case.name}_{variant}"
|
||||
run_name = f"v38_a7b_{args.run_tag}_{name}"[:96]
|
||||
output_prefix = f"v38_a7b/{args.run_tag}/{name}"
|
||||
prompt = _configure_prompt(
|
||||
template,
|
||||
case=case,
|
||||
action=action,
|
||||
output_prefix=output_prefix,
|
||||
run_name=run_name,
|
||||
reference_image=args.reference_image,
|
||||
)
|
||||
result, entry = _execute(
|
||||
args,
|
||||
name=name,
|
||||
prompt=prompt,
|
||||
expected_seconds=5.0,
|
||||
boundaries=(),
|
||||
)
|
||||
status = _output_text(entry, "900")
|
||||
probe = _marker_json(_output_text(entry, "908"), "A3C_PROBE_JSON=")
|
||||
video_records = _output_latents(entry, "902", args.output_root)
|
||||
audio_records = _output_latents(entry, "903", args.output_root)
|
||||
packed_rows = _parse_packed_rows(status)
|
||||
storage = _latest_manifest(args.output_root, run_name)
|
||||
manifest = storage["manifest"]
|
||||
contract = manifest.get("contract") or {}
|
||||
global_contract = contract.get("global") or {}
|
||||
chunk_contracts = contract.get("chunk_contracts") or []
|
||||
sampler_id, sampler = _find_one(prompt, "H3ContinuumSamplerV38MemoryPolicyExperimental")
|
||||
checks = {
|
||||
"one_physical_group": len(video_records) == len(audio_records) == 1,
|
||||
"saved_video_sha_matches_probe": [item["tensor_sha256"] for item in video_records]
|
||||
== list(probe.get("input_video_sha256") or []),
|
||||
"saved_audio_sha_matches_probe": [item["tensor_sha256"] for item in audio_records]
|
||||
== list(probe.get("input_audio_sha256") or []),
|
||||
"finite": all(probe.get("output_video_finite") or [])
|
||||
and all(probe.get("output_audio_finite") or []),
|
||||
"media": int(result["media"]["frames"]) == 120
|
||||
and abs(float(result["media"]["format_duration"]) - 5.0) <= 0.05
|
||||
and int(result["media"]["audio_sample_rate"]) == 32000
|
||||
and int(result["media"]["audio_channels"]) == 2,
|
||||
"audio_health": bool(result["audio_health"]["pass"]),
|
||||
"storage_complete": manifest.get("status") == "complete",
|
||||
"one_chunk_contract": len(chunk_contracts) == 1,
|
||||
"packed_rows_valid": packed_rows["observed_groups"] == 1
|
||||
and len(packed_rows["groups"]) == 1
|
||||
and packed_rows["groups"][0]["component_sum"]
|
||||
== packed_rows["groups"][0]["total"],
|
||||
"experimental_sampler_only": sampler["class_type"]
|
||||
== "H3ContinuumSamplerV38MemoryPolicyExperimental",
|
||||
"policy_status": (
|
||||
POLICY_STATUS not in status
|
||||
if action == ACTION_DISABLED
|
||||
else POLICY_STATUS in status
|
||||
and "automatic MODEL unload was not executed" in status
|
||||
and "automatic attention/backend switching was not executed" in status
|
||||
and "external MODEL wrapper was preserved" in status
|
||||
),
|
||||
}
|
||||
result.update(
|
||||
{
|
||||
"action": action,
|
||||
"run_name": run_name,
|
||||
"sampler_id": sampler_id,
|
||||
"status": status,
|
||||
"seed": _one_seed(status),
|
||||
"image_geometry": _image_geometry(status),
|
||||
"probe": probe,
|
||||
"video_latents": video_records,
|
||||
"audio_latents": audio_records,
|
||||
"packed_rows": packed_rows,
|
||||
"run_storage": storage,
|
||||
"global_hash": (
|
||||
str(chunk_contracts[0].get("global_hash"))
|
||||
if chunk_contracts
|
||||
else ""
|
||||
),
|
||||
"sigmas_hash": str(
|
||||
(global_contract.get("sigmas") or {}).get("exact_sha256") or ""
|
||||
),
|
||||
"model_contract_hash": _sha256_json(global_contract.get("model")),
|
||||
"reference_contract": copy.deepcopy(global_contract.get("reference")),
|
||||
"reference_video_contract": copy.deepcopy(
|
||||
global_contract.get("reference_video")
|
||||
),
|
||||
"assembly_normalized": copy.deepcopy(
|
||||
(probe.get("input_plan") or {}).get("normalized")
|
||||
),
|
||||
"checks": checks,
|
||||
"pass": all(checks.values()),
|
||||
}
|
||||
)
|
||||
result_path = args.evidence_root / name / "result.json"
|
||||
result_path.write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
if not result["pass"]:
|
||||
failed = [key for key, value in checks.items() if not value]
|
||||
raise GateFailure(f"{name} failed: {failed}")
|
||||
return result
|
||||
|
||||
|
||||
def _latent_hashes(result: Mapping[str, Any], stream: str) -> list[str]:
|
||||
return list((result.get("probe") or {}).get(f"input_{stream}_sha256") or [])
|
||||
|
||||
|
||||
def _plan_without_runtime(value: Any) -> Any:
|
||||
return _cross_run_plan_identity(value)
|
||||
|
||||
|
||||
def _effective_contract_checks(
|
||||
case: A7bCase,
|
||||
disabled: Mapping[str, Any],
|
||||
reduced: Mapping[str, Any],
|
||||
) -> dict[str, bool]:
|
||||
base_rows = disabled["packed_rows"]["groups"][0]
|
||||
reduced_rows = reduced["packed_rows"]["groups"][0]
|
||||
checks = {
|
||||
"global_identity_changed": disabled["global_hash"]
|
||||
and reduced["global_hash"]
|
||||
and disabled["global_hash"] != reduced["global_hash"],
|
||||
"actual_total_rows_decreased": reduced_rows["total"] < base_rows["total"],
|
||||
"condition_video_rows_decreased": reduced_rows["condition_video"]
|
||||
< base_rows["condition_video"],
|
||||
"output_variation_expected": _latent_hashes(disabled, "video")
|
||||
!= _latent_hashes(reduced, "video")
|
||||
or _latent_hashes(disabled, "audio") != _latent_hashes(reduced, "audio"),
|
||||
"assembly_semantics_unchanged": _plan_without_runtime(
|
||||
disabled["assembly_normalized"]
|
||||
)
|
||||
== _plan_without_runtime(reduced["assembly_normalized"]),
|
||||
"seed_unchanged": disabled["seed"] == reduced["seed"],
|
||||
"sigmas_unchanged": disabled["sigmas_hash"]
|
||||
and disabled["sigmas_hash"] == reduced["sigmas_hash"],
|
||||
"external_model_wrapper_unchanged": disabled["model_contract_hash"]
|
||||
== reduced["model_contract_hash"],
|
||||
}
|
||||
if case.is_image:
|
||||
base_contract = disabled.get("reference_contract") or {}
|
||||
reduced_contract = reduced.get("reference_contract") or {}
|
||||
base_geometry = disabled.get("image_geometry")
|
||||
reduced_geometry = reduced.get("image_geometry")
|
||||
checks.update(
|
||||
{
|
||||
"image_mode_one_step": base_contract.get("size_mode") == IMAGE_MAX
|
||||
and reduced_contract.get("size_mode") == IMAGE_MATCH,
|
||||
"image_contract_hash_changed": base_contract.get("combined_hash")
|
||||
!= reduced_contract.get("combined_hash"),
|
||||
"image_geometry_decreased": base_geometry is not None
|
||||
and reduced_geometry is not None
|
||||
and reduced_geometry[0] * reduced_geometry[1]
|
||||
< base_geometry[0] * base_geometry[1],
|
||||
}
|
||||
)
|
||||
elif case.is_video:
|
||||
base_contract = disabled.get("reference_video_contract") or {}
|
||||
reduced_contract = reduced.get("reference_video_contract") or {}
|
||||
checks.update(
|
||||
{
|
||||
"video_mode_one_step": base_contract.get("size_mode")
|
||||
== VIDEO_BALANCED
|
||||
and reduced_contract.get("size_mode") == VIDEO_EFFICIENT,
|
||||
"video_contract_hash_changed": base_contract.get("combined_hash")
|
||||
!= reduced_contract.get("combined_hash"),
|
||||
"video_geometry_decreased": int(reduced_contract.get("target_width", 0))
|
||||
* int(reduced_contract.get("target_height", 0))
|
||||
< int(base_contract.get("target_width", 0))
|
||||
* int(base_contract.get("target_height", 0)),
|
||||
"video_frame_count_unchanged": base_contract.get("frame_count")
|
||||
== reduced_contract.get("frame_count"),
|
||||
}
|
||||
)
|
||||
return checks
|
||||
|
||||
|
||||
def _g1_checks(
|
||||
result: Mapping[str, Any],
|
||||
*,
|
||||
baseline_result: Mapping[str, Any],
|
||||
baseline_prompt: Mapping[str, Any],
|
||||
) -> dict[str, bool]:
|
||||
baseline_probe = baseline_result.get("probe") or {}
|
||||
current_probe = result.get("probe") or {}
|
||||
_baseline_sampler_id, baseline_sampler = _find_one(
|
||||
baseline_prompt, "H3ContinuumSamplerV38"
|
||||
)
|
||||
current_prompt = json.loads(Path(result["prompt"]).read_text(encoding="utf-8"))
|
||||
_current_sampler_id, current_sampler = _find_one(
|
||||
current_prompt, "H3ContinuumSamplerV38MemoryPolicyExperimental"
|
||||
)
|
||||
return {
|
||||
"video_latent_bit_exact": list(current_probe.get("input_video_sha256") or [])
|
||||
== list(baseline_probe.get("input_video_sha256") or []),
|
||||
"audio_latent_bit_exact": list(current_probe.get("input_audio_sha256") or [])
|
||||
== list(baseline_probe.get("input_audio_sha256") or []),
|
||||
"assembly_semantics_bit_exact": _plan_without_runtime(
|
||||
(current_probe.get("input_plan") or {}).get("normalized")
|
||||
)
|
||||
== _plan_without_runtime(
|
||||
(baseline_probe.get("input_plan") or {}).get("normalized")
|
||||
),
|
||||
"decoded_video_bit_exact": (result.get("decoded") or {}).get("video_sha256")
|
||||
== (baseline_result.get("decoded") or {}).get("video_sha256"),
|
||||
"decoded_audio_bit_exact": (result.get("decoded") or {}).get(
|
||||
"audio_pcm_sha256"
|
||||
)
|
||||
== (baseline_result.get("decoded") or {}).get("audio_pcm_sha256"),
|
||||
"seed_input_unchanged": current_sampler["inputs"].get("base_seed")
|
||||
== baseline_sampler["inputs"].get("base_seed"),
|
||||
"sampler_link_unchanged": current_sampler["inputs"].get("sampler")
|
||||
== baseline_sampler["inputs"].get("sampler"),
|
||||
"sigmas_link_unchanged": current_sampler["inputs"].get("sigmas")
|
||||
== baseline_sampler["inputs"].get("sigmas"),
|
||||
"no_reference_contract": result.get("reference_contract") is None
|
||||
and result.get("reference_video_contract") is None,
|
||||
"disabled_status_no_action": POLICY_STATUS not in str(result.get("status")),
|
||||
}
|
||||
|
||||
|
||||
def run(args: argparse.Namespace) -> dict[str, Any]:
|
||||
args.evidence_root.mkdir(parents=True, exist_ok=True)
|
||||
template = json.loads(args.template.read_text(encoding="utf-8"))
|
||||
baseline_result = json.loads(args.a7a_g1_result.read_text(encoding="utf-8"))
|
||||
baseline_prompt = json.loads(
|
||||
Path(baseline_result["prompt"]).read_text(encoding="utf-8")
|
||||
)
|
||||
cases = (
|
||||
A7bCase("g2_image_1", "image", reference_count=1),
|
||||
A7bCase("g3_video_short", "video", video_file=args.short_video),
|
||||
A7bCase("g4_images_3", "image", reference_count=3),
|
||||
A7bCase("g5_video_high_row", "video", video_file=args.high_video),
|
||||
)
|
||||
summary: dict[str, Any] = {
|
||||
"format": "h3-continuum-v38-a7b-memory-action-gpu-matrix-v1",
|
||||
"server": args.server,
|
||||
"backend_pid": args.backend_pid,
|
||||
"run_tag": args.run_tag,
|
||||
"settings": {
|
||||
"resolution": "576x576",
|
||||
"steps": 8,
|
||||
"fixed_seed": True,
|
||||
"run_storage": "Save + Auto Resume with unique run names",
|
||||
"policy": "explicit opt-in one-step Reference downgrade",
|
||||
"auto_unload": "not executed; advisory-only",
|
||||
"backend_switch": "not executed; advisory-only",
|
||||
},
|
||||
"results": {},
|
||||
"pass": False,
|
||||
"production_status": "unchanged; Experimental path only; A5 HOLD",
|
||||
}
|
||||
summary_path = args.evidence_root / "summary.json"
|
||||
try:
|
||||
g1_case = A7bCase("g1_disabled", "none")
|
||||
g1 = _run_variant(
|
||||
args,
|
||||
template=template,
|
||||
case=g1_case,
|
||||
action=ACTION_DISABLED,
|
||||
)
|
||||
g1_parity = _g1_checks(
|
||||
g1,
|
||||
baseline_result=baseline_result,
|
||||
baseline_prompt=baseline_prompt,
|
||||
)
|
||||
summary["results"][g1_case.name] = {
|
||||
"baseline": str(args.a7a_g1_result),
|
||||
"disabled": g1,
|
||||
"checks": g1_parity,
|
||||
"pass": all(g1_parity.values()),
|
||||
}
|
||||
summary_path.write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
if not all(g1_parity.values()):
|
||||
failed = [key for key, value in g1_parity.items() if not value]
|
||||
raise GateFailure(f"G1 Disabled parity failed: {failed}")
|
||||
print("A7b G1 Disabled parity PASS", flush=True)
|
||||
|
||||
for case in cases:
|
||||
disabled = _run_variant(
|
||||
args,
|
||||
template=template,
|
||||
case=case,
|
||||
action=ACTION_DISABLED,
|
||||
)
|
||||
reduced = _run_variant(
|
||||
args,
|
||||
template=template,
|
||||
case=case,
|
||||
action=ACTION_REDUCE,
|
||||
)
|
||||
checks = _effective_contract_checks(case, disabled, reduced)
|
||||
case_result = {
|
||||
"case": {
|
||||
"name": case.name,
|
||||
"conditioning": case.conditioning,
|
||||
"reference_count": case.reference_count,
|
||||
"video_file": case.video_file,
|
||||
},
|
||||
"disabled": disabled,
|
||||
"reduced": reduced,
|
||||
"checks": checks,
|
||||
"pass": all(checks.values()),
|
||||
}
|
||||
summary["results"][case.name] = case_result
|
||||
summary_path.write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
print(
|
||||
f"A7b {case.name}: pass={case_result['pass']} "
|
||||
f"rows={disabled['packed_rows']['peak_total_rows']}->"
|
||||
f"{reduced['packed_rows']['peak_total_rows']}",
|
||||
flush=True,
|
||||
)
|
||||
if not case_result["pass"]:
|
||||
failed = [key for key, value in checks.items() if not value]
|
||||
raise GateFailure(f"{case.name} failed: {failed}")
|
||||
summary["pass"] = True
|
||||
summary["status"] = "A7b v1 Memory Action Policy GPU Experimental PASS"
|
||||
return summary
|
||||
except Exception as exc:
|
||||
summary["failure_type"] = type(exc).__name__
|
||||
summary["failure"] = str(exc)
|
||||
summary["status"] = "A7b STOP / Production unchanged / A5 HOLD"
|
||||
return summary
|
||||
finally:
|
||||
summary_path.write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8190")
|
||||
parser.add_argument("--backend-pid", type=int, required=True)
|
||||
parser.add_argument("--run-tag", required=True)
|
||||
parser.add_argument("--evidence-root", type=Path, required=True)
|
||||
parser.add_argument("--template", type=Path, required=True)
|
||||
parser.add_argument("--a7a-g1-result", type=Path, required=True)
|
||||
parser.add_argument("--reference-image", required=True)
|
||||
parser.add_argument("--short-video", required=True)
|
||||
parser.add_argument("--high-video", required=True)
|
||||
parser.add_argument(
|
||||
"--output-root",
|
||||
type=Path,
|
||||
default=Path(r"D:\output\video\comfy_video"),
|
||||
)
|
||||
parser.add_argument("--ffmpeg", default=shutil.which("ffmpeg"))
|
||||
parser.add_argument("--ffprobe", default=shutil.which("ffprobe"))
|
||||
parser.add_argument("--timeout-seconds", type=float, default=3600.0)
|
||||
args = parser.parse_args()
|
||||
if not args.ffmpeg or not args.ffprobe:
|
||||
raise SystemExit("ffmpeg and ffprobe are required")
|
||||
summary = run(args)
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"status": summary.get("status"),
|
||||
"pass": summary.get("pass"),
|
||||
"failure": summary.get("failure"),
|
||||
"summary": str(args.evidence_root / "summary.json"),
|
||||
},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
flush=True,
|
||||
)
|
||||
return 0 if summary["pass"] else 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,788 @@
|
||||
"""Run the A8a read-only Adaptive Continuity GPU Matrix.
|
||||
|
||||
The runner is evidence-only. It compares the public V3.8 Production path with
|
||||
accepted pre-A8 evidence, exercises the accepted Issue #13 same-prompt stress
|
||||
path, and splits the Review/Run Storage gate across a real backend restart.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
from typing import Any, Mapping
|
||||
import uuid
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
REPO_ROOT = TOOLS_ROOT.parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
if str(REPO_ROOT.parent) not in sys.path:
|
||||
sys.path.insert(0, str(REPO_ROOT.parent))
|
||||
|
||||
from v38_a2_audio_only_gpu_canary import _history_entry, _output_latents, _output_text
|
||||
from v38_a2_audio_only_gpu_canary import _audio_health
|
||||
from v38_a3c_selective_refine_gpu_matrix import (
|
||||
GateFailure,
|
||||
_decoded_stream_hash,
|
||||
_execute,
|
||||
_marker_json,
|
||||
)
|
||||
from v38_a7a_packed_row_gpu_matrix import (
|
||||
FirstPassCase,
|
||||
_configure_first_pass,
|
||||
_cross_run_plan_identity,
|
||||
)
|
||||
from v38_review_phase_f_gpu_gate_runner import _manifest_snapshot
|
||||
from v38_review_phase_f_recovery_runner import _cached_nodes, _preserved_prefix
|
||||
from v38_easy_gpu_gate_runner import _output_media, _probe_media
|
||||
|
||||
_OBSERVER_SPEC = importlib.util.spec_from_file_location(
|
||||
"h3_a8a_observer_contract",
|
||||
REPO_ROOT / "v3" / "adaptive_continuity.py",
|
||||
)
|
||||
if _OBSERVER_SPEC is None or _OBSERVER_SPEC.loader is None:
|
||||
raise RuntimeError("could not load the A8a observer contract")
|
||||
_OBSERVER_MODULE = importlib.util.module_from_spec(_OBSERVER_SPEC)
|
||||
_OBSERVER_SPEC.loader.exec_module(_OBSERVER_MODULE)
|
||||
ADAPTIVE_CONTINUITY_PLANNER_HASH = _OBSERVER_MODULE.ADAPTIVE_CONTINUITY_PLANNER_HASH
|
||||
|
||||
|
||||
SUMMARY_PATTERN = re.compile(
|
||||
r"planner_hash=([0-9a-f]{64}),\s*observed_groups=(\d+),\s*"
|
||||
r"execution_applied=false"
|
||||
)
|
||||
DECISION_PATTERN = re.compile(
|
||||
r"physical_group=(\d+),\s*logical_chunks=(\[[^\]]+\]),\s*"
|
||||
r"boundary=(\d+)/(\d+),\s*motion=([0-9.]+),\s*context=(\d+),\s*"
|
||||
r"transport=([^,]+),\s*terminal_atomic=(true|false),\s*"
|
||||
r"reused=(true|false),\s*recommendation=([^,]+),\s*"
|
||||
r"confidence=([0-9.]+),\s*reason=(.*?),\s*"
|
||||
r"fallback_reason=(.*?),\s*decision_hash=([0-9a-f]{64}),\s*"
|
||||
r"execution_applied=false\."
|
||||
)
|
||||
|
||||
|
||||
def _write_json(path: Path, value: Any) -> None:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(json.dumps(value, indent=2, ensure_ascii=False), encoding="utf-8")
|
||||
|
||||
|
||||
def _load_json(path: Path) -> Any:
|
||||
return json.loads(path.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def _load_completed(path: Path) -> dict[str, Any] | None:
|
||||
if not path.exists():
|
||||
return None
|
||||
value = _load_json(path)
|
||||
checks = value.get("checks") or {}
|
||||
if "observer_not_persisted" in checks and value.get("run_storage"):
|
||||
# Early runner revisions searched values too, which incorrectly treated
|
||||
# the existing report_summary status field as a schema mutation.
|
||||
manifest = value["run_storage"]["manifest"]
|
||||
keys: list[str] = []
|
||||
|
||||
def collect(current: Any) -> None:
|
||||
if isinstance(current, Mapping):
|
||||
for key, item in current.items():
|
||||
keys.append(str(key).lower())
|
||||
collect(item)
|
||||
elif isinstance(current, list):
|
||||
for item in current:
|
||||
collect(item)
|
||||
|
||||
collect(manifest)
|
||||
checks.pop("observer_not_persisted", None)
|
||||
checks["observer_not_persisted_as_schema"] = not any(
|
||||
key.startswith("adaptive_continuity") or key == "decision_hash"
|
||||
for key in keys
|
||||
)
|
||||
value["checks"] = checks
|
||||
value["pass"] = all(checks.values())
|
||||
_write_json(path, value)
|
||||
if bool(value.get("pass")) and all((value.get("checks") or {}).values()):
|
||||
value["resumed_without_resampling"] = True
|
||||
return value
|
||||
return None
|
||||
|
||||
|
||||
def _parse_observer(status: str) -> dict[str, Any]:
|
||||
summary_lines = [
|
||||
line
|
||||
for line in status.splitlines()
|
||||
if line.startswith("Adaptive Continuity observer [A8a v1]:")
|
||||
]
|
||||
advisory_lines = [
|
||||
line
|
||||
for line in status.splitlines()
|
||||
if line.startswith("Adaptive Continuity advisory [A8a v1]:")
|
||||
or "Adaptive Continuity observer [A8a v1]: unavailable" in line
|
||||
]
|
||||
if len(summary_lines) != 1:
|
||||
raise GateFailure(f"expected one A8a observer summary, found {len(summary_lines)}")
|
||||
match = SUMMARY_PATTERN.search(summary_lines[0])
|
||||
if match is None:
|
||||
raise GateFailure("A8a observer summary could not be parsed")
|
||||
records: list[dict[str, Any]] = []
|
||||
for line in status.splitlines():
|
||||
if not line.startswith("Adaptive Continuity decision [A8a v1]:"):
|
||||
continue
|
||||
current = DECISION_PATTERN.search(line)
|
||||
if current is None:
|
||||
raise GateFailure(f"A8a decision could not be parsed: {line}")
|
||||
fallback = current.group(13)
|
||||
record = {
|
||||
"physical_group": int(current.group(1)),
|
||||
"logical_chunks": json.loads(current.group(2)),
|
||||
"boundary_index": int(current.group(3)),
|
||||
"boundary_count": int(current.group(4)),
|
||||
"observed_motion_score": float(current.group(5)),
|
||||
"current_context_frames": int(current.group(6)),
|
||||
"resolved_transport": current.group(7),
|
||||
"terminal_atomic": current.group(8) == "true",
|
||||
"reused": current.group(9) == "true",
|
||||
"recommendation": current.group(10),
|
||||
"confidence": float(current.group(11)),
|
||||
"reason": current.group(12),
|
||||
"fallback_reason": None if fallback == "none" else fallback,
|
||||
"decision_hash": current.group(14),
|
||||
"execution_applied": False,
|
||||
}
|
||||
# Motion is intentionally formatted to six decimal places in the human
|
||||
# report while the decision hash retains the full observed float. The
|
||||
# report can therefore validate hash presence/shape, not recompute it.
|
||||
record["hash_well_formed"] = bool(re.fullmatch(r"[0-9a-f]{64}", record["decision_hash"]))
|
||||
records.append(record)
|
||||
return {
|
||||
"planner_hash": match.group(1),
|
||||
"observed_groups": int(match.group(2)),
|
||||
"records": records,
|
||||
"advisories": advisory_lines,
|
||||
"summary": summary_lines[0],
|
||||
}
|
||||
|
||||
|
||||
def _observer_checks(
|
||||
observer: Mapping[str, Any],
|
||||
expected: list[tuple[list[int], int, str, bool, bool]],
|
||||
*,
|
||||
total_chunks: int | None = None,
|
||||
) -> dict[str, bool]:
|
||||
records = list(observer["records"])
|
||||
return {
|
||||
"planner_hash": observer["planner_hash"] == ADAPTIVE_CONTINUITY_PLANNER_HASH,
|
||||
"one_record_per_physical_group": len(records) == len(expected),
|
||||
"summary_group_count": int(observer["observed_groups"]) == len(expected),
|
||||
"physical_order": [item["physical_group"] for item in records]
|
||||
== list(range(1, len(expected) + 1)),
|
||||
"logical_groups": [item["logical_chunks"] for item in records]
|
||||
== [item[0] for item in expected],
|
||||
"context_frames": [item["current_context_frames"] for item in records]
|
||||
== [item[1] for item in expected],
|
||||
"transport": [item["resolved_transport"] for item in records]
|
||||
== [item[2] for item in expected],
|
||||
"terminal_atomic": [item["terminal_atomic"] for item in records]
|
||||
== [item[3] for item in expected],
|
||||
"reused": [item["reused"] for item in records]
|
||||
== [item[4] for item in expected],
|
||||
"boundary_count": all(
|
||||
int(record["boundary_count"])
|
||||
== max(
|
||||
0,
|
||||
int(total_chunks if total_chunks is not None else sum(len(item[0]) for item in expected)) - 1,
|
||||
)
|
||||
for record in records
|
||||
),
|
||||
"decision_hashes": all(item["hash_well_formed"] for item in records),
|
||||
"execution_applied_false": all(not item["execution_applied"] for item in records),
|
||||
"no_observer_advisory": not observer["advisories"],
|
||||
}
|
||||
|
||||
|
||||
def _baseline_signature(result: Mapping[str, Any]) -> dict[str, Any]:
|
||||
probe = result["probe"]
|
||||
return {
|
||||
"video": list(probe.get("input_video_sha256") or []),
|
||||
"audio": list(probe.get("input_audio_sha256") or []),
|
||||
"assembly": copy.deepcopy((probe.get("input_plan") or {}).get("normalized")),
|
||||
"decoded": copy.deepcopy(result.get("decoded") or {}),
|
||||
}
|
||||
|
||||
|
||||
def _run_public_case(
|
||||
args: argparse.Namespace,
|
||||
*,
|
||||
name: str,
|
||||
case: FirstPassCase,
|
||||
template_path: Path,
|
||||
baseline_path: Path,
|
||||
expected: list[tuple[list[int], int, str, bool, bool]],
|
||||
) -> dict[str, Any]:
|
||||
template = _load_json(template_path)
|
||||
output_prefix = f"v38_a8a/{args.run_tag}/{name}"
|
||||
prompt = _configure_first_pass(
|
||||
template,
|
||||
case=case,
|
||||
diagnostics="Detailed Report",
|
||||
output_prefix=output_prefix,
|
||||
reference_image="unused.png",
|
||||
reference_video="unused.mp4",
|
||||
)
|
||||
result, entry = _execute(
|
||||
args,
|
||||
name=name,
|
||||
prompt=prompt,
|
||||
expected_seconds=case.expected_seconds,
|
||||
boundaries=tuple(float(index * 5) for index in range(1, case.chunks)),
|
||||
)
|
||||
status = _output_text(entry, "900")
|
||||
probe = _marker_json(_output_text(entry, "908"), "A3C_PROBE_JSON=")
|
||||
observer = _parse_observer(status)
|
||||
baseline = _baseline_signature(_load_json(baseline_path))
|
||||
current = {
|
||||
"video": list(probe.get("input_video_sha256") or []),
|
||||
"audio": list(probe.get("input_audio_sha256") or []),
|
||||
"assembly": copy.deepcopy((probe.get("input_plan") or {}).get("normalized")),
|
||||
"decoded": copy.deepcopy(result.get("decoded") or {}),
|
||||
}
|
||||
checks = {
|
||||
**_observer_checks(observer, expected, total_chunks=case.chunks),
|
||||
"video_latent_sha_parity": current["video"] == baseline["video"],
|
||||
"audio_latent_sha_parity": current["audio"] == baseline["audio"],
|
||||
"assembly_plan_parity": _cross_run_plan_identity(current["assembly"])
|
||||
== _cross_run_plan_identity(baseline["assembly"]),
|
||||
"decoded_video_parity": current["decoded"].get("video_sha256")
|
||||
== baseline["decoded"].get("video_sha256"),
|
||||
"decoded_audio_parity": current["decoded"].get("audio_pcm_sha256")
|
||||
== baseline["decoded"].get("audio_pcm_sha256"),
|
||||
"audio_health": bool(result["audio_health"]["pass"]),
|
||||
"no_reference_video": not any(
|
||||
key.startswith("reference_video_") for key in prompt["305"]["inputs"]
|
||||
),
|
||||
}
|
||||
payload = {
|
||||
**result,
|
||||
"status": status,
|
||||
"probe": probe,
|
||||
"observer": observer,
|
||||
"baseline_path": str(baseline_path),
|
||||
"baseline": baseline,
|
||||
"current": current,
|
||||
"checks": checks,
|
||||
"pass": all(checks.values()),
|
||||
}
|
||||
_write_json(args.evidence_root / name / "result.json", payload)
|
||||
if not payload["pass"]:
|
||||
raise GateFailure(f"{name} failed: {[key for key, value in checks.items() if not value]}")
|
||||
print(f"A8a {name}: PASS ({result['api_elapsed_seconds']:.3f}s)", flush=True)
|
||||
return payload
|
||||
|
||||
|
||||
def _reachable_prompt(prompt: Mapping[str, Any], roots: tuple[str, ...]) -> dict[str, Any]:
|
||||
keep: set[str] = set()
|
||||
|
||||
def visit(node_id: str) -> None:
|
||||
if node_id in keep:
|
||||
return
|
||||
node = prompt.get(node_id)
|
||||
if not isinstance(node, Mapping):
|
||||
raise GateFailure(f"prompt dependency is missing: {node_id}")
|
||||
keep.add(node_id)
|
||||
for value in (node.get("inputs") or {}).values():
|
||||
if isinstance(value, list) and len(value) == 2 and str(value[0]) in prompt:
|
||||
visit(str(value[0]))
|
||||
|
||||
for root in roots:
|
||||
visit(root)
|
||||
return {key: copy.deepcopy(value) for key, value in prompt.items() if key in keep}
|
||||
|
||||
|
||||
def _diagnostic_signature(value: Mapping[str, Any]) -> dict[str, Any]:
|
||||
def tensor_shas(key: str) -> list[str]:
|
||||
return [str(item.get("sha256") or "") for item in (value.get(key) or [])]
|
||||
|
||||
calls = []
|
||||
for call in value.get("sample_calls") or []:
|
||||
calls.append(
|
||||
{
|
||||
"sample_number": call.get("sample_number"),
|
||||
"seed": call.get("seed"),
|
||||
"sigmas": (call.get("sigmas") or {}).get("sha256"),
|
||||
"prompt_embedding": (call.get("prompt_embedding") or {}).get("sha256"),
|
||||
"output_video": (call.get("output_video") or {}).get("sha256"),
|
||||
"output_audio": (call.get("output_audio") or {}).get("sha256"),
|
||||
}
|
||||
)
|
||||
return {
|
||||
"physical_group_count": value.get("physical_group_count"),
|
||||
"logical_chunk_count": value.get("logical_chunk_count"),
|
||||
"physical_decode_group_count": value.get("physical_decode_group_count"),
|
||||
"production_transport": value.get("production_transport"),
|
||||
"transport": value.get("transport"),
|
||||
"context_frames": value.get("context_frames"),
|
||||
"audio_prefix_steps": value.get("audio_prefix_steps"),
|
||||
"video_prefix_slots": value.get("video_prefix_slots"),
|
||||
"synchronize_sampling": value.get("synchronize_sampling"),
|
||||
"audio_continuity_forced": value.get("audio_continuity_forced"),
|
||||
"requested_audio_continuity": value.get("requested_audio_continuity"),
|
||||
"physical_video_sha256": tensor_shas("physical_video_groups"),
|
||||
"physical_audio_sha256": tensor_shas("physical_audio_groups"),
|
||||
"sample_calls": calls,
|
||||
"final_prefix_bit_exact": [
|
||||
[item.get("bit_exact"), item.get("audio_bit_exact")]
|
||||
for item in (value.get("final_prefix_pairs") or [])
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def _completed_history_result(
|
||||
args: argparse.Namespace,
|
||||
*,
|
||||
name: str,
|
||||
expected_seconds: float,
|
||||
boundaries: tuple[float, ...],
|
||||
) -> tuple[dict[str, Any], Mapping[str, Any]] | None:
|
||||
"""Recover evidence after Sampling when only runner post-processing failed."""
|
||||
|
||||
history_path = args.evidence_root / name / "history.json"
|
||||
if not history_path.exists():
|
||||
return None
|
||||
history = _load_json(history_path)
|
||||
if not isinstance(history, Mapping) or len(history) != 1:
|
||||
return None
|
||||
entry = _history_entry(history, str(next(iter(history))))
|
||||
media_path = _output_media(history, args.output_root)
|
||||
media = _probe_media(media_path, args.ffprobe)
|
||||
result = {
|
||||
"name": name,
|
||||
"prompt_id": str(next(iter(history))),
|
||||
"api_elapsed_seconds": None,
|
||||
"prompt": str(args.evidence_root / name / "prompt.json"),
|
||||
"history": str(history_path),
|
||||
"media_path": str(media_path),
|
||||
"media": media,
|
||||
"decoded": {
|
||||
"video_sha256": _decoded_stream_hash(
|
||||
media_path, ffmpeg=args.ffmpeg, stream="video"
|
||||
),
|
||||
"audio_pcm_sha256": _decoded_stream_hash(
|
||||
media_path, ffmpeg=args.ffmpeg, stream="audio"
|
||||
),
|
||||
},
|
||||
"audio_health": _audio_health(
|
||||
media_path,
|
||||
ffmpeg=args.ffmpeg,
|
||||
expected_seconds=expected_seconds,
|
||||
boundaries=boundaries,
|
||||
),
|
||||
"resources": {"salvaged_from_completed_history": True},
|
||||
"completed_history_reused_without_resampling": True,
|
||||
}
|
||||
return result, entry
|
||||
|
||||
|
||||
def _run_issue13(args: argparse.Namespace) -> dict[str, Any]:
|
||||
prompt = _reachable_prompt(_load_json(args.issue_template), ("191", "249"))
|
||||
# The accepted R2.6 wrapper later gained this required diagnostic-only
|
||||
# selector. "Recursive" exactly preserves the accepted R2.6 source path.
|
||||
prompt["305"]["inputs"]["continuation_source_mode"] = "Recursive"
|
||||
prompt["191"]["inputs"]["filename_prefix"] = (
|
||||
f"v38_a8a/{args.run_tag}/g3_issue13_6x5_same_prompt"
|
||||
)
|
||||
recovered = _completed_history_result(
|
||||
args,
|
||||
name="g3_issue13_6x5_same_prompt",
|
||||
expected_seconds=30.0,
|
||||
boundaries=(5.0, 10.0, 15.0, 20.0, 25.0),
|
||||
)
|
||||
if recovered is None:
|
||||
result, entry = _execute(
|
||||
args,
|
||||
name="g3_issue13_6x5_same_prompt",
|
||||
prompt=prompt,
|
||||
expected_seconds=30.0,
|
||||
boundaries=(5.0, 10.0, 15.0, 20.0, 25.0),
|
||||
)
|
||||
else:
|
||||
result, entry = recovered
|
||||
status = _output_text(entry, "249")
|
||||
diagnostic_line = next(
|
||||
(
|
||||
line
|
||||
for line in status.splitlines()
|
||||
if line.startswith("V3.6-R1 diagnostic: ")
|
||||
),
|
||||
"",
|
||||
)
|
||||
if not diagnostic_line:
|
||||
raise GateFailure("V3.6-R1 diagnostic JSON is missing")
|
||||
diagnostic = json.loads(diagnostic_line[len("V3.6-R1 diagnostic: ") :])
|
||||
observer = _parse_observer(status)
|
||||
baseline_diagnostic = _load_json(args.issue_baseline)["diagnostic"]
|
||||
baseline = _diagnostic_signature(baseline_diagnostic)
|
||||
current = _diagnostic_signature(diagnostic)
|
||||
expected = [
|
||||
([index], 0 if index == 1 else 22, "initial" if index == 1 else "masked_av_prefix_22_v1", False, False)
|
||||
for index in range(1, 7)
|
||||
]
|
||||
checks = {
|
||||
**_observer_checks(observer, expected, total_chunks=6),
|
||||
"accepted_r26_diagnostic_parity": current == baseline,
|
||||
"six_physical_groups": diagnostic.get("physical_group_count") == 6,
|
||||
"five_exact_prefix_pairs": len(diagnostic.get("final_prefix_pairs") or []) == 5
|
||||
and all(
|
||||
bool(item.get("bit_exact")) and bool(item.get("audio_bit_exact"))
|
||||
for item in (diagnostic.get("final_prefix_pairs") or [])
|
||||
),
|
||||
"same_prompt": len(set(diagnostic.get("logical_prompt_hashes") or [])) <= 1,
|
||||
"audio_health": bool(result["audio_health"]["pass"]),
|
||||
"no_reference_video": "reference_video_1" not in prompt["305"]["inputs"],
|
||||
}
|
||||
payload = {
|
||||
**result,
|
||||
"status": status,
|
||||
"diagnostic": diagnostic,
|
||||
"observer": observer,
|
||||
"baseline_path": str(args.issue_baseline),
|
||||
"baseline_signature": baseline,
|
||||
"current_signature": current,
|
||||
"checks": checks,
|
||||
"pass": all(checks.values()),
|
||||
}
|
||||
_write_json(args.evidence_root / "g3_issue13_6x5_same_prompt" / "result.json", payload)
|
||||
if not payload["pass"]:
|
||||
raise GateFailure(
|
||||
"g3_issue13_6x5_same_prompt failed: "
|
||||
f"{[key for key, value in checks.items() if not value]}"
|
||||
)
|
||||
elapsed = result.get("api_elapsed_seconds")
|
||||
elapsed_text = "completed-history" if elapsed is None else f"{float(elapsed):.3f}s"
|
||||
print(f"A8a g3_issue13_6x5_same_prompt: PASS ({elapsed_text})", flush=True)
|
||||
return payload
|
||||
|
||||
|
||||
def _review_prompt(
|
||||
args: argparse.Namespace,
|
||||
*,
|
||||
output_prefix: str,
|
||||
run_name: str,
|
||||
) -> dict[str, Any]:
|
||||
template = _load_json(args.t2_template)
|
||||
case = FirstPassCase("g5_review", 3, False, "none", "accepted")
|
||||
prompt = _configure_first_pass(
|
||||
template,
|
||||
case=case,
|
||||
diagnostics="Detailed Report",
|
||||
output_prefix=output_prefix,
|
||||
reference_image="unused.png",
|
||||
reference_video="unused.mp4",
|
||||
)
|
||||
inputs = prompt["305"]["inputs"]
|
||||
inputs.update(
|
||||
{
|
||||
"run_storage": "Save + Auto Resume",
|
||||
"run_name": run_name,
|
||||
"project_id": str(uuid.uuid5(uuid.NAMESPACE_URL, run_name)),
|
||||
"generation_mode": "Review Each Chunk",
|
||||
"review_action": "Continue / Next",
|
||||
}
|
||||
)
|
||||
return prompt
|
||||
|
||||
|
||||
def _manifest_entry_metadata(storage: Mapping[str, Any]) -> list[dict[str, Any]]:
|
||||
result = []
|
||||
for stored in (storage["manifest"].get("chunks") or []):
|
||||
entry = stored.get("entry") or {}
|
||||
result.append(
|
||||
{
|
||||
"context_frames": int(entry.get("context_frames", 0)),
|
||||
"motion_score": float(entry.get("motion_score", 0.0)),
|
||||
}
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
def _review_metadata_checks(
|
||||
observer: Mapping[str, Any], storage: Mapping[str, Any]
|
||||
) -> dict[str, bool]:
|
||||
records = list(observer["records"])
|
||||
metadata = _manifest_entry_metadata(storage)
|
||||
count = min(len(records), len(metadata))
|
||||
schema_keys: list[str] = []
|
||||
|
||||
def collect_keys(current: Any) -> None:
|
||||
if isinstance(current, Mapping):
|
||||
for key, item in current.items():
|
||||
schema_keys.append(str(key).lower())
|
||||
collect_keys(item)
|
||||
elif isinstance(current, list):
|
||||
for item in current:
|
||||
collect_keys(item)
|
||||
|
||||
collect_keys(storage["manifest"])
|
||||
return {
|
||||
"trace_matches_saved_context": count == len(records)
|
||||
and all(records[index]["current_context_frames"] == metadata[index]["context_frames"] for index in range(count)),
|
||||
"trace_matches_saved_motion": count == len(records)
|
||||
and all(abs(records[index]["observed_motion_score"] - metadata[index]["motion_score"]) <= 0.000001 for index in range(count)),
|
||||
"observer_not_persisted_as_schema": not any(
|
||||
key.startswith("adaptive_continuity") or key == "decision_hash"
|
||||
for key in schema_keys
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def _run_review_queue(
|
||||
args: argparse.Namespace,
|
||||
*,
|
||||
queue_index: int,
|
||||
run_name: str,
|
||||
before: Mapping[str, Any] | None,
|
||||
) -> dict[str, Any]:
|
||||
prompt = _review_prompt(
|
||||
args,
|
||||
output_prefix=f"v38_a8a/{args.run_tag}/g5_review_q{queue_index}",
|
||||
run_name=run_name,
|
||||
)
|
||||
result, entry = _execute(
|
||||
args,
|
||||
name=f"g5_review_q{queue_index}",
|
||||
prompt=prompt,
|
||||
expected_seconds=float(queue_index * 5),
|
||||
boundaries=tuple(float(index * 5) for index in range(1, queue_index)),
|
||||
)
|
||||
status = _output_text(entry, "900")
|
||||
observer = _parse_observer(status)
|
||||
storage = _manifest_snapshot(args.run_storage_root / run_name)
|
||||
expected = [
|
||||
([index], 0 if index == 1 else 22, "initial" if index == 1 else "masked_av_prefix_22_v1", False, index < queue_index)
|
||||
for index in range(1, queue_index + 1)
|
||||
]
|
||||
cached = sorted(_cached_nodes(_load_json(Path(result["history"]))))
|
||||
checks = {
|
||||
**_observer_checks(observer, expected, total_chunks=3),
|
||||
**_review_metadata_checks(observer, storage),
|
||||
"sampler_executed": "305" not in cached,
|
||||
"chunk_count": len(storage["chunks"]) == queue_index,
|
||||
"status": storage["status"] == ("complete" if queue_index == 3 else "review_ready"),
|
||||
"one_new_group": before is None or len(storage["chunks"]) == len(before["chunks"]) + 1,
|
||||
"prefix_exact_reuse": before is None or _preserved_prefix(before, storage),
|
||||
"audio_health": bool(result["audio_health"]["pass"]),
|
||||
"no_reference_video": "reference_video_1" not in prompt["305"]["inputs"],
|
||||
}
|
||||
payload = {
|
||||
**result,
|
||||
"status_text": status,
|
||||
"observer": observer,
|
||||
"run_storage": storage,
|
||||
"cached_nodes": cached,
|
||||
"checks": checks,
|
||||
"pass": all(checks.values()),
|
||||
}
|
||||
_write_json(args.evidence_root / f"g5_review_q{queue_index}" / "result.json", payload)
|
||||
if not payload["pass"]:
|
||||
raise GateFailure(
|
||||
f"g5_review_q{queue_index} failed: "
|
||||
f"{[key for key, value in checks.items() if not value]}"
|
||||
)
|
||||
print(f"A8a g5_review_q{queue_index}: PASS ({result['api_elapsed_seconds']:.3f}s)", flush=True)
|
||||
return payload
|
||||
|
||||
|
||||
def _compact_result(result: Mapping[str, Any]) -> dict[str, Any]:
|
||||
return {
|
||||
"pass": result.get("pass"),
|
||||
"api_elapsed_seconds": result.get("api_elapsed_seconds"),
|
||||
"resources": result.get("resources"),
|
||||
"checks": result.get("checks"),
|
||||
"observer": result.get("observer"),
|
||||
"result_path": str(Path(result["history"]).parent / "result.json"),
|
||||
}
|
||||
|
||||
|
||||
def run(args: argparse.Namespace) -> tuple[dict[str, Any], int]:
|
||||
args.evidence_root.mkdir(parents=True, exist_ok=True)
|
||||
summary_path = args.evidence_root / "gate_summary.json"
|
||||
summary = _load_json(summary_path) if summary_path.exists() else {
|
||||
"format": "h3-continuum-v38-a8a-adaptive-continuity-gpu-matrix-v1",
|
||||
"run_tag": args.run_tag,
|
||||
"server": args.server,
|
||||
"results": {},
|
||||
"pass": False,
|
||||
"production_status": "read-only observer; execution_applied=false; A8b HOLD; A5 HOLD",
|
||||
}
|
||||
summary["backend_pids"] = list(dict.fromkeys([*(summary.get("backend_pids") or []), args.backend_pid]))
|
||||
summary.pop("failure_type", None)
|
||||
summary.pop("failure", None)
|
||||
try:
|
||||
if args.stage == "pre-restart":
|
||||
public_root = args.public_baseline_root
|
||||
cases = (
|
||||
(
|
||||
"g1_1x5",
|
||||
FirstPassCase("g1", 1, False, "none", "accepted"),
|
||||
args.t2_template,
|
||||
public_root / "g1_1x5_t2va_detailed" / "result.json",
|
||||
[([1], 0, "initial", False, False)],
|
||||
),
|
||||
(
|
||||
"g2_3x5",
|
||||
FirstPassCase("g2", 3, False, "none", "accepted"),
|
||||
args.t2_template,
|
||||
public_root / "g2_3x5_continuation_detailed" / "result.json",
|
||||
[
|
||||
([1], 0, "initial", False, False),
|
||||
([2], 22, "masked_av_prefix_22_v1", False, False),
|
||||
([3], 22, "masked_av_prefix_22_v1", False, False),
|
||||
],
|
||||
),
|
||||
)
|
||||
for name, case, template, baseline, expected in cases:
|
||||
result_path = args.evidence_root / name / "result.json"
|
||||
current = _load_completed(result_path) or _run_public_case(
|
||||
args,
|
||||
name=name,
|
||||
case=case,
|
||||
template_path=template,
|
||||
baseline_path=baseline,
|
||||
expected=expected,
|
||||
)
|
||||
summary["results"][name] = _compact_result(current)
|
||||
_write_json(summary_path, summary)
|
||||
|
||||
issue_path = args.evidence_root / "g3_issue13_6x5_same_prompt" / "result.json"
|
||||
issue = _load_completed(issue_path) or _run_issue13(args)
|
||||
summary["results"]["g3_issue13_6x5_same_prompt"] = _compact_result(issue)
|
||||
_write_json(summary_path, summary)
|
||||
|
||||
terminal_path = args.evidence_root / "g4_fl2va_terminal" / "result.json"
|
||||
terminal = _load_completed(terminal_path) or _run_public_case(
|
||||
args,
|
||||
name="g4_fl2va_terminal",
|
||||
case=FirstPassCase("g4", 3, True, "none", "accepted"),
|
||||
template_path=args.terminal_template,
|
||||
baseline_path=public_root / "g3_fl2va_terminal_detailed" / "result.json",
|
||||
expected=[
|
||||
([1], 0, "initial", False, False),
|
||||
([2, 3], 22, "masked_av_prefix_22_v1", True, False),
|
||||
],
|
||||
)
|
||||
summary["results"]["g4_fl2va_terminal"] = _compact_result(terminal)
|
||||
_write_json(summary_path, summary)
|
||||
|
||||
run_name = f"v38_a8a_review_restart_{args.run_tag}"
|
||||
q1_path = args.evidence_root / "g5_review_q1" / "result.json"
|
||||
q1 = _load_completed(q1_path) or _run_review_queue(
|
||||
args,
|
||||
queue_index=1,
|
||||
run_name=run_name,
|
||||
before=None,
|
||||
)
|
||||
summary["results"]["g5_review_q1"] = _compact_result(q1)
|
||||
summary["restart_state"] = {
|
||||
"run_name": run_name,
|
||||
"q1_manifest": q1["run_storage"],
|
||||
"pre_restart_backend_pid": args.backend_pid,
|
||||
}
|
||||
summary["status"] = "A8a pre-restart gates PASS; backend restart required"
|
||||
_write_json(summary_path, summary)
|
||||
return summary, 0
|
||||
|
||||
state = summary.get("restart_state") or {}
|
||||
if not state.get("run_name") or not state.get("q1_manifest"):
|
||||
raise GateFailure("post-restart stage requires completed pre-restart state")
|
||||
if int(state.get("pre_restart_backend_pid")) == int(args.backend_pid):
|
||||
raise GateFailure("post-restart stage must use a fresh backend PID")
|
||||
run_name = str(state["run_name"])
|
||||
before = state["q1_manifest"]
|
||||
disk_before = _manifest_snapshot(args.run_storage_root / run_name)
|
||||
if not _preserved_prefix(before, disk_before) or len(disk_before["chunks"]) != 1:
|
||||
raise GateFailure("Run Storage prefix was not restored exactly after restart")
|
||||
|
||||
q2 = _run_review_queue(
|
||||
args,
|
||||
queue_index=2,
|
||||
run_name=run_name,
|
||||
before=disk_before,
|
||||
)
|
||||
summary["results"]["g5_review_q2_after_restart"] = _compact_result(q2)
|
||||
_write_json(summary_path, summary)
|
||||
q3 = _run_review_queue(
|
||||
args,
|
||||
queue_index=3,
|
||||
run_name=run_name,
|
||||
before=q2["run_storage"],
|
||||
)
|
||||
summary["results"]["g5_review_q3_complete"] = _compact_result(q3)
|
||||
summary["restart_state"]["post_restart_backend_pid"] = args.backend_pid
|
||||
summary["pass"] = all(bool(item.get("pass")) for item in summary["results"].values())
|
||||
summary["status"] = (
|
||||
"A8a Adaptive Continuity Observer GPU Experimental PASS"
|
||||
if summary["pass"]
|
||||
else "A8a STOP / Production unchanged"
|
||||
)
|
||||
_write_json(summary_path, summary)
|
||||
return summary, 0 if summary["pass"] else 2
|
||||
except Exception as exc:
|
||||
summary["pass"] = False
|
||||
summary["status"] = "A8a STOP / Production unchanged"
|
||||
summary["failure_type"] = type(exc).__name__
|
||||
summary["failure"] = str(exc)
|
||||
_write_json(summary_path, summary)
|
||||
return summary, 2
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--stage", choices=("pre-restart", "post-restart"), required=True)
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8190")
|
||||
parser.add_argument("--backend-pid", type=int, required=True)
|
||||
parser.add_argument("--run-tag", required=True)
|
||||
parser.add_argument("--evidence-root", type=Path, required=True)
|
||||
parser.add_argument("--t2-template", type=Path, required=True)
|
||||
parser.add_argument("--terminal-template", type=Path, required=True)
|
||||
parser.add_argument("--public-baseline-root", type=Path, required=True)
|
||||
parser.add_argument("--issue-template", type=Path, required=True)
|
||||
parser.add_argument("--issue-baseline", type=Path, required=True)
|
||||
parser.add_argument(
|
||||
"--run-storage-root",
|
||||
type=Path,
|
||||
default=Path(r"D:\output\video\comfy_video\h3_continuum\runs"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--output-root",
|
||||
type=Path,
|
||||
default=Path(r"D:\output\video\comfy_video"),
|
||||
)
|
||||
parser.add_argument("--timeout-seconds", type=float, default=3600.0)
|
||||
parser.add_argument("--ffmpeg", default=shutil.which("ffmpeg"))
|
||||
parser.add_argument("--ffprobe", default=shutil.which("ffprobe"))
|
||||
args = parser.parse_args()
|
||||
if not args.ffmpeg or not args.ffprobe:
|
||||
raise SystemExit("ffmpeg and ffprobe are required")
|
||||
summary, code = run(args)
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"status": summary.get("status"),
|
||||
"pass": summary.get("pass"),
|
||||
"failure": summary.get("failure"),
|
||||
"summary": str(args.evidence_root / "gate_summary.json"),
|
||||
},
|
||||
ensure_ascii=False,
|
||||
),
|
||||
flush=True,
|
||||
)
|
||||
return code
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,397 @@
|
||||
"""Run the Easy Load Audio + Driving Audio GPU acceptance gate."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
from dataclasses import asdict, dataclass
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from typing import Any, Mapping
|
||||
import uuid
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
from p32_api_runner import _json_request, submit_and_wait
|
||||
from p32_gpu_profile_probe import configure_profile
|
||||
from v36_r1_stress_gate_runner import ResourceMonitor
|
||||
from v38_easy_gpu_gate_runner import _ensure_profile_route
|
||||
|
||||
|
||||
class GateFailure(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class GateCase:
|
||||
name: str
|
||||
duration: int
|
||||
enabled: bool
|
||||
sequence: str
|
||||
|
||||
|
||||
CASES = (
|
||||
GateCase("g0_10s_off", 10, False, "G0"),
|
||||
GateCase("g1_10s_on", 10, True, "G1"),
|
||||
GateCase("g2_20s_on", 20, True, "G2"),
|
||||
GateCase("g3_10s_on_1", 10, True, "G3 ON-1"),
|
||||
GateCase("g3_10s_off", 10, False, "G3 OFF"),
|
||||
GateCase("g3_10s_on_2", 10, True, "G3 ON-2"),
|
||||
)
|
||||
|
||||
|
||||
def _find_nodes(prompt: Mapping[str, Any], class_type: str) -> list[str]:
|
||||
return [
|
||||
str(node_id)
|
||||
for node_id, node in prompt.items()
|
||||
if str(node.get("class_type")) == class_type
|
||||
]
|
||||
|
||||
|
||||
def _one_node(prompt: Mapping[str, Any], class_type: str) -> str:
|
||||
values = _find_nodes(prompt, class_type)
|
||||
if len(values) != 1:
|
||||
raise GateFailure(f"expected one {class_type}, found {len(values)}")
|
||||
return values[0]
|
||||
|
||||
|
||||
def _next_node_id(prompt: Mapping[str, Any]) -> str:
|
||||
return str(max(int(value) for value in prompt if str(value).isdigit()) + 1)
|
||||
|
||||
|
||||
def configure_case(
|
||||
source: Mapping[str, Any],
|
||||
*,
|
||||
case: GateCase,
|
||||
audio_file: str,
|
||||
seed: int,
|
||||
) -> dict[str, Any]:
|
||||
prompt = copy.deepcopy(dict(source))
|
||||
easy_id = _one_node(prompt, "H3ContinuumEasyV38")
|
||||
easy_inputs = prompt[easy_id].setdefault("inputs", {})
|
||||
easy_inputs.update(
|
||||
{
|
||||
"duration": int(case.duration),
|
||||
"seed": int(seed),
|
||||
"seed_mode": "Fixed",
|
||||
"preset": "Draft — 0.30 MP",
|
||||
"custom_mp": 0.30,
|
||||
"run_storage": "Off",
|
||||
}
|
||||
)
|
||||
helper_id = _one_node(prompt, "H3ContinuumEasyReferences")
|
||||
prompt[helper_id].setdefault("inputs", {}).clear()
|
||||
audio_vae_id = None
|
||||
for candidate in _find_nodes(prompt, "VAELoader"):
|
||||
vae_name = str(prompt[candidate].get("inputs", {}).get("vae_name", ""))
|
||||
if "audio" in vae_name.lower():
|
||||
audio_vae_id = candidate
|
||||
break
|
||||
if audio_vae_id is None:
|
||||
raise GateFailure("source prompt has no Audio VAE loader")
|
||||
easy_inputs["audio_vae"] = [audio_vae_id, 0]
|
||||
if case.enabled:
|
||||
loader_id = _next_node_id(prompt)
|
||||
prompt[loader_id] = {
|
||||
"inputs": {"audio": audio_file},
|
||||
"class_type": "H3EasyLoadAudio",
|
||||
"_meta": {"title": "H3 Easy Load Audio"},
|
||||
}
|
||||
easy_inputs["driving_audio"] = [loader_id, 0]
|
||||
save_audio_id = str(int(loader_id) + 1)
|
||||
prompt[save_audio_id] = {
|
||||
"inputs": {
|
||||
"audio": [easy_id, 4],
|
||||
"filename_prefix": f"audio/V38_Easy_Driving/{case.name}",
|
||||
},
|
||||
"class_type": "SaveAudio",
|
||||
"_meta": {"title": "Save Audio (FLAC) (DEPRECATED)"},
|
||||
}
|
||||
else:
|
||||
easy_inputs.pop("driving_audio", None)
|
||||
|
||||
scheduler_id = _one_node(prompt, "BasicScheduler")
|
||||
prompt[scheduler_id].setdefault("inputs", {}).update(
|
||||
{"scheduler": "simple", "steps": 8, "denoise": 1.0}
|
||||
)
|
||||
assembly_id = _one_node(prompt, "H3ContinuumAssembleSeamV35")
|
||||
prompt[assembly_id].setdefault("inputs", {}).update(
|
||||
{
|
||||
"exact_total_duration": True,
|
||||
"audio_seam": "Auto",
|
||||
"video_seam": "Auto",
|
||||
"buffer_backend": "Auto",
|
||||
"diagnostics": "Detailed Report",
|
||||
}
|
||||
)
|
||||
for save_id in _find_nodes(prompt, "SaveVideo"):
|
||||
prompt[save_id].setdefault("inputs", {})["filename_prefix"] = (
|
||||
f"video/V38_Easy_Driving/{case.name}"
|
||||
)
|
||||
_ensure_profile_route(prompt)
|
||||
return configure_profile(prompt, "sage")
|
||||
|
||||
|
||||
def _history_media(
|
||||
history: Mapping[str, Any], output_root: Path, suffix: str
|
||||
) -> Path:
|
||||
for entry in history.values():
|
||||
outputs = entry.get("outputs", {}) if isinstance(entry, Mapping) else {}
|
||||
for output in outputs.values():
|
||||
if not isinstance(output, Mapping):
|
||||
continue
|
||||
for field in ("audio", "videos", "gifs", "images"):
|
||||
for media in output.get(field, []) or []:
|
||||
filename = str(media.get("filename", ""))
|
||||
if Path(filename).suffix.lower() != suffix:
|
||||
continue
|
||||
path = output_root / str(media.get("subfolder") or "") / filename
|
||||
if path.is_file():
|
||||
return path
|
||||
raise GateFailure(f"history returned no existing {suffix} output")
|
||||
|
||||
|
||||
def _ffprobe(path: Path, ffprobe: str) -> dict[str, Any]:
|
||||
result = subprocess.run(
|
||||
[
|
||||
ffprobe,
|
||||
"-v",
|
||||
"error",
|
||||
"-count_frames",
|
||||
"-show_entries",
|
||||
"stream=codec_type,width,height,r_frame_rate,nb_read_frames,sample_rate,channels,duration:format=duration,size",
|
||||
"-of",
|
||||
"json",
|
||||
str(path),
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
return json.loads(result.stdout)
|
||||
|
||||
|
||||
def _media_contract(path: Path, ffprobe: str) -> dict[str, Any]:
|
||||
payload = _ffprobe(path, ffprobe)
|
||||
streams = list(payload.get("streams") or [])
|
||||
video = next((x for x in streams if x.get("codec_type") == "video"), {})
|
||||
audio = next((x for x in streams if x.get("codec_type") == "audio"), {})
|
||||
return {
|
||||
"path": str(path),
|
||||
"sha256": hashlib.sha256(path.read_bytes()).hexdigest(),
|
||||
"size_bytes": int(path.stat().st_size),
|
||||
"width": int(video.get("width", 0)),
|
||||
"height": int(video.get("height", 0)),
|
||||
"frames": int(video.get("nb_read_frames", 0)),
|
||||
"fps": str(video.get("r_frame_rate", "")),
|
||||
"video_duration": float(video.get("duration", 0.0)),
|
||||
"audio_duration": float(audio.get("duration", 0.0)),
|
||||
"format_duration": float(payload.get("format", {}).get("duration", 0.0)),
|
||||
"audio_sample_rate": int(audio.get("sample_rate", 0)),
|
||||
"audio_channels": int(audio.get("channels", 0)),
|
||||
}
|
||||
|
||||
|
||||
def _decode_pcm(path: Path, ffmpeg: str, duration: int | None = None) -> np.ndarray:
|
||||
command = [ffmpeg, "-v", "error", "-i", str(path)]
|
||||
if duration is not None:
|
||||
command += ["-t", str(int(duration))]
|
||||
command += ["-ar", "32000", "-ac", "2", "-f", "f32le", "pipe:1"]
|
||||
result = subprocess.run(command, check=True, capture_output=True)
|
||||
return np.frombuffer(result.stdout, dtype="<f4").reshape(-1, 2).copy()
|
||||
|
||||
|
||||
def _audio_evidence(
|
||||
*,
|
||||
input_path: Path,
|
||||
saved_path: Path,
|
||||
video_path: Path,
|
||||
duration: int,
|
||||
ffmpeg: str,
|
||||
) -> dict[str, Any]:
|
||||
source = _decode_pcm(input_path, ffmpeg, duration)
|
||||
saved = _decode_pcm(saved_path, ffmpeg)
|
||||
final = _decode_pcm(video_path, ffmpeg)
|
||||
count = min(len(source), len(saved))
|
||||
source_bytes = source[:count].astype("<f4", copy=False).tobytes()
|
||||
saved_bytes = saved[:count].astype("<f4", copy=False).tobytes()
|
||||
boundary = int(10 * 32000)
|
||||
boundary_delta = None
|
||||
if duration > 10 and len(final) > boundary:
|
||||
boundary_delta = float(np.max(np.abs(final[boundary] - final[boundary - 1])))
|
||||
diffs = np.abs(np.diff(final, axis=0)) if len(final) > 1 else np.zeros((0, 2))
|
||||
return {
|
||||
"source_frames": int(len(source)),
|
||||
"saved_frames": int(len(saved)),
|
||||
"final_frames": int(len(final)),
|
||||
"source_prefix_pcm_sha256": hashlib.sha256(source_bytes).hexdigest(),
|
||||
"saved_pcm_sha256": hashlib.sha256(saved_bytes).hexdigest(),
|
||||
"saved_pcm_bit_exact": source_bytes == saved_bytes,
|
||||
"finite": bool(np.isfinite(final).all()),
|
||||
"max_abs": float(np.max(np.abs(final))) if final.size else 0.0,
|
||||
"max_adjacent_delta": float(np.max(diffs)) if diffs.size else 0.0,
|
||||
"p999_adjacent_delta": float(np.quantile(diffs, 0.999)) if diffs.size else 0.0,
|
||||
"ten_second_boundary_delta": boundary_delta,
|
||||
}
|
||||
|
||||
|
||||
def _find_backend_pid() -> int | None:
|
||||
try:
|
||||
import psutil
|
||||
except Exception:
|
||||
return None
|
||||
candidates = []
|
||||
for process in psutil.process_iter(["pid", "cmdline", "memory_info"]):
|
||||
try:
|
||||
command = " ".join(process.info.get("cmdline") or [])
|
||||
if "ComfyUI_W" in command and "main.py" in command:
|
||||
candidates.append((int(process.info["memory_info"].rss), process.pid))
|
||||
except Exception:
|
||||
continue
|
||||
return max(candidates)[1] if candidates else None
|
||||
|
||||
|
||||
def run(args) -> dict[str, Any]:
|
||||
source = json.loads(args.source_prompt.read_text(encoding="utf-8"))
|
||||
args.output_root.mkdir(parents=True, exist_ok=True)
|
||||
(args.output_root / "source_prompt.json").write_text(
|
||||
json.dumps(source, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
ffmpeg = shutil.which("ffmpeg")
|
||||
ffprobe = shutil.which("ffprobe")
|
||||
if not args.dry_run and (ffmpeg is None or ffprobe is None):
|
||||
raise GateFailure("ffmpeg and ffprobe are required")
|
||||
backend_pid = _find_backend_pid()
|
||||
results = []
|
||||
for case in CASES:
|
||||
case_root = args.output_root / case.name
|
||||
case_root.mkdir(parents=True, exist_ok=True)
|
||||
prompt = configure_case(
|
||||
source,
|
||||
case=case,
|
||||
audio_file=args.audio_file,
|
||||
seed=args.seed,
|
||||
)
|
||||
prompt_path = case_root / "prompt.json"
|
||||
prompt_path.write_text(
|
||||
json.dumps(prompt, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
record: dict[str, Any] = {
|
||||
"case": asdict(case),
|
||||
"prompt": str(prompt_path),
|
||||
"seed": int(args.seed),
|
||||
}
|
||||
if args.dry_run:
|
||||
record["status"] = "DRY_RUN"
|
||||
results.append(record)
|
||||
continue
|
||||
queue = _json_request(f"{args.server.rstrip('/')}/queue")
|
||||
if queue.get("queue_running") or queue.get("queue_pending"):
|
||||
raise GateFailure("ComfyUI queue is not empty")
|
||||
print(f"START {case.name}", flush=True)
|
||||
started = time.perf_counter()
|
||||
with ResourceMonitor(backend_pid, args.monitor_interval) as monitor:
|
||||
prompt_id, history, elapsed = submit_and_wait(
|
||||
server=args.server,
|
||||
prompt=prompt,
|
||||
client_id=f"v38-easy-driving-{uuid.uuid4().hex}",
|
||||
timeout_seconds=args.timeout_seconds,
|
||||
poll_seconds=args.poll_seconds,
|
||||
)
|
||||
history_path = case_root / "history.json"
|
||||
history_path.write_text(
|
||||
json.dumps(history, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
video_path = _history_media(history, args.media_root, ".mp4")
|
||||
media = _media_contract(video_path, ffprobe)
|
||||
expected_frames = int(case.duration * 24)
|
||||
checks = {
|
||||
"frames": media["frames"] == expected_frames,
|
||||
"fps": media["fps"] == "24/1",
|
||||
"duration": abs(media["format_duration"] - case.duration) <= 0.02,
|
||||
"audio_rate": media["audio_sample_rate"] == 32000,
|
||||
"audio_channels": media["audio_channels"] == 2,
|
||||
}
|
||||
if not all(checks.values()):
|
||||
raise GateFailure(f"media contract failed for {case.name}: {checks}")
|
||||
audio = None
|
||||
if case.enabled:
|
||||
saved_path = _history_media(history, args.media_root, ".flac")
|
||||
audio = _audio_evidence(
|
||||
input_path=args.input_root / args.audio_file,
|
||||
saved_path=saved_path,
|
||||
video_path=video_path,
|
||||
duration=case.duration,
|
||||
ffmpeg=ffmpeg,
|
||||
)
|
||||
if not audio["finite"]:
|
||||
raise GateFailure(f"non-finite final audio in {case.name}")
|
||||
record.update(
|
||||
{
|
||||
"prompt_id": prompt_id,
|
||||
"api_elapsed_seconds": float(elapsed),
|
||||
"wall_elapsed_seconds": float(time.perf_counter() - started),
|
||||
"history": str(history_path),
|
||||
"resources": monitor.as_dict(),
|
||||
"media": media,
|
||||
"audio": audio,
|
||||
"checks": checks,
|
||||
"status": "PASS",
|
||||
}
|
||||
)
|
||||
(case_root / "summary.json").write_text(
|
||||
json.dumps(record, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
results.append(record)
|
||||
print(f"PASS {case.name} elapsed={elapsed:.3f}s", flush=True)
|
||||
summary = {
|
||||
"format": "h3-continuum-v38-easy-driving-audio-gpu-gate-v1",
|
||||
"server": args.server,
|
||||
"source_prompt": str(args.source_prompt),
|
||||
"audio_file": args.audio_file,
|
||||
"seed": int(args.seed),
|
||||
"backend_pid": backend_pid,
|
||||
"dry_run": bool(args.dry_run),
|
||||
"results": results,
|
||||
"status": "DRY_RUN" if args.dry_run else "PASS",
|
||||
}
|
||||
(args.output_root / "gate_summary.json").write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
return summary
|
||||
|
||||
|
||||
def _parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8188")
|
||||
parser.add_argument("--source-prompt", type=Path, required=True)
|
||||
parser.add_argument("--output-root", type=Path, required=True)
|
||||
parser.add_argument("--media-root", type=Path, default=Path(r"D:\output\video\comfy_video"))
|
||||
parser.add_argument("--input-root", type=Path, default=Path(r"D:\StabilityMatrix\Data\Packages\ComfyUI_W\input"))
|
||||
parser.add_argument("--audio-file", required=True)
|
||||
parser.add_argument("--seed", type=int, default=927966463230733)
|
||||
parser.add_argument("--timeout-seconds", type=float, default=3600.0)
|
||||
parser.add_argument("--poll-seconds", type=float, default=2.0)
|
||||
parser.add_argument("--monitor-interval", type=float, default=0.25)
|
||||
parser.add_argument("--dry-run", action="store_true")
|
||||
return parser
|
||||
|
||||
|
||||
def main() -> int:
|
||||
args = _parser().parse_args()
|
||||
print(json.dumps(run(args), ensure_ascii=False))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,581 @@
|
||||
"""Run the V3.8 Easy Mode Phase 3 GPU acceptance matrix.
|
||||
|
||||
The runner starts from one successful ComfyUI history prompt, preserves its
|
||||
installed model/LoRA/VAE stack, and changes only the Easy inputs, image
|
||||
presence, attention route, output prefix, and fixed seed needed by the gate.
|
||||
It writes every submitted API prompt, returned history, resource sample, and
|
||||
media probe under one evidence directory.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
from dataclasses import asdict, dataclass
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from typing import Any, Mapping
|
||||
import uuid
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
from p32_api_runner import _json_request, submit_and_wait
|
||||
from p32_gpu_profile_probe import configure_profile
|
||||
from v36_r1_stress_gate_runner import ResourceMonitor
|
||||
|
||||
|
||||
PROFILES = ("sage", "sage_sol", "sage_spectrum", "sage_sol_spectrum")
|
||||
REFERENCE_PROFILE_CASE = "i2va_reference1_10s"
|
||||
|
||||
|
||||
class GateFailure(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class GateCase:
|
||||
name: str
|
||||
duration: int
|
||||
chunks: int
|
||||
chunk_seconds: float
|
||||
first: bool
|
||||
last: bool
|
||||
reference_slot: int | None
|
||||
prompt: str
|
||||
expected_mode: str
|
||||
expected_width: int
|
||||
expected_height: int
|
||||
|
||||
|
||||
CASES = {
|
||||
REFERENCE_PROFILE_CASE: GateCase(
|
||||
name=REFERENCE_PROFILE_CASE,
|
||||
duration=10,
|
||||
chunks=1,
|
||||
chunk_seconds=10.0,
|
||||
first=True,
|
||||
last=False,
|
||||
reference_slot=1,
|
||||
prompt=(
|
||||
"A continuous cinematic tracking shot begins from the supplied First "
|
||||
"Image. Use <Picture 2> as the identity, face, clothing, and color "
|
||||
"reference. The woman walks naturally toward camera through the city, "
|
||||
"with coherent body motion, stable facial identity, realistic wind, "
|
||||
"footsteps, and urban ambience."
|
||||
),
|
||||
expected_mode="Hybrid I2VA + Reference + Continuation",
|
||||
expected_width=480,
|
||||
expected_height=640,
|
||||
),
|
||||
"fl2va_reference1_15s": GateCase(
|
||||
name="fl2va_reference1_15s",
|
||||
duration=15,
|
||||
chunks=2,
|
||||
chunk_seconds=7.5,
|
||||
first=True,
|
||||
last=True,
|
||||
reference_slot=1,
|
||||
prompt=(
|
||||
"A continuous cinematic shot starts from the supplied First Image and "
|
||||
"converges naturally to the supplied Last Image. Use <Picture 3> as the "
|
||||
"identity, face, clothing, and color reference throughout. The woman "
|
||||
"walks forward, turns smoothly, and reaches the final pose without a "
|
||||
"cut. Preserve stable anatomy, natural motion, footsteps, and ambience."
|
||||
),
|
||||
expected_mode="Hybrid FL2VA + Reference + Continuation",
|
||||
expected_width=480,
|
||||
expected_height=640,
|
||||
),
|
||||
"i2va_reference2_only_20s": GateCase(
|
||||
name="i2va_reference2_only_20s",
|
||||
duration=20,
|
||||
chunks=2,
|
||||
chunk_seconds=10.0,
|
||||
first=True,
|
||||
last=False,
|
||||
reference_slot=2,
|
||||
prompt=(
|
||||
"A single continuous cinematic shot begins from the supplied First "
|
||||
"Image. Use <Picture 2> as the identity, face, clothing, and color "
|
||||
"reference; the second helper socket is the only connected reference "
|
||||
"and must compact to the first active reference. The woman walks, looks "
|
||||
"toward camera, and continues forward with stable identity and ambience."
|
||||
),
|
||||
expected_mode="Hybrid I2VA + Reference + Continuation",
|
||||
expected_width=480,
|
||||
expected_height=640,
|
||||
),
|
||||
"t2va_no_reference_30s": GateCase(
|
||||
name="t2va_no_reference_30s",
|
||||
duration=30,
|
||||
chunks=3,
|
||||
chunk_seconds=10.0,
|
||||
first=False,
|
||||
last=False,
|
||||
reference_slot=None,
|
||||
prompt=(
|
||||
"A single continuous cinematic wide shot follows a woman walking through "
|
||||
"a modern city plaza. She changes direction smoothly while the camera "
|
||||
"tracks beside her, preserving natural anatomy, coherent motion, stable "
|
||||
"lighting, footsteps, wind, and distant urban ambience."
|
||||
),
|
||||
expected_mode="T2VA + Continuation",
|
||||
expected_width=736,
|
||||
expected_height=416,
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
SPECTRUM_DEFAULTS = {
|
||||
"enabled": False,
|
||||
"blend_weight": 0.5,
|
||||
"degree": 1,
|
||||
"ridge_lambda": 0.1,
|
||||
"window_size": 2.0,
|
||||
"flex_window": 0.75,
|
||||
"warmup_steps": 1,
|
||||
"tail_actual_steps": 1,
|
||||
"max_history": 8,
|
||||
"debug": False,
|
||||
"history_storage": "system_ram",
|
||||
"bootstrap_first_forecast": True,
|
||||
"anchor_residual_feedback": False,
|
||||
"selective_rollback_correction": False,
|
||||
"offline_smoothing_replay": True,
|
||||
"audio_blend_weight": 0.0,
|
||||
"offline_archive_storage": "system_ram",
|
||||
"model_aware_mode": "off",
|
||||
"model_aware_risk_threshold": 0.65,
|
||||
"model_aware_trust_shrinkage": False,
|
||||
"model_aware_replay_generic_correction": False,
|
||||
"generic_correction_mode": "coordinate_rls",
|
||||
"generic_correction_limiter": "hard_clip",
|
||||
"generic_correction_limit": 0.4,
|
||||
"generic_correction_attenuation": "no_attenuation",
|
||||
}
|
||||
|
||||
|
||||
def _find_nodes(prompt: Mapping[str, Any], class_type: str) -> list[str]:
|
||||
return [
|
||||
str(node_id)
|
||||
for node_id, node in prompt.items()
|
||||
if str(node.get("class_type")) == class_type
|
||||
]
|
||||
|
||||
|
||||
def _one_node(prompt: Mapping[str, Any], class_type: str) -> str:
|
||||
values = _find_nodes(prompt, class_type)
|
||||
if len(values) != 1:
|
||||
raise GateFailure(f"expected one {class_type}, found {len(values)}")
|
||||
return values[0]
|
||||
|
||||
|
||||
def _next_node_id(prompt: Mapping[str, Any]) -> str:
|
||||
numeric = [int(value) for value in prompt if str(value).isdigit()]
|
||||
return str((max(numeric) if numeric else 0) + 1)
|
||||
|
||||
|
||||
def _history_prompt(server: str, prompt_id: str) -> tuple[dict[str, Any], Any]:
|
||||
history = _json_request(f"{server.rstrip('/')}/history/{prompt_id}")
|
||||
entry = history.get(str(prompt_id))
|
||||
if not isinstance(entry, Mapping):
|
||||
raise GateFailure(f"history does not contain prompt {prompt_id}")
|
||||
raw = entry.get("prompt")
|
||||
if not isinstance(raw, list) or len(raw) < 3 or not isinstance(raw[2], Mapping):
|
||||
raise GateFailure("history entry has no API prompt")
|
||||
return copy.deepcopy(dict(raw[2])), history
|
||||
|
||||
|
||||
def _ensure_load_image(
|
||||
prompt: dict[str, Any], *, image: str, title: str
|
||||
) -> list[Any]:
|
||||
for node_id in _find_nodes(prompt, "LoadImage"):
|
||||
if prompt[node_id].get("inputs", {}).get("image") == image:
|
||||
return [node_id, 0]
|
||||
node_id = _next_node_id(prompt)
|
||||
prompt[node_id] = {
|
||||
"class_type": "LoadImage",
|
||||
"inputs": {"image": str(image)},
|
||||
"_meta": {"title": str(title)},
|
||||
}
|
||||
return [node_id, 0]
|
||||
|
||||
|
||||
def _ensure_profile_route(prompt: dict[str, Any]) -> None:
|
||||
easy_id = _one_node(prompt, "H3ContinuumEasyV38")
|
||||
easy_inputs = prompt[easy_id].setdefault("inputs", {})
|
||||
upstream = easy_inputs.get("model")
|
||||
if not isinstance(upstream, list) or len(upstream) != 2:
|
||||
raise GateFailure("Easy node has no MODEL link")
|
||||
spectrum_nodes = _find_nodes(prompt, "SpectrumApplyMiniMaxH3")
|
||||
if len(spectrum_nodes) > 1:
|
||||
raise GateFailure("multiple Spectrum nodes are not supported by this gate")
|
||||
if spectrum_nodes:
|
||||
spectrum_id = spectrum_nodes[0]
|
||||
spectrum_inputs = prompt[spectrum_id].setdefault("inputs", {})
|
||||
if easy_inputs.get("model") != [spectrum_id, 0]:
|
||||
spectrum_inputs["model"] = list(upstream)
|
||||
easy_inputs["model"] = [spectrum_id, 0]
|
||||
return
|
||||
spectrum_id = _next_node_id(prompt)
|
||||
prompt[spectrum_id] = {
|
||||
"class_type": "SpectrumApplyMiniMaxH3",
|
||||
"inputs": {**SPECTRUM_DEFAULTS, "model": list(upstream)},
|
||||
"_meta": {"title": "Spectrum"},
|
||||
}
|
||||
easy_inputs["model"] = [spectrum_id, 0]
|
||||
|
||||
|
||||
def configure_case(
|
||||
source: Mapping[str, Any],
|
||||
*,
|
||||
case: GateCase,
|
||||
profile: str,
|
||||
seed: int,
|
||||
output_prefix: str,
|
||||
reference_image_1: str,
|
||||
reference_image_2: str,
|
||||
last_image: str,
|
||||
) -> dict[str, Any]:
|
||||
prompt = copy.deepcopy(dict(source))
|
||||
easy_id = _one_node(prompt, "H3ContinuumEasyV38")
|
||||
helper_id = _one_node(prompt, "H3ContinuumEasyReferences")
|
||||
easy_inputs = prompt[easy_id].setdefault("inputs", {})
|
||||
first_link = easy_inputs.get("first_frame")
|
||||
if case.first and not isinstance(first_link, list):
|
||||
raise GateFailure("source prompt has no First Image link")
|
||||
|
||||
if case.first:
|
||||
easy_inputs["first_frame"] = list(first_link)
|
||||
easy_inputs["aspect"] = "Auto from First Image"
|
||||
else:
|
||||
easy_inputs.pop("first_frame", None)
|
||||
easy_inputs["aspect"] = "Landscape 16:9"
|
||||
if case.last:
|
||||
easy_inputs["last_frame"] = _ensure_load_image(
|
||||
prompt, image=last_image, title="Last Image"
|
||||
)
|
||||
else:
|
||||
easy_inputs.pop("last_frame", None)
|
||||
|
||||
helper_inputs = prompt[helper_id].setdefault("inputs", {})
|
||||
helper_inputs.clear()
|
||||
if case.reference_slot is not None:
|
||||
reference_file = (
|
||||
reference_image_1 if case.reference_slot == 1 else reference_image_2
|
||||
)
|
||||
helper_inputs[f"reference_image_{case.reference_slot}"] = _ensure_load_image(
|
||||
prompt,
|
||||
image=reference_file,
|
||||
title=f"Reference Image {case.reference_slot}",
|
||||
)
|
||||
|
||||
easy_inputs.update(
|
||||
{
|
||||
"duration": int(case.duration),
|
||||
"seed": int(seed),
|
||||
"seed_mode": "Fixed",
|
||||
"preset": "Draft — 0.30 MP",
|
||||
"custom_mp": 0.30,
|
||||
"run_storage": "Off",
|
||||
}
|
||||
)
|
||||
prompt_link = easy_inputs.get("prompt_text")
|
||||
if not isinstance(prompt_link, list) or len(prompt_link) != 2:
|
||||
raise GateFailure("Easy node has no Prompt link")
|
||||
prompt_node = str(prompt_link[0])
|
||||
prompt[prompt_node].setdefault("inputs", {})["value"] = case.prompt
|
||||
|
||||
scheduler_id = _one_node(prompt, "BasicScheduler")
|
||||
prompt[scheduler_id].setdefault("inputs", {}).update(
|
||||
{"scheduler": "simple", "steps": 8, "denoise": 1.0}
|
||||
)
|
||||
assembly_id = _one_node(prompt, "H3ContinuumAssembleSeamV35")
|
||||
prompt[assembly_id].setdefault("inputs", {}).update(
|
||||
{
|
||||
"exact_total_duration": True,
|
||||
"audio_seam": "Auto",
|
||||
"video_seam": "Auto",
|
||||
"buffer_backend": "Auto",
|
||||
"diagnostics": "Detailed Report",
|
||||
}
|
||||
)
|
||||
for save_id in _find_nodes(prompt, "SaveVideo"):
|
||||
prompt[save_id].setdefault("inputs", {})["filename_prefix"] = str(
|
||||
output_prefix
|
||||
)
|
||||
|
||||
_ensure_profile_route(prompt)
|
||||
return configure_profile(prompt, profile)
|
||||
|
||||
|
||||
def _walk_strings(value: Any):
|
||||
if isinstance(value, str):
|
||||
yield value
|
||||
elif isinstance(value, Mapping):
|
||||
for item in value.values():
|
||||
yield from _walk_strings(item)
|
||||
elif isinstance(value, (list, tuple)):
|
||||
for item in value:
|
||||
yield from _walk_strings(item)
|
||||
|
||||
|
||||
def _output_media(history: Mapping[str, Any], output_root: Path) -> Path:
|
||||
for value in history.values():
|
||||
if not isinstance(value, Mapping):
|
||||
continue
|
||||
outputs = value.get("outputs")
|
||||
if not isinstance(outputs, Mapping):
|
||||
continue
|
||||
for output in outputs.values():
|
||||
if not isinstance(output, Mapping):
|
||||
continue
|
||||
for field in ("images", "videos", "gifs"):
|
||||
for media in output.get(field, []) or []:
|
||||
if not isinstance(media, Mapping):
|
||||
continue
|
||||
filename = media.get("filename")
|
||||
if not filename or Path(str(filename)).suffix.lower() != ".mp4":
|
||||
continue
|
||||
path = output_root / str(media.get("subfolder") or "") / str(
|
||||
filename
|
||||
)
|
||||
if path.is_file():
|
||||
return path
|
||||
raise GateFailure("history returned no existing MP4 output")
|
||||
|
||||
|
||||
def _probe_media(path: Path, ffprobe: str) -> dict[str, Any]:
|
||||
result = subprocess.run(
|
||||
[
|
||||
ffprobe,
|
||||
"-v",
|
||||
"error",
|
||||
"-count_frames",
|
||||
"-show_entries",
|
||||
"stream=codec_type,width,height,r_frame_rate,nb_read_frames,sample_rate,channels,duration:format=duration,size",
|
||||
"-of",
|
||||
"json",
|
||||
str(path),
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
payload = json.loads(result.stdout)
|
||||
streams = list(payload.get("streams") or [])
|
||||
video = next((item for item in streams if item.get("codec_type") == "video"), None)
|
||||
audio = next((item for item in streams if item.get("codec_type") == "audio"), None)
|
||||
if not isinstance(video, Mapping) or not isinstance(audio, Mapping):
|
||||
raise GateFailure("output lacks video or audio stream")
|
||||
digest = hashlib.sha256()
|
||||
with path.open("rb") as stream:
|
||||
for block in iter(lambda: stream.read(1024 * 1024), b""):
|
||||
digest.update(block)
|
||||
return {
|
||||
"path": str(path),
|
||||
"sha256": digest.hexdigest(),
|
||||
"size_bytes": int(path.stat().st_size),
|
||||
"width": int(video.get("width", 0)),
|
||||
"height": int(video.get("height", 0)),
|
||||
"frames": int(video.get("nb_read_frames", 0)),
|
||||
"fps": str(video.get("r_frame_rate", "")),
|
||||
"video_duration": float(video.get("duration", 0.0)),
|
||||
"audio_duration": float(audio.get("duration", 0.0)),
|
||||
"format_duration": float(payload.get("format", {}).get("duration", 0.0)),
|
||||
"audio_sample_rate": int(audio.get("sample_rate", 0)),
|
||||
"audio_channels": int(audio.get("channels", 0)),
|
||||
}
|
||||
|
||||
|
||||
def _validate_result(
|
||||
history: Mapping[str, Any], *, case: GateCase, media: Mapping[str, Any]
|
||||
) -> dict[str, Any]:
|
||||
text = "\n".join(_walk_strings(history))
|
||||
required = [
|
||||
case.expected_mode,
|
||||
f"/ {case.duration} sec",
|
||||
f"{case.chunks} chunks",
|
||||
f"{case.chunk_seconds:.3f}s per chunk",
|
||||
f"{case.expected_width} x {case.expected_height}",
|
||||
]
|
||||
if case.reference_slot is not None:
|
||||
required.append("Reference conditioning: 1 image(s), size=Match Output")
|
||||
missing = [value for value in required if value not in text]
|
||||
if missing:
|
||||
raise GateFailure(f"status evidence is missing: {missing}")
|
||||
if "H3C-P103 Warning" in text or "H3C-P102 Warning" in text:
|
||||
raise GateFailure("Picture numbering produced a reference prompt warning")
|
||||
expected_frames = int(case.duration * 24)
|
||||
media_checks = {
|
||||
"geometry": (media["width"], media["height"])
|
||||
== (case.expected_width, case.expected_height),
|
||||
"frames": int(media["frames"]) == expected_frames,
|
||||
"fps": str(media["fps"]) == "24/1",
|
||||
"duration": abs(float(media["format_duration"]) - case.duration) <= 0.02,
|
||||
"audio_rate": int(media["audio_sample_rate"]) == 32000,
|
||||
"audio_channels": int(media["audio_channels"]) == 2,
|
||||
}
|
||||
if not all(media_checks.values()):
|
||||
raise GateFailure(f"media contract failed: {media_checks}")
|
||||
return {"required_status": required, "media_checks": media_checks}
|
||||
|
||||
|
||||
def _find_backend_pid() -> int | None:
|
||||
try:
|
||||
import psutil
|
||||
except Exception:
|
||||
return None
|
||||
candidates = []
|
||||
for process in psutil.process_iter(["pid", "cmdline", "memory_info"]):
|
||||
try:
|
||||
command = " ".join(process.info.get("cmdline") or [])
|
||||
if "ComfyUI_W" in command and "main.py" in command:
|
||||
rss = int(process.info["memory_info"].rss)
|
||||
candidates.append((rss, int(process.info["pid"])))
|
||||
except Exception:
|
||||
continue
|
||||
return max(candidates)[1] if candidates else None
|
||||
|
||||
|
||||
def run(args) -> dict[str, Any]:
|
||||
source, source_history = _history_prompt(args.server, args.history_prompt_id)
|
||||
args.output_root.mkdir(parents=True, exist_ok=True)
|
||||
(args.output_root / "source_history.json").write_text(
|
||||
json.dumps(source_history, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
(args.output_root / "source_prompt.json").write_text(
|
||||
json.dumps(source, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
ffprobe = shutil.which("ffprobe")
|
||||
if not args.dry_run and ffprobe is None:
|
||||
raise GateFailure("ffprobe is required for GPU acceptance")
|
||||
backend_pid = _find_backend_pid()
|
||||
matrix = [
|
||||
(CASES[REFERENCE_PROFILE_CASE], profile) for profile in PROFILES
|
||||
] + [
|
||||
(CASES["fl2va_reference1_15s"], "sage"),
|
||||
(CASES["i2va_reference2_only_20s"], "sage"),
|
||||
(CASES["t2va_no_reference_30s"], "sage"),
|
||||
]
|
||||
results = []
|
||||
for case, profile in matrix:
|
||||
label = f"{case.name}__{profile}"
|
||||
run_root = args.output_root / label
|
||||
run_root.mkdir(parents=True, exist_ok=True)
|
||||
prompt = configure_case(
|
||||
source,
|
||||
case=case,
|
||||
profile=profile,
|
||||
seed=args.seed,
|
||||
output_prefix=f"video/V38_Easy_Phase3/{label}",
|
||||
reference_image_1=args.reference_image_1,
|
||||
reference_image_2=args.reference_image_2,
|
||||
last_image=args.last_image,
|
||||
)
|
||||
prompt_path = run_root / "prompt.json"
|
||||
prompt_path.write_text(
|
||||
json.dumps(prompt, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
record: dict[str, Any] = {
|
||||
"label": label,
|
||||
"case": asdict(case),
|
||||
"profile": profile,
|
||||
"seed": int(args.seed),
|
||||
"prompt": str(prompt_path),
|
||||
}
|
||||
if args.dry_run:
|
||||
record["dry_run"] = True
|
||||
results.append(record)
|
||||
continue
|
||||
queue = _json_request(f"{args.server.rstrip('/')}/queue")
|
||||
if queue.get("queue_running") or queue.get("queue_pending"):
|
||||
raise GateFailure("ComfyUI queue is not empty")
|
||||
print(f"START {label}", flush=True)
|
||||
started = time.perf_counter()
|
||||
with ResourceMonitor(backend_pid, args.monitor_interval) as monitor:
|
||||
prompt_id, history, elapsed = submit_and_wait(
|
||||
server=args.server,
|
||||
prompt=prompt,
|
||||
client_id=f"v38-easy-phase3-{uuid.uuid4().hex}",
|
||||
timeout_seconds=args.timeout_seconds,
|
||||
poll_seconds=args.poll_seconds,
|
||||
)
|
||||
history_path = run_root / "history.json"
|
||||
history_path.write_text(
|
||||
json.dumps(history, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
media = _probe_media(_output_media(history, args.media_root), ffprobe)
|
||||
validation = _validate_result(history, case=case, media=media)
|
||||
record.update(
|
||||
{
|
||||
"prompt_id": prompt_id,
|
||||
"api_elapsed_seconds": float(elapsed),
|
||||
"wall_elapsed_seconds": float(time.perf_counter() - started),
|
||||
"history": str(history_path),
|
||||
"resources": monitor.as_dict(),
|
||||
"media": media,
|
||||
"validation": validation,
|
||||
"status": "PASS",
|
||||
}
|
||||
)
|
||||
(run_root / "summary.json").write_text(
|
||||
json.dumps(record, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
results.append(record)
|
||||
print(f"PASS {label} elapsed={elapsed:.3f}s", flush=True)
|
||||
summary = {
|
||||
"format": "h3-continuum-v38-easy-phase3-gpu-gate-v1",
|
||||
"source_history_prompt_id": args.history_prompt_id,
|
||||
"server": args.server,
|
||||
"media_root": str(args.media_root),
|
||||
"seed": int(args.seed),
|
||||
"backend_pid": backend_pid,
|
||||
"dry_run": bool(args.dry_run),
|
||||
"results": results,
|
||||
"status": "DRY_RUN" if args.dry_run else "PASS",
|
||||
}
|
||||
(args.output_root / "gate_summary.json").write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
return summary
|
||||
|
||||
|
||||
def _parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8188")
|
||||
parser.add_argument("--history-prompt-id", required=True)
|
||||
parser.add_argument("--output-root", type=Path, required=True)
|
||||
parser.add_argument(
|
||||
"--media-root",
|
||||
type=Path,
|
||||
default=Path(r"D:\output\video\comfy_video"),
|
||||
)
|
||||
parser.add_argument("--seed", type=int, default=927966463230733)
|
||||
parser.add_argument("--reference-image-1", required=True)
|
||||
parser.add_argument("--reference-image-2", required=True)
|
||||
parser.add_argument("--last-image", required=True)
|
||||
parser.add_argument("--timeout-seconds", type=float, default=3600.0)
|
||||
parser.add_argument("--poll-seconds", type=float, default=2.0)
|
||||
parser.add_argument("--monitor-interval", type=float, default=1.0)
|
||||
parser.add_argument("--dry-run", action="store_true")
|
||||
return parser
|
||||
|
||||
|
||||
def main() -> int:
|
||||
args = _parser().parse_args()
|
||||
summary = run(args)
|
||||
print(json.dumps({"status": summary["status"]}, ensure_ascii=False))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,345 @@
|
||||
"""G4 FL2VA conditioning determinism Gate (evidence-only, no Sampling)."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from typing import Any, Mapping
|
||||
import uuid
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
from p32_api_runner import submit_and_wait
|
||||
|
||||
|
||||
CHECKPOINTS = ("P0", "P1", "P2", "P3", "P4", "P5", "P6", "P7")
|
||||
FIRST_IMAGE = "20260830030614-Anima-Luc_v2_00008_-1635935150-ER SDE.webp"
|
||||
VIDEO_VAE = "minimax_h3_video_vae_fp16.safetensors"
|
||||
CLIP = "qwen3vl_32b_minimax_h3_nvfp4_awq.safetensors"
|
||||
PROMPT = (
|
||||
"A continuous cinematic shot begins from the supplied First Image. "
|
||||
"The subject moves naturally while identity, clothing, lighting, camera "
|
||||
"direction, footsteps, and ambience remain coherent."
|
||||
)
|
||||
|
||||
|
||||
class GateFailure(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
def _write(path: Path, value: Any) -> None:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(json.dumps(value, indent=2, ensure_ascii=False), encoding="utf-8")
|
||||
|
||||
|
||||
def _sha256_file(path: Path) -> str:
|
||||
digest = hashlib.sha256()
|
||||
with path.open("rb") as stream:
|
||||
for block in iter(lambda: stream.read(1024 * 1024), b""):
|
||||
digest.update(block)
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def _prompt(*, context: str, focus_mode: str, nonce: int) -> dict[str, Any]:
|
||||
return {
|
||||
"1": {
|
||||
"class_type": "LoadImage",
|
||||
"inputs": {"image": FIRST_IMAGE},
|
||||
"_meta": {"title": "LoadImage"},
|
||||
},
|
||||
"2": {
|
||||
"class_type": "VAELoader",
|
||||
"inputs": {"vae_name": VIDEO_VAE},
|
||||
"_meta": {"title": "Video VAE"},
|
||||
},
|
||||
"3": {
|
||||
"class_type": "CLIPLoader",
|
||||
"inputs": {"clip_name": CLIP, "type": "minimax", "device": "default"},
|
||||
"_meta": {"title": "MiniMax H3 Text Encoder"},
|
||||
},
|
||||
"4": {
|
||||
"class_type": "H3G4ConditioningDeterminismDiagnostic",
|
||||
"inputs": {
|
||||
"video_vae": ["2", 0],
|
||||
"clip": ["3", 0],
|
||||
"first_image": ["1", 0],
|
||||
"prompt": PROMPT,
|
||||
"width": 544,
|
||||
"height": 544,
|
||||
"frame_count": 124,
|
||||
"execution_context": context,
|
||||
"focus_mode": focus_mode,
|
||||
"diagnostic_nonce": int(nonce),
|
||||
},
|
||||
"_meta": {"title": "G4 Conditioning Determinism Collector"},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def _extract(history: Mapping[str, Any], prompt_id: str) -> dict[str, Any]:
|
||||
record = history.get(prompt_id)
|
||||
if not isinstance(record, Mapping):
|
||||
raise GateFailure(f"history record missing for {prompt_id}")
|
||||
outputs = record.get("outputs")
|
||||
if not isinstance(outputs, Mapping):
|
||||
raise GateFailure("history outputs are missing")
|
||||
node = outputs.get("4")
|
||||
if not isinstance(node, Mapping):
|
||||
raise GateFailure("diagnostic node output is missing")
|
||||
text = node.get("text")
|
||||
if not isinstance(text, list) or len(text) != 1:
|
||||
raise GateFailure(f"unexpected diagnostic text output: {text!r}")
|
||||
result = json.loads(str(text[0]))
|
||||
if result.get("format") != "h3-v38-g4-conditioning-determinism-v1":
|
||||
raise GateFailure("unexpected diagnostic output format")
|
||||
missing = [key for key in CHECKPOINTS if key not in result.get("checkpoints", {})]
|
||||
if missing:
|
||||
raise GateFailure(f"missing checkpoints: {missing}")
|
||||
return result
|
||||
|
||||
|
||||
def _run_case(args, *, name: str, context: str, focus_mode: str, nonce: int) -> dict[str, Any]:
|
||||
case_root = args.evidence_root / args.stage / name
|
||||
prompt = _prompt(context=context, focus_mode=focus_mode, nonce=nonce)
|
||||
_write(case_root / "prompt.json", prompt)
|
||||
print(f"G4 diagnostic start: {name}", flush=True)
|
||||
prompt_id, history, elapsed = submit_and_wait(
|
||||
server=args.server,
|
||||
prompt=prompt,
|
||||
client_id=f"g4diag-{uuid.uuid4().hex}",
|
||||
timeout_seconds=float(args.timeout_seconds),
|
||||
poll_seconds=float(args.poll_seconds),
|
||||
)
|
||||
_write(case_root / "history.json", history)
|
||||
result = _extract(history, prompt_id)
|
||||
_write(case_root / "result.json", result)
|
||||
output = {
|
||||
"name": name,
|
||||
"prompt_id": prompt_id,
|
||||
"api_elapsed_seconds": elapsed,
|
||||
"prompt": str(case_root / "prompt.json"),
|
||||
"history": str(case_root / "history.json"),
|
||||
"result_path": str(case_root / "result.json"),
|
||||
"result": result,
|
||||
}
|
||||
print(f"G4 diagnostic end: {name}; {elapsed:.3f}s", flush=True)
|
||||
return output
|
||||
|
||||
|
||||
def _checkpoint_sha(run: Mapping[str, Any], checkpoint: str) -> str:
|
||||
return str(run["result"]["checkpoints"][checkpoint]["sha256"])
|
||||
|
||||
|
||||
def _compare(left: Mapping[str, Any], right: Mapping[str, Any]) -> dict[str, Any]:
|
||||
rows = {}
|
||||
first = None
|
||||
for checkpoint in CHECKPOINTS:
|
||||
left_sha = _checkpoint_sha(left, checkpoint)
|
||||
right_sha = _checkpoint_sha(right, checkpoint)
|
||||
match = left_sha == right_sha
|
||||
rows[checkpoint] = {
|
||||
"left_sha256": left_sha,
|
||||
"right_sha256": right_sha,
|
||||
"match": match,
|
||||
}
|
||||
if first is None and not match:
|
||||
first = checkpoint
|
||||
return {"first_divergence": first, "checkpoints": rows, "all_match": first is None}
|
||||
|
||||
|
||||
def _focus_mode(*firsts: str | None) -> str:
|
||||
if "P2" in firsts:
|
||||
return "vae_repeat"
|
||||
if "P5" in firsts:
|
||||
return "qwen_repeat"
|
||||
return "standard"
|
||||
|
||||
|
||||
def _focus_checks(run: Mapping[str, Any]) -> dict[str, Any]:
|
||||
result = run["result"]
|
||||
mode = str(result["focus_mode"])
|
||||
if mode == "vae_repeat":
|
||||
rows = result["focus"]["vae_repeat"]
|
||||
hashes = [str(row["sha256"]) for row in rows]
|
||||
return {"mode": mode, "hashes": hashes, "all_match": len(set(hashes)) == 1}
|
||||
if mode == "qwen_repeat":
|
||||
rows = result["focus"]["qwen_repeat"]
|
||||
token_hashes = [str(row["tokens"]["sha256"]) for row in rows]
|
||||
cond_hashes = [str(row["conditioning"]["sha256"]) for row in rows]
|
||||
return {
|
||||
"mode": mode,
|
||||
"token_hashes": token_hashes,
|
||||
"conditioning_hashes": cond_hashes,
|
||||
"tokens_all_match": len(set(token_hashes)) == 1,
|
||||
"conditioning_all_match": len(set(cond_hashes)) == 1,
|
||||
}
|
||||
return {"mode": "standard"}
|
||||
|
||||
|
||||
def _prepare(args) -> dict[str, Any]:
|
||||
cold = _run_case(args, name="cold_a", context="Cold A", focus_mode="standard", nonce=1)
|
||||
warm = _run_case(args, name="warm_b", context="Warm B", focus_mode="standard", nonce=2)
|
||||
full = _run_case(args, name="full_context", context="Full", focus_mode="standard", nonce=3)
|
||||
review = _run_case(args, name="review_context", context="Review", focus_mode="standard", nonce=4)
|
||||
cold_warm = _compare(cold, warm)
|
||||
full_review = _compare(full, review)
|
||||
mode = _focus_mode(cold_warm["first_divergence"], full_review["first_divergence"])
|
||||
focus = None
|
||||
focus_checks = None
|
||||
if mode != "standard":
|
||||
focus = _run_case(args, name=mode, context="Warm B", focus_mode=mode, nonce=5)
|
||||
focus_checks = _focus_checks(focus)
|
||||
summary = {
|
||||
"format": "h3-v38-g4-conditioning-determinism-prepare-v1",
|
||||
"stage": "prepare",
|
||||
"server": args.server,
|
||||
"runner_sha256": _sha256_file(Path(__file__)),
|
||||
"runs": {"cold_a": cold, "warm_b": warm, "full": full, "review": review, "focus": focus},
|
||||
"comparisons": {"cold_vs_warm": cold_warm, "full_vs_review": full_review},
|
||||
"focus_mode": mode,
|
||||
"focus_checks": focus_checks,
|
||||
}
|
||||
_write(args.evidence_root / "prepare_summary.json", summary)
|
||||
return summary
|
||||
|
||||
|
||||
def _classify(prepare: Mapping[str, Any], restart_compare: Mapping[str, Any]) -> dict[str, Any]:
|
||||
cold_first = prepare["comparisons"]["cold_vs_warm"]["first_divergence"]
|
||||
context_first = prepare["comparisons"]["full_vs_review"]["first_divergence"]
|
||||
restart_first = restart_compare["first_divergence"]
|
||||
first = context_first or cold_first or restart_first
|
||||
standalone_first = cold_first or restart_first
|
||||
if standalone_first is None and context_first is not None:
|
||||
case = "CASE F"
|
||||
reason = "standalone repeats match; Full/Review context is the only divergence"
|
||||
elif first in ("P0", "P1"):
|
||||
case = "CASE A"
|
||||
reason = "resize/input path is the first divergence"
|
||||
elif first == "P2":
|
||||
case = "CASE B"
|
||||
reason = "Video VAE identity latent is the first divergence"
|
||||
elif first in ("P3", "P4", "P5", "P6"):
|
||||
case = "CASE C"
|
||||
reason = "Qwen/CLIP image-conditioning path is the first divergence"
|
||||
elif first == "P7":
|
||||
case = "CASE D"
|
||||
reason = "conditioning assembly/keyframe attachment is the first divergence"
|
||||
else:
|
||||
case = "CASE E"
|
||||
reason = "P0-P7 are bit-exact; the G4 hypothesis must move to Sampling or later runtime ordering"
|
||||
return {"case": case, "first_divergence": first, "reason": reason}
|
||||
|
||||
|
||||
def _short(value: str) -> str:
|
||||
return value[:12]
|
||||
|
||||
|
||||
def _report_markdown(summary: Mapping[str, Any]) -> str:
|
||||
prepare = summary["prepare"]
|
||||
restart = summary["restart_c"]
|
||||
full = prepare["runs"]["full"]
|
||||
review = prepare["runs"]["review"]
|
||||
repeat_cmp = prepare["comparisons"]["cold_vs_warm"]
|
||||
context_cmp = prepare["comparisons"]["full_vs_review"]
|
||||
restart_cmp = summary["comparisons"]["cold_vs_restart"]
|
||||
lines = [
|
||||
"# G4-Diagnostic FL2VA Conditioning Determinism — STOP Report",
|
||||
"",
|
||||
f"Classification: **{summary['classification']['case']}** ",
|
||||
f"First divergence: **{summary['classification']['first_divergence'] or 'none through P7'}** ",
|
||||
f"Result: {summary['classification']['reason']}",
|
||||
"",
|
||||
"Production code was not changed. GPU Sampling was not executed.",
|
||||
"",
|
||||
"| Checkpoint | Full | Review | Full/Review | Repeat | Restart |",
|
||||
"|---|---:|---:|---|---|---|",
|
||||
]
|
||||
for checkpoint in CHECKPOINTS:
|
||||
full_sha = _checkpoint_sha(full, checkpoint)
|
||||
review_sha = _checkpoint_sha(review, checkpoint)
|
||||
lines.append(
|
||||
f"| {checkpoint} | `{_short(full_sha)}` | `{_short(review_sha)}` | "
|
||||
f"{'PASS' if context_cmp['checkpoints'][checkpoint]['match'] else 'FAIL'} | "
|
||||
f"{'PASS' if repeat_cmp['checkpoints'][checkpoint]['match'] else 'FAIL'} | "
|
||||
f"{'PASS' if restart_cmp['checkpoints'][checkpoint]['match'] else 'FAIL'} |"
|
||||
)
|
||||
lines.extend(
|
||||
[
|
||||
"",
|
||||
"## Focused repeat",
|
||||
"",
|
||||
"```json",
|
||||
json.dumps(prepare.get("focus_checks"), indent=2, ensure_ascii=False),
|
||||
"```",
|
||||
"",
|
||||
"## Runtime state",
|
||||
"",
|
||||
"Cold, warm, Full-context, Review-context, and restart state snapshots are retained in the JSON evidence. Patch UUID creation differences across restart are recorded but are not treated as tensor divergence by themselves.",
|
||||
"",
|
||||
"## Next action",
|
||||
"",
|
||||
"STOP. Present the first divergence, impact, and a minimal branch-specific fix proposal for approval. Do not add caches, deterministic-mode forcing, model reloads, dtype/seed changes, or Run Storage contract changes in this Gate.",
|
||||
"",
|
||||
]
|
||||
)
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def _restart(args) -> dict[str, Any]:
|
||||
prepare_path = args.evidence_root / "prepare_summary.json"
|
||||
if not prepare_path.is_file():
|
||||
raise GateFailure(f"prepare summary missing: {prepare_path}")
|
||||
prepare = json.loads(prepare_path.read_text(encoding="utf-8"))
|
||||
restart = _run_case(args, name="restart_c", context="Restart C", focus_mode="standard", nonce=101)
|
||||
cold_restart = _compare(prepare["runs"]["cold_a"], restart)
|
||||
classification = _classify(prepare, cold_restart)
|
||||
summary = {
|
||||
"format": "h3-v38-g4-conditioning-determinism-final-v1",
|
||||
"stage": "stopped",
|
||||
"prepare": prepare,
|
||||
"restart_c": restart,
|
||||
"comparisons": {"cold_vs_restart": cold_restart},
|
||||
"classification": classification,
|
||||
}
|
||||
_write(args.evidence_root / "g4_conditioning_determinism_summary.json", summary)
|
||||
report = _report_markdown(summary)
|
||||
(args.evidence_root / "G4_CONDITIONING_DETERMINISM_STOP_REPORT.md").write_text(
|
||||
report,
|
||||
encoding="utf-8",
|
||||
)
|
||||
return summary
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--stage", choices=("prepare", "restart"), required=True)
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8190")
|
||||
parser.add_argument(
|
||||
"--evidence-root",
|
||||
type=Path,
|
||||
default=Path(
|
||||
r"D:\Codex\_test_results\ComfyUI-H3-Continuum"
|
||||
r"\v38-g4-conditioning-determinism-20260831_150837"
|
||||
),
|
||||
)
|
||||
parser.add_argument("--timeout-seconds", type=float, default=1800.0)
|
||||
parser.add_argument("--poll-seconds", type=float, default=1.0)
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main() -> int:
|
||||
args = parse_args()
|
||||
args.evidence_root.mkdir(parents=True, exist_ok=True)
|
||||
summary = _prepare(args) if args.stage == "prepare" else _restart(args)
|
||||
print(json.dumps(summary.get("classification", {"stage": args.stage}), ensure_ascii=False), flush=True)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,719 @@
|
||||
"""Run and compare the G4 Sampling determinism Order Matrix."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
from typing import Any, Mapping
|
||||
import uuid
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
from p32_api_runner import submit_and_wait
|
||||
from v36_r1_stress_gate_runner import ResourceMonitor
|
||||
|
||||
|
||||
SAMPLING_CHECKPOINTS = ("S0", "S1", "S2", "S3", "S4", "S5", "S6", "S7", "S8")
|
||||
MODEL_CHECKPOINTS = ("M0", "M1", "M2", "M3")
|
||||
ORIGINAL_G4 = {
|
||||
"full": {
|
||||
"video": "d6da9472755a991898378543356a1e57960e8aece0803bd9918c20422cb66805",
|
||||
"audio": "dab3e1ee457cd1dc1d580cba8d47a6679f1a37d40b949a2fac7c63a47a3b7768",
|
||||
},
|
||||
"full_then_review": {
|
||||
"video": "140064e63344d75e535f48ec49e488ca574cc069ee920cdaa507801c3504fb43",
|
||||
"audio": "4742f4d9eef6ffd64413cce2c052689fe13e4f2f98c914142039ab419aa908cf",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class GateFailure(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
def _write(path: Path, value: Any) -> None:
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(json.dumps(value, indent=2, ensure_ascii=False), encoding="utf-8")
|
||||
|
||||
|
||||
def _sha256_file(path: Path) -> str:
|
||||
digest = hashlib.sha256()
|
||||
with path.open("rb") as stream:
|
||||
for block in iter(lambda: stream.read(1024 * 1024), b""):
|
||||
digest.update(block)
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def _find_one(prompt: Mapping[str, Any], class_type: str) -> tuple[str, dict[str, Any]]:
|
||||
matches = [
|
||||
(str(node_id), node)
|
||||
for node_id, node in prompt.items()
|
||||
if str(node.get("class_type")) == class_type
|
||||
]
|
||||
if len(matches) != 1:
|
||||
raise GateFailure(f"expected one {class_type}, found {len(matches)}")
|
||||
return matches[0]
|
||||
|
||||
|
||||
def _prompt(
|
||||
template: Mapping[str, Any],
|
||||
*,
|
||||
label: str,
|
||||
mode: str,
|
||||
run_name: str,
|
||||
output_prefix: str,
|
||||
nonce: int,
|
||||
trace_steps: bool,
|
||||
) -> tuple[dict[str, Any], str]:
|
||||
prompt = copy.deepcopy(dict(template))
|
||||
node_id, sampler = _find_one(prompt, "H3ContinuumSamplerV38")
|
||||
sampler["class_type"] = "H3G4SamplingDeterminismDiagnostic"
|
||||
sampler["_meta"] = {"title": "H3 G4 Sampling Determinism Diagnostic"}
|
||||
sampler["inputs"].update(
|
||||
{
|
||||
"aspect": "Square 1:1",
|
||||
"preset": "Draft — 0.30 MP",
|
||||
"custom_mp": 0.30,
|
||||
"chunks": 3,
|
||||
"chunk_seconds": 5.0,
|
||||
"continuity": "Balanced — 22 frames",
|
||||
"base_seed": 927966463230733,
|
||||
"audio_continuity": True,
|
||||
"diagnostics": "Basic",
|
||||
"reroll_from_chunk": "Auto",
|
||||
"reroll_nonce": 0,
|
||||
"strict_compatibility": False,
|
||||
"debug": False,
|
||||
"show_preview": False,
|
||||
"run_storage": "Save + Auto Resume",
|
||||
"run_name": run_name,
|
||||
"reference_size": "Match Output",
|
||||
"project_id": str(uuid.uuid5(uuid.NAMESPACE_URL, run_name)),
|
||||
"video_reference_size": "Efficient - 0.4 MP",
|
||||
"continuation_backend": "Standard",
|
||||
"generation_mode": mode,
|
||||
"review_action": "Continue / Next",
|
||||
"diagnostic_label": label,
|
||||
"diagnostic_nonce": int(nonce),
|
||||
"trace_steps": bool(trace_steps),
|
||||
}
|
||||
)
|
||||
_, save_video = _find_one(prompt, "SaveVideo")
|
||||
save_video["inputs"]["filename_prefix"] = output_prefix
|
||||
return prompt, node_id
|
||||
|
||||
|
||||
def _extract(history: Mapping[str, Any], prompt_id: str, node_id: str) -> dict[str, Any]:
|
||||
record = history.get(prompt_id)
|
||||
if not isinstance(record, Mapping):
|
||||
raise GateFailure(f"history record missing for {prompt_id}")
|
||||
outputs = record.get("outputs")
|
||||
if not isinstance(outputs, Mapping):
|
||||
raise GateFailure("history outputs missing")
|
||||
node = outputs.get(str(node_id))
|
||||
if not isinstance(node, Mapping):
|
||||
raise GateFailure(f"diagnostic output missing for node {node_id}")
|
||||
text = node.get("text")
|
||||
if not isinstance(text, list) or len(text) != 1:
|
||||
raise GateFailure(f"unexpected diagnostic text output: {text!r}")
|
||||
result = json.loads(str(text[0]))
|
||||
if result.get("format") != "h3-v38-g4-sampling-determinism-v1":
|
||||
raise GateFailure("unexpected diagnostic format")
|
||||
if not result.get("hooks_restored"):
|
||||
raise GateFailure("diagnostic hooks were not restored")
|
||||
for sample in result.get("physical_samples", []):
|
||||
complete = sample.get("capture_complete") or {}
|
||||
if not complete.get("all_sampling_checkpoints"):
|
||||
raise GateFailure(f"sampling checkpoints incomplete: {complete}")
|
||||
if not complete.get("all_model_checkpoints"):
|
||||
raise GateFailure(f"model checkpoints incomplete: {complete}")
|
||||
return result
|
||||
|
||||
|
||||
def _run_case(
|
||||
args,
|
||||
template: Mapping[str, Any],
|
||||
*,
|
||||
label: str,
|
||||
mode: str,
|
||||
nonce: int,
|
||||
run_name: str,
|
||||
) -> dict[str, Any]:
|
||||
case_root = args.evidence_root / f"stage_{args.stage.lower()}" / label
|
||||
prompt, node_id = _prompt(
|
||||
template,
|
||||
label=label,
|
||||
mode=mode,
|
||||
run_name=run_name,
|
||||
output_prefix=f"v38_g4_sampling_diagnostic/{args.run_tag}/{label}",
|
||||
nonce=nonce,
|
||||
trace_steps=args.trace_steps,
|
||||
)
|
||||
_write(case_root / "prompt.json", prompt)
|
||||
print(f"G4 Sampling diagnostic start: {label}", flush=True)
|
||||
with ResourceMonitor(args.backend_pid, interval_seconds=args.monitor_interval) as monitor:
|
||||
prompt_id, history, elapsed = submit_and_wait(
|
||||
server=args.server,
|
||||
prompt=prompt,
|
||||
client_id=f"g4sampling-{uuid.uuid4().hex}",
|
||||
timeout_seconds=args.timeout_seconds,
|
||||
poll_seconds=args.poll_seconds,
|
||||
)
|
||||
_write(case_root / "history.json", history)
|
||||
result = _extract(history, prompt_id, node_id)
|
||||
_write(case_root / "diagnostic.json", result)
|
||||
output = {
|
||||
"label": label,
|
||||
"mode": mode,
|
||||
"run_name": run_name,
|
||||
"prompt_id": prompt_id,
|
||||
"api_elapsed_seconds": elapsed,
|
||||
"resources": monitor.as_dict(),
|
||||
"prompt": str(case_root / "prompt.json"),
|
||||
"history": str(case_root / "history.json"),
|
||||
"diagnostic_path": str(case_root / "diagnostic.json"),
|
||||
"diagnostic": result,
|
||||
}
|
||||
_write(case_root / "result.json", output)
|
||||
print(f"G4 Sampling diagnostic end: {label}; {elapsed:.3f}s", flush=True)
|
||||
return output
|
||||
|
||||
|
||||
def _stage(args) -> dict[str, Any]:
|
||||
template = json.loads(args.template_prompt.read_text(encoding="utf-8"))
|
||||
prefix = f"v38_g4_sampling_{args.run_tag}_{args.stage.lower()}"
|
||||
definitions = {
|
||||
"A": [("A_fresh_full", "Full Run", f"{prefix}_full")],
|
||||
"B": [("B_fresh_review", "Review Each Chunk", f"{prefix}_review")],
|
||||
"C": [
|
||||
("C_full", "Full Run", f"{prefix}_full"),
|
||||
("C_review_after_full", "Review Each Chunk", f"{prefix}_review"),
|
||||
],
|
||||
"D": [
|
||||
("D_review_1", "Review Each Chunk", f"{prefix}_review_1"),
|
||||
("D_review_2", "Review Each Chunk", f"{prefix}_review_2"),
|
||||
],
|
||||
}
|
||||
runs = []
|
||||
for offset, (label, mode, run_name) in enumerate(definitions[args.stage], 1):
|
||||
run_root = args.run_storage_root / run_name
|
||||
if run_root.exists():
|
||||
raise GateFailure(f"refusing existing Run Storage: {run_root}")
|
||||
runs.append(
|
||||
_run_case(
|
||||
args,
|
||||
template,
|
||||
label=label,
|
||||
mode=mode,
|
||||
nonce=args.nonce_base + offset,
|
||||
run_name=run_name,
|
||||
)
|
||||
)
|
||||
result = {
|
||||
"format": "h3-v38-g4-sampling-determinism-stage-v1",
|
||||
"stage": args.stage,
|
||||
"backend_pid": args.backend_pid,
|
||||
"backend_log": str(args.backend_log),
|
||||
"server": args.server,
|
||||
"run_tag": args.run_tag,
|
||||
"trace_steps": bool(args.trace_steps),
|
||||
"runner_sha256": _sha256_file(Path(__file__)),
|
||||
"template_sha256": _sha256_file(args.template_prompt),
|
||||
"runs": runs,
|
||||
}
|
||||
_write(args.evidence_root / f"stage_{args.stage.lower()}.json", result)
|
||||
return result
|
||||
|
||||
|
||||
def _first_sample(run: Mapping[str, Any]) -> Mapping[str, Any]:
|
||||
samples = run["diagnostic"].get("physical_samples") or []
|
||||
if not samples:
|
||||
raise GateFailure(f"no physical samples in {run.get('label')}")
|
||||
return samples[0]
|
||||
|
||||
|
||||
def _normalized_payload(value: Any) -> Any:
|
||||
if isinstance(value, Mapping):
|
||||
if value.get("__type__") == "uuid.UUID" and "value" in value:
|
||||
return {"__type__": "uuid.UUID", "present": True}
|
||||
return {
|
||||
str(key): _normalized_payload(item)
|
||||
for key, item in sorted(value.items(), key=lambda item: str(item[0]))
|
||||
if str(key) != "legacy_g4_sha256"
|
||||
}
|
||||
if isinstance(value, list):
|
||||
return [_normalized_payload(item) for item in value]
|
||||
return value
|
||||
|
||||
|
||||
def _comparison_sha(checkpoint: Mapping[str, Any]) -> str:
|
||||
if checkpoint.get("kind") != "structured" or "payload" not in checkpoint:
|
||||
return str(checkpoint["sha256"])
|
||||
payload = _normalized_payload(checkpoint["payload"])
|
||||
encoded = json.dumps(
|
||||
payload,
|
||||
sort_keys=True,
|
||||
separators=(",", ":"),
|
||||
ensure_ascii=False,
|
||||
).encode("utf-8")
|
||||
return hashlib.sha256(encoded).hexdigest()
|
||||
|
||||
|
||||
def _sha(value: Mapping[str, Any], name: str) -> str:
|
||||
return _comparison_sha(value[name])
|
||||
|
||||
|
||||
def _compare_samples(left_run: Mapping[str, Any], right_run: Mapping[str, Any]) -> dict[str, Any]:
|
||||
left = _first_sample(left_run)
|
||||
right = _first_sample(right_run)
|
||||
checkpoints: dict[str, Any] = {}
|
||||
first_sampling = None
|
||||
for name in SAMPLING_CHECKPOINTS:
|
||||
left_sha = _sha(left["checkpoints"], name)
|
||||
right_sha = _sha(right["checkpoints"], name)
|
||||
match = left_sha == right_sha
|
||||
checkpoints[name] = {
|
||||
"left_sha256": left_sha,
|
||||
"right_sha256": right_sha,
|
||||
"match": match,
|
||||
}
|
||||
if first_sampling is None and not match:
|
||||
first_sampling = name
|
||||
model: dict[str, Any] = {}
|
||||
first_model = None
|
||||
for name in MODEL_CHECKPOINTS:
|
||||
left_sha = _sha(left["model"], name)
|
||||
right_sha = _sha(right["model"], name)
|
||||
match = left_sha == right_sha
|
||||
model[name] = {
|
||||
"left_sha256": left_sha,
|
||||
"right_sha256": right_sha,
|
||||
"match": match,
|
||||
}
|
||||
if first_model is None and not match:
|
||||
first_model = name
|
||||
output = {
|
||||
"left_sha256": str(left["output"]["sha256"]),
|
||||
"right_sha256": str(right["output"]["sha256"]),
|
||||
"match": left["output"]["sha256"] == right["output"]["sha256"],
|
||||
"left_streams": left["output"]["streams"],
|
||||
"right_streams": right["output"]["streams"],
|
||||
}
|
||||
return {
|
||||
"left": left_run["label"],
|
||||
"right": right_run["label"],
|
||||
"first_sampling_divergence": first_sampling,
|
||||
"sampling": checkpoints,
|
||||
"first_model_divergence": first_model,
|
||||
"model": model,
|
||||
"output": output,
|
||||
}
|
||||
|
||||
|
||||
def _classification(comparison: Mapping[str, Any]) -> dict[str, Any]:
|
||||
first_s = comparison.get("first_sampling_divergence")
|
||||
if (
|
||||
first_s is None
|
||||
and comparison.get("first_model_divergence") is None
|
||||
and comparison["output"]["match"]
|
||||
):
|
||||
return {
|
||||
"case": "NO DIVERGENCE REPRODUCED",
|
||||
"reason": "S0-S8, M0-M3, and the final sampled AV latent are exact",
|
||||
}
|
||||
if first_s == "S0":
|
||||
case, reason = "CASE S-A", "target latent construction differs"
|
||||
elif first_s == "S2":
|
||||
case, reason = "CASE S-B", "prepare_noise / RNG path differs"
|
||||
elif first_s == "S3":
|
||||
case, reason = "CASE S-C", "denoise mask differs"
|
||||
elif first_s == "S8":
|
||||
case, reason = "CASE S-D", "model runtime signature differs before Sampling"
|
||||
elif first_s is not None:
|
||||
case, reason = "CASE S-OTHER", f"Sampling boundary first differs at {first_s}"
|
||||
else:
|
||||
first_m = comparison.get("first_model_divergence")
|
||||
if first_m is None:
|
||||
case, reason = "CASE M-E", "M0-M3 match; step trace is required"
|
||||
elif first_m == "M3" and all(
|
||||
comparison["model"][name]["match"] for name in ("M0", "M1", "M2")
|
||||
):
|
||||
case, reason = (
|
||||
"CASE M-FORWARD",
|
||||
"identical first model inputs produce a different first model output",
|
||||
)
|
||||
else:
|
||||
case, reason = "CASE M-INPUT", f"first model-call difference is {first_m}"
|
||||
return {"case": case, "reason": reason}
|
||||
|
||||
|
||||
def _stream_pair(sample: Mapping[str, Any]) -> dict[str, str]:
|
||||
streams = sample["output"]["streams"]
|
||||
return {
|
||||
"video": str(
|
||||
streams["video"].get("legacy_g4_sha256", streams["video"]["sha256"])
|
||||
),
|
||||
"audio": str(
|
||||
streams["audio"].get("legacy_g4_sha256", streams["audio"]["sha256"])
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def _short(value: str) -> str:
|
||||
return value[:12]
|
||||
|
||||
|
||||
def _gib(value: int | float) -> str:
|
||||
return f"{float(value) / (1024 ** 3):.2f}"
|
||||
|
||||
|
||||
def _report(summary: Mapping[str, Any]) -> str:
|
||||
lines = [
|
||||
"# G4 Sampling Determinism Diagnostic — STOP Report",
|
||||
"",
|
||||
f"Classification: **{summary['classification']['case']}** ",
|
||||
f"First divergence: **{summary['first_divergence']}** ",
|
||||
f"Result: {summary['classification']['reason']}",
|
||||
"",
|
||||
"Production code and defaults were not changed.",
|
||||
"",
|
||||
"## Order Matrix",
|
||||
"",
|
||||
"| Order | Left output | Right output | Result |",
|
||||
"|---|---:|---:|---|",
|
||||
]
|
||||
for name, comparison in summary["order_matrix"].items():
|
||||
output = comparison["output"]
|
||||
s8 = comparison["sampling"]["S8"]
|
||||
lines.append(
|
||||
f"| {name} | `{_short(output['left_sha256'])}` | "
|
||||
f"`{_short(output['right_sha256'])}` | "
|
||||
f"{'PASS' if output['match'] else 'FAIL'} "
|
||||
f"(S8 state {'exact' if s8['match'] else 'changed'}) |"
|
||||
)
|
||||
lines.extend(
|
||||
[
|
||||
"",
|
||||
"The sampled AV latent is exact in every accepted order. In the same-backend "
|
||||
"C and D comparisons, S8 records the expected warm-residency transition: "
|
||||
"`model_device` changes from `cpu` to `cuda:0`, and "
|
||||
"`current_weight_patch_uuid_present` changes from `false` to `true`. "
|
||||
"M0-M3 and the final AV latent remain exact, so this observed S8 state "
|
||||
"transition is not causal in the reproduced runs.",
|
||||
]
|
||||
)
|
||||
focus = summary["focus_comparison"]
|
||||
lines.extend(
|
||||
[
|
||||
"",
|
||||
"## Sampling Boundary",
|
||||
"",
|
||||
"| Checkpoint | Left SHA | Right SHA | Result |",
|
||||
"|---|---:|---:|---|",
|
||||
]
|
||||
)
|
||||
for name in SAMPLING_CHECKPOINTS:
|
||||
row = focus["sampling"][name]
|
||||
lines.append(
|
||||
f"| {name} | `{_short(row['left_sha256'])}` | "
|
||||
f"`{_short(row['right_sha256'])}` | "
|
||||
f"{'PASS' if row['match'] else 'FAIL'} |"
|
||||
)
|
||||
lines.extend(
|
||||
[
|
||||
"",
|
||||
"## First model call",
|
||||
"",
|
||||
"| Checkpoint | Left SHA | Right SHA | Result |",
|
||||
"|---|---:|---:|---|",
|
||||
]
|
||||
)
|
||||
for name in MODEL_CHECKPOINTS:
|
||||
row = focus["model"][name]
|
||||
lines.append(
|
||||
f"| {name} | `{_short(row['left_sha256'])}` | "
|
||||
f"`{_short(row['right_sha256'])}` | "
|
||||
f"{'PASS' if row['match'] else 'FAIL'} |"
|
||||
)
|
||||
lines.extend(
|
||||
[
|
||||
"",
|
||||
"S7 equals the previously accepted P7 conditioning hash in all six runs. "
|
||||
"A step trace was not run because M0-M3 and the final output are exact. "
|
||||
"Accelerator A/B was not run because no model-forward divergence was observed.",
|
||||
"",
|
||||
"## Performance and resources",
|
||||
"",
|
||||
"| Run | Sampling | API | Peak VRAM | Peak RSS | Min available RAM |",
|
||||
"|---|---:|---:|---:|---:|---:|",
|
||||
]
|
||||
)
|
||||
for label, item in summary["performance"].items():
|
||||
resource = item["resources"]
|
||||
lines.append(
|
||||
f"| {label} | {item['sampling_seconds']:.2f}s | "
|
||||
f"{item['api_seconds']:.2f}s | "
|
||||
f"{_gib(resource['peak_device_used_bytes'])} GiB | "
|
||||
f"{_gib(resource['peak_process_rss_bytes'])} GiB | "
|
||||
f"{_gib(resource['minimum_system_available_bytes'])} GiB |"
|
||||
)
|
||||
lines.extend(
|
||||
[
|
||||
"",
|
||||
"## Root-cause assessment and disposition",
|
||||
"",
|
||||
"- **Gate disposition:** STOP / inconclusive because the historical Full-to-Review "
|
||||
"bit divergence is not reproducible in the current exact-order tests.",
|
||||
"- **First sampled divergence:** None. S0-S7, M0-M3, and final AV are exact. "
|
||||
"The C/D S8 difference is a non-causal warm model-residency state transition.",
|
||||
"- **Root cause:** Unresolved transient runtime or numerical state in the historical "
|
||||
"G4 run. Current evidence excludes target latent, fixed latent, noise, mask, "
|
||||
"SIGMAS, seed, sampler, conditioning, and the first model call in the reproduced runs.",
|
||||
"- **Minimal fix:** None is justified. Do not change Production. If further diagnosis "
|
||||
"is approved, repeat only the exact public-node C order while capturing the startup, "
|
||||
"extension, driver, kernel, and model-residency signature; enable a deferred/no-sync "
|
||||
"step trace only after the divergent output is reproduced.",
|
||||
"- **V3.7 / Full Run impact:** None now because no Production code changed. Speculative "
|
||||
"model reload, attention, cache, dtype, or deterministic-mode changes could alter "
|
||||
"V3.7 and Full Run performance or numerical behavior and therefore are not acceptable "
|
||||
"without a reproduced cause.",
|
||||
"- **Difficulty:** High. The historical condition is transient, non-reproducible, and "
|
||||
"sensitive to observation timing.",
|
||||
"",
|
||||
"## Control and retained evidence",
|
||||
"",
|
||||
"The public-node/no-hook control reproduces the historical Full hash, while its "
|
||||
"Review Queue 1 now matches Full rather than the historical divergent Review hash. "
|
||||
"The legacy control runner began Queue 2 after Queue 1 passed; that out-of-scope "
|
||||
"queue was interrupted immediately and is not a Product failure.",
|
||||
"",
|
||||
"```json",
|
||||
json.dumps(summary["control"], indent=2, ensure_ascii=False),
|
||||
"```",
|
||||
"",
|
||||
"STOP. No Production fix, accelerator change, deterministic-mode forcing, cache, model reload, seed/SIGMAS change, Run Storage change, commit, push, or release was performed.",
|
||||
"",
|
||||
]
|
||||
)
|
||||
return "\n".join(lines)
|
||||
|
||||
|
||||
def _analyze(args) -> dict[str, Any]:
|
||||
stages = {}
|
||||
for stage in "ABCD":
|
||||
path = args.evidence_root / f"stage_{stage.lower()}.json"
|
||||
if path.is_file():
|
||||
stages[stage] = json.loads(path.read_text(encoding="utf-8"))
|
||||
required = {"A", "B", "C", "D"}
|
||||
if set(stages) != required:
|
||||
raise GateFailure(f"analysis requires A-D; found {sorted(stages)}")
|
||||
a = stages["A"]["runs"][0]
|
||||
b = stages["B"]["runs"][0]
|
||||
c_full, c_review = stages["C"]["runs"]
|
||||
d1, d2 = stages["D"]["runs"]
|
||||
matrix = {
|
||||
"Fresh Full vs Fresh Review": _compare_samples(a, b),
|
||||
"Full -> Review": _compare_samples(c_full, c_review),
|
||||
"Review -> Review": _compare_samples(d1, d2),
|
||||
}
|
||||
focus_name = "Full -> Review" if not matrix["Full -> Review"]["output"]["match"] else "Fresh Full vs Fresh Review"
|
||||
focus = matrix[focus_name]
|
||||
first = focus["first_sampling_divergence"] or focus["first_model_divergence"]
|
||||
if first is None and not focus["output"]["match"]:
|
||||
first = "Sampler step trace required"
|
||||
elif first is None:
|
||||
first = "none through final sampled latent"
|
||||
classification = _classification(focus)
|
||||
if all(item["output"]["match"] for item in matrix.values()):
|
||||
s8_changed = [
|
||||
name
|
||||
for name, item in matrix.items()
|
||||
if not item["sampling"]["S8"]["match"]
|
||||
]
|
||||
classification = {
|
||||
"case": "NO DIVERGENCE REPRODUCED",
|
||||
"reason": (
|
||||
"S0-S7, M0-M3, and final sampled AV are exact in all orders; "
|
||||
"S8 contains only the non-causal warm runtime-state transition "
|
||||
f"in {', '.join(s8_changed)}"
|
||||
if s8_changed
|
||||
else "S0-S8, M0-M3, and final sampled AV are exact in all orders"
|
||||
),
|
||||
}
|
||||
if s8_changed:
|
||||
first = (
|
||||
"S8 runtime state only in same-backend C/D; "
|
||||
"no sampled bit divergence through final latent"
|
||||
)
|
||||
|
||||
c_full_streams = _stream_pair(_first_sample(c_full))
|
||||
c_review_streams = _stream_pair(_first_sample(c_review))
|
||||
no_hook = None
|
||||
if args.no_hook_control.is_file():
|
||||
no_hook = json.loads(args.no_hook_control.read_text(encoding="utf-8"))
|
||||
no_hook_full = None
|
||||
no_hook_review = None
|
||||
if no_hook is not None:
|
||||
no_hook_full = {
|
||||
"video": no_hook["results"]["full"]["run_storage"]["chunks"][0]["video_latent_sha256"],
|
||||
"audio": no_hook["results"]["full"]["run_storage"]["chunks"][0]["audio_latent_sha256"],
|
||||
}
|
||||
no_hook_review = {
|
||||
"video": no_hook["results"]["review_q1"]["run_storage"]["chunks"][0]["video_latent_sha256"],
|
||||
"audio": no_hook["results"]["review_q1"]["run_storage"]["chunks"][0]["audio_latent_sha256"],
|
||||
}
|
||||
control = {
|
||||
"hook_noninterference_current_no_hook_full": (
|
||||
None if no_hook_full is None else c_full_streams == no_hook_full
|
||||
),
|
||||
"hook_noninterference_current_no_hook_review": (
|
||||
None if no_hook_review is None else c_review_streams == no_hook_review
|
||||
),
|
||||
"observed_c_full": c_full_streams,
|
||||
"observed_c_review": c_review_streams,
|
||||
"current_no_hook_full": no_hook_full,
|
||||
"current_no_hook_review": no_hook_review,
|
||||
"historical_g4_full": ORIGINAL_G4["full"],
|
||||
"historical_g4_divergent_review": ORIGINAL_G4["full_then_review"],
|
||||
"historical_full_reproduced": c_full_streams == ORIGINAL_G4["full"],
|
||||
"historical_divergent_review_reproduced": (
|
||||
c_review_streams == ORIGINAL_G4["full_then_review"]
|
||||
),
|
||||
"current_no_hook_chunk_1_matches_full": (
|
||||
None if no_hook_full is None else no_hook_full == no_hook_review
|
||||
),
|
||||
"all_hooks_restored": all(
|
||||
run["diagnostic"].get("hooks_restored")
|
||||
for stage in stages.values()
|
||||
for run in stage["runs"]
|
||||
),
|
||||
}
|
||||
p7 = None
|
||||
if args.conditioning_summary.is_file():
|
||||
conditioning = json.loads(args.conditioning_summary.read_text(encoding="utf-8"))
|
||||
p7 = _comparison_sha(
|
||||
conditioning["prepare"]["runs"]["full"]["result"]["checkpoints"]["P7"]
|
||||
)
|
||||
s7_checks = {}
|
||||
for run in (a, b, c_full, c_review, d1, d2):
|
||||
sample = _first_sample(run)
|
||||
s7 = _comparison_sha(sample["checkpoints"]["S7"])
|
||||
s7_checks[run["label"]] = {
|
||||
"s7_sha256": s7,
|
||||
"p7_sha256": p7,
|
||||
"matches_p7": None if p7 is None else s7 == p7,
|
||||
}
|
||||
resources = {
|
||||
run["label"]: run["resources"]
|
||||
for stage in stages.values()
|
||||
for run in stage["runs"]
|
||||
}
|
||||
performance = {
|
||||
run["label"]: {
|
||||
"sampling_seconds": float(
|
||||
run["diagnostic"]["sampler_node_elapsed_seconds"]
|
||||
),
|
||||
"api_seconds": float(run["api_elapsed_seconds"]),
|
||||
"resources": run["resources"],
|
||||
}
|
||||
for stage in stages.values()
|
||||
for run in stage["runs"]
|
||||
}
|
||||
summary = {
|
||||
"format": "h3-v38-g4-sampling-determinism-final-v1",
|
||||
"stage": "stopped",
|
||||
"production_changed": False,
|
||||
"focus": focus_name,
|
||||
"first_divergence": first,
|
||||
"classification": classification,
|
||||
"order_matrix": matrix,
|
||||
"focus_comparison": focus,
|
||||
"control": control,
|
||||
"p7_parity": s7_checks,
|
||||
"resources": resources,
|
||||
"performance": performance,
|
||||
"stages": {
|
||||
stage: str(args.evidence_root / f"stage_{stage.lower()}.json")
|
||||
for stage in stages
|
||||
},
|
||||
}
|
||||
_write(args.evidence_root / "g4_sampling_determinism_summary.json", summary)
|
||||
(args.evidence_root / "G4_SAMPLING_DETERMINISM_STOP_REPORT.md").write_text(
|
||||
_report(summary),
|
||||
encoding="utf-8",
|
||||
)
|
||||
return summary
|
||||
|
||||
|
||||
def _parser() -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--stage", choices=("A", "B", "C", "D", "analyze"), required=True)
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8190")
|
||||
parser.add_argument("--template-prompt", type=Path)
|
||||
parser.add_argument("--evidence-root", type=Path, required=True)
|
||||
parser.add_argument("--run-storage-root", type=Path)
|
||||
parser.add_argument("--run-tag", default="20260831_154505")
|
||||
parser.add_argument("--backend-pid", type=int)
|
||||
parser.add_argument("--backend-log", type=Path)
|
||||
parser.add_argument("--nonce-base", type=int, default=1000)
|
||||
parser.add_argument("--trace-steps", action="store_true")
|
||||
parser.add_argument("--timeout-seconds", type=float, default=2400.0)
|
||||
parser.add_argument("--poll-seconds", type=float, default=2.0)
|
||||
parser.add_argument("--monitor-interval", type=float, default=1.0)
|
||||
parser.add_argument(
|
||||
"--conditioning-summary",
|
||||
type=Path,
|
||||
default=Path(
|
||||
r"D:\Codex\_test_results\ComfyUI-H3-Continuum"
|
||||
r"\v38-g4-conditioning-determinism-20260831_150837"
|
||||
r"\g4_conditioning_determinism_summary.json"
|
||||
),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--no-hook-control",
|
||||
type=Path,
|
||||
default=Path(
|
||||
r"D:\Codex\_test_results\ComfyUI-H3-Continuum"
|
||||
r"\v38-g4-sampling-determinism-20260831_154505"
|
||||
r"\no_hook_control\gpu_r1\g4_summary.json"
|
||||
),
|
||||
)
|
||||
return parser
|
||||
|
||||
|
||||
def main() -> int:
|
||||
args = _parser().parse_args()
|
||||
args.evidence_root.mkdir(parents=True, exist_ok=True)
|
||||
if args.stage != "analyze":
|
||||
if args.template_prompt is None or args.run_storage_root is None:
|
||||
raise GateFailure("stage execution requires template prompt and Run Storage root")
|
||||
if args.backend_pid is None or args.backend_log is None:
|
||||
raise GateFailure("stage execution requires backend PID and log")
|
||||
result = _stage(args)
|
||||
else:
|
||||
result = _analyze(args)
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"stage": result.get("stage"),
|
||||
"first_divergence": result.get("first_divergence"),
|
||||
"classification": result.get("classification"),
|
||||
"summary": str(args.evidence_root / "g4_sampling_determinism_summary.json"),
|
||||
},
|
||||
indent=2,
|
||||
ensure_ascii=False,
|
||||
),
|
||||
flush=True,
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,430 @@
|
||||
"""Run the three-case V3.8 main-sampler resolution GPU mini Gate."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
from dataclasses import asdict, dataclass
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import Any, Mapping
|
||||
import uuid
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
from p32_api_runner import _json_request, submit_and_wait
|
||||
from v36_r1_stress_gate_runner import ResourceMonitor
|
||||
from v38_easy_gpu_gate_runner import _output_media, _probe_media
|
||||
|
||||
|
||||
class GateFailure(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class GateCase:
|
||||
name: str
|
||||
aspect: str
|
||||
preset: str
|
||||
custom_mp: float
|
||||
first_image: bool
|
||||
expected_width: int
|
||||
expected_height: int
|
||||
prompt: str
|
||||
|
||||
|
||||
CASES = (
|
||||
GateCase(
|
||||
name="g1_draft_landscape",
|
||||
aspect="Landscape 16:9",
|
||||
preset="Draft — 0.30 MP",
|
||||
custom_mp=0.30,
|
||||
first_image=False,
|
||||
expected_width=736,
|
||||
expected_height=416,
|
||||
prompt=(
|
||||
"A continuous cinematic landscape shot tracks a woman walking across "
|
||||
"a modern plaza. Natural body motion, stable lighting, footsteps, wind, "
|
||||
"and distant city ambience continue without a cut."
|
||||
),
|
||||
),
|
||||
GateCase(
|
||||
name="g2_balanced_portrait",
|
||||
aspect="Portrait 9:16",
|
||||
preset="Balanced — 0.60 MP",
|
||||
custom_mp=0.30,
|
||||
first_image=False,
|
||||
expected_width=576,
|
||||
expected_height=1024,
|
||||
prompt=(
|
||||
"A continuous portrait-format cinematic shot follows a woman walking "
|
||||
"toward camera through a city street. Preserve coherent anatomy, natural "
|
||||
"motion, stable exposure, footsteps, and urban ambience."
|
||||
),
|
||||
),
|
||||
GateCase(
|
||||
name="g3_native_auto_first_image",
|
||||
aspect="Auto from First Image",
|
||||
preset="Native 768",
|
||||
custom_mp=0.30,
|
||||
first_image=True,
|
||||
expected_width=768,
|
||||
expected_height=1024,
|
||||
prompt=(
|
||||
"A continuous cinematic shot begins from the supplied First Image. The "
|
||||
"subject moves naturally while identity, clothing, lighting, camera "
|
||||
"direction, footsteps, and ambience remain coherent."
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def _sha256(path: Path) -> str:
|
||||
digest = hashlib.sha256()
|
||||
with path.open("rb") as stream:
|
||||
for block in iter(lambda: stream.read(1024 * 1024), b""):
|
||||
digest.update(block)
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def _resolve_origin(
|
||||
node_id: str,
|
||||
output_slot: int,
|
||||
*,
|
||||
nodes: Mapping[str, Mapping[str, Any]],
|
||||
links: Mapping[str, list[Any]],
|
||||
seen: set[tuple[str, int]] | None = None,
|
||||
) -> list[Any] | None:
|
||||
seen = set(seen or ())
|
||||
key = (str(node_id), int(output_slot))
|
||||
if key in seen:
|
||||
return None
|
||||
seen.add(key)
|
||||
node = nodes.get(str(node_id))
|
||||
if not isinstance(node, Mapping):
|
||||
return None
|
||||
mode = int(node.get("mode", 0) or 0)
|
||||
if mode == 0:
|
||||
return [str(node_id), int(output_slot)]
|
||||
if mode != 4:
|
||||
return None
|
||||
outputs = list(node.get("outputs") or [])
|
||||
output_type = outputs[output_slot].get("type") if output_slot < len(outputs) else None
|
||||
candidates = []
|
||||
for input_value in node.get("inputs") or []:
|
||||
link_id = input_value.get("link")
|
||||
input_type = input_value.get("type")
|
||||
if link_id is None:
|
||||
continue
|
||||
if output_type not in (None, "*") and input_type not in (output_type, "*"):
|
||||
continue
|
||||
candidates.append(str(link_id))
|
||||
if len(candidates) != 1:
|
||||
return None
|
||||
link = links.get(candidates[0])
|
||||
if not link:
|
||||
return None
|
||||
return _resolve_origin(
|
||||
str(link[1]),
|
||||
int(link[2]),
|
||||
nodes=nodes,
|
||||
links=links,
|
||||
seen=seen,
|
||||
)
|
||||
|
||||
|
||||
def _build_prompt(
|
||||
workflow: Mapping[str, Any],
|
||||
object_info: Mapping[str, Any],
|
||||
*,
|
||||
case: GateCase,
|
||||
image_name: str,
|
||||
output_prefix: str,
|
||||
seed: int,
|
||||
) -> dict[str, Any]:
|
||||
nodes = {str(node["id"]): copy.deepcopy(node) for node in workflow["nodes"]}
|
||||
links = {str(link[0]): list(link) for link in workflow["links"]}
|
||||
sampler_ids = [node_id for node_id, node in nodes.items() if node["type"] == "H3ContinuumSamplerV37"]
|
||||
if len(sampler_ids) != 1:
|
||||
raise GateFailure(f"expected one V3.7 source sampler, found {len(sampler_ids)}")
|
||||
sampler_id = sampler_ids[0]
|
||||
nodes[sampler_id]["type"] = "H3ContinuumSamplerV38"
|
||||
nodes[sampler_id].setdefault("properties", {})["Node name for S&R"] = (
|
||||
"H3ContinuumSamplerV38"
|
||||
)
|
||||
sampler_named = dict(nodes[sampler_id].get("widgets_values_named") or {})
|
||||
sampler_named.pop("width", None)
|
||||
sampler_named.pop("height", None)
|
||||
sampler_named.update(
|
||||
{
|
||||
"aspect": case.aspect,
|
||||
"preset": case.preset,
|
||||
"custom_mp": case.custom_mp,
|
||||
"chunks": 1,
|
||||
"chunk_seconds": 5.0,
|
||||
"base_seed": int(seed),
|
||||
"diagnostics": "Detailed Report",
|
||||
"show_preview": False,
|
||||
"run_storage": "Off",
|
||||
"run_name": "",
|
||||
"project_id": f"v38-resolution-{case.name}-{seed}",
|
||||
}
|
||||
)
|
||||
nodes[sampler_id]["widgets_values_named"] = sampler_named
|
||||
|
||||
for node in nodes.values():
|
||||
if node["type"] == "PrimitiveStringMultiline":
|
||||
node.setdefault("widgets_values_named", {})["value"] = case.prompt
|
||||
elif node["type"] == "LoadImage" and int(node["id"]) == 114:
|
||||
node.setdefault("widgets_values_named", {})["image"] = image_name
|
||||
elif node["type"] == "SaveVideo":
|
||||
node.setdefault("widgets_values_named", {})["filename_prefix"] = output_prefix
|
||||
|
||||
prompt: dict[str, Any] = {}
|
||||
|
||||
def add_node(node_id: str) -> None:
|
||||
if node_id in prompt:
|
||||
return
|
||||
node = nodes[node_id]
|
||||
if int(node.get("mode", 0) or 0) != 0:
|
||||
return
|
||||
class_type = str(node["type"])
|
||||
info = object_info.get(class_type)
|
||||
if not isinstance(info, Mapping):
|
||||
raise GateFailure(f"object_info has no node class {class_type}")
|
||||
valid_inputs = set()
|
||||
input_schema = info.get("input") or {}
|
||||
valid_inputs.update((input_schema.get("required") or {}).keys())
|
||||
valid_inputs.update((input_schema.get("optional") or {}).keys())
|
||||
api_inputs: dict[str, Any] = {}
|
||||
for input_value in node.get("inputs") or []:
|
||||
name = str(input_value.get("name"))
|
||||
if name in {"width", "height"}:
|
||||
continue
|
||||
if node_id == sampler_id and name == "first_frame" and not case.first_image:
|
||||
continue
|
||||
link_id = input_value.get("link")
|
||||
if link_id is None or name not in valid_inputs:
|
||||
continue
|
||||
link = links.get(str(link_id))
|
||||
if not link:
|
||||
continue
|
||||
origin = _resolve_origin(
|
||||
str(link[1]),
|
||||
int(link[2]),
|
||||
nodes=nodes,
|
||||
links=links,
|
||||
)
|
||||
if origin is None:
|
||||
continue
|
||||
api_inputs[name] = origin
|
||||
add_node(str(origin[0]))
|
||||
for name, value in (node.get("widgets_values_named") or {}).items():
|
||||
if name in valid_inputs and name not in api_inputs:
|
||||
api_inputs[str(name)] = value
|
||||
prompt[node_id] = {
|
||||
"class_type": class_type,
|
||||
"inputs": api_inputs,
|
||||
"_meta": {"title": str(node.get("title") or class_type)},
|
||||
}
|
||||
|
||||
output_ids = [
|
||||
node_id
|
||||
for node_id, node in nodes.items()
|
||||
if node["type"] == "SaveVideo" and int(node.get("mode", 0) or 0) == 0
|
||||
]
|
||||
if len(output_ids) != 1:
|
||||
raise GateFailure(f"expected one active SaveVideo, found {len(output_ids)}")
|
||||
add_node(output_ids[0])
|
||||
if sampler_id not in prompt:
|
||||
raise GateFailure("V3.8 sampler is not connected to the SaveVideo output")
|
||||
return prompt
|
||||
|
||||
|
||||
def _media_health(path: Path, ffmpeg: str) -> dict[str, Any]:
|
||||
video_result = subprocess.run(
|
||||
[
|
||||
ffmpeg,
|
||||
"-v",
|
||||
"error",
|
||||
"-i",
|
||||
str(path),
|
||||
"-vf",
|
||||
"fps=1,scale=64:64",
|
||||
"-pix_fmt",
|
||||
"rgb24",
|
||||
"-f",
|
||||
"rawvideo",
|
||||
"-",
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
frame_size = 64 * 64 * 3
|
||||
frame_count = len(video_result.stdout) // frame_size
|
||||
frames = np.frombuffer(video_result.stdout[: frame_count * frame_size], dtype=np.uint8)
|
||||
frames = frames.reshape(frame_count, 64, 64, 3)
|
||||
frame_means = frames.mean(axis=(1, 2, 3))
|
||||
video_std = float(frames.astype(np.float32).std())
|
||||
|
||||
audio_result = subprocess.run(
|
||||
[
|
||||
ffmpeg,
|
||||
"-v",
|
||||
"error",
|
||||
"-i",
|
||||
str(path),
|
||||
"-map",
|
||||
"0:a:0",
|
||||
"-f",
|
||||
"f32le",
|
||||
"-acodec",
|
||||
"pcm_f32le",
|
||||
"-",
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
)
|
||||
audio = np.frombuffer(audio_result.stdout, dtype=np.float32)
|
||||
return {
|
||||
"sampled_video_frames": int(frame_count),
|
||||
"video_mean": float(frames.mean()),
|
||||
"video_std": video_std,
|
||||
"black_sample_fraction": float(np.mean(frame_means < 2.0)),
|
||||
"video_not_black_or_collapsed": bool(
|
||||
frame_count > 0 and video_std > 2.0 and np.any(frame_means >= 2.0)
|
||||
),
|
||||
"audio_samples": int(audio.size),
|
||||
"audio_finite": bool(audio.size > 0 and np.isfinite(audio).all()),
|
||||
"audio_peak": float(np.max(np.abs(audio))) if audio.size else 0.0,
|
||||
}
|
||||
|
||||
|
||||
def run(args) -> dict[str, Any]:
|
||||
workflow = json.loads(args.workflow.read_text(encoding="utf-8"))
|
||||
object_info = _json_request(f"{args.server.rstrip('/')}/object_info")
|
||||
if "H3ContinuumSamplerV38" not in object_info:
|
||||
raise GateFailure("runtime has no H3ContinuumSamplerV38")
|
||||
ffmpeg = shutil.which("ffmpeg")
|
||||
ffprobe = shutil.which("ffprobe")
|
||||
if not ffmpeg or not ffprobe:
|
||||
raise GateFailure("ffmpeg and ffprobe are required")
|
||||
args.output_root.mkdir(parents=True, exist_ok=True)
|
||||
results = []
|
||||
for index, case in enumerate(CASES, start=1):
|
||||
case_root = args.output_root / case.name
|
||||
case_root.mkdir(parents=True, exist_ok=True)
|
||||
prompt = _build_prompt(
|
||||
workflow,
|
||||
object_info,
|
||||
case=case,
|
||||
image_name=args.image_name,
|
||||
output_prefix=f"v38_resolution_gate/{case.name}",
|
||||
seed=args.seed,
|
||||
)
|
||||
prompt_path = case_root / "prompt.json"
|
||||
prompt_path.write_text(
|
||||
json.dumps(prompt, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
print(
|
||||
f"V3.8 Resolution Gate start {index}/{len(CASES)} {case.name}",
|
||||
flush=True,
|
||||
)
|
||||
if args.dry_run:
|
||||
results.append({"case": asdict(case), "prompt": str(prompt_path)})
|
||||
continue
|
||||
with ResourceMonitor(args.backend_pid, args.monitor_interval) as monitor:
|
||||
prompt_id, history, elapsed = submit_and_wait(
|
||||
server=args.server,
|
||||
prompt=prompt,
|
||||
client_id=f"v38-resolution-{uuid.uuid4().hex}",
|
||||
timeout_seconds=args.timeout_seconds,
|
||||
poll_seconds=args.poll_seconds,
|
||||
)
|
||||
history_path = case_root / "history.json"
|
||||
history_path.write_text(
|
||||
json.dumps(history, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
media_path = _output_media(history, args.media_root)
|
||||
media = _probe_media(media_path, ffprobe)
|
||||
health = _media_health(media_path, ffmpeg)
|
||||
checks = {
|
||||
"geometry": (media["width"], media["height"])
|
||||
== (case.expected_width, case.expected_height),
|
||||
"frames": int(media["frames"]) == 120,
|
||||
"fps": str(media["fps"]) == "24/1",
|
||||
"duration": abs(float(media["format_duration"]) - 5.0) <= 0.02,
|
||||
"audio_rate": int(media["audio_sample_rate"]) == 32000,
|
||||
"audio_channels": int(media["audio_channels"]) == 2,
|
||||
"audio_finite": bool(health["audio_finite"]),
|
||||
"video_not_black_or_collapsed": bool(
|
||||
health["video_not_black_or_collapsed"]
|
||||
),
|
||||
}
|
||||
if not all(checks.values()):
|
||||
raise GateFailure(f"{case.name} failed: {checks}")
|
||||
result = {
|
||||
"case": asdict(case),
|
||||
"prompt_id": prompt_id,
|
||||
"api_elapsed_seconds": float(elapsed),
|
||||
"prompt": str(prompt_path),
|
||||
"history": str(history_path),
|
||||
"media": media,
|
||||
"health": health,
|
||||
"resource": monitor.as_dict(),
|
||||
"checks": checks,
|
||||
}
|
||||
results.append(result)
|
||||
print(
|
||||
f"V3.8 Resolution Gate PASS {case.name} "
|
||||
f"{media['width']}x{media['height']} {elapsed:.3f}s",
|
||||
flush=True,
|
||||
)
|
||||
summary = {
|
||||
"format": "h3-continuum-v38-main-resolution-gpu-gate-v1",
|
||||
"server": args.server,
|
||||
"backend_pid": args.backend_pid,
|
||||
"workflow": str(args.workflow),
|
||||
"workflow_sha256": _sha256(args.workflow),
|
||||
"image_name": args.image_name,
|
||||
"seed": args.seed,
|
||||
"dry_run": bool(args.dry_run),
|
||||
"pass": bool(not args.dry_run and len(results) == len(CASES)),
|
||||
"results": results,
|
||||
}
|
||||
(args.output_root / "gate_summary.json").write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
return summary
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8190")
|
||||
parser.add_argument("--workflow", type=Path, required=True)
|
||||
parser.add_argument("--output-root", type=Path, required=True)
|
||||
parser.add_argument("--media-root", type=Path, required=True)
|
||||
parser.add_argument("--image-name", required=True)
|
||||
parser.add_argument("--backend-pid", type=int, default=None)
|
||||
parser.add_argument("--seed", type=int, default=927966463230733)
|
||||
parser.add_argument("--timeout-seconds", type=float, default=1200.0)
|
||||
parser.add_argument("--poll-seconds", type=float, default=2.0)
|
||||
parser.add_argument("--monitor-interval", type=float, default=1.0)
|
||||
parser.add_argument("--dry-run", action="store_true")
|
||||
args = parser.parse_args()
|
||||
summary = run(args)
|
||||
print(json.dumps(summary, indent=2, ensure_ascii=False), flush=True)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,415 @@
|
||||
"""Run the Phase F Full-vs-Review GPU parity checkpoint.
|
||||
|
||||
This first checkpoint intentionally submits identical V3.8 sampler inputs for
|
||||
successive Review/Continue queues. It therefore exercises the same ComfyUI
|
||||
cache contract as a fixed-seed workflow instead of adding a test-only cache
|
||||
nonce that could hide a Production integration defect.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import Any, Mapping
|
||||
import uuid
|
||||
|
||||
|
||||
TOOLS_ROOT = Path(__file__).resolve().parent
|
||||
if str(TOOLS_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(TOOLS_ROOT))
|
||||
|
||||
from p32_api_runner import submit_and_wait
|
||||
from v36_r1_stress_gate_runner import ResourceMonitor
|
||||
from v38_easy_gpu_gate_runner import _output_media, _probe_media
|
||||
|
||||
|
||||
class GateFailure(RuntimeError):
|
||||
pass
|
||||
|
||||
|
||||
def _sha256_file(path: Path) -> str:
|
||||
digest = hashlib.sha256()
|
||||
with path.open("rb") as stream:
|
||||
for block in iter(lambda: stream.read(1024 * 1024), b""):
|
||||
digest.update(block)
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def _find_one(prompt: Mapping[str, Any], class_type: str) -> tuple[str, dict[str, Any]]:
|
||||
matches = [
|
||||
(str(node_id), node)
|
||||
for node_id, node in prompt.items()
|
||||
if str(node.get("class_type")) == class_type
|
||||
]
|
||||
if len(matches) != 1:
|
||||
raise GateFailure(f"expected one {class_type}, found {len(matches)}")
|
||||
return matches[0]
|
||||
|
||||
|
||||
def _build_prompt(
|
||||
template: Mapping[str, Any],
|
||||
*,
|
||||
run_name: str,
|
||||
generation_mode: str,
|
||||
review_action: str,
|
||||
output_prefix: str,
|
||||
seed: int,
|
||||
) -> dict[str, Any]:
|
||||
prompt = copy.deepcopy(dict(template))
|
||||
_, sampler = _find_one(prompt, "H3ContinuumSamplerV38")
|
||||
inputs = sampler["inputs"]
|
||||
inputs.update(
|
||||
{
|
||||
"aspect": "Landscape 16:9",
|
||||
"preset": "Draft — 0.30 MP",
|
||||
"custom_mp": 0.30,
|
||||
"chunks": 3,
|
||||
"chunk_seconds": 10.0,
|
||||
"base_seed": int(seed),
|
||||
"diagnostics": "Detailed Report",
|
||||
"reroll_from_chunk": "Auto",
|
||||
"reroll_nonce": 0,
|
||||
"strict_compatibility": False,
|
||||
"debug": True,
|
||||
"show_preview": False,
|
||||
"run_storage": "Save + Auto Resume",
|
||||
"run_name": run_name,
|
||||
"project_id": str(uuid.uuid5(uuid.NAMESPACE_URL, run_name)),
|
||||
"generation_mode": generation_mode,
|
||||
"review_action": review_action,
|
||||
}
|
||||
)
|
||||
_, save_video = _find_one(prompt, "SaveVideo")
|
||||
save_video["inputs"]["filename_prefix"] = output_prefix
|
||||
return prompt
|
||||
|
||||
|
||||
def _latest_manifest(run_root: Path) -> tuple[Path, dict[str, Any]]:
|
||||
candidates = list((run_root / "revisions").glob("*/manifest.json"))
|
||||
if not candidates:
|
||||
raise GateFailure(f"Run Storage manifest is missing: {run_root}")
|
||||
candidates.sort(key=lambda path: path.stat().st_mtime_ns, reverse=True)
|
||||
path = candidates[0]
|
||||
return path, json.loads(path.read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
def _tensor_sha256(path: Path, key: str) -> str:
|
||||
from safetensors import safe_open
|
||||
|
||||
with safe_open(path, framework="pt", device="cpu") as handle:
|
||||
tensor = handle.get_tensor(key).contiguous()
|
||||
digest = hashlib.sha256()
|
||||
digest.update(str(tensor.dtype).encode("ascii"))
|
||||
digest.update(json.dumps(list(tensor.shape), separators=(",", ":")).encode("ascii"))
|
||||
digest.update(tensor.numpy().tobytes(order="C"))
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
def _manifest_snapshot(run_root: Path) -> dict[str, Any]:
|
||||
manifest_path, manifest = _latest_manifest(run_root)
|
||||
revision_root = manifest_path.parent
|
||||
chunks = []
|
||||
for stored in manifest.get("chunks") or []:
|
||||
chunk_path = revision_root / "chunks" / str(stored["filename"])
|
||||
entry = dict(stored.get("entry") or {})
|
||||
chunks.append(
|
||||
{
|
||||
"sequence_index": int(stored["sequence_index"]),
|
||||
"filename": str(stored["filename"]),
|
||||
"file_sha256": _sha256_file(chunk_path),
|
||||
"manifest_file_sha256": str(stored["file_sha256"]),
|
||||
"video_latent_sha256": _tensor_sha256(chunk_path, "video"),
|
||||
"audio_latent_sha256": _tensor_sha256(chunk_path, "audio"),
|
||||
"seed": int(entry["seed"]),
|
||||
"prompt_hash": str(entry["prompt_hash"]),
|
||||
"plan": entry.get("plan"),
|
||||
}
|
||||
)
|
||||
return {
|
||||
"path": str(manifest_path),
|
||||
"mtime_ns": manifest_path.stat().st_mtime_ns,
|
||||
"status": str(manifest.get("status")),
|
||||
"review_control_version": manifest.get("review_control_version"),
|
||||
"review_pause_reason": manifest.get("review_pause_reason"),
|
||||
"review_unit": manifest.get("review_unit"),
|
||||
"branch_regenerate_from": manifest.get("branch_regenerate_from"),
|
||||
"effective_reroll_nonce": manifest.get("effective_reroll_nonce"),
|
||||
"chunks": chunks,
|
||||
"report_summary": str(manifest.get("report_summary") or ""),
|
||||
"manifest": manifest,
|
||||
}
|
||||
|
||||
|
||||
def _stream_sha256(command: list[str]) -> tuple[str, int]:
|
||||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
if process.stdout is None:
|
||||
raise GateFailure("failed to open ffmpeg stdout")
|
||||
digest = hashlib.sha256()
|
||||
size = 0
|
||||
while True:
|
||||
block = process.stdout.read(1024 * 1024)
|
||||
if not block:
|
||||
break
|
||||
digest.update(block)
|
||||
size += len(block)
|
||||
stderr = process.stderr.read().decode("utf-8", errors="replace") if process.stderr else ""
|
||||
code = process.wait()
|
||||
if code:
|
||||
raise GateFailure(f"ffmpeg raw decode failed ({code}): {stderr[-2000:]}")
|
||||
return digest.hexdigest(), size
|
||||
|
||||
|
||||
def _decoded_hashes(media_path: Path, ffmpeg: str, probe: Mapping[str, Any]) -> dict[str, Any]:
|
||||
video_sha, video_bytes = _stream_sha256(
|
||||
[
|
||||
ffmpeg,
|
||||
"-v",
|
||||
"error",
|
||||
"-i",
|
||||
str(media_path),
|
||||
"-map",
|
||||
"0:v:0",
|
||||
"-pix_fmt",
|
||||
"rgb24",
|
||||
"-f",
|
||||
"rawvideo",
|
||||
"-",
|
||||
]
|
||||
)
|
||||
pcm_sha, pcm_bytes = _stream_sha256(
|
||||
[
|
||||
ffmpeg,
|
||||
"-v",
|
||||
"error",
|
||||
"-i",
|
||||
str(media_path),
|
||||
"-map",
|
||||
"0:a:0",
|
||||
"-ac",
|
||||
"2",
|
||||
"-ar",
|
||||
"32000",
|
||||
"-c:a",
|
||||
"pcm_f32le",
|
||||
"-f",
|
||||
"f32le",
|
||||
"-",
|
||||
]
|
||||
)
|
||||
return {
|
||||
"raw_rgb24_sha256": video_sha,
|
||||
"raw_rgb24_bytes": video_bytes,
|
||||
"pcm_f32le_32k_stereo_sha256": pcm_sha,
|
||||
"pcm_f32le_32k_stereo_bytes": pcm_bytes,
|
||||
"decoded_frames": int(probe["frames"]),
|
||||
"width": int(probe["width"]),
|
||||
"height": int(probe["height"]),
|
||||
"fps": str(probe["fps"]),
|
||||
"audio_sample_rate": int(probe["audio_sample_rate"]),
|
||||
"audio_channels": int(probe["audio_channels"]),
|
||||
"format_duration": float(probe["format_duration"]),
|
||||
}
|
||||
|
||||
|
||||
def _run_queue(
|
||||
args: argparse.Namespace,
|
||||
*,
|
||||
name: str,
|
||||
prompt: dict[str, Any],
|
||||
run_root: Path,
|
||||
) -> dict[str, Any]:
|
||||
case_root = args.output_root / name
|
||||
case_root.mkdir(parents=True, exist_ok=True)
|
||||
prompt_path = case_root / "prompt.json"
|
||||
prompt_path.write_text(json.dumps(prompt, indent=2, ensure_ascii=False), encoding="utf-8")
|
||||
print(f"Phase F queue start: {name}", flush=True)
|
||||
with ResourceMonitor(args.backend_pid, args.monitor_interval) as monitor:
|
||||
prompt_id, history, elapsed = submit_and_wait(
|
||||
server=args.server,
|
||||
prompt=prompt,
|
||||
client_id=f"v38-phase-f-{uuid.uuid4().hex}",
|
||||
timeout_seconds=args.timeout_seconds,
|
||||
poll_seconds=args.poll_seconds,
|
||||
)
|
||||
history_path = case_root / "history.json"
|
||||
history_path.write_text(json.dumps(history, indent=2, ensure_ascii=False), encoding="utf-8")
|
||||
media_path = _output_media(history, args.media_root)
|
||||
ffprobe = shutil.which("ffprobe")
|
||||
ffmpeg = shutil.which("ffmpeg")
|
||||
if not ffprobe or not ffmpeg:
|
||||
raise GateFailure("ffmpeg and ffprobe are required")
|
||||
media = _probe_media(media_path, ffprobe)
|
||||
decoded = _decoded_hashes(media_path, ffmpeg, media)
|
||||
storage = _manifest_snapshot(run_root)
|
||||
result = {
|
||||
"name": name,
|
||||
"prompt_id": prompt_id,
|
||||
"api_elapsed_seconds": float(elapsed),
|
||||
"prompt": str(prompt_path),
|
||||
"history": str(history_path),
|
||||
"media_path": str(media_path),
|
||||
"media_file_sha256": _sha256_file(media_path),
|
||||
"media": media,
|
||||
"decoded": decoded,
|
||||
"resource": monitor.as_dict(),
|
||||
"run_storage": storage,
|
||||
}
|
||||
(case_root / "summary.json").write_text(
|
||||
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
print(
|
||||
f"Phase F queue end: {name}; chunks={len(storage['chunks'])}; "
|
||||
f"status={storage['status']}; {elapsed:.3f}s",
|
||||
flush=True,
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
def _parity(full: Mapping[str, Any], review: Mapping[str, Any]) -> dict[str, Any]:
|
||||
full_chunks = full["run_storage"]["chunks"]
|
||||
review_chunks = review["run_storage"]["chunks"]
|
||||
fields = ("seed", "prompt_hash", "video_latent_sha256", "audio_latent_sha256", "plan")
|
||||
chunk_checks = []
|
||||
for index in range(max(len(full_chunks), len(review_chunks))):
|
||||
if index >= len(full_chunks) or index >= len(review_chunks):
|
||||
chunk_checks.append({"index": index + 1, "present": False})
|
||||
continue
|
||||
checks = {field: full_chunks[index][field] == review_chunks[index][field] for field in fields}
|
||||
chunk_checks.append({"index": index + 1, "present": True, "checks": checks})
|
||||
decoded_fields = (
|
||||
"raw_rgb24_sha256",
|
||||
"pcm_f32le_32k_stereo_sha256",
|
||||
"decoded_frames",
|
||||
"width",
|
||||
"height",
|
||||
"fps",
|
||||
"audio_sample_rate",
|
||||
"audio_channels",
|
||||
"format_duration",
|
||||
)
|
||||
decoded_checks = {
|
||||
field: full["decoded"][field] == review["decoded"][field]
|
||||
for field in decoded_fields
|
||||
}
|
||||
passed = (
|
||||
len(full_chunks) == len(review_chunks) == 3
|
||||
and all(item.get("present") and all(item["checks"].values()) for item in chunk_checks)
|
||||
and all(decoded_checks.values())
|
||||
)
|
||||
return {"pass": passed, "chunks": chunk_checks, "decoded": decoded_checks}
|
||||
|
||||
|
||||
def run(args: argparse.Namespace) -> dict[str, Any]:
|
||||
args.output_root.mkdir(parents=True, exist_ok=True)
|
||||
template = json.loads(args.template_prompt.read_text(encoding="utf-8"))
|
||||
stamp = args.run_tag
|
||||
full_run_name = f"v38_phase_f_g0_full_{stamp}"
|
||||
review_run_name = f"v38_phase_f_g1_review_{stamp}"
|
||||
runs_root = args.run_storage_root
|
||||
summary: dict[str, Any] = {
|
||||
"format": "h3-continuum-v38-review-phase-f-g0-g1-v1",
|
||||
"server": args.server,
|
||||
"backend_pid": args.backend_pid,
|
||||
"template_prompt": str(args.template_prompt),
|
||||
"template_prompt_sha256": _sha256_file(args.template_prompt),
|
||||
"seed": int(args.seed),
|
||||
"run_names": {"g0": full_run_name, "g1": review_run_name},
|
||||
"pass": False,
|
||||
"stopped": False,
|
||||
"results": {},
|
||||
}
|
||||
summary_path = args.output_root / "gate_summary.json"
|
||||
try:
|
||||
g0_prompt = _build_prompt(
|
||||
template,
|
||||
run_name=full_run_name,
|
||||
generation_mode="Full Run",
|
||||
review_action="Continue / Next",
|
||||
output_prefix=f"v38_phase_f/{stamp}/g0_full",
|
||||
seed=args.seed,
|
||||
)
|
||||
g0 = _run_queue(
|
||||
args,
|
||||
name="g0_full",
|
||||
prompt=g0_prompt,
|
||||
run_root=runs_root / full_run_name,
|
||||
)
|
||||
summary["results"]["g0"] = g0
|
||||
if len(g0["run_storage"]["chunks"]) != 3 or g0["run_storage"]["status"] != "complete":
|
||||
raise GateFailure("G0 Full baseline did not complete exactly three chunks")
|
||||
|
||||
review_results = []
|
||||
previous_mtime = None
|
||||
for queue_index in range(1, 4):
|
||||
prompt = _build_prompt(
|
||||
template,
|
||||
run_name=review_run_name,
|
||||
generation_mode="Review Each Chunk",
|
||||
review_action="Continue / Next",
|
||||
output_prefix=f"v38_phase_f/{stamp}/g1_review_q{queue_index}",
|
||||
seed=args.seed,
|
||||
)
|
||||
result = _run_queue(
|
||||
args,
|
||||
name=f"g1_review_q{queue_index}",
|
||||
prompt=prompt,
|
||||
run_root=runs_root / review_run_name,
|
||||
)
|
||||
review_results.append(result)
|
||||
summary["results"]["g1"] = review_results
|
||||
actual_chunks = len(result["run_storage"]["chunks"])
|
||||
expected_status = "complete" if queue_index == 3 else "review_ready"
|
||||
if actual_chunks != queue_index or result["run_storage"]["status"] != expected_status:
|
||||
unchanged = previous_mtime == result["run_storage"]["mtime_ns"]
|
||||
raise GateFailure(
|
||||
"G1 Review queue progression failed: "
|
||||
f"queue={queue_index}, chunks={actual_chunks}, "
|
||||
f"status={result['run_storage']['status']}, "
|
||||
f"manifest_unchanged={unchanged}"
|
||||
)
|
||||
previous_mtime = result["run_storage"]["mtime_ns"]
|
||||
|
||||
parity = _parity(g0, review_results[-1])
|
||||
summary["parity"] = parity
|
||||
if not parity["pass"]:
|
||||
raise GateFailure("G0 Full and G1 Review exact parity failed")
|
||||
summary["pass"] = True
|
||||
return summary
|
||||
except Exception as exc:
|
||||
summary["stopped"] = True
|
||||
summary["failure_type"] = type(exc).__name__
|
||||
summary["failure"] = str(exc)
|
||||
return summary
|
||||
finally:
|
||||
summary_path.write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8190")
|
||||
parser.add_argument("--template-prompt", type=Path, required=True)
|
||||
parser.add_argument("--output-root", type=Path, required=True)
|
||||
parser.add_argument("--media-root", type=Path, required=True)
|
||||
parser.add_argument("--run-storage-root", type=Path, required=True)
|
||||
parser.add_argument("--run-tag", required=True)
|
||||
parser.add_argument("--backend-pid", type=int, default=None)
|
||||
parser.add_argument("--seed", type=int, default=927966463230733)
|
||||
parser.add_argument("--timeout-seconds", type=float, default=2400.0)
|
||||
parser.add_argument("--poll-seconds", type=float, default=2.0)
|
||||
parser.add_argument("--monitor-interval", type=float, default=1.0)
|
||||
args = parser.parse_args()
|
||||
summary = run(args)
|
||||
print(json.dumps(summary, indent=2, ensure_ascii=False), flush=True)
|
||||
return 0 if summary["pass"] else 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -0,0 +1,197 @@
|
||||
"""Resume the stopped Phase F G1 run after the Review cache fix.
|
||||
|
||||
The failed Queue 2 prompt is submitted unchanged for both recovery queues. This
|
||||
keeps the sampler inputs (and the complete API graph) identical while proving
|
||||
that Review mode no longer reuses the sampler's ComfyUI output cache.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import copy
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Any, Mapping
|
||||
|
||||
from v38_review_phase_f_gpu_gate_runner import (
|
||||
GateFailure,
|
||||
_find_one,
|
||||
_manifest_snapshot,
|
||||
_parity,
|
||||
_run_queue,
|
||||
_sha256_file,
|
||||
)
|
||||
|
||||
|
||||
def _cached_nodes(history: Mapping[str, Any]) -> set[str]:
|
||||
nodes: set[str] = set()
|
||||
for prompt_history in history.values():
|
||||
for message in (prompt_history.get("status") or {}).get("messages") or []:
|
||||
if len(message) != 2 or message[0] != "execution_cached":
|
||||
continue
|
||||
nodes.update(str(node_id) for node_id in (message[1].get("nodes") or []))
|
||||
return nodes
|
||||
|
||||
|
||||
def _chunk_identity(chunk: Mapping[str, Any]) -> dict[str, Any]:
|
||||
fields = (
|
||||
"sequence_index",
|
||||
"file_sha256",
|
||||
"video_latent_sha256",
|
||||
"audio_latent_sha256",
|
||||
"seed",
|
||||
"prompt_hash",
|
||||
"plan",
|
||||
)
|
||||
return {field: copy.deepcopy(chunk[field]) for field in fields}
|
||||
|
||||
|
||||
def _preserved_prefix(before: Mapping[str, Any], after: Mapping[str, Any]) -> bool:
|
||||
before_chunks = before["chunks"]
|
||||
after_chunks = after["chunks"]
|
||||
return len(after_chunks) >= len(before_chunks) and all(
|
||||
_chunk_identity(old) == _chunk_identity(after_chunks[index])
|
||||
for index, old in enumerate(before_chunks)
|
||||
)
|
||||
|
||||
|
||||
def _sampler_inputs(prompt: Mapping[str, Any]) -> tuple[str, Mapping[str, Any]]:
|
||||
node_id, sampler = _find_one(prompt, "H3ContinuumSamplerV38")
|
||||
return node_id, sampler["inputs"]
|
||||
|
||||
|
||||
def run(args: argparse.Namespace) -> dict[str, Any]:
|
||||
args.output_root.mkdir(parents=True, exist_ok=True)
|
||||
prior = json.loads(args.prior_summary.read_text(encoding="utf-8"))
|
||||
g0 = prior["results"]["g0"]
|
||||
failed_q2 = prior["results"]["g1"][-1]
|
||||
prompt_path = Path(failed_q2["prompt"])
|
||||
prompt = json.loads(prompt_path.read_text(encoding="utf-8"))
|
||||
sampler_id, sampler_inputs = _sampler_inputs(prompt)
|
||||
review_run_name = str(prior["run_names"]["g1"])
|
||||
run_root = args.run_storage_root / review_run_name
|
||||
before = _manifest_snapshot(run_root)
|
||||
summary: dict[str, Any] = {
|
||||
"format": "h3-continuum-v38-review-phase-f-r1-recovery-v1",
|
||||
"server": args.server,
|
||||
"backend_pid": args.backend_pid,
|
||||
"prior_summary": str(args.prior_summary),
|
||||
"failed_queue_prompt": str(prompt_path),
|
||||
"failed_queue_prompt_sha256": _sha256_file(prompt_path),
|
||||
"sampler_node_id": sampler_id,
|
||||
"sampler_inputs": sampler_inputs,
|
||||
"run_name": review_run_name,
|
||||
"initial_run_storage": before,
|
||||
"pass": False,
|
||||
"stopped": False,
|
||||
"results": {},
|
||||
}
|
||||
summary_path = args.output_root / "recovery_summary.json"
|
||||
try:
|
||||
if len(before["chunks"]) != 1 or before["status"] != "review_ready":
|
||||
raise GateFailure(
|
||||
"Recovery must start at Chunk 1 review_ready: "
|
||||
f"chunks={len(before['chunks'])}, status={before['status']}"
|
||||
)
|
||||
|
||||
q2 = _run_queue(
|
||||
args,
|
||||
name="g1_recovery_q2",
|
||||
prompt=prompt,
|
||||
run_root=run_root,
|
||||
)
|
||||
q2_cached = sorted(_cached_nodes(json.loads(Path(q2["history"]).read_text(encoding="utf-8"))))
|
||||
q2_storage = q2["run_storage"]
|
||||
q2_checks = {
|
||||
"exact_failed_prompt_reused": _sha256_file(Path(q2["prompt"]))
|
||||
== summary["failed_queue_prompt_sha256"],
|
||||
"sampler_not_cached": sampler_id not in q2_cached,
|
||||
"status_review_ready": q2_storage["status"] == "review_ready",
|
||||
"exactly_two_chunks": len(q2_storage["chunks"]) == 2,
|
||||
"exactly_one_new_physical_chunk": len(q2_storage["chunks"])
|
||||
== len(before["chunks"]) + 1,
|
||||
"chunk_1_exactly_reused": _preserved_prefix(before, q2_storage),
|
||||
"manifest_updated": q2_storage["mtime_ns"] != before["mtime_ns"],
|
||||
}
|
||||
summary["results"]["q2"] = {
|
||||
**q2,
|
||||
"cached_nodes": q2_cached,
|
||||
"checks": q2_checks,
|
||||
}
|
||||
if not all(q2_checks.values()):
|
||||
raise GateFailure(f"Recovery Queue 2 failed: {q2_checks}")
|
||||
|
||||
q3 = _run_queue(
|
||||
args,
|
||||
name="g1_recovery_q3",
|
||||
prompt=prompt,
|
||||
run_root=run_root,
|
||||
)
|
||||
q3_cached = sorted(_cached_nodes(json.loads(Path(q3["history"]).read_text(encoding="utf-8"))))
|
||||
q3_storage = q3["run_storage"]
|
||||
q3_checks = {
|
||||
"same_prompt_as_queue_2": _sha256_file(Path(q3["prompt"]))
|
||||
== _sha256_file(Path(q2["prompt"])),
|
||||
"sampler_not_cached": sampler_id not in q3_cached,
|
||||
"status_complete": q3_storage["status"] == "complete",
|
||||
"exactly_three_chunks": len(q3_storage["chunks"]) == 3,
|
||||
"exactly_one_new_physical_chunk": len(q3_storage["chunks"])
|
||||
== len(q2_storage["chunks"]) + 1,
|
||||
"chunks_1_2_exactly_reused": _preserved_prefix(q2_storage, q3_storage),
|
||||
"manifest_updated": q3_storage["mtime_ns"] != q2_storage["mtime_ns"],
|
||||
}
|
||||
parity = _parity(g0, q3)
|
||||
summary["results"]["q3"] = {
|
||||
**q3,
|
||||
"cached_nodes": q3_cached,
|
||||
"checks": q3_checks,
|
||||
}
|
||||
summary["parity"] = parity
|
||||
if not all(q3_checks.values()):
|
||||
raise GateFailure(f"Recovery Queue 3 failed: {q3_checks}")
|
||||
if not parity["pass"]:
|
||||
raise GateFailure("Recovered G1 does not exactly match the Phase F G0 baseline")
|
||||
summary["pass"] = True
|
||||
return summary
|
||||
except Exception as exc:
|
||||
summary["stopped"] = True
|
||||
summary["failure_type"] = type(exc).__name__
|
||||
summary["failure"] = str(exc)
|
||||
return summary
|
||||
finally:
|
||||
summary_path.write_text(
|
||||
json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--server", default="http://127.0.0.6:8190")
|
||||
parser.add_argument("--prior-summary", type=Path, required=True)
|
||||
parser.add_argument("--output-root", type=Path, required=True)
|
||||
parser.add_argument("--media-root", type=Path, required=True)
|
||||
parser.add_argument("--run-storage-root", type=Path, required=True)
|
||||
parser.add_argument("--backend-pid", type=int, default=None)
|
||||
parser.add_argument("--timeout-seconds", type=float, default=2400.0)
|
||||
parser.add_argument("--poll-seconds", type=float, default=2.0)
|
||||
parser.add_argument("--monitor-interval", type=float, default=1.0)
|
||||
args = parser.parse_args()
|
||||
summary = run(args)
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"pass": summary["pass"],
|
||||
"stopped": summary["stopped"],
|
||||
"failure": summary.get("failure"),
|
||||
"summary": str(args.output_root / "recovery_summary.json"),
|
||||
},
|
||||
indent=2,
|
||||
ensure_ascii=False,
|
||||
),
|
||||
flush=True,
|
||||
)
|
||||
return 0 if summary["pass"] else 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
+29
-29
@@ -1,29 +1,29 @@
|
||||
param(
|
||||
[string]$Python = 'python',
|
||||
[string]$ComfyRoot = '',
|
||||
[switch]$SkipTests,
|
||||
[switch]$SkipRuntime
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$repository = Split-Path -Parent $PSScriptRoot
|
||||
Push-Location $repository
|
||||
try {
|
||||
& $Python -m compileall -q .
|
||||
if ($LASTEXITCODE -ne 0) { throw 'compileall failed' }
|
||||
|
||||
if (-not $SkipTests) {
|
||||
& $Python -m pytest -q
|
||||
if ($LASTEXITCODE -ne 0) { throw 'pytest failed' }
|
||||
}
|
||||
|
||||
if (-not $SkipRuntime) {
|
||||
$arguments = @('tools/verify_runtime.py')
|
||||
if ($ComfyRoot) { $arguments += @('--comfy-root', $ComfyRoot) }
|
||||
& $Python @arguments
|
||||
if ($LASTEXITCODE -ne 0) { throw 'runtime verification failed' }
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
param(
|
||||
[string]$Python = 'python',
|
||||
[string]$ComfyRoot = '',
|
||||
[switch]$SkipTests,
|
||||
[switch]$SkipRuntime
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$repository = Split-Path -Parent $PSScriptRoot
|
||||
Push-Location $repository
|
||||
try {
|
||||
& $Python -m compileall -q .
|
||||
if ($LASTEXITCODE -ne 0) { throw 'compileall failed' }
|
||||
|
||||
if (-not $SkipTests) {
|
||||
& $Python -m pytest -q
|
||||
if ($LASTEXITCODE -ne 0) { throw 'pytest failed' }
|
||||
}
|
||||
|
||||
if (-not $SkipRuntime) {
|
||||
$arguments = @('tools/verify_runtime.py')
|
||||
if ($ComfyRoot) { $arguments += @('--comfy-root', $ComfyRoot) }
|
||||
& $Python @arguments
|
||||
if ($LASTEXITCODE -ne 0) { throw 'runtime verification failed' }
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
+47
-40
@@ -8,6 +8,17 @@ import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
EXPECTED_PUBLIC_NODE_DISPLAY_NAMES = {
|
||||
"H3ContinuumSamplerV38": "H3 Continuum Sampler V3.8",
|
||||
"H3ContinuumReferenceAudios": "H3 Continuum Reference Audios",
|
||||
"H3ContinuumAssembleSeamV35": "H3 Continuum Finalize",
|
||||
"H3EasyLoadImage": "H3 Continuum Load Image",
|
||||
"H3EasyLoadAudio": "H3 Continuum Load Audio",
|
||||
"H3ContinuumLoadVideo": "H3 Continuum Load Video",
|
||||
"H3ContinuumSecondPassV35": "H3 Continuum Second Pass",
|
||||
}
|
||||
|
||||
|
||||
def load_package(root: Path):
|
||||
name = "h3_continuum_join_verify"
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
@@ -23,6 +34,35 @@ def load_package(root: Path):
|
||||
return module
|
||||
|
||||
|
||||
def public_registration_issues(module) -> list[str]:
|
||||
"""Return exact public-surface differences for the installed V3.8 package."""
|
||||
|
||||
expected = EXPECTED_PUBLIC_NODE_DISPLAY_NAMES
|
||||
actual_classes = set(getattr(module, "NODE_CLASS_MAPPINGS", {}))
|
||||
expected_classes = set(expected)
|
||||
issues: list[str] = []
|
||||
if actual_classes != expected_classes:
|
||||
missing = sorted(expected_classes - actual_classes)
|
||||
extra = sorted(actual_classes - expected_classes)
|
||||
if missing:
|
||||
issues.append(f"missing public node IDs: {missing}")
|
||||
if extra:
|
||||
issues.append(f"unexpected public node IDs: {extra}")
|
||||
|
||||
actual_names = dict(getattr(module, "NODE_DISPLAY_NAME_MAPPINGS", {}))
|
||||
for node_id, display_name in expected.items():
|
||||
actual_name = actual_names.get(node_id)
|
||||
if actual_name != display_name:
|
||||
issues.append(
|
||||
f"display name mismatch for {node_id}: "
|
||||
f"expected {display_name!r}, got {actual_name!r}"
|
||||
)
|
||||
unexpected_names = sorted(set(actual_names) - expected_classes)
|
||||
if unexpected_names:
|
||||
issues.append(f"unexpected display-name IDs: {unexpected_names}")
|
||||
return issues
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--comfy-root", type=Path, required=True)
|
||||
@@ -65,47 +105,14 @@ def main() -> int:
|
||||
print(f"V2 prompt/session core self-test FAILED: {exc}")
|
||||
return 1
|
||||
|
||||
current_required = {
|
||||
"H3ContinuumSamplerV34",
|
||||
"H3ContinuumSamplerV35",
|
||||
"H3ContinuumSamplerV36",
|
||||
"H3ContinuumSamplerV37",
|
||||
"H3ContinuumStillImageGuideV37",
|
||||
"H3ContinuumAssembleSeamV34",
|
||||
"H3ContinuumAssembleSeamV35",
|
||||
"H3ContinuumHiResFixV35",
|
||||
"H3ContinuumLatentResizeV35",
|
||||
"H3ContinuumSecondPassV35",
|
||||
"H3ContinuumConditioningBridgeV35",
|
||||
"H3ContinuumClipOverrides",
|
||||
"H3ContinuumResult",
|
||||
}
|
||||
legacy_required = {
|
||||
"H3ContinuumJoin",
|
||||
"H3ContinuumFinish",
|
||||
"H3ContinuumAssemble",
|
||||
"H3ContinuumSaveState",
|
||||
"H3ContinuumLoadState",
|
||||
"H3ContinuumSamplerV2",
|
||||
"H3ContinuumPromptPlanPreview",
|
||||
"H3ContinuumSaveSession",
|
||||
"H3ContinuumLoadSession",
|
||||
"H3ContinuumSessionInfo",
|
||||
"H3ContinuumSampler",
|
||||
"H3ContinuumAdvanced",
|
||||
"H3ContinuumSamplerProduction",
|
||||
"H3ContinuumSamplerTimelineVideo",
|
||||
"H3ContinuumSamplerV3",
|
||||
"H3ContinuumAdvancedV3",
|
||||
"H3ContinuumAssembleV3",
|
||||
"H3ContinuumAssembleSeamExperimental",
|
||||
}
|
||||
expected = current_required | legacy_required
|
||||
actual = set(module.NODE_CLASS_MAPPINGS)
|
||||
if actual != expected:
|
||||
print(f"Node registration mismatch: expected {sorted(expected)}, got {sorted(actual)}")
|
||||
registration_issues = public_registration_issues(module)
|
||||
if registration_issues:
|
||||
print("H3 Continuum V3.8 public-node verification FAILED:")
|
||||
for issue in registration_issues:
|
||||
print(f" - {issue}")
|
||||
return 1
|
||||
print(f"H3 Continuum Join {PACKAGE_VERSION} runtime verification passed.")
|
||||
actual = set(module.NODE_CLASS_MAPPINGS)
|
||||
print(f"H3 Continuum {PACKAGE_VERSION} runtime verification passed.")
|
||||
print(layout_report)
|
||||
print(f"V{PACKAGE_VERSION} Fixed 3x5s prompt-plan self-test passed.")
|
||||
print("Registered nodes:")
|
||||
|
||||
Reference in New Issue
Block a user