Stabilize Continuum cloning and workflow guidance
This commit is contained in:
+20
-12
@@ -19,7 +19,9 @@ from .prompts import (
|
||||
apply_prompt_overrides,
|
||||
build_sampler_prompt_plan,
|
||||
make_prompt_plan,
|
||||
parse_sparse_prompt_overrides,
|
||||
prompt_plan_report,
|
||||
validate_sparse_prompt_overrides,
|
||||
)
|
||||
from .sequence import run_sequence
|
||||
from .session import entry_to_state, session_summary, validate_session
|
||||
@@ -32,6 +34,7 @@ from .session_io import (
|
||||
|
||||
CATEGORY = "MiniMax H3/Continuum"
|
||||
LOG = logging.getLogger("h3_continuum_join")
|
||||
SPARSE_OVERRIDE_SCHEMA_VERSION = 1
|
||||
|
||||
|
||||
def _repair_v200_example_widget_shift(
|
||||
@@ -493,6 +496,10 @@ class H3ContinuumClipOverrides:
|
||||
{
|
||||
"default": PROMPT_FORMAT_OPTIONS[0],
|
||||
"display_name": "Prompt Format",
|
||||
"tooltip": (
|
||||
"Retained for V2.1.7 workflow compatibility. Sparse overrides "
|
||||
"use explicit [Clip N] sections."
|
||||
),
|
||||
},
|
||||
),
|
||||
"override_script": (
|
||||
@@ -501,8 +508,8 @@ class H3ContinuumClipOverrides:
|
||||
"forceInput": True,
|
||||
"display_name": "Override Script",
|
||||
"tooltip": (
|
||||
"Connect one Text (Multiline). Use ---, [Chunk N], or "
|
||||
"timeline sections according to Prompt Format."
|
||||
"Connect one Text (Multiline). Define only the clips to replace "
|
||||
"with [Clip N] or [Chunk N] sections."
|
||||
),
|
||||
},
|
||||
),
|
||||
@@ -517,8 +524,8 @@ class H3ContinuumClipOverrides:
|
||||
def build(self, prompt_mode, override_script):
|
||||
return (
|
||||
{
|
||||
"prompt_mode": str(prompt_mode),
|
||||
"prompt_script": str(override_script),
|
||||
"schema_version": SPARSE_OVERRIDE_SCHEMA_VERSION,
|
||||
"overrides": parse_sparse_prompt_overrides(override_script),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -724,15 +731,16 @@ class H3ContinuumSampler:
|
||||
|
||||
clip_prompt_inputs = {}
|
||||
if prompt_overrides:
|
||||
override_plan = make_prompt_plan(
|
||||
mode=prompt_overrides.get("prompt_mode", PROMPT_FORMAT_OPTIONS[0]),
|
||||
script=prompt_overrides.get("prompt_script", ""),
|
||||
chunks=int(chunks),
|
||||
chunk_seconds=float(chunk_seconds),
|
||||
if (
|
||||
type(prompt_overrides.get("schema_version")) is not int
|
||||
or prompt_overrides.get("schema_version") != SPARSE_OVERRIDE_SCHEMA_VERSION
|
||||
):
|
||||
raise ValueError("unsupported H3_CONTINUUM_CLIP_OVERRIDES schema")
|
||||
sparse_overrides = validate_sparse_prompt_overrides(
|
||||
prompt_overrides.get("overrides"), chunks=int(chunks)
|
||||
)
|
||||
for index, prompt in enumerate(override_plan.get("prompts", []), start=1):
|
||||
if isinstance(prompt, str) and prompt.strip():
|
||||
clip_prompt_inputs[f"clip_{index}_prompt"] = prompt
|
||||
for index, prompt in sparse_overrides.items():
|
||||
clip_prompt_inputs[f"clip_{index}_prompt"] = prompt
|
||||
|
||||
images, audio, last_state, session, report = H3ContinuumSamplerV2().run(
|
||||
model=model,
|
||||
|
||||
@@ -60,6 +60,24 @@ def _parse_timeline_sections(script):
|
||||
finish()
|
||||
if not sections: raise PromptPlanError("timeline contains no sections")
|
||||
return sections
|
||||
def parse_sparse_prompt_overrides(script):
|
||||
sections=_parse_timeline_sections(script); overrides={}
|
||||
for item in sections:
|
||||
if item["kind"]!="chunk": raise PromptPlanError("Sparse Clip Overrides only accepts [Clip N] or [Chunk N] sections")
|
||||
index=int(item["index"])
|
||||
if index in overrides: raise PromptPlanError(f"Sparse Clip Overrides defines Clip {index} more than once")
|
||||
overrides[index]=item["prompt"]
|
||||
return overrides
|
||||
def validate_sparse_prompt_overrides(overrides,*,chunks):
|
||||
chunks=int(chunks)
|
||||
if not isinstance(overrides,dict): raise PromptPlanError("Sparse Clip Overrides must be a dictionary")
|
||||
validated={}
|
||||
for index,prompt in overrides.items():
|
||||
if type(index) is not int: raise PromptPlanError("Sparse Clip Override numbers must be integers")
|
||||
if not 1<=index<=chunks: raise PromptPlanError(f"Sparse Clip Override {index} is outside the configured 1-{chunks} chunks")
|
||||
validated[index]=_normalize_prompt(prompt,label=f"Clip {index} Override")
|
||||
if not validated: raise PromptPlanError("Sparse Clip Overrides contains no overrides")
|
||||
return validated
|
||||
def _parse_timeline(script,chunks,chunk_seconds):
|
||||
sections=_parse_timeline_sections(script); prompts=[]; notes=[]
|
||||
for chunk_index in range(1,chunks+1):
|
||||
|
||||
+6
-4
@@ -16,7 +16,7 @@ from ..constants import (
|
||||
SEAM_CORRECTION_OPTIONS, V2_CONTINUITY_AUTO, normalize_diagnostics_mode,
|
||||
)
|
||||
from ..continuation import POLICY_REPLACE, prepare_conditioning
|
||||
from ..model_patch import clone_model_for_chunk, patch_model
|
||||
from ..model_patch import clone_model_for_chunk
|
||||
from ..state import assert_context_unchanged, context_fingerprint, make_plan, select_context, validate_state
|
||||
from ..temporal import align_frame_count_up, largest_context_capacity, make_extension_shape
|
||||
from ..version import PACKAGE_VERSION
|
||||
@@ -87,7 +87,9 @@ def run_sequence(*,model:Any,clip:Any,video_vae:Any,audio_vae:Any,sampler:Any,si
|
||||
issues=check_comfy_h3_runtime()
|
||||
if issues and strict_compatibility: raise SequenceRuntimeError("H3 runtime is incompatible: "+"; ".join(issues))
|
||||
assets=prepare_identity_assets(video_vae,width=width,height=height,first_frame=first_frame,last_frame=last_frame,encode_latents=False)
|
||||
patched_model=patch_model(model,strict=bool(strict_compatibility),debug=bool(debug)); current_model_fingerprint=model_fingerprint(patched_model)
|
||||
current_model_fingerprint=model_fingerprint(model,extra_wrapper_keys=("h3_continuum_join.apply_model.v1",))
|
||||
accelerators=accelerator_summary(model)
|
||||
if "Continuum APPLY_MODEL wrapper installed" not in accelerators: accelerators+="; Continuum APPLY_MODEL wrapper installed"
|
||||
preserved,reuse_notes=_preserved_prefix(session=session,prompt_hashes=prompt_hashes,chunks=chunks,reroll_from_chunk=int(reroll_from_chunk),width=width,height=height,chunk_seconds=chunk_seconds,identity_hash=assets.identity_hash)
|
||||
if session is not None:
|
||||
old_fingerprint=str(session.get("model_fingerprint",""))
|
||||
@@ -112,7 +114,7 @@ def run_sequence(*,model:Any,clip:Any,video_vae:Any,audio_vae:Any,sampler:Any,si
|
||||
video_context,audio_context,grid_offset=select_context(previous_state,context_frames,include_audio=bool(audio_continuity)); context_before=context_fingerprint(video_context,audio_context)
|
||||
conditioning=prepare_conditioning(base_conditioning,video_context=video_context,audio_context=audio_context,audio_grid_offset=grid_offset,context_frames=context_frames,new_frame_count=shape.total_frames,first_frame_policy=POLICY_REPLACE,preserve_last_frame=True)
|
||||
clip_index=int(previous_state["clip_index"])+1; chunk_plan=make_plan(continuation=True,clip_index=clip_index,total_frames=shape.total_frames,trim_frames=context_frames,width=width,height=height,context_frames=context_frames,state_capacity_frames=largest_context_capacity(shape.net_new_frames),requested_extend_seconds=chunk_seconds,debug=debug)
|
||||
chunk_model=clone_model_for_chunk(patched_model,strict=bool(strict_compatibility),debug=bool(debug),chunk_index=clip_index,context_frames=context_frames if previous_state is not None else None)
|
||||
chunk_model=clone_model_for_chunk(model,strict=bool(strict_compatibility),debug=bool(debug),chunk_index=clip_index,context_frames=context_frames if previous_state is not None else None)
|
||||
sampled=sample_chunk(model=chunk_model,conditioning=conditioning,latent=latent,sampler=sampler,sigmas=sigmas,seed=seed,enable_preview=bool(enable_preview))
|
||||
if context_before is not None and video_context is not None: assert_context_unchanged(video_context,audio_context,context_before)
|
||||
entry=make_chunk_entry(latent=sampled,plan=chunk_plan,prompt=prompt,prompt_hash=prompt_hash_value,seed=seed,context_frames=context_frames,motion_score=motion_score,reused=False); previous_state=entry_to_state(entry); entries.append(entry); retained_frames+=int(chunk_plan["net_frames"])
|
||||
@@ -128,7 +130,7 @@ def run_sequence(*,model:Any,clip:Any,video_vae:Any,audio_vae:Any,sampler:Any,si
|
||||
settings={"continuity":continuity,"audio_continuity":bool(audio_continuity),"exact_total_duration":bool(exact_total_duration),"prompt_mode":plan["mode"],"base_seed":int(base_seed),"reroll_nonce":int(reroll_nonce),"diagnostics_mode":diagnostics_mode,"initial_state_source":initial_state is not None}
|
||||
new_session=make_session(chunks=entries,width=width,height=height,chunk_seconds=chunk_seconds,identity_hash=assets.identity_hash,model_fingerprint_value=current_model_fingerprint,parent_session_id=parent_id,reroll_from_chunk=int(reroll_from_chunk),settings=settings)
|
||||
decoded_gib=float(images.shape[0])*float(width)*float(height)*3.0*4.0/(1024.0**3)
|
||||
report_lines=[f"H3 Continuum V2 {PACKAGE_VERSION}",prompt_plan_report(plan),f"Seam correction: {seam_correction}.",accelerator_summary(patched_model),"Execution: conditioning precomputed; call-local MODEL clone per chunk; decode deferred until sampling completed.",*reuse_notes]
|
||||
report_lines=[f"H3 Continuum V2 {PACKAGE_VERSION}",prompt_plan_report(plan),f"Seam correction: {seam_correction}.",accelerators,"Execution: conditioning precomputed; single call-local MODEL clone per chunk; decode deferred until sampling completed.",*reuse_notes]
|
||||
if diagnostics_mode!=DIAGNOSTICS_OFF: report_lines.extend([f"Decode RAM estimate: {decode_estimate_gib:.2f} GiB including transient headroom"+(f"; available at start {available_ram_gib:.2f} GiB." if available_ram_gib is not None else "."),*sampling_reports,*decode_reports])
|
||||
if duration_report: report_lines.append(duration_report)
|
||||
report_lines.extend([session_summary(new_session),f"Output: {images.shape[0]} frames ({images.shape[0]/FPS:.3f}s), audio samples={audio['waveform'].shape[-1]}, decoded tensor≈{decoded_gib:.2f} GiB."])
|
||||
|
||||
+5
-1
@@ -33,7 +33,9 @@ def _now_iso() -> str:
|
||||
return datetime.now(timezone.utc).replace(microsecond=0).isoformat()
|
||||
|
||||
|
||||
def model_fingerprint(model: Any) -> str:
|
||||
def model_fingerprint(
|
||||
model: Any, *, extra_wrapper_keys: tuple[str, ...] = ()
|
||||
) -> str:
|
||||
base = getattr(model, "model", None)
|
||||
inner = getattr(base, "diffusion_model", None)
|
||||
options = getattr(model, "model_options", {}) or {}
|
||||
@@ -44,6 +46,8 @@ def model_fingerprint(model: Any) -> str:
|
||||
for group in wrappers.values():
|
||||
if isinstance(group, dict):
|
||||
wrapper_keys.extend(str(key) for key in group)
|
||||
if extra_wrapper_keys:
|
||||
wrapper_keys = sorted(set(wrapper_keys).union(map(str, extra_wrapper_keys)))
|
||||
descriptor = {
|
||||
"base": f"{type(base).__module__}.{type(base).__name__}" if base is not None else "missing",
|
||||
"inner": f"{type(inner).__module__}.{type(inner).__name__}" if inner is not None else "missing",
|
||||
|
||||
Reference in New Issue
Block a user