Release v3.6.1 compatibility hotfix

This commit is contained in:
ukr8b3g-cmyk
2026-08-28 00:59:08 +09:00
parent e626053893
commit 8dec0b7ceb
36 changed files with 3469 additions and 74 deletions
+194
View File
@@ -0,0 +1,194 @@
"""Analyze finalized Audio Continuity research outputs without changing them."""
from __future__ import annotations
import argparse
import hashlib
import importlib.util
import json
from pathlib import Path
import subprocess
import sys
from typing import Any
import numpy as np
import torch
from v36_r2_audio_boundary_analyze import _decode_audio, boundary_metrics
ROOT = Path(__file__).resolve().parents[1]
PACKAGE_NAME = "ComfyUI_H3_Continuum_Join"
def _load_package() -> None:
if PACKAGE_NAME in sys.modules:
return
spec = importlib.util.spec_from_file_location(
PACKAGE_NAME,
ROOT / "__init__.py",
submodule_search_locations=[str(ROOT)],
)
if spec is None:
raise RuntimeError("could not create the Continuum package spec")
module = importlib.util.module_from_spec(spec)
module.__path__ = [str(ROOT)]
sys.modules[PACKAGE_NAME] = module
_load_package()
from ComfyUI_H3_Continuum_Join.v2.seam_guard import _correlation # noqa: E402
def _window_rms_floor(value: np.ndarray, *, sample_rate: int) -> float:
frame = max(1, int(round(sample_rate * 0.010)))
usable = len(value) // frame * frame
if usable <= 0:
return 0.0
blocks = value[:usable].reshape(-1, frame, value.shape[1])
rms = np.sqrt(np.mean(np.square(blocks), axis=(1, 2)))
return float(np.percentile(rms, 10))
def _adjacent_alignment(
audio: np.ndarray,
*,
sample_rate: int,
boundary_sample: int,
) -> dict[str, Any]:
mono = torch.from_numpy(audio.mean(axis=1).astype(np.float32, copy=False))
window = max(8, int(round(sample_rate * 0.080)))
max_lag = max(1, int(round(sample_rate * 0.020)))
before = mono[:boundary_sample]
after = mono[boundary_sample:]
if before.numel() < window + max_lag or after.numel() < window + max_lag:
raise ValueError("insufficient decoded audio for adjacent-window alignment")
def correlation_at(lag: int) -> float:
if lag >= 0:
left = before[-window:]
right = after[lag : lag + window]
else:
stop = int(before.numel()) + lag
left = before[stop - window : stop]
right = after[:window]
return float(_correlation(left, right))
baseline = correlation_at(0)
candidates = [(lag, correlation_at(lag)) for lag in range(-max_lag, max_lag + 1)]
best_lag, best_correlation = max(candidates, key=lambda item: item[1])
return {
"window_ms": 80.0,
"search_ms": 20.0,
"correlation_at_zero": baseline,
"best_correlation": best_correlation,
"best_lag_samples": int(best_lag),
"best_lag_ms": float(best_lag * 1000.0 / sample_rate),
}
def _probe(path: Path, ffprobe: Path) -> dict[str, Any]:
completed = subprocess.run(
[
str(ffprobe),
"-v",
"error",
"-count_frames",
"-show_entries",
"stream=index,codec_type,width,height,nb_read_frames,duration,sample_rate,channels",
"-show_entries",
"format=duration",
"-of",
"json",
str(path),
],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)
return json.loads(completed.stdout)
def analyze(
path: Path,
*,
ffmpeg: Path,
ffprobe: Path,
sample_rate: int,
fps: float,
boundary_frames: list[int],
expected_frames: int,
) -> dict[str, Any]:
audio = _decode_audio(path, ffmpeg, sample_rate)
pcm = audio.astype("<f4", copy=False).tobytes(order="C")
boundaries: list[dict[str, Any]] = []
long = max(1, int(round(sample_rate * 0.250)))
for frame in boundary_frames:
sample = int(round(frame * sample_rate / fps))
before = audio[max(0, sample - long) : sample]
after = audio[sample : min(len(audio), sample + long)]
boundaries.append(
{
"frame": int(frame),
**boundary_metrics(audio, sample_rate=sample_rate, boundary_sample=sample),
**_adjacent_alignment(
audio,
sample_rate=sample_rate,
boundary_sample=sample,
),
"rms_floor_before_250ms_p10_10ms": _window_rms_floor(
before, sample_rate=sample_rate
),
"rms_floor_after_250ms_p10_10ms": _window_rms_floor(
after, sample_rate=sample_rate
),
}
)
expected_duration = expected_frames / fps
decoded_duration = len(audio) / sample_rate
return {
"format": "h3-continuum-audio-continuity-output-analysis-v1",
"path": str(path),
"sample_rate": int(sample_rate),
"fps": float(fps),
"expected_frames": int(expected_frames),
"expected_duration_seconds": expected_duration,
"decoded_samples_per_channel": int(len(audio)),
"decoded_duration_seconds": decoded_duration,
"decoded_duration_error_seconds": decoded_duration - expected_duration,
"pcm_f32le_md5": hashlib.md5(pcm).hexdigest(),
"finite": bool(np.isfinite(audio).all()),
"probe": _probe(path, ffprobe),
"boundaries": boundaries,
}
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--input", type=Path, required=True)
parser.add_argument("--result", type=Path, required=True)
parser.add_argument("--ffmpeg", type=Path, default=Path(r"C:\FFmpeg\bin\ffmpeg.exe"))
parser.add_argument("--ffprobe", type=Path, default=Path(r"C:\FFmpeg\bin\ffprobe.exe"))
parser.add_argument("--sample-rate", type=int, default=32000)
parser.add_argument("--fps", type=float, default=24.0)
parser.add_argument("--expected-frames", type=int, default=360)
parser.add_argument("--boundary-frames", type=int, nargs="+", default=[124, 243])
args = parser.parse_args()
result = analyze(
args.input,
ffmpeg=args.ffmpeg,
ffprobe=args.ffprobe,
sample_rate=args.sample_rate,
fps=args.fps,
boundary_frames=list(args.boundary_frames),
expected_frames=args.expected_frames,
)
args.result.parent.mkdir(parents=True, exist_ok=True)
args.result.write_text(json.dumps(result, indent=2), encoding="utf-8")
print(json.dumps(result))
return 0
if __name__ == "__main__":
raise SystemExit(main())
+163
View File
@@ -0,0 +1,163 @@
"""Run the research-only Reference 22f/37T vs 22f/40T GPU screen."""
from __future__ import annotations
import argparse
import json
from pathlib import Path
import sys
import time
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,
_extract_evidence,
configure_prompt,
)
PROMPTS = {
"music": (
"A continuous cinematic performance driven by a steady electronic dance "
"beat at 120 BPM. The percussion, bass pulse, and musical phrase continue "
"without stopping while the camera glides smoothly through a neon studio."
),
"dialogue": (
"A single radio host speaks continuously in a calm natural voice inside a "
"quiet studio, maintaining the same speaker, room tone, cadence, and breath "
"throughout the shot. <d>Tonight we follow the lights along the harbor, and "
"every turn reveals another part of the city.</d>"
),
"ambient": (
"A continuous locked cinematic shot of steady rain falling outside a quiet "
"workshop. Rainfall, a low ventilation hum, and distant machinery form an "
"uninterrupted ambient sound bed with stable texture and level."
),
}
TRANSPORTS = {
"baseline37": "reference_context_v1",
"experimental40": "reference_context_audio40_research_v1",
}
def _configure(source, *, label, transport, seed, output_prefix, nonce):
prompt = configure_prompt(
source,
transport=transport,
output_prefix=output_prefix,
seed=seed,
chunks=3,
synchronize_sampling=True,
diagnostic_nonce=nonce,
)
prompt["188"]["inputs"]["value"] = PROMPTS[label]
prompt["305"]["inputs"].update(
{
"width": 576,
"height": 576,
"audio_continuity": True,
"continuation_transport": transport,
}
)
prompt["306"]["inputs"].update(
{
"audio_seam": "Off",
"video_seam": "Off",
"exact_total_duration": True,
}
)
prompt["191"]["inputs"]["filename_prefix"] = output_prefix
return prompt
def _run_one(args, source, *, content, variant, order_index):
transport = TRANSPORTS[variant]
run_root = args.output_root / f"{order_index:02d}_{content}_{variant}"
run_root.mkdir(parents=True, exist_ok=True)
output_prefix = f"video/AudioResearch_{content}_{variant}_seed{args.seed}"
prompt = _configure(
source,
label=content,
transport=transport,
seed=args.seed,
output_prefix=output_prefix,
nonce=order_index,
)
prompt_path = run_root / "prompt.json"
prompt_path.write_text(json.dumps(prompt, indent=2), encoding="utf-8")
with ResourceMonitor(args.backend_pid) as monitor:
prompt_id, history, elapsed = submit_and_wait(
server=args.server,
prompt=prompt,
client_id=f"audio-research-{uuid.uuid4().hex}",
timeout_seconds=args.timeout_seconds,
poll_seconds=2.0,
)
history_path = run_root / "history.json"
history_path.write_text(json.dumps(history, indent=2), encoding="utf-8")
summary = {
"content": content,
"variant": variant,
"transport": transport,
"seed": args.seed,
"prompt_id": prompt_id,
"api_elapsed_seconds": elapsed,
"resources": monitor.as_dict(),
"evidence": _extract_evidence(history),
"output_prefix": output_prefix,
"prompt": str(prompt_path),
"history": str(history_path),
}
(run_root / "summary.json").write_text(
json.dumps(summary, indent=2), encoding="utf-8"
)
return summary
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--prompt", type=Path, required=True)
parser.add_argument("--output-root", type=Path, required=True)
parser.add_argument("--server", default="http://127.0.0.6:8188")
parser.add_argument("--seed", type=int, default=238985343135609)
parser.add_argument("--backend-pid", type=int, default=None)
parser.add_argument("--timeout-seconds", type=float, default=2400.0)
args = parser.parse_args()
source = json.loads(args.prompt.read_text(encoding="utf-8"))
args.output_root.mkdir(parents=True, exist_ok=True)
schedule = (
("music", "baseline37"),
("music", "experimental40"),
("dialogue", "experimental40"),
("dialogue", "baseline37"),
("ambient", "baseline37"),
("ambient", "experimental40"),
)
started = time.perf_counter()
results = [
_run_one(args, source, content=content, variant=variant, order_index=index)
for index, (content, variant) in enumerate(schedule, start=1)
]
aggregate = {
"format": "h3-continuum-audio-context-research-v1",
"elapsed_seconds": time.perf_counter() - started,
"schedule": [list(item) for item in schedule],
"results": results,
}
(args.output_root / "aggregate.json").write_text(
json.dumps(aggregate, indent=2), encoding="utf-8"
)
print(json.dumps(aggregate, ensure_ascii=False))
return 0
if __name__ == "__main__":
raise SystemExit(main())
+44 -1
View File
@@ -786,6 +786,7 @@ class H3ContinuumMaskedPrefixR1Diagnostic:
required["continuation_transport"] = (
(
"reference_context_v1",
"reference_context_audio40_research_v1",
"masked_video_prefix_v1",
"masked_av_prefix_22_v1",
"masked_av_prefix_39_v1",
@@ -827,6 +828,7 @@ class H3ContinuumMaskedPrefixR1Diagnostic:
transport = str(continuation_transport)
if transport not in (
"reference_context_v1",
"reference_context_audio40_research_v1",
"masked_video_prefix_v1",
"masked_av_prefix_22_v1",
"masked_av_prefix_39_v1",
@@ -836,6 +838,12 @@ class H3ContinuumMaskedPrefixR1Diagnostic:
modules = _resolve_continuum_modules()
production_class = _diagnostic_public_v35_class()
original_sample = modules.sequence.sample_chunk
original_select_context = modules.sequence.select_context
production_transport = (
"reference_context_v1"
if transport == "reference_context_audio40_research_v1"
else transport
)
continuity = str(kwargs.get("continuity", ""))
context_frames = int(
modules.constants.CONTINUITY_FRAMES.get(continuity, 22)
@@ -860,6 +868,7 @@ class H3ContinuumMaskedPrefixR1Diagnostic:
effective_audio_continuity = True
diagnostic: dict[str, Any] = {
"transport": transport,
"production_transport": production_transport,
"context_frames": context_frames,
"video_prefix_slots": video_prefix_slots,
"audio_prefix_steps": audio_prefix_steps,
@@ -869,6 +878,8 @@ class H3ContinuumMaskedPrefixR1Diagnostic:
"diagnostic_nonce": int(diagnostic_nonce),
"sample_calls": [],
}
if transport == "reference_context_audio40_research_v1":
diagnostic["reference_audio_steps"] = 40
sample_number = 0
previous_output_tail = None
previous_output_audio_tail = None
@@ -894,6 +905,11 @@ class H3ContinuumMaskedPrefixR1Diagnostic:
evidence["minimax_ref_kinds"] = [
item.get("kind") for item in (metadata.get("minimax_refs") or [])
]
evidence["minimax_ref_audio_steps"] = [
int(item.get("ref_audio_t", 0))
for item in (metadata.get("minimax_refs") or [])
if int(item.get("ref_audio_t", 0)) > 0
]
evidence["minimax_keyframe_indices"] = [
int(item.get("resolved_frame_index"))
for item in (metadata.get("minimax_keyframes") or [])
@@ -1059,14 +1075,41 @@ class H3ContinuumMaskedPrefixR1Diagnostic:
kwargs["audio_continuity"] = effective_audio_continuity
def select_context_with_research_audio40(
state,
requested_context_frames,
*,
include_audio,
):
video, audio, grid_offset = original_select_context(
state,
requested_context_frames,
include_audio=include_audio,
)
if (
transport == "reference_context_audio40_research_v1"
and include_audio
and int(requested_context_frames) == 22
):
checked = modules.state.validate_state(state)
retained = checked["audio_tail"]
if int(retained.shape[-1]) < 40:
raise ValueError(
"Audio40 research requires at least 40 retained audio ticks"
)
audio = retained[..., -40:].contiguous()
return video, audio, grid_offset
modules.sequence.sample_chunk = sampled_with_evidence
modules.sequence.select_context = select_context_with_research_audio40
try:
outputs = production_class().run(
continuation_transport=transport,
continuation_transport=production_transport,
**kwargs,
)
finally:
modules.sequence.sample_chunk = original_sample
modules.sequence.select_context = original_select_context
video_latents = outputs[0]
audio_latents = outputs[1]
+180
View File
@@ -0,0 +1,180 @@
"""Measure chunk-wise color/contrast drift and build an Issue #13 contact sheet."""
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
def _video_path(output_root: 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
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)),
"highlight_clip_fraction": float(np.mean(y >= (250.0 / 255.0))),
"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 _contact_sheet(rows: list[tuple[str, list[np.ndarray]]], output: Path) -> None:
thumb_w, thumb_h = 256, 256
label_w, top_h = 220, 42
width = label_w + thumb_w * 5
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(5):
draw.text(
(label_w + column * thumb_w + 8, 14),
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 run(args: argparse.Namespace) -> dict:
summary = json.loads((args.output_root / "summary.json").read_text(encoding="utf-8"))
all_rows = []
sheets = []
videos = {}
for record in summary["cases"]:
case = str(record["case"])
path = _video_path(args.output_root, record, args.video_root)
frames, fps = _read_frames(path)
metrics, representatives = _chunk_metrics(
frames, chunks=5, 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))
videos[case] = {
"path": str(path),
"sha256": hashlib.sha256(path.read_bytes()).hexdigest(),
"fps": fps,
"frame_count": len(frames),
"metrics": metrics,
"drift_chunk5_minus_chunk1": {
key: metrics[-1][key] - metrics[0][key]
for key in (
"luma_mean",
"luma_std",
"saturation_mean",
"saturation_p95",
"contrast_p95_p05",
"highlight_clip_fraction",
"shadow_clip_fraction",
)
},
}
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)
result = {
"format": "h3-continuum-issue13-drift-analysis-v1",
"sample_radius_frames": args.radius,
"videos": videos,
"csv": str(csv_path),
"contact_sheet": str(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())
+262
View File
@@ -0,0 +1,262 @@
"""Run the Issue #13 long-form contrast/style drift diagnostic matrix.
This tool is diagnostic-only. It mutates an accepted API prompt in memory and
does not import into or change the Production node 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."
)
VARIED_PROMPTS = (
BASE_PROMPT,
BASE_PROMPT
+ " Keep the lighting natural and avoid increasing contrast or saturation.",
BASE_PROMPT
+ " Use restrained color, soft highlight rolloff, and matte natural skin texture.",
BASE_PROMPT
+ " Maintain neutral exposure, stable white balance, and gentle midtone contrast.",
BASE_PROMPT
+ " Preserve the original natural color and texture without glossy or oily buildup.",
)
CASE_ORDER = (
"fixed_standard",
"list_same_standard",
"timeline_same_standard",
"list_varied_standard",
"fixed_compatibility",
)
def _script_for_case(case: str) -> tuple[str, str, str]:
if case == "fixed_standard":
return "Fixed", BASE_PROMPT, "Standard"
if case == "list_same_standard":
return "List", "\n---\n".join([BASE_PROMPT] * 5), "Standard"
if case == "timeline_same_standard":
return (
"Timeline",
"\n\n".join(
f"[Chunk {index}]\n{BASE_PROMPT}" for index in range(1, 6)
),
"Standard",
)
if case == "list_varied_standard":
return "List", "\n---\n".join(VARIED_PROMPTS), "Standard"
if case == "fixed_compatibility":
return "Fixed", BASE_PROMPT, "Compatibility"
raise ValueError(f"unknown Issue #13 case: {case}")
def configure_prompt(
source: dict,
*,
case: str,
output_prefix: str,
seed: int,
steps: int,
size: int,
) -> dict:
prompt = copy.deepcopy(source)
prompt_mode, script, backend = _script_for_case(case)
sampler = prompt["305"]
sampler["class_type"] = "H3ContinuumSamplerV36"
sampler["_meta"] = {"title": f"Issue #13 Drift Diagnostic — {case}"}
inputs = sampler["inputs"]
inputs.update(
{
"prompt_mode": prompt_mode,
"chunks": 5,
"chunk_seconds": 5.0,
"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_backend": backend,
"first_frame": ["119", 0],
}
)
for key in (
"continuation_transport",
"synchronize_sampling",
"diagnostic_nonce",
"last_frame",
):
inputs.pop(key, None)
prompt["188"]["inputs"]["value"] = script
prompt["153"]["inputs"].update(
{"scheduler": "simple", "steps": int(steps), "denoise": 1.0}
)
prompt["297"]["inputs"]["value"] = max(0.05, (float(size) * size) / 1_000_000.0)
prompt["306"]["inputs"].update(
{
"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]
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 run(args: argparse.Namespace) -> dict:
source = json.loads(args.prompt.read_text(encoding="utf-8"))
cases = list(args.cases or CASE_ORDER)
unknown = [case for case in cases if case not in CASE_ORDER]
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 case in cases:
if case in completed_cases:
print(f"ISSUE13 SKIP completed case={case}", flush=True)
continue
configured = configure_prompt(
source,
case=case,
output_prefix=f"video/issue13/Issue13_{case}_seed{args.seed}",
seed=args.seed,
steps=args.steps,
size=args.size,
)
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 START case={case}", flush=True)
prompt_id, history, elapsed = submit_and_wait(
server=args.server,
prompt=configured,
client_id=f"issue13-{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",
)
text = _status_text(history, prompt_id)
result = {
"case": case,
"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(text.encode("utf-8")).hexdigest(),
"status": text,
}
(case_root / "summary.json").write_text(
json.dumps(result, indent=2, ensure_ascii=False),
encoding="utf-8",
)
results.append(result)
print(
f"ISSUE13 COMPLETE case={case} prompt_id={prompt_id} "
f"elapsed={elapsed:.3f}s",
flush=True,
)
summary = {
"format": "h3-continuum-issue13-drift-gate-v1",
"server": args.server,
"source_prompt": str(args.prompt),
"seed": int(args.seed),
"steps": int(args.steps),
"size": int(args.size),
"chunks": 5,
"chunk_seconds": 5.0,
"cases": results,
}
summary_path.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("--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("--timeout-seconds", type=float, default=3600.0)
parser.add_argument("--cases", nargs="*", choices=CASE_ORDER)
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())
+437
View File
@@ -0,0 +1,437 @@
"""Run the private V3.6 FL2VA 3x5 Terminal Merge combined GPU gate."""
from __future__ import annotations
import argparse
import copy
import json
from pathlib import Path
import sys
import time
import uuid
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 p32_api_runner import submit_and_wait
from v36_r1_stress_gate_runner import ResourceMonitor, _extract_evidence
TIMELINE_PROMPT = """[0-5s]
A continuous cinematic live-action tracking shot begins from the supplied First Frame. The woman in the orange jacket rides her skateboard forward along the waterfront promenade while the low camera tracks beside her. Natural rolling skateboard wheels, wind, and distant city traffic.
[5-10s]
She accelerates through smooth continuous S-turns without stopping. Her hair and jacket react to speed while the camera maintains the same forward direction with a steady pan and partial orbit. Preserve her face, orange jacket, white trousers, skateboard, waterfront, and natural contrast.
[10-15s]
Still moving forward, she approaches the blue waterfront sculpture, gradually eases her speed, turns toward the camera, and converges naturally to the supplied Last Frame pose and composition. Continuous city ambience and skateboard sound."""
CONDITIONS = {
"a1_reference_video": ("reference_context_v1", False),
"a2_masked_video": ("masked_video_prefix_v1", False),
"b1_reference_av": ("reference_context_v1", True),
"b2_masked_av": ("masked_av_prefix_22_v1", True),
}
def configure_prompt(
source: Mapping[str, Any],
*,
transport: str,
audio_continuity: bool,
output_prefix: str,
seed: int,
diagnostic_nonce: int,
steps: int = 20,
audio_seam: str = "Auto",
) -> dict[str, Any]:
prompt = copy.deepcopy(dict(source))
prompt["290"] = {
"class_type": "LoadImage",
"_meta": {"title": "Last Frame"},
"inputs": {"image": "exec-758fca62-818a-446e-a279-829cc126d899.png"},
}
prompt["292"] = {
"class_type": "ImageScaleToTotalPixels",
"_meta": {"title": "Scale Last Frame"},
"inputs": {
"upscale_method": "area",
"megapixels": ["297", 0],
"resolution_steps": 32,
"image": ["290", 0],
},
}
sampler = prompt["305"]
sampler["class_type"] = "H3ContinuumMaskedPrefixR1Diagnostic"
sampler["_meta"] = {"title": "V3.6 FL2VA Combined Gate Diagnostic"}
sampler["inputs"].update(
{
"prompt_mode": "Timeline — [0-5s] sections",
"chunks": 3,
"chunk_seconds": 5.0,
"width": 640,
"height": 640,
"continuity": "Balanced — 22 frames",
"base_seed": int(seed),
"audio_continuity": bool(audio_continuity),
"diagnostics": "Detailed Report",
"show_preview": False,
"run_storage": "Off",
"continuation_transport": str(transport),
"synchronize_sampling": True,
"diagnostic_nonce": int(diagnostic_nonce),
"last_frame": ["292", 0],
}
)
sampler["inputs"]["first_frame"] = ["119", 0]
prompt["188"]["inputs"]["value"] = TIMELINE_PROMPT
prompt["153"]["inputs"].update(
{"scheduler": "simple", "steps": int(steps), "denoise": 1.0}
)
prompt["306"]["inputs"].update(
{
"exact_total_duration": True,
"audio_seam": str(audio_seam),
"video_seam": "Off",
"buffer_backend": "Auto",
"diagnostics": "Detailed Report",
}
)
prompt["191"]["inputs"]["filename_prefix"] = str(output_prefix)
return prompt
def _validate_diagnostic(
diagnostic: Mapping[str, Any],
*,
transport: str,
audio_continuity: bool,
) -> None:
calls = list(diagnostic.get("sample_calls") or [])
if len(calls) != 2:
raise RuntimeError(f"expected 2 physical Sampling calls, got {len(calls)}")
if int(diagnostic.get("logical_chunk_count", 0)) != 3:
raise RuntimeError(f"logical chunk count mismatch: {diagnostic.get('logical_chunk_count')}")
if int(diagnostic.get("physical_group_count", 0)) != 2:
raise RuntimeError(f"physical group count mismatch: {diagnostic.get('physical_group_count')}")
if int(diagnostic.get("physical_decode_group_count", 0)) != 2:
raise RuntimeError("physical decode group count mismatch")
groups = list(diagnostic.get("decode_groups") or [])
if len(groups) != 2:
raise RuntimeError(f"expected 2 decode groups, got {len(groups)}")
terminal = groups[1]
expected = {
"logical_chunk_indices": [2, 3],
"terminal_merged": True,
"total_frames": 260,
"trim_frames": 22,
"expected_video_latent_t": 77,
"expected_audio_latent_t": 433,
}
for key, value in expected.items():
if terminal.get(key) != value:
raise RuntimeError(f"terminal contract mismatch {key}: {terminal.get(key)!r}")
first, second = calls
if first.get("minimax_keyframe_indices") != [0]:
raise RuntimeError(f"Group 1 First Frame contract mismatch: {first.get('minimax_keyframe_indices')}")
if second.get("minimax_keyframe_indices") != [259]:
raise RuntimeError(f"Terminal Last Frame contract mismatch: {second.get('minimax_keyframe_indices')}")
if int(second.get("input_video", {}).get("shape", [0, 0, 0])[2]) != 77:
raise RuntimeError("Terminal input Video T is not 77")
masked = transport != "reference_context_v1"
if masked:
if second.get("minimax_ref_kinds"):
raise RuntimeError(f"masked Terminal emitted refs: {second.get('minimax_ref_kinds')}")
if bool(second.get("continuum_interop_emitted")):
raise RuntimeError("masked Terminal emitted old Spectrum interop")
required = {
"source_tail_matches_target_prefix": True,
"video_mask_prefix_zero": True,
"video_mask_generated_one": True,
}
if transport == "masked_av_prefix_22_v1":
required.update(
{
"source_audio_tail_matches_target_prefix": True,
"audio_mask_prefix_zero": True,
"audio_mask_generated_one": True,
}
)
else:
required["audio_mask_all_one"] = True
for key, value in required.items():
if second.get(key) is not value:
raise RuntimeError(f"masked evidence failed {key}: {second.get(key)!r}")
pairs = list(diagnostic.get("final_prefix_pairs") or [])
if len(pairs) != 1:
raise RuntimeError(f"expected one final prefix pair, got {len(pairs)}")
pair = pairs[0]
if pair.get("bit_exact") is not True or float(pair.get("max_abs_diff", 1)) != 0:
raise RuntimeError(f"final Video prefix is not exact: {pair}")
if transport == "masked_av_prefix_22_v1":
if pair.get("audio_bit_exact") is not True or float(
pair.get("audio_max_abs_diff", 1)
) != 0:
raise RuntimeError(f"final Audio prefix is not exact: {pair}")
else:
kinds = list(second.get("minimax_ref_kinds") or [])
if "video" not in kinds and "video_audio" not in kinds:
raise RuntimeError(f"Reference Terminal lacks Video context: {kinds}")
if audio_continuity and "audio" not in kinds and "video_audio" not in kinds:
raise RuntimeError(f"Reference AV Terminal lacks Audio context: {kinds}")
if not bool(second.get("continuum_interop_emitted")):
raise RuntimeError("Reference Terminal lacks Continuum interop")
def _run_prompt(
*,
prompt: dict[str, Any],
run_root: Path,
args,
label: str,
require_diagnostic: bool,
) -> dict[str, Any]:
run_root.mkdir(parents=True, exist_ok=True)
prompt_path = run_root / "prompt.json"
prompt_path.write_text(json.dumps(prompt, indent=2, ensure_ascii=False), encoding="utf-8")
print(f"START {label}", 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"v36-fl2va-{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")
evidence = _extract_evidence(history)
result = {
"label": label,
"prompt_id": prompt_id,
"api_elapsed_seconds": float(elapsed),
"prompt": str(prompt_path),
"history": str(history_path),
"resources": monitor.as_dict(),
**evidence,
}
if require_diagnostic and not result.get("diagnostic"):
raise RuntimeError(f"{label} returned no V3.6 diagnostic evidence")
(run_root / "summary.json").write_text(
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
)
print(f"DONE {label} elapsed={elapsed:.3f}s", flush=True)
return result
def _run_condition(
*,
source: Mapping[str, Any],
args,
label: str,
transport: str,
audio_continuity: bool,
seed: int,
nonce: int,
cache_only_off: bool,
) -> list[dict[str, Any]]:
output_prefix = f"video/V36_FL2VA_{label}_seed{seed}_Auto"
prompt = configure_prompt(
source,
transport=transport,
audio_continuity=audio_continuity,
output_prefix=output_prefix,
seed=seed,
diagnostic_nonce=nonce,
audio_seam="Auto",
)
result = _run_prompt(
prompt=prompt,
run_root=args.output_root / label,
args=args,
label=label,
require_diagnostic=True,
)
cache = result.get("prompt_clip_cache")
if not cache or int(cache.get("encode_calls", -1)) != 0:
raise RuntimeError(f"measured run was not Prompt/CLIP cache HIT: {cache}")
_validate_diagnostic(
result["diagnostic"],
transport=transport,
audio_continuity=audio_continuity,
)
outputs = [result]
if cache_only_off:
raw = copy.deepcopy(prompt)
raw["306"]["inputs"]["audio_seam"] = "Off"
raw["191"]["inputs"]["filename_prefix"] = (
f"video/V36_FL2VA_{label}_seed{seed}_SeamOff"
)
raw_result = _run_prompt(
prompt=raw,
run_root=args.output_root / f"{label}_seam_off_cache",
args=args,
label=f"{label}_seam_off_cache",
require_diagnostic=False,
)
raw_result["cache_only_expected"] = True
outputs.append(raw_result)
return outputs
def run(args) -> dict[str, Any]:
source = json.loads(args.prompt.read_text(encoding="utf-8"))
args.output_root.mkdir(parents=True, exist_ok=True)
nonce = int(time.time()) & 0x7FFFFFFF
runs: list[dict[str, Any]] = []
if not args.skip_warmup:
warm = configure_prompt(
source,
transport="reference_context_v1",
audio_continuity=False,
output_prefix="video/V36_FL2VA_cache_warmup",
seed=args.seeds[0],
diagnostic_nonce=nonce,
steps=1,
audio_seam="Off",
)
runs.append(
_run_prompt(
prompt=warm,
run_root=args.output_root / "cache_warmup",
args=args,
label="cache_warmup",
require_diagnostic=True,
)
)
schedule: list[tuple[int, str]]
if args.phase == "gate-a":
schedule = [(args.seeds[0], label) for label in CONDITIONS]
elif args.phase == "joint-multiseed":
schedule = [
(args.seeds[0], "b1_reference_av"),
(args.seeds[0], "b2_masked_av"),
(args.seeds[1], "b2_masked_av"),
(args.seeds[1], "b1_reference_av"),
(args.seeds[2], "b1_reference_av"),
(args.seeds[2], "b2_masked_av"),
]
else:
schedule = [
(args.seeds[1], "b1_reference_av"),
(args.seeds[1], "b2_masked_av"),
(args.seeds[2], "b2_masked_av"),
]
for index, (seed, condition) in enumerate(schedule, start=1):
nonce += 1
transport, audio_continuity = CONDITIONS[condition]
label = f"{index:02d}_seed{seed}_{condition}"
runs.extend(
_run_condition(
source=source,
args=args,
label=label,
transport=transport,
audio_continuity=audio_continuity,
seed=seed,
nonce=nonce,
cache_only_off=(
condition.startswith("b")
and (
args.phase == "gate-a"
or (args.phase == "r2-short" and seed == args.seeds[1])
)
),
)
)
measured = [run for run in runs if run.get("diagnostic") and run["label"] != "cache_warmup"]
first_video_hashes = {
run["diagnostic"]["physical_video_groups"][0]["sha256"] for run in measured
}
first_audio_hashes = {
run["diagnostic"]["physical_audio_groups"][0]["sha256"] for run in measured
}
first_seeds_by_requested: dict[int, set[int]] = {}
first_video_hashes_by_requested: dict[int, set[str]] = {}
first_audio_hashes_by_requested: dict[int, set[str]] = {}
for run in measured:
requested = int(run["label"].split("_seed", 1)[1].split("_", 1)[0])
actual = int(run["diagnostic"]["sample_calls"][0]["seed"])
first_seeds_by_requested.setdefault(requested, set()).add(actual)
first_video_hashes_by_requested.setdefault(requested, set()).add(
run["diagnostic"]["physical_video_groups"][0]["sha256"]
)
first_audio_hashes_by_requested.setdefault(requested, set()).add(
run["diagnostic"]["physical_audio_groups"][0]["sha256"]
)
if args.phase == "gate-a" and (len(first_video_hashes) != 1 or len(first_audio_hashes) != 1):
raise RuntimeError("Gate A physical Group 1 hashes differ across conditions")
if any(len(values) != 1 for values in first_seeds_by_requested.values()):
raise RuntimeError(
f"physical Group 1 seeds differ within a Base Seed: {first_seeds_by_requested}"
)
if any(len(values) != 1 for values in first_video_hashes_by_requested.values()):
raise RuntimeError(
"physical Group 1 Video hashes differ within a Base Seed: "
f"{first_video_hashes_by_requested}"
)
if any(len(values) != 1 for values in first_audio_hashes_by_requested.values()):
raise RuntimeError(
"physical Group 1 Audio hashes differ within a Base Seed: "
f"{first_audio_hashes_by_requested}"
)
result = {
"format": "h3-continuum-v36-fl2va-combined-gate-v1",
"phase": args.phase,
"server": args.server,
"seeds": [int(value) for value in args.seeds],
"conditions": CONDITIONS,
"group1_video_hash_count": len(first_video_hashes),
"group1_audio_hash_count": len(first_audio_hashes),
"runs": runs,
}
(args.output_root / "gate_summary.json").write_text(
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
)
return result
def _parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--server", default="http://127.0.0.1:8188")
parser.add_argument("--prompt", type=Path, required=True)
parser.add_argument("--output-root", type=Path, required=True)
parser.add_argument(
"--phase",
choices=("gate-a", "joint-multiseed", "r2-short"),
default="gate-a",
)
parser.add_argument(
"--seeds",
type=int,
nargs=3,
default=(238985343135606, 238985343135607, 238985343135608),
)
parser.add_argument("--backend-pid", type=int)
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("--skip-warmup", action="store_true")
return parser
def main() -> int:
result = run(_parser().parse_args())
print(json.dumps(result, ensure_ascii=False))
return 0
if __name__ == "__main__":
raise SystemExit(main())
+167
View File
@@ -0,0 +1,167 @@
"""Run V3.6 PIG-3 Reference Image + Audio with Masked AV continuation."""
from __future__ import annotations
import argparse
import copy
import json
from pathlib import Path
import sys
import time
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 _extract_evidence
DEFAULT_SOURCE = Path(
r"D:\Codex\_test_results\ComfyUI-H3-Continuum\v36-fl2va-combined-20260826"
r"\gate-a\04_seed238985343135606_b2_masked_av\prompt.json"
)
DEFAULT_OUTPUT = Path(
r"D:\Codex\_test_results\ComfyUI-H3-Continuum\v36-production-integration"
r"\pig3-reference-masked"
)
PROMPT = (
"A continuous cinematic shot of <Picture 1> walking forward with clear body "
"motion while the camera tracks smoothly. Preserve the person's identity, "
"clothing, colors, and environment. Use <Audio 1> as the persistent voice and "
"sound reference across both five-second chunks."
)
def configure(source: dict, *, seed: int, diagnostic_nonce: int) -> dict:
prompt = copy.deepcopy(source)
prompt["400"] = {
"class_type": "LoadAudio",
"_meta": {"title": "PIG-3 Reference Audio"},
"inputs": {"audio": "V36_PIG3_reference_audio.mp3"},
}
sampler = prompt["305"]
sampler["class_type"] = "H3ContinuumMaskedPrefixR1Diagnostic"
sampler["_meta"] = {"title": "V3.6 PIG-3 Reference + Masked AV"}
sampler["inputs"].update(
{
"prompt_mode": "Fixed",
"chunks": 2,
"chunk_seconds": 5.0,
"width": 384,
"height": 384,
"continuity": "Balanced — 22 frames",
"base_seed": int(seed),
"audio_continuity": True,
"diagnostics": "Detailed Report",
"reroll_from_chunk": "Auto",
"reroll_nonce": 0,
"show_preview": False,
"run_storage": "Off",
"run_name": "",
"project_id": "",
"reference_size": "Match Output",
"continuation_transport": "masked_av_prefix_22_v1",
"synchronize_sampling": True,
"diagnostic_nonce": int(diagnostic_nonce),
"reference_image_1": ["119", 0],
"reference_audio_1": ["400", 0],
"reference_audio_vae": ["136", 0],
}
)
sampler["inputs"].pop("last_frame", None)
prompt["188"]["inputs"]["value"] = PROMPT
prompt["153"]["inputs"].update(
{"scheduler": "simple", "steps": 4, "denoise": 1.0}
)
prompt["306"]["inputs"].update(
{
"exact_total_duration": True,
"audio_seam": "Auto",
"video_seam": "Off",
"buffer_backend": "Auto",
"diagnostics": "Detailed Report",
}
)
prompt["191"]["inputs"]["filename_prefix"] = (
"video/V36_PIG3_Reference_Image_Audio_Masked_AV"
)
return prompt
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--server", default="http://127.0.0.1:8188")
parser.add_argument("--source", type=Path, default=DEFAULT_SOURCE)
parser.add_argument("--output", type=Path, default=DEFAULT_OUTPUT)
parser.add_argument("--seed", type=int, default=238985343135610)
parser.add_argument("--timeout-seconds", type=float, default=1800.0)
args = parser.parse_args()
args.output.mkdir(parents=True, exist_ok=True)
source = json.loads(args.source.read_text(encoding="utf-8"))
prompt = configure(source, seed=args.seed, diagnostic_nonce=9301)
(args.output / "prompt.json").write_text(
json.dumps(prompt, indent=2, ensure_ascii=False), encoding="utf-8"
)
started = time.perf_counter()
prompt_id, history, elapsed = submit_and_wait(
server=args.server,
prompt=prompt,
client_id=f"v36-pig3-{uuid.uuid4().hex}",
timeout_seconds=args.timeout_seconds,
poll_seconds=1.0,
)
wall = time.perf_counter() - started
(args.output / "history.json").write_text(
json.dumps(history, indent=2, ensure_ascii=False), encoding="utf-8"
)
evidence = _extract_evidence(history)
diagnostic = evidence.get("diagnostic") or {}
calls = list(diagnostic.get("sample_calls") or [])
if len(calls) != 2:
raise RuntimeError(f"expected two physical groups, got {len(calls)}")
for index, call in enumerate(calls, start=1):
kinds = list(call.get("minimax_ref_kinds") or [])
if kinds.count("image") != 1 or kinds.count("audio") != 1:
raise RuntimeError(f"group {index} Reference kinds mismatch: {kinds}")
if "video" in kinds or "video_audio" in kinds:
raise RuntimeError(f"group {index} emitted old Continuation refs: {kinds}")
continuation = calls[1]
for key in (
"source_tail_matches_target_prefix",
"source_audio_tail_matches_target_prefix",
"video_mask_prefix_zero",
"video_mask_generated_one",
"audio_mask_prefix_zero",
"audio_mask_generated_one",
):
if continuation.get(key) is not True:
raise RuntimeError(f"continuation evidence failed {key}")
pairs = list(diagnostic.get("final_prefix_pairs") or [])
if len(pairs) != 1:
raise RuntimeError(f"expected one finalized prefix pair, got {len(pairs)}")
pair = pairs[0]
if pair.get("bit_exact") is not True or pair.get("audio_bit_exact") is not True:
raise RuntimeError(f"final protected prefixes are not bit-exact: {pair}")
result = {
"gate": "V3.6 PIG-3 Reference + Masked AV",
"status": "PASS",
"prompt_id": prompt_id,
"api_elapsed_seconds": float(elapsed),
"wall_seconds": float(wall),
"seed": int(args.seed),
"prompt": PROMPT,
**evidence,
}
(args.output / "gate_summary.json").write_text(
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
)
print(json.dumps({"status": "PASS", "output": str(args.output)}))
return 0
if __name__ == "__main__":
raise SystemExit(main())
@@ -0,0 +1,273 @@
"""Run the private V3.6 Production Integration Run Storage GPU gate."""
from __future__ import annotations
import argparse
import copy
import json
from pathlib import Path
import re
import sys
import time
import uuid
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 p32_api_runner import submit_and_wait
from v36_r1_stress_gate_runner import _extract_evidence, _walk_strings
DEFAULT_SOURCE = Path(
r"D:\Codex\_test_results\ComfyUI-H3-Continuum\v36-fl2va-combined-20260826"
r"\gate-a\04_seed238985343135606_b2_masked_av\prompt.json"
)
DEFAULT_OUTPUT_ROOT = Path(
r"D:\Codex\_test_results\ComfyUI-H3-Continuum\v36-production-integration"
)
RUN_STORAGE_ROOT = Path(
r"D:\output\video\comfy_video\h3_continuum\runs"
)
def _run_storage_lines(history: Mapping[str, Any]) -> list[str]:
lines: list[str] = []
for text in _walk_strings(history):
lines.extend(
line for line in text.splitlines() if line.startswith("Run Storage:")
)
return list(dict.fromkeys(lines))
def _summary_counts(lines: list[str]) -> tuple[int, int, str]:
if not lines:
raise RuntimeError("Run Storage summary was not returned")
line = lines[-1]
match = re.search(
r"revision ([0-9a-f]+); (\d+) reused, (\d+) generated", line
)
if not match:
raise RuntimeError(f"unrecognized Run Storage summary: {line}")
return int(match.group(2)), int(match.group(3)), match.group(1)
def configure_prompt(
source: Mapping[str, Any],
*,
run_name: str,
regenerate_from: str,
reroll_nonce: int,
diagnostic_nonce: int,
output_prefix: str,
) -> dict[str, Any]:
prompt = copy.deepcopy(dict(source))
sampler = prompt["305"]
sampler["class_type"] = "H3ContinuumMaskedPrefixR1Diagnostic"
sampler["_meta"] = {"title": "V3.6 Production Integration Gate"}
sampler["inputs"].update(
{
"chunks": 3,
"chunk_seconds": 5.0,
"width": 384,
"height": 384,
"continuity": "Balanced — 22 frames",
"audio_continuity": True,
"diagnostics": "Detailed Report",
"reroll_from_chunk": str(regenerate_from),
"reroll_nonce": int(reroll_nonce),
"show_preview": False,
"run_storage": "Save + Auto Resume",
"run_name": str(run_name),
"project_id": "",
"continuation_transport": "masked_av_prefix_22_v1",
"synchronize_sampling": True,
"diagnostic_nonce": int(diagnostic_nonce),
}
)
prompt["153"]["inputs"].update(
{"scheduler": "simple", "steps": 1, "denoise": 1.0}
)
prompt["306"]["inputs"].update(
{
"exact_total_duration": True,
"audio_seam": "Auto",
"video_seam": "Off",
"buffer_backend": "Auto",
"diagnostics": "Detailed Report",
}
)
prompt["191"]["inputs"]["filename_prefix"] = str(output_prefix)
return prompt
def run_one(
*,
source: Mapping[str, Any],
server: str,
output_root: Path,
run_name: str,
label: str,
regenerate_from: str,
reroll_nonce: int,
diagnostic_nonce: int,
timeout_seconds: float,
) -> dict[str, Any]:
run_root = output_root / label
run_root.mkdir(parents=True, exist_ok=True)
prompt = configure_prompt(
source,
run_name=run_name,
regenerate_from=regenerate_from,
reroll_nonce=reroll_nonce,
diagnostic_nonce=diagnostic_nonce,
output_prefix=f"video/V36_PIG2_{run_name}_{label}",
)
(run_root / "prompt.json").write_text(
json.dumps(prompt, indent=2, ensure_ascii=False), encoding="utf-8"
)
started = time.perf_counter()
prompt_id, history, elapsed = submit_and_wait(
server=server,
prompt=prompt,
client_id=f"v36-pig2-{uuid.uuid4().hex}",
timeout_seconds=timeout_seconds,
poll_seconds=1.0,
)
wall = time.perf_counter() - started
(run_root / "history.json").write_text(
json.dumps(history, indent=2, ensure_ascii=False), encoding="utf-8"
)
evidence = _extract_evidence(history)
storage_lines = _run_storage_lines(history)
reused, generated, revision = _summary_counts(storage_lines)
result = {
"label": label,
"prompt_id": prompt_id,
"api_elapsed_seconds": float(elapsed),
"wall_seconds": float(wall),
"regenerate_from": regenerate_from,
"reroll_nonce": int(reroll_nonce),
"run_storage_lines": storage_lines,
"reused": reused,
"generated": generated,
"revision": revision,
**evidence,
}
(run_root / "summary.json").write_text(
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
)
return result
def _manifest_records(run_name: str) -> list[dict[str, Any]]:
run_root = RUN_STORAGE_ROOT / run_name
records: list[dict[str, Any]] = []
for path in sorted(run_root.glob("revisions/*/manifest.json")):
payload = json.loads(path.read_text(encoding="utf-8"))
records.append({"path": str(path), "manifest": payload})
return records
def validate(results: list[dict[str, Any]], manifests: list[dict[str, Any]]) -> None:
expected_counts = [(0, 3, 2), (3, 0, 0), (1, 2, 1), (1, 2, 1)]
for result, (reused, generated, sample_calls) in zip(
results, expected_counts, strict=True
):
if (result["reused"], result["generated"]) != (reused, generated):
raise RuntimeError(
f"{result['label']} storage counts mismatch: "
f"{result['reused']}/{result['generated']}"
)
diagnostic = result.get("diagnostic") or {}
calls = list(diagnostic.get("sample_calls") or [])
if len(calls) != sample_calls:
raise RuntimeError(
f"{result['label']} expected {sample_calls} Sampling calls, got {len(calls)}"
)
if sample_calls == 1:
shape = list(calls[0].get("input_video", {}).get("shape") or [])
audio_shape = list(calls[0].get("input_audio", {}).get("shape") or [])
if len(shape) < 3 or shape[2] != 77:
raise RuntimeError(f"{result['label']} did not regenerate Terminal 77T")
if not audio_shape or audio_shape[-1] != 433:
raise RuntimeError(f"{result['label']} did not regenerate Terminal Audio 433T")
if results[0]["revision"] != results[1]["revision"]:
raise RuntimeError("Auto Resume did not select the saved masked revision")
if not manifests:
raise RuntimeError("Run Storage created no revision manifests")
for record in manifests:
manifest = record["manifest"]
semantics = (
(manifest.get("contract") or {}).get("global", {}).get(
"execution_semantics", {}
)
)
if semantics.get("continuation_transport") != "masked_av_prefix_22_v1":
raise RuntimeError(
f"manifest lacks masked transport identity: {record['path']}"
)
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--server", default="http://127.0.0.1:8188")
parser.add_argument("--source", type=Path, default=DEFAULT_SOURCE)
parser.add_argument("--output-root", type=Path, default=DEFAULT_OUTPUT_ROOT)
parser.add_argument("--timeout-seconds", type=float, default=1800.0)
parser.add_argument("--run-name", default="")
args = parser.parse_args()
stamp = time.strftime("%Y%m%d_%H%M%S")
run_name = args.run_name or f"v36_pig2_masked_{stamp}"
output_root = args.output_root / run_name
output_root.mkdir(parents=True, exist_ok=True)
source = json.loads(args.source.read_text(encoding="utf-8"))
specifications = (
("01_initial_save", "Auto", 0, 9101),
("02_auto_resume", "Auto", 0, 9102),
("03_regenerate_chunk2", "Chunk 2", 1, 9103),
("04_regenerate_chunk3", "Chunk 3", 2, 9104),
)
results = []
for label, regenerate_from, reroll_nonce, diagnostic_nonce in specifications:
print(f"START {label}", flush=True)
result = run_one(
source=source,
server=args.server,
output_root=output_root,
run_name=run_name,
label=label,
regenerate_from=regenerate_from,
reroll_nonce=reroll_nonce,
diagnostic_nonce=diagnostic_nonce,
timeout_seconds=args.timeout_seconds,
)
results.append(result)
print(
f"DONE {label} elapsed={result['api_elapsed_seconds']:.3f}s "
f"reused={result['reused']} generated={result['generated']}",
flush=True,
)
manifests = _manifest_records(run_name)
validate(results, manifests)
summary = {
"gate": "V3.6 PIG-2 Run Storage / Session identity",
"status": "PASS",
"run_name": run_name,
"source_prompt": str(args.source),
"results": results,
"manifests": manifests,
}
(output_root / "gate_summary.json").write_text(
json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8"
)
print(json.dumps({"status": "PASS", "output_root": str(output_root)}))
return 0
if __name__ == "__main__":
raise SystemExit(main())
+134
View File
@@ -0,0 +1,134 @@
"""Run one V3.6-R1 masked-prefix A/B case through the ComfyUI API."""
from __future__ import annotations
import argparse
import copy
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
def configure_prompt(
source: dict,
*,
transport: str,
output_prefix: str,
seed: int,
) -> dict:
prompt = copy.deepcopy(source)
for node_id in ("250", "292", "302", "304"):
prompt.pop(node_id, None)
sampler = prompt["305"]
sampler["class_type"] = "H3ContinuumMaskedPrefixR1Diagnostic"
sampler["_meta"] = {"title": "H3 Continuum V3.6-R1 Masked Prefix Diagnostic"}
sampler["inputs"].update(
{
"prompt_mode": "Fixed — one prompt",
"chunks": 2,
"chunk_seconds": 5.0,
"width": 640,
"height": 640,
"continuity": "Balanced — 22 frames",
"base_seed": int(seed),
"audio_continuity": False,
"diagnostics": "Detailed Report",
"show_preview": False,
"run_storage": "Off",
"continuation_transport": str(transport),
}
)
prompt["188"]["inputs"]["value"] = (
"A cinematic live-action tracking shot of one skateboarder moving "
"continuously along a waterfront promenade. The subject maintains "
"forward momentum, body pose, direction, and camera-relative speed "
"throughout the shot. Natural city ambience, rolling skateboard wheels, "
"and distant traffic are audible."
)
prompt["226"]["inputs"]["samples"] = ["305", 0]
prompt["227"]["inputs"]["samples"] = ["305", 1]
prompt["306"]["inputs"].update(
{
"audio_seam": "Off",
"video_seam": "Off",
"assembly_plan": ["305", 2],
"driving_audio": ["305", 4],
}
)
prompt["249"]["inputs"]["source"] = ["305", 3]
prompt["191"]["inputs"]["filename_prefix"] = str(output_prefix)
return prompt
def run(args) -> dict:
source = json.loads(args.prompt.read_text(encoding="utf-8"))
configured = configure_prompt(
source,
transport=args.transport,
output_prefix=f"video/V36_R1_{args.transport}_seed{args.seed}",
seed=args.seed,
)
args.output_root.mkdir(parents=True, exist_ok=True)
prompt_path = args.output_root / f"prompt_{args.transport}.json"
prompt_path.write_text(
json.dumps(configured, indent=2, ensure_ascii=False),
encoding="utf-8",
)
prompt_id, history, elapsed = submit_and_wait(
server=args.server,
prompt=configured,
client_id=f"v36-r1-{uuid.uuid4().hex}",
timeout_seconds=args.timeout_seconds,
poll_seconds=2.0,
)
history_path = args.output_root / f"history_{args.transport}.json"
history_path.write_text(
json.dumps(history, indent=2, ensure_ascii=False),
encoding="utf-8",
)
summary = {
"format": "h3-continuum-v36-r1-api-run-v1",
"transport": args.transport,
"prompt_id": prompt_id,
"api_elapsed_seconds": elapsed,
"prompt": str(prompt_path),
"history": str(history_path),
}
(args.output_root / f"summary_{args.transport}.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.1:8188")
parser.add_argument("--prompt", type=Path, required=True)
parser.add_argument("--output-root", type=Path, required=True)
parser.add_argument(
"--transport",
choices=("reference_context_v1", "masked_video_prefix_v1"),
required=True,
)
parser.add_argument("--timeout-seconds", type=float, default=1800.0)
parser.add_argument("--seed", type=int, default=238985343135586)
return parser
def main() -> int:
print(json.dumps(run(_parser().parse_args()), ensure_ascii=False))
return 0
if __name__ == "__main__":
raise SystemExit(main())
+256
View File
@@ -0,0 +1,256 @@
#!/usr/bin/env python3
"""Aggregate V3.6-R1 Stress Gate timings and boundary video metrics."""
from __future__ import annotations
import argparse
import json
import math
import re
from pathlib import Path
import cv2
import numpy as np
SAMPLING_RE = re.compile(r"sampling=([0-9.]+)s")
def _median(values: list[float]) -> float:
values = sorted(values)
middle = len(values) // 2
if len(values) % 2:
return values[middle]
return (values[middle - 1] + values[middle]) / 2.0
def _read_summary(path: Path) -> dict:
return json.loads(path.read_text(encoding="utf-8"))
def _sampling_seconds(run: dict) -> list[float]:
values: list[float] = []
for line in run["performance_lines"]:
if "physical group" not in line:
continue
match = SAMPLING_RE.search(line)
if match:
values.append(float(match.group(1)))
return values
def _video_path(output_prefix: str, output_dir: Path) -> Path:
stem = Path(output_prefix).name
matches = sorted(output_dir.glob(f"{stem}_*.mp4"), key=lambda path: path.stat().st_mtime)
if not matches:
raise FileNotFoundError(f"No output video for {stem}")
return matches[-1]
def _read_frames(path: Path) -> tuple[list[np.ndarray], float]:
capture = cv2.VideoCapture(str(path))
if not capture.isOpened():
raise RuntimeError(f"Unable to open {path}")
fps = float(capture.get(cv2.CAP_PROP_FPS))
frames: list[np.ndarray] = []
while True:
ok, frame = capture.read()
if not ok:
break
frames.append(frame)
capture.release()
return frames, fps
def _safe_cosine(left: np.ndarray, right: np.ndarray) -> float:
denominator = float(np.linalg.norm(left) * np.linalg.norm(right))
if denominator <= 1e-12:
return 1.0
return float(np.dot(left, right) / denominator)
def _boundary_metrics(frames: list[np.ndarray], boundary: int) -> dict:
first = max(0, boundary - 12)
last = min(len(frames) - 1, boundary + 24)
magnitudes: list[float] = []
mean_vectors: list[np.ndarray] = []
for index in range(first, last):
previous = cv2.cvtColor(frames[index], cv2.COLOR_BGR2GRAY)
current = cv2.cvtColor(frames[index + 1], cv2.COLOR_BGR2GRAY)
previous = cv2.resize(previous, (320, 320), interpolation=cv2.INTER_AREA)
current = cv2.resize(current, (320, 320), interpolation=cv2.INTER_AREA)
flow = cv2.calcOpticalFlowFarneback(
previous,
current,
None,
0.5,
3,
21,
3,
5,
1.2,
0,
)
magnitude = np.linalg.norm(flow, axis=2)
magnitudes.append(float(np.median(magnitude)))
mean_vectors.append(np.mean(flow.reshape(-1, 2), axis=0))
transition_index = boundary - first - 1
pre = magnitudes[max(0, transition_index - 6) : max(0, transition_index)]
post = magnitudes[transition_index + 1 : transition_index + 7]
pre_magnitude = float(np.median(pre)) if pre else 0.0
post_magnitude = float(np.median(post)) if post else 0.0
magnitude_ratio = post_magnitude / pre_magnitude if pre_magnitude > 1e-12 else math.inf
pre_vectors = mean_vectors[max(0, transition_index - 6) : max(0, transition_index)]
post_vectors = mean_vectors[transition_index + 1 : transition_index + 7]
pre_vector = np.mean(pre_vectors, axis=0) if pre_vectors else np.zeros(2, dtype=np.float32)
post_vector = np.mean(post_vectors, axis=0) if post_vectors else np.zeros(2, dtype=np.float32)
accelerations = np.diff(np.asarray(magnitudes, dtype=np.float64))
jerks = np.diff(accelerations)
local_jerk = jerks[max(0, transition_index - 3) : transition_index + 4]
before_frames = frames[max(0, boundary - 12) : boundary]
after_frames = frames[boundary : min(len(frames), boundary + 24)]
def color_stats(items: list[np.ndarray]) -> tuple[float, float, float]:
if not items:
return 0.0, 0.0, 0.0
luma: list[float] = []
contrast: list[float] = []
saturation: list[float] = []
for item in items:
gray = cv2.cvtColor(item, cv2.COLOR_BGR2GRAY)
hsv = cv2.cvtColor(item, cv2.COLOR_BGR2HSV)
luma.append(float(gray.mean()))
contrast.append(float(gray.std()))
saturation.append(float(hsv[:, :, 1].mean()))
return float(np.mean(luma)), float(np.mean(contrast)), float(np.mean(saturation))
before_luma, before_contrast, before_saturation = color_stats(before_frames)
after_luma, after_contrast, after_saturation = color_stats(after_frames)
return {
"boundary_frame": boundary,
"flow_magnitude_pre": pre_magnitude,
"flow_magnitude_post": post_magnitude,
"flow_magnitude_ratio_post_over_pre": magnitude_ratio,
"flow_direction_cosine": _safe_cosine(pre_vector, post_vector),
"flow_peak_abs_jerk": float(np.max(np.abs(local_jerk))) if len(local_jerk) else 0.0,
"luma_delta": after_luma - before_luma,
"contrast_delta": after_contrast - before_contrast,
"saturation_delta": after_saturation - before_saturation,
}
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--normal-root", type=Path, required=True)
parser.add_argument("--output-dir", type=Path, required=True)
parser.add_argument("--result", type=Path, required=True)
args = parser.parse_args()
runs = []
for summary_path in sorted(args.normal_root.glob("normal_*/summary.json")):
run = _read_summary(summary_path)
sampling = _sampling_seconds(run)
diagnostics = run["diagnostic"]
calls = diagnostics["sample_calls"]
continuation_calls = calls[1:]
video_path = _video_path(run["output_prefix"], args.output_dir)
frames, fps = _read_frames(video_path)
layouts = [call["packed_layouts"][0] for call in continuation_calls]
runs.append(
{
"label": run["label"],
"seed": run["seed"],
"transport": run["transport"],
"api_elapsed_seconds": run["api_elapsed_seconds"],
"sampling_seconds": sampling,
"continuation_sampling_seconds": sum(sampling[1:]),
"sample_host_continuation_seconds": sum(
float(call["sample_host_elapsed_seconds"]) for call in continuation_calls
),
"packed_seq_len": [layout["seq_len"] for layout in layouts],
"packed_rows_by_kind": [layout["rows_by_kind"] for layout in layouts],
"final_prefix_bit_exact": [
pair["bit_exact"] for pair in diagnostics["final_prefix_pairs"]
],
"final_prefix_max_abs_diff": [
pair["max_abs_diff"] for pair in diagnostics["final_prefix_pairs"]
],
"peak_process_rss_bytes": run["resources"]["peak_process_rss_bytes"],
"peak_process_uss_bytes": run["resources"]["peak_process_uss_bytes"],
"peak_device_used_bytes": run["resources"]["peak_device_used_bytes"],
"video": str(video_path),
"video_width": int(frames[0].shape[1]),
"video_height": int(frames[0].shape[0]),
"video_frames": len(frames),
"video_fps": fps,
"video_duration_seconds": len(frames) / fps,
"boundaries": [_boundary_metrics(frames, boundary) for boundary in (120, 240)],
}
)
pairs = []
for seed in sorted({run["seed"] for run in runs}):
by_transport = {run["transport"]: run for run in runs if run["seed"] == seed}
reference = by_transport["reference_context_v1"]
masked = by_transport["masked_video_prefix_v1"]
pairs.append(
{
"seed": seed,
"reference_api_seconds": reference["api_elapsed_seconds"],
"masked_api_seconds": masked["api_elapsed_seconds"],
"api_masked_faster_seconds": reference["api_elapsed_seconds"]
- masked["api_elapsed_seconds"],
"api_masked_faster_percent": 100.0
* (reference["api_elapsed_seconds"] - masked["api_elapsed_seconds"])
/ reference["api_elapsed_seconds"],
"reference_continuation_sampling_seconds": reference[
"continuation_sampling_seconds"
],
"masked_continuation_sampling_seconds": masked[
"continuation_sampling_seconds"
],
"continuation_masked_faster_percent": 100.0
* (
reference["continuation_sampling_seconds"]
- masked["continuation_sampling_seconds"]
)
/ reference["continuation_sampling_seconds"],
}
)
result = {
"format": "h3-continuum-v36-r1-stress-gate-analysis-v1",
"runs": runs,
"pairs": pairs,
"medians": {
"reference_api_seconds": _median(
[run["api_elapsed_seconds"] for run in runs if run["transport"] == "reference_context_v1"]
),
"masked_api_seconds": _median(
[run["api_elapsed_seconds"] for run in runs if run["transport"] == "masked_video_prefix_v1"]
),
"api_masked_faster_percent": _median(
[pair["api_masked_faster_percent"] for pair in pairs]
),
"reference_continuation_sampling_seconds": _median(
[pair["reference_continuation_sampling_seconds"] for pair in pairs]
),
"masked_continuation_sampling_seconds": _median(
[pair["masked_continuation_sampling_seconds"] for pair in pairs]
),
"continuation_masked_faster_percent": _median(
[pair["continuation_masked_faster_percent"] for pair in pairs]
),
},
}
args.result.parent.mkdir(parents=True, exist_ok=True)
args.result.write_text(json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8")
print(json.dumps({"pairs": pairs, "medians": result["medians"]}, indent=2))
if __name__ == "__main__":
main()
+416
View File
@@ -0,0 +1,416 @@
"""Run the V3.6-R1 three-chunk I2VA Strong Motion Stress Gate."""
from __future__ import annotations
import argparse
import copy
import json
from pathlib import Path
import re
import sys
import threading
import time
import uuid
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 p32_api_runner import submit_and_wait
STRONG_MOTION_PROMPT = (
"A dynamic cinematic live-action shot of the woman in the orange jacket "
"accelerating rapidly on her skateboard along the waterfront promenade. "
"She performs fast continuous S-turns, leaning deeply from side to side "
"while her hair and jacket react to speed. The low tracking camera sweeps "
"alongside her with a strong continuous pan and partial orbit, maintaining "
"motion through the sequence while preserving her face, orange jacket, "
"white trousers, skateboard, city skyline, cool daylight, and natural contrast."
)
TRANSPORTS = ("reference_context_v1", "masked_video_prefix_v1")
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):
for item in value:
yield from _walk_strings(item)
def _extract_evidence(history: Mapping[str, Any]) -> dict[str, Any]:
lines: list[str] = []
diagnostic = None
for text in _walk_strings(history):
for line in text.splitlines():
if line.startswith(("Prompt/CLIP cache [V3.5]", "Performance [V3.5")):
lines.append(line)
marker = "V3.6-R1 diagnostic: "
if marker in line:
diagnostic = json.loads(line.split(marker, 1)[1])
cache_line = next(
(line for line in lines if line.startswith("Prompt/CLIP cache [V3.5]")),
None,
)
cache = None
if cache_line:
match = re.search(
r"hits=(\d+), misses=(\d+), bypasses=(\d+), encode_calls=(\d+)",
cache_line,
)
if match:
cache = {
"hits": int(match.group(1)),
"misses": int(match.group(2)),
"bypasses": int(match.group(3)),
"encode_calls": int(match.group(4)),
}
return {
"prompt_clip_cache": cache,
"performance_lines": lines,
"diagnostic": diagnostic,
}
class ResourceMonitor:
def __init__(self, backend_pid: int | None, interval_seconds: float = 1.0):
self.backend_pid = int(backend_pid) if backend_pid else None
self.interval_seconds = float(interval_seconds)
self.peak_process_rss_bytes = 0
self.peak_process_uss_bytes = 0
self.minimum_system_available_bytes: int | None = None
self.peak_device_used_bytes = 0
self.samples = 0
self._stop = threading.Event()
self._thread: threading.Thread | None = None
self._psutil = None
self._process = None
self._nvml = None
self._nvml_handle = None
def __enter__(self):
try:
import psutil
self._psutil = psutil
if self.backend_pid:
self._process = psutil.Process(self.backend_pid)
except Exception:
self._psutil = None
self._process = None
try:
import pynvml
pynvml.nvmlInit()
self._nvml = pynvml
self._nvml_handle = pynvml.nvmlDeviceGetHandleByIndex(0)
except Exception:
self._nvml = None
self._nvml_handle = None
self._sample()
self._thread = threading.Thread(target=self._loop, daemon=True)
self._thread.start()
return self
def __exit__(self, exc_type, exc, tb):
self._stop.set()
if self._thread is not None:
self._thread.join(timeout=max(2.0, self.interval_seconds * 2.0))
self._sample()
if self._nvml is not None:
try:
self._nvml.nvmlShutdown()
except Exception:
pass
def _loop(self):
while not self._stop.wait(self.interval_seconds):
self._sample()
def _sample(self):
self.samples += 1
if self._psutil is not None:
try:
available = int(self._psutil.virtual_memory().available)
if self.minimum_system_available_bytes is None:
self.minimum_system_available_bytes = available
else:
self.minimum_system_available_bytes = min(
self.minimum_system_available_bytes, available
)
except Exception:
pass
if self._process is not None:
try:
self.peak_process_rss_bytes = max(
self.peak_process_rss_bytes,
int(self._process.memory_info().rss),
)
full = self._process.memory_full_info()
self.peak_process_uss_bytes = max(
self.peak_process_uss_bytes,
int(getattr(full, "uss", 0) or 0),
)
except Exception:
pass
if self._nvml is not None and self._nvml_handle is not None:
try:
used = int(self._nvml.nvmlDeviceGetMemoryInfo(self._nvml_handle).used)
self.peak_device_used_bytes = max(self.peak_device_used_bytes, used)
except Exception:
pass
def as_dict(self) -> dict[str, Any]:
return {
"backend_pid": self.backend_pid,
"samples": int(self.samples),
"peak_process_rss_bytes": int(self.peak_process_rss_bytes),
"peak_process_uss_bytes": int(self.peak_process_uss_bytes),
"minimum_system_available_bytes": self.minimum_system_available_bytes,
"peak_device_used_bytes": int(self.peak_device_used_bytes),
}
def configure_prompt(
source: Mapping[str, Any],
*,
transport: str,
output_prefix: str,
seed: int,
chunks: int,
synchronize_sampling: bool,
diagnostic_nonce: int,
) -> dict[str, Any]:
prompt = copy.deepcopy(dict(source))
sampler = prompt["305"]
sampler["class_type"] = "H3ContinuumMaskedPrefixR1Diagnostic"
sampler["_meta"] = {"title": "H3 Continuum V3.6-R1 Stress Diagnostic"}
sampler["inputs"].update(
{
"prompt_mode": "Fixed — one prompt",
"chunks": int(chunks),
"chunk_seconds": 5.0,
"width": 640,
"height": 640,
"continuity": "Balanced — 22 frames",
"base_seed": int(seed),
"audio_continuity": False,
"diagnostics": "Detailed Report",
"show_preview": False,
"run_storage": "Off",
"continuation_transport": str(transport),
"synchronize_sampling": bool(synchronize_sampling),
"diagnostic_nonce": int(diagnostic_nonce),
}
)
prompt["188"]["inputs"]["value"] = STRONG_MOTION_PROMPT
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)
return prompt
def _run_one(
*,
source: Mapping[str, Any],
args,
label: str,
transport: str,
seed: int,
chunks: int,
synchronize_sampling: bool,
nonce: int,
warmup: bool,
) -> dict[str, Any]:
run_root = args.output_root / label
run_root.mkdir(parents=True, exist_ok=True)
output_prefix = f"video/V36_R1_Stress_{label}_seed{seed}"
prompt = configure_prompt(
source,
transport=transport,
output_prefix=output_prefix,
seed=seed,
chunks=chunks,
synchronize_sampling=synchronize_sampling,
diagnostic_nonce=nonce,
)
prompt_path = run_root / "prompt.json"
prompt_path.write_text(
json.dumps(prompt, indent=2, ensure_ascii=False), encoding="utf-8"
)
print(
f"START label={label} transport={transport} seed={seed} chunks={chunks} "
f"sync={synchronize_sampling}",
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"v36-r1-stress-{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"
)
evidence = _extract_evidence(history)
result = {
"label": label,
"warmup": bool(warmup),
"transport": transport,
"seed": int(seed),
"chunks": int(chunks),
"synchronize_sampling": bool(synchronize_sampling),
"prompt_id": prompt_id,
"api_elapsed_seconds": float(elapsed),
"output_prefix": output_prefix,
"prompt": str(prompt_path),
"history": str(history_path),
"resources": monitor.as_dict(),
**evidence,
}
(run_root / "summary.json").write_text(
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
)
cache = result.get("prompt_clip_cache")
if not warmup and (not cache or cache.get("encode_calls") != 0):
raise RuntimeError(
f"measured run {label} did not use the required Prompt/CLIP cache HIT: {cache}"
)
diagnostic = result.get("diagnostic") or {}
calls = list(diagnostic.get("sample_calls") or [])
if transport == "masked_video_prefix_v1" and chunks >= 2:
for call in calls[1:]:
layouts = list(call.get("packed_layouts") or [])
if not layouts:
raise RuntimeError(f"masked continuation call has no PackedLayout evidence: {label}")
rows = dict(layouts[0].get("rows_by_kind") or {})
if int(rows.get("cond", 0)) != 0 or int(rows.get("ref_img", 0)) != 0:
raise RuntimeError(
f"masked continuation retained unfair I2VA/reference rows in {label}: {rows}"
)
final_pairs = list(diagnostic.get("final_prefix_pairs") or [])
if len(final_pairs) != chunks - 1 or not all(
bool(item.get("bit_exact")) for item in final_pairs
):
raise RuntimeError(
f"masked final prefix contract failed in {label}: {final_pairs}"
)
print(
f"DONE label={label} elapsed={elapsed:.3f}s cache={cache} "
f"rss={monitor.peak_process_rss_bytes / 2**30:.3f}GiB",
flush=True,
)
return result
def run(args) -> dict[str, Any]:
source = json.loads(args.prompt.read_text(encoding="utf-8"))
args.output_root.mkdir(parents=True, exist_ok=True)
seeds = [int(args.seed) + index for index in range(3)]
if args.mode == "normal":
schedule = [
(seeds[0], "reference_context_v1"),
(seeds[0], "masked_video_prefix_v1"),
(seeds[1], "masked_video_prefix_v1"),
(seeds[1], "reference_context_v1"),
(seeds[2], "reference_context_v1"),
(seeds[2], "masked_video_prefix_v1"),
]
else:
schedule = [
(seeds[0], "reference_context_v1"),
(seeds[0], "masked_video_prefix_v1"),
]
results = []
nonce = int(time.time()) & 0x7FFFFFFF
if not args.skip_warmup:
results.append(
_run_one(
source=source,
args=args,
label=f"warmup_{args.mode}",
transport="masked_video_prefix_v1",
seed=seeds[0],
chunks=int(args.warmup_chunks),
synchronize_sampling=False,
nonce=nonce,
warmup=True,
)
)
nonce += 1
for index, (seed, transport) in enumerate(schedule, start=1):
short = "reference" if transport.startswith("reference") else "masked"
label = f"{args.mode}_{index:02d}_seed{seed}_{short}"
results.append(
_run_one(
source=source,
args=args,
label=label,
transport=transport,
seed=seed,
chunks=3,
synchronize_sampling=args.mode == "sync",
nonce=nonce,
warmup=False,
)
)
nonce += 1
summary = {
"format": "h3-continuum-v36-r1-stress-gate-v1",
"mode": args.mode,
"server": args.server,
"base_seed": int(args.seed),
"warmup_excluded": True,
"pinned_memory_required_disabled": True,
"runs": results,
}
(args.output_root / "stress_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.1:8188")
parser.add_argument("--prompt", type=Path, required=True)
parser.add_argument("--output-root", type=Path, required=True)
parser.add_argument("--mode", choices=("normal", "sync"), default="normal")
parser.add_argument("--seed", type=int, default=238985343135601)
parser.add_argument("--backend-pid", type=int)
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("--skip-warmup", action="store_true")
parser.add_argument("--warmup-chunks", type=int, choices=(1, 2), default=1)
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())
+170
View File
@@ -0,0 +1,170 @@
"""Measure the R2 39f/65T decoded-audio transition around the chunk boundary."""
from __future__ import annotations
import argparse
import json
import math
from pathlib import Path
import subprocess
from typing import Any
import numpy as np
def _decode_audio(path: Path, ffmpeg: Path, sample_rate: int) -> np.ndarray:
completed = subprocess.run(
[
str(ffmpeg),
"-v",
"error",
"-i",
str(path),
"-map",
"0:a:0",
"-f",
"f32le",
"-acodec",
"pcm_f32le",
"-ac",
"2",
"-ar",
str(sample_rate),
"pipe:1",
],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
values = np.frombuffer(completed.stdout, dtype="<f4")
if values.size % 2:
raise RuntimeError(f"decoded stereo PCM has odd sample count: {values.size}")
return values.reshape(-1, 2).astype(np.float64, copy=False)
def _rms(value: np.ndarray) -> float:
return float(np.sqrt(np.mean(np.square(value)))) if value.size else 0.0
def _spectral_distance(before: np.ndarray, after: np.ndarray) -> float:
count = min(len(before), len(after))
if count < 8:
return math.nan
window = np.hanning(count)[:, None]
left = np.abs(np.fft.rfft(before[-count:] * window, axis=0)).reshape(-1)
right = np.abs(np.fft.rfft(after[:count] * window, axis=0)).reshape(-1)
denominator = float(np.linalg.norm(left) * np.linalg.norm(right))
if denominator <= 1e-20:
return 0.0
return float(1.0 - np.dot(left, right) / denominator)
def _zero_crossing_rate(value: np.ndarray) -> float:
if len(value) < 2:
return 0.0
signs = np.signbit(value)
return float(np.mean(signs[1:] != signs[:-1]))
def boundary_metrics(
audio: np.ndarray,
*,
sample_rate: int,
boundary_sample: int,
) -> dict[str, Any]:
if not 1 <= boundary_sample < len(audio):
raise ValueError(
f"boundary sample {boundary_sample} is outside decoded audio length {len(audio)}"
)
short = max(1, int(round(sample_rate * 0.05)))
long = max(short, int(round(sample_rate * 0.25)))
before_short = audio[boundary_sample - short : boundary_sample]
after_short = audio[boundary_sample : boundary_sample + short]
before_long = audio[boundary_sample - long : boundary_sample]
after_long = audio[boundary_sample : boundary_sample + long]
neighborhood = audio[boundary_sample - long : boundary_sample + long]
differences = np.abs(np.diff(neighborhood, axis=0)).reshape(-1)
global_differences = np.abs(np.diff(audio, axis=0)).reshape(-1)
sample_jump = float(np.max(np.abs(audio[boundary_sample] - audio[boundary_sample - 1])))
p50 = float(np.percentile(differences, 50)) if differences.size else 0.0
p99 = float(np.percentile(differences, 99)) if differences.size else 0.0
before_rms = _rms(before_short)
after_rms = _rms(after_short)
before_peak = float(np.max(np.abs(before_short)))
after_peak = float(np.max(np.abs(after_short)))
dc_jump = float(
np.max(np.abs(np.mean(after_short, axis=0) - np.mean(before_short, axis=0)))
)
return {
"decoded_samples_per_channel": int(len(audio)),
"decoded_duration_seconds": float(len(audio) / sample_rate),
"boundary_sample": int(boundary_sample),
"boundary_seconds": float(boundary_sample / sample_rate),
"sample_jump": sample_jump,
"local_abs_diff_p50": p50,
"local_abs_diff_p99": p99,
"sample_jump_over_local_p99": sample_jump / p99 if p99 > 0 else math.inf,
"global_abs_diff_p99": float(np.percentile(global_differences, 99)),
"global_abs_diff_max": float(np.max(global_differences)),
"sample_jump_global_percentile": float(
100.0 * np.mean(global_differences <= sample_jump)
),
"dc_jump_50ms": dc_jump,
"rms_before_50ms": before_rms,
"rms_after_50ms": after_rms,
"rms_ratio_after_over_before": after_rms / before_rms if before_rms > 0 else math.inf,
"peak_before_50ms": before_peak,
"peak_after_50ms": after_peak,
"peak_ratio_after_over_before": after_peak / before_peak if before_peak > 0 else math.inf,
"zero_crossing_before_250ms": _zero_crossing_rate(before_long),
"zero_crossing_after_250ms": _zero_crossing_rate(after_long),
"spectral_cosine_distance_250ms": _spectral_distance(before_long, after_long),
"finite": bool(np.isfinite(audio).all()),
}
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--reference", type=Path, required=True)
parser.add_argument("--masked", type=Path, required=True)
parser.add_argument("--result", type=Path, required=True)
parser.add_argument("--ffmpeg", type=Path, default=Path(r"C:\FFmpeg\bin\ffmpeg.exe"))
parser.add_argument("--sample-rate", type=int, default=32000)
parser.add_argument("--boundary-frame", type=int, default=124)
parser.add_argument("--fps", type=float, default=24.0)
args = parser.parse_args()
boundary_sample = int(round(args.boundary_frame * args.sample_rate / args.fps))
result = {
"format": "h3-continuum-v36-r2-audio-boundary-v1",
"sample_rate": int(args.sample_rate),
"boundary_frame": int(args.boundary_frame),
"fps": float(args.fps),
"boundary_sample_rounding": "round(frame * sample_rate / fps)",
"reference": {
"path": str(args.reference),
**boundary_metrics(
_decode_audio(args.reference, args.ffmpeg, args.sample_rate),
sample_rate=args.sample_rate,
boundary_sample=boundary_sample,
),
},
"masked": {
"path": str(args.masked),
**boundary_metrics(
_decode_audio(args.masked, args.ffmpeg, args.sample_rate),
sample_rate=args.sample_rate,
boundary_sample=boundary_sample,
),
},
}
args.result.parent.mkdir(parents=True, exist_ok=True)
args.result.write_text(
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
)
print(json.dumps(result, indent=2, ensure_ascii=False))
return 0
if __name__ == "__main__":
raise SystemExit(main())
+61
View File
@@ -0,0 +1,61 @@
"""Reassemble an accepted R2 prompt with Audio Seam Auto via ComfyUI cache."""
from __future__ import annotations
import argparse
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
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--server", default="http://127.0.0.1:8188")
parser.add_argument("--prompt", type=Path, required=True)
parser.add_argument("--output-root", type=Path, required=True)
parser.add_argument("--filename-prefix", required=True)
parser.add_argument("--timeout-seconds", type=float, default=300.0)
args = parser.parse_args()
prompt = json.loads(args.prompt.read_text(encoding="utf-8"))
prompt["306"]["inputs"]["audio_seam"] = "Auto"
prompt["191"]["inputs"]["filename_prefix"] = str(args.filename_prefix)
args.output_root.mkdir(parents=True, exist_ok=True)
prompt_path = args.output_root / "prompt.json"
prompt_path.write_text(
json.dumps(prompt, indent=2, ensure_ascii=False), encoding="utf-8"
)
prompt_id, history, elapsed = submit_and_wait(
server=args.server,
prompt=prompt,
client_id=f"v36-r2-seam-{uuid.uuid4().hex}",
timeout_seconds=args.timeout_seconds,
poll_seconds=1.0,
)
history_path = args.output_root / "history.json"
history_path.write_text(
json.dumps(history, indent=2, ensure_ascii=False), encoding="utf-8"
)
result = {
"prompt_id": prompt_id,
"api_elapsed_seconds": float(elapsed),
"prompt": str(prompt_path),
"history": str(history_path),
}
(args.output_root / "summary.json").write_text(
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
)
print(json.dumps(result, ensure_ascii=False))
return 0
if __name__ == "__main__":
raise SystemExit(main())
+292
View File
@@ -0,0 +1,292 @@
"""Run one-seed V3.6-R2 Joint AV GPU structure gates."""
from __future__ import annotations
import argparse
import copy
import json
from pathlib import Path
import sys
import time
import uuid
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 p32_api_runner import submit_and_wait
from v36_r1_stress_gate_runner import ResourceMonitor, _extract_evidence
PROFILES = {
"r2-1-39": {
"continuity": "Strong — 39 frames (Experimental)",
"transport": "masked_av_prefix_39_v1",
"reference_label": "reference_39f",
"masked_label": "masked_av_39f_65t",
"output_tag": "R2_Gate1",
},
"r2-2-22": {
"continuity": "Balanced — 22 frames",
"transport": "masked_av_prefix_22_v1",
"reference_label": "reference_22f",
"masked_label": "masked_av_22f_37t",
"output_tag": "R2_Gate2",
},
}
PROMPT = (
"A continuous cinematic live-action tracking shot of one skateboarder "
"moving steadily along a waterfront promenade while the camera follows at "
"constant speed. Preserve forward motion, body pose, direction, and camera "
"movement through the entire shot. Natural city ambience, rolling skateboard "
"wheels, wind, and distant traffic continue without interruption."
)
def configure_prompt(
source: Mapping[str, Any],
*,
transport: str,
output_prefix: str,
seed: int,
synchronize_sampling: bool,
diagnostic_nonce: int,
chunks: int,
continuity: str,
) -> dict[str, Any]:
prompt = copy.deepcopy(dict(source))
sampler = prompt["305"]
sampler["class_type"] = "H3ContinuumMaskedPrefixR1Diagnostic"
sampler["_meta"] = {"title": "H3 Continuum V3.6-R2 Joint AV Diagnostic"}
sampler["inputs"].pop("first_frame", None)
sampler["inputs"].update(
{
"prompt_mode": "Fixed — one prompt",
"chunks": int(chunks),
"chunk_seconds": 5.0,
"width": 640,
"height": 640,
"continuity": str(continuity),
"base_seed": int(seed),
"audio_continuity": True,
"diagnostics": "Detailed Report",
"show_preview": False,
"run_storage": "Off",
"continuation_transport": str(transport),
"synchronize_sampling": bool(synchronize_sampling),
"diagnostic_nonce": int(diagnostic_nonce),
}
)
prompt["188"]["inputs"]["value"] = PROMPT
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)
return prompt
def _validate_masked(diagnostic: Mapping[str, Any]) -> None:
calls = list(diagnostic.get("sample_calls") or [])
if len(calls) != 2:
raise RuntimeError(f"expected two physical Sampling calls, got {len(calls)}")
continuation = calls[1]
if continuation.get("minimax_ref_kinds"):
raise RuntimeError(
f"masked AV continuation unexpectedly emitted refs: "
f"{continuation.get('minimax_ref_kinds')}"
)
if bool(continuation.get("continuum_interop_emitted")):
raise RuntimeError("masked AV continuation emitted old Spectrum interop")
checks = {
"source_tail_matches_target_prefix": True,
"source_audio_tail_matches_target_prefix": True,
"video_mask_prefix_zero": True,
"video_mask_generated_one": True,
"audio_mask_prefix_zero": True,
"audio_mask_generated_one": True,
}
for name, expected in checks.items():
if continuation.get(name) is not expected:
raise RuntimeError(f"masked AV evidence failed {name}: {continuation.get(name)!r}")
pairs = list(diagnostic.get("final_prefix_pairs") or [])
if len(pairs) != 1:
raise RuntimeError(f"expected one finalized AV prefix pair, got {len(pairs)}")
pair = pairs[0]
if not bool(pair.get("bit_exact")) or float(pair.get("max_abs_diff", 1.0)) != 0.0:
raise RuntimeError(f"final video prefix is not bit-exact: {pair}")
if not bool(pair.get("audio_bit_exact")) or float(
pair.get("audio_max_abs_diff", 1.0)
) != 0.0:
raise RuntimeError(f"final audio prefix is not bit-exact: {pair}")
def _validate_reference(diagnostic: Mapping[str, Any]) -> None:
calls = list(diagnostic.get("sample_calls") or [])
if len(calls) != 2:
raise RuntimeError(f"expected two physical Sampling calls, got {len(calls)}")
continuation = calls[1]
kinds = list(continuation.get("minimax_ref_kinds") or [])
separate_av = "video" in kinds and "audio" in kinds
combined_av = "video_audio" in kinds
if not separate_av and not combined_av:
raise RuntimeError(f"39f reference route lacks AV refs: {kinds}")
if not bool(continuation.get("continuum_interop_emitted")):
raise RuntimeError("39f reference route lacks Continuum interop")
def _run_one(
*,
source: Mapping[str, Any],
args,
transport: str,
label: str,
nonce: int,
chunks: int,
warmup: bool,
) -> dict[str, Any]:
run_root = args.output_root / label
run_root.mkdir(parents=True, exist_ok=True)
profile = PROFILES[args.profile]
output_prefix = f"video/V36_{profile['output_tag']}_{label}_seed{args.seed}"
prompt = configure_prompt(
source,
transport=transport,
output_prefix=output_prefix,
seed=args.seed,
synchronize_sampling=not warmup,
diagnostic_nonce=nonce,
chunks=chunks,
continuity=str(profile["continuity"]),
)
prompt_path = run_root / "prompt.json"
prompt_path.write_text(
json.dumps(prompt, indent=2, ensure_ascii=False), encoding="utf-8"
)
print(f"START {label} transport={transport} chunks={chunks}", 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"v36-r2-{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"
)
evidence = _extract_evidence(history)
result = {
"label": label,
"warmup": bool(warmup),
"transport": transport,
"seed": int(args.seed),
"chunks": int(chunks),
"synchronize_sampling": not warmup,
"prompt_id": prompt_id,
"api_elapsed_seconds": float(elapsed),
"output_prefix": output_prefix,
"prompt": str(prompt_path),
"history": str(history_path),
"resources": monitor.as_dict(),
**evidence,
}
(run_root / "summary.json").write_text(
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
)
cache = result.get("prompt_clip_cache")
if not warmup and (not cache or cache.get("encode_calls") != 0):
raise RuntimeError(f"measured run did not use Prompt/CLIP cache HIT: {cache}")
if not warmup:
diagnostic = result.get("diagnostic") or {}
if transport.startswith("masked_av_prefix_"):
_validate_masked(diagnostic)
else:
_validate_reference(diagnostic)
print(f"DONE {label} elapsed={elapsed:.3f}s cache={cache}", flush=True)
return result
def run(args) -> dict[str, Any]:
source = json.loads(args.prompt.read_text(encoding="utf-8"))
profile = PROFILES[args.profile]
args.output_root.mkdir(parents=True, exist_ok=True)
nonce = int(time.time()) & 0x7FFFFFFF
runs = []
schedule = [(str(profile["transport"]), str(profile["masked_label"]))]
if not args.resume_masked_only:
runs.append(
_run_one(
source=source,
args=args,
transport=str(profile["transport"]),
label="warmup",
nonce=nonce,
chunks=1,
warmup=True,
)
)
schedule.insert(0, ("reference_context_v1", str(profile["reference_label"])))
for transport, label in schedule:
nonce += 1
runs.append(
_run_one(
source=source,
args=args,
transport=transport,
label=label,
nonce=nonce,
chunks=2,
warmup=False,
)
)
result = {
"format": "h3-continuum-v36-r2-gpu-structure-gate-v1",
"server": args.server,
"seed": int(args.seed),
"profile": args.profile,
"continuity": str(profile["continuity"]),
"audio_continuity": True,
"synchronized_sampling": True,
"runs": runs,
}
(args.output_root / "gate_summary.json").write_text(
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
)
return result
def _parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--server", default="http://127.0.0.1:8188")
parser.add_argument("--prompt", type=Path, required=True)
parser.add_argument("--output-root", type=Path, required=True)
parser.add_argument("--seed", type=int, default=238985343135604)
parser.add_argument("--profile", choices=tuple(PROFILES), default="r2-1-39")
parser.add_argument("--backend-pid", type=int)
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(
"--resume-masked-only",
action="store_true",
help="Resume after a completed Reference run without repeating it.",
)
return parser
def main() -> int:
print(json.dumps(run(_parser().parse_args()), ensure_ascii=False))
return 0
if __name__ == "__main__":
raise SystemExit(main())