Release H3 Continuum V3.3.0
This commit is contained in:
+31
-2
@@ -91,14 +91,43 @@ def encode_prompt_conditioning(
|
||||
*,
|
||||
first_image: torch.Tensor | None,
|
||||
last_image: torch.Tensor | None,
|
||||
reference_audio_assets=None,
|
||||
timeline_video_assets=None,
|
||||
) -> list:
|
||||
images = []
|
||||
if first_image is not None:
|
||||
images.append(first_image)
|
||||
if last_image is not None:
|
||||
images.append(last_image)
|
||||
tokens = clip.tokenize(str(prompt), images=images)
|
||||
return clip.encode_from_tokens_scheduled(tokens)
|
||||
tokenize_options = {"images": images}
|
||||
if reference_audio_assets is not None or timeline_video_assets is not None:
|
||||
from ..reference_audio import reference_audio_item
|
||||
|
||||
ref_items = [
|
||||
*({"type": "image", "data": image} for image in images),
|
||||
]
|
||||
if timeline_video_assets is not None:
|
||||
ref_items.append(dict(timeline_video_assets.item))
|
||||
if reference_audio_assets is not None:
|
||||
ref_items.append(reference_audio_item())
|
||||
tokenize_options = {
|
||||
"minimax_ref_items": ref_items
|
||||
}
|
||||
tokens = clip.tokenize(str(prompt), **tokenize_options)
|
||||
conditioning = clip.encode_from_tokens_scheduled(tokens)
|
||||
if reference_audio_assets is None and timeline_video_assets is None:
|
||||
return conditioning
|
||||
refs = []
|
||||
if timeline_video_assets is not None:
|
||||
refs.append(dict(timeline_video_assets.block))
|
||||
if reference_audio_assets is not None:
|
||||
from ..reference_audio import reference_audio_block
|
||||
|
||||
refs.append(dict(reference_audio_block(reference_audio_assets)))
|
||||
return [
|
||||
[tensor, {**dict(metadata), "minimax_refs": list(refs)}]
|
||||
for tensor, metadata in conditioning
|
||||
]
|
||||
|
||||
|
||||
def attach_keyframes(
|
||||
|
||||
@@ -305,6 +305,9 @@ class H3ContinuumSamplerV2:
|
||||
show_preview=True,
|
||||
latent_only=False,
|
||||
reference_assets=None,
|
||||
reference_audio_source=None,
|
||||
reference_audio_vae=None,
|
||||
timeline_video_source=None,
|
||||
**clip_prompt_inputs,
|
||||
):
|
||||
(
|
||||
@@ -371,6 +374,9 @@ class H3ContinuumSamplerV2:
|
||||
initial_state=initial_state,
|
||||
latent_only=bool(latent_only),
|
||||
reference_assets=reference_assets,
|
||||
reference_audio_source=reference_audio_source,
|
||||
reference_audio_vae=reference_audio_vae,
|
||||
timeline_video_source=timeline_video_source,
|
||||
)
|
||||
|
||||
|
||||
|
||||
+80
-20
@@ -13,12 +13,19 @@ from ..constants import (
|
||||
from ..version import PROMPT_PLAN_SCHEMA_VERSION
|
||||
_TIMELINE_HEADER=re.compile(r"^\s*\[\s*(?P<start>\d+(?:\.\d+)?)\s*(?:s|sec|seconds)?\s*[-–—]\s*(?P<end>\d+(?:\.\d+)?)\s*(?:s|sec|seconds)?\s*\]\s*$",re.IGNORECASE)
|
||||
_CHUNK_HEADER=re.compile(r"^\s*\[\s*(?:chunk|clip)\s*(?P<index>\d+)\s*\]\s*$",re.IGNORECASE)
|
||||
_TIMELINE_LIKE_HEADER=re.compile(r"^\s*\[\s*(?:(?:chunk|clip)\b|\d+(?:\.\d+)?[^\]]*(?:[-–—]|\bto\b))",re.IGNORECASE)
|
||||
_LIST_SEPARATOR=re.compile(r"^\s*---+\s*$",re.MULTILINE)
|
||||
class PromptPlanError(ValueError): pass
|
||||
def _prompt_error(code,reason,*,line_number=None,source=None,suggested_fix):
|
||||
location=f" line {line_number}" if line_number is not None else ""
|
||||
lines=[f"{code}{location}: {reason}"]
|
||||
if source is not None: lines.append(f"Source: {source}")
|
||||
if suggested_fix: lines.append(f"Suggested fix: {suggested_fix}")
|
||||
raise PromptPlanError("\n".join(lines))
|
||||
def prompt_hash(prompt:str)->str: return hashlib.sha256(prompt.encode("utf-8")).hexdigest()
|
||||
def _normalize_prompt(value:str,*,label:str)->str:
|
||||
text=str(value).strip()
|
||||
if not text: raise PromptPlanError(f"{label} is empty")
|
||||
if not text: _prompt_error("H3C-P005",f"{label} is empty",suggested_fix="provide non-empty prompt text")
|
||||
return text
|
||||
def _parse_json_list(script:str):
|
||||
stripped=script.lstrip()
|
||||
@@ -35,33 +42,46 @@ def _parse_list(script,chunks):
|
||||
if len(values)<chunks: notes.append(f"repeated the last prompt for {chunks-len(values)} chunk(s)"); values.extend([values[-1]]*(chunks-len(values)))
|
||||
elif len(values)>chunks: notes.append(f"ignored {len(values)-chunks} extra prompt(s)"); values=values[:chunks]
|
||||
return values,notes
|
||||
def _parse_timeline_sections(script):
|
||||
def _timeline_preamble(script):
|
||||
body=[]
|
||||
for line in str(script).splitlines():
|
||||
if _TIMELINE_HEADER.match(line) or _CHUNK_HEADER.match(line): break
|
||||
body.append(line)
|
||||
return "\n".join(body).strip()
|
||||
def _parse_timeline_sections(script,*,allow_preamble=True):
|
||||
preamble=_timeline_preamble(script)
|
||||
sections=[]; current=None; body=[]
|
||||
def finish():
|
||||
nonlocal current,body
|
||||
if current is None:
|
||||
if any(line.strip() for line in body): raise PromptPlanError("timeline text before the first [0-5s] or [Chunk 1] header is not allowed")
|
||||
if any(line.strip() for line in body) and not allow_preamble: raise PromptPlanError("timeline text before the first [0-5s] or [Chunk 1] header is not allowed")
|
||||
body=[]; return
|
||||
current["prompt"]=_normalize_prompt("\n".join(body),label="timeline section"); sections.append(current); current=None; body=[]
|
||||
for line in str(script).splitlines():
|
||||
if not any(line.strip() for line in body):
|
||||
_prompt_error("H3C-P005","timeline section body is empty",line_number=current["line_number"],source=current["source"],suggested_fix="add prompt text below this header")
|
||||
prompt=_normalize_prompt("\n".join(body),label="timeline section")
|
||||
current["prompt"]=f"{preamble}\n\n{prompt}" if preamble else prompt
|
||||
sections.append(current); current=None; body=[]
|
||||
for line_number,line in enumerate(str(script).splitlines(),start=1):
|
||||
time_match=_TIMELINE_HEADER.match(line); chunk_match=_CHUNK_HEADER.match(line)
|
||||
if time_match or chunk_match:
|
||||
finish()
|
||||
if time_match:
|
||||
start=float(time_match.group("start")); end=float(time_match.group("end"))
|
||||
if not end>start: raise PromptPlanError(f"timeline range must increase: {line.strip()}")
|
||||
current={"kind":"time","start":start,"end":end}
|
||||
if not end>start: _prompt_error("H3C-P002","timeline end must be greater than its start",line_number=line_number,source=line.strip(),suggested_fix="use an increasing range such as [0-5s]")
|
||||
current={"kind":"time","start":start,"end":end,"line_number":line_number,"source":line.strip()}
|
||||
else:
|
||||
index=int(chunk_match.group("index"))
|
||||
if index<1: raise PromptPlanError("chunk numbers are one-based")
|
||||
current={"kind":"chunk","index":index}
|
||||
if index<1: _prompt_error("H3C-P004","chunk numbers are one-based",line_number=line_number,source=line.strip(),suggested_fix="use [Chunk 1] or a larger one-based chunk number")
|
||||
current={"kind":"chunk","index":index,"line_number":line_number,"source":line.strip()}
|
||||
continue
|
||||
if _TIMELINE_LIKE_HEADER.match(line):
|
||||
_prompt_error("H3C-P001","invalid timeline header",line_number=line_number,source=line.strip(),suggested_fix="use [0-5s] or [Chunk 1]")
|
||||
body.append(line)
|
||||
finish()
|
||||
if not sections: raise PromptPlanError("timeline contains no sections")
|
||||
return sections
|
||||
def parse_sparse_prompt_overrides(script):
|
||||
sections=_parse_timeline_sections(script); overrides={}
|
||||
sections=_parse_timeline_sections(script,allow_preamble=False); 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"])
|
||||
@@ -79,24 +99,53 @@ def validate_sparse_prompt_overrides(overrides,*,chunks):
|
||||
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=[]
|
||||
sections=_parse_timeline_sections(script); prompts=[]; notes=[]; diagnostics=[]
|
||||
if _timeline_preamble(script): notes.append("applied timeline preamble to all chunks")
|
||||
seen_chunks={}; total_end=chunks*chunk_seconds; usable=[]
|
||||
for item in sections:
|
||||
if item["kind"]=="chunk":
|
||||
index=int(item["index"])
|
||||
if index in seen_chunks:
|
||||
_prompt_error("H3C-P003",f"timeline defines Chunk {index} more than once",line_number=item["line_number"],source=item["source"],suggested_fix=f"keep only one [Chunk {index}] section")
|
||||
seen_chunks[index]=item
|
||||
if index<=chunks: usable.append(item)
|
||||
else: diagnostics.append({"level":"warning","code":"H3C-P104","message":f"ignored {item['source']} because the configured sequence has only {chunks} chunk(s)"})
|
||||
elif min(total_end,item["end"])-max(0.0,item["start"])>0:
|
||||
usable.append(item)
|
||||
else:
|
||||
diagnostics.append({"level":"warning","code":"H3C-P104","message":f"ignored {item['source']} because it is outside 0-{total_end:.3f}s"})
|
||||
if not usable:
|
||||
_prompt_error("H3C-P005","timeline contains no usable prompt section for the configured sequence",suggested_fix="add a section such as [0-5s] with non-empty prompt text")
|
||||
previous_prompt=None; previous_source=None
|
||||
for chunk_index in range(1,chunks+1):
|
||||
chunk_sections=[item for item in sections if item["kind"]=="chunk" and item["index"]==chunk_index]
|
||||
if len(chunk_sections)>1: raise PromptPlanError(f"timeline defines Chunk {chunk_index} more than once")
|
||||
if chunk_sections: prompts.append(chunk_sections[0]["prompt"]); continue
|
||||
if chunk_sections:
|
||||
selected=chunk_sections[0]; prompts.append(selected["prompt"]); previous_prompt=selected["prompt"]; previous_source=f"{selected['source']} at line {selected['line_number']}"
|
||||
diagnostics.append({"level":"info","code":"H3C-P000","message":f"Chunk {chunk_index} source: {previous_source}"}); continue
|
||||
start=(chunk_index-1)*chunk_seconds; end=chunk_index*chunk_seconds; scored=[]
|
||||
for order,item in enumerate(sections):
|
||||
if item["kind"]!="time": continue
|
||||
overlap=max(0.0,min(end,item["end"])-max(start,item["start"]))
|
||||
if overlap>0: scored.append((overlap,-order,item))
|
||||
if not scored: raise PromptPlanError(f"timeline does not cover chunk {chunk_index} ({start:.3f}-{end:.3f}s)")
|
||||
scored.sort(reverse=True,key=lambda row:(row[0],row[1])); prompts.append(scored[0][2]["prompt"])
|
||||
if not scored:
|
||||
if previous_prompt is None:
|
||||
selected=usable[0]; fallback_reason=f"used earliest valid prompt from {selected['source']}"
|
||||
else:
|
||||
selected=None; fallback_reason=f"reused previous prompt from {previous_source}"
|
||||
prompt=selected["prompt"] if selected is not None else previous_prompt
|
||||
source=f"{selected['source']} at line {selected['line_number']}" if selected is not None else previous_source
|
||||
prompts.append(prompt); previous_prompt=prompt; previous_source=source
|
||||
diagnostics.append({"level":"warning","code":"H3C-P101","message":f"Timeline does not cover Chunk {chunk_index} ({start:.3f}-{end:.3f}s); {fallback_reason}."})
|
||||
diagnostics.append({"level":"info","code":"H3C-P000","message":f"Chunk {chunk_index} source: fallback to {source}"}); continue
|
||||
scored.sort(reverse=True,key=lambda row:(row[0],row[1])); selected=scored[0][2]; prompts.append(selected["prompt"]); previous_prompt=selected["prompt"]; previous_source=f"{selected['source']} at line {selected['line_number']}"
|
||||
diagnostics.append({"level":"info","code":"H3C-P000","message":f"Chunk {chunk_index} source: {previous_source}"})
|
||||
if len(scored)>1 and abs(scored[0][0]-scored[1][0])<1e-9: notes.append(f"chunk {chunk_index} had an equal-overlap timeline tie; used the earlier section")
|
||||
return prompts,notes
|
||||
return prompts,notes,diagnostics
|
||||
def detect_prompt_mode(script):
|
||||
text=str(script)
|
||||
for line in text.splitlines():
|
||||
if _TIMELINE_HEADER.match(line) or _CHUNK_HEADER.match(line): return PROMPT_MODE_TIMELINE
|
||||
if _TIMELINE_LIKE_HEADER.match(line): _prompt_error("H3C-P001","invalid timeline header",source=line.strip(),suggested_fix="use [0-5s] or [Chunk 1]")
|
||||
if _parse_json_list(text) is not None or _LIST_SEPARATOR.search(text): return PROMPT_MODE_LIST
|
||||
return PROMPT_MODE_FIXED
|
||||
def resolve_prompt_mode(mode,script):
|
||||
@@ -114,9 +163,11 @@ def make_prompt_plan(*,mode,script,chunks,chunk_seconds):
|
||||
detected={PROMPT_MODE_FIXED:PROMPT_FORMAT_FIXED,PROMPT_MODE_LIST:PROMPT_FORMAT_LIST,PROMPT_MODE_TIMELINE:PROMPT_FORMAT_TIMELINE}[resolved_mode]; notes.append(f"Auto detected {detected}")
|
||||
if resolved_mode==PROMPT_MODE_FIXED: prompt=_normalize_prompt(script,label="fixed prompt"); prompts=[prompt]*chunks
|
||||
elif resolved_mode==PROMPT_MODE_LIST: prompts,parse_notes=_parse_list(script,chunks); notes.extend(parse_notes)
|
||||
elif resolved_mode==PROMPT_MODE_TIMELINE: prompts,parse_notes=_parse_timeline(script,chunks,chunk_seconds); notes.extend(parse_notes)
|
||||
elif resolved_mode==PROMPT_MODE_TIMELINE: prompts,parse_notes,diagnostics=_parse_timeline(script,chunks,chunk_seconds); notes.extend(parse_notes)
|
||||
else: raise PromptPlanError(f"unknown prompt mode: {resolved_mode!r}")
|
||||
return {"magic":PROMPT_PLAN_MAGIC,"schema_version":PROMPT_PLAN_SCHEMA_VERSION,"mode":resolved_mode,"chunks":chunks,"chunk_seconds":chunk_seconds,"prompts":prompts,"hashes":[prompt_hash(p) for p in prompts],"notes":notes}
|
||||
result={"magic":PROMPT_PLAN_MAGIC,"schema_version":PROMPT_PLAN_SCHEMA_VERSION,"mode":resolved_mode,"chunks":chunks,"chunk_seconds":chunk_seconds,"prompts":prompts,"hashes":[prompt_hash(p) for p in prompts],"notes":notes}
|
||||
if resolved_mode==PROMPT_MODE_TIMELINE: result["diagnostics"]=diagnostics
|
||||
return result
|
||||
def validate_prompt_plan(plan):
|
||||
if not isinstance(plan,dict) or plan.get("magic")!=PROMPT_PLAN_MAGIC: raise PromptPlanError("invalid H3 Continuum prompt plan")
|
||||
if int(plan.get("schema_version",-1))!=PROMPT_PLAN_SCHEMA_VERSION: raise PromptPlanError(f"unsupported prompt-plan schema {plan.get('schema_version')}; expected {PROMPT_PLAN_SCHEMA_VERSION}")
|
||||
@@ -127,6 +178,8 @@ def validate_prompt_plan(plan):
|
||||
for index,prompt in enumerate(prompts):
|
||||
_normalize_prompt(prompt,label=f"prompt {index+1}")
|
||||
if hashes[index]!=prompt_hash(prompt): raise PromptPlanError(f"prompt-plan hash mismatch at chunk {index+1}")
|
||||
diagnostics=plan.get("diagnostics")
|
||||
if diagnostics is not None and (not isinstance(diagnostics,list) or not all(isinstance(item,dict) for item in diagnostics)): raise PromptPlanError("prompt-plan diagnostics are invalid")
|
||||
return plan
|
||||
def build_sampler_prompt_plan(*,prompt_mode,prompt_script,sequence_prompt,prompt_plan,chunks,chunk_seconds):
|
||||
chunks=int(chunks); chunk_seconds=float(chunk_seconds)
|
||||
@@ -143,9 +196,16 @@ def apply_prompt_overrides(plan,overrides):
|
||||
if value is None: continue
|
||||
prompts[index]=_normalize_prompt(value,label=f"Clip {index+1} Prompt"); replaced.append(index+1)
|
||||
if not replaced: return plan
|
||||
result=dict(plan); result["mode"]=PROMPT_MODE_LIST; result["prompts"]=prompts; result["hashes"]=[prompt_hash(p) for p in prompts]; result["notes"]=list(plan.get("notes") or [])+["external Clip Prompt input(s): "+", ".join(map(str,replaced))]
|
||||
result=dict(plan); result["mode"]=PROMPT_MODE_LIST; result["prompts"]=prompts; result["hashes"]=[prompt_hash(p) for p in prompts]; result["notes"]=list(plan.get("notes") or [])+["external Clip Prompt input(s): "+", ".join(map(str,replaced))]; result.pop("diagnostics",None)
|
||||
return validate_prompt_plan(result)
|
||||
def prompt_plan_report(plan):
|
||||
plan=validate_prompt_plan(plan); unique=len(set(plan["hashes"])); note="; ".join(plan.get("notes") or [])
|
||||
result=f"Prompt plan: {plan['mode']}; {plan['chunks']} chunks; {unique} unique prompt(s); {plan['chunk_seconds']:.3f}s per chunk."
|
||||
return result+(" "+note+"." if note else "")
|
||||
if note: result+=" "+note+"."
|
||||
diagnostics=list(plan.get("diagnostics") or [])
|
||||
if not diagnostics: return result+"\nPrompt Preflight: OK."
|
||||
lines=[result,"Prompt Preflight:"]
|
||||
for item in diagnostics:
|
||||
level=str(item.get("level","info")).upper(); code=str(item.get("code","H3C-P000")); message=str(item.get("message",""))
|
||||
lines.append(f"- {level} {code}: {message}")
|
||||
return "\n".join(lines)
|
||||
|
||||
+43
-11
@@ -67,19 +67,19 @@ def _preserved_prefix(*,session,prompt_hashes,chunks,reroll_from_chunk,width,hei
|
||||
elif reroll_from_chunk>0: notes.append(f"preserved chunks 1-{len(preserved)}; regenerated from chunk {reroll_from_chunk}")
|
||||
return preserved,notes
|
||||
|
||||
def _conditioning_cache(*,clip,prompts,assets,final_has_last_frame,reference_assets=None):
|
||||
def _conditioning_cache(*,clip,prompts,assets,final_has_last_frame,reference_assets=None,reference_audio_assets=None,timeline_video_assets=None):
|
||||
cache={}; final_index=len(prompts)-1
|
||||
for index,prompt in enumerate(prompts):
|
||||
include_last=bool(final_has_last_frame and index==final_index); key=(prompt,include_last)
|
||||
if key in cache: continue
|
||||
if reference_assets is not None:
|
||||
from ..reference import encode_reference_prompt
|
||||
cache[key]=encode_reference_prompt(clip,prompt,reference_assets)
|
||||
cache[key]=encode_reference_prompt(clip,prompt,reference_assets,reference_audio_assets=reference_audio_assets,timeline_video_assets=timeline_video_assets)
|
||||
else:
|
||||
cache[key]=encode_prompt_conditioning(clip,prompt,first_image=assets.first_image,last_image=assets.last_image if include_last else None)
|
||||
cache[key]=encode_prompt_conditioning(clip,prompt,first_image=assets.first_image,last_image=assets.last_image if include_last else None,reference_audio_assets=reference_audio_assets,timeline_video_assets=timeline_video_assets)
|
||||
return cache
|
||||
|
||||
def run_sequence(*,model:Any,clip:Any,video_vae:Any,audio_vae:Any,sampler:Any,sigmas:torch.Tensor,first_frame:torch.Tensor|None,last_frame:torch.Tensor|None,prompt_plan:dict[str,Any],width:int,height:int,continuity:str,base_seed:int,audio_continuity:bool,exact_total_duration:bool,diagnostics_mode:str,reroll_from_chunk:int,reroll_nonce:int,strict_compatibility:bool,debug:bool,seam_correction:str=SEAM_CORRECTION_OFF,enable_preview:bool=True,session:dict[str,Any]|None=None,initial_state:dict[str,Any]|None=None,latent_only:bool=False,reference_assets=None):
|
||||
def run_sequence(*,model:Any,clip:Any,video_vae:Any,audio_vae:Any,sampler:Any,sigmas:torch.Tensor,first_frame:torch.Tensor|None,last_frame:torch.Tensor|None,prompt_plan:dict[str,Any],width:int,height:int,continuity:str,base_seed:int,audio_continuity:bool,exact_total_duration:bool,diagnostics_mode:str,reroll_from_chunk:int,reroll_nonce:int,strict_compatibility:bool,debug:bool,seam_correction:str=SEAM_CORRECTION_OFF,enable_preview:bool=True,session:dict[str,Any]|None=None,initial_state:dict[str,Any]|None=None,latent_only:bool=False,reference_assets=None,reference_audio_source=None,reference_audio_vae=None,timeline_video_source=None):
|
||||
from ..conditioning import detect_conditioning_mode, conditioning_mode_label
|
||||
from ..run_storage import get_active_run_storage
|
||||
storage_controller=get_active_run_storage()
|
||||
@@ -97,15 +97,27 @@ def run_sequence(*,model:Any,clip:Any,video_vae:Any,audio_vae:Any,sampler:Any,si
|
||||
from ..reference import validate_reference_prompts
|
||||
if first_frame is not None or last_frame is not None: raise SequenceRuntimeError("Reference images cannot be combined with First Frame or Last Frame in V3.2")
|
||||
reference_warning=validate_reference_prompts(prompts,reference_assets.count)
|
||||
from ..reference_audio import (
|
||||
combine_reference_audio_identity,
|
||||
validate_reference_audio_prompts,
|
||||
)
|
||||
reference_audio_warning=validate_reference_audio_prompts(prompts,reference_audio_source)
|
||||
from ..timeline_video import (
|
||||
combine_timeline_video_identity,
|
||||
validate_timeline_video_prompts,
|
||||
)
|
||||
timeline_video_warning=validate_timeline_video_prompts(prompts,timeline_video_source)
|
||||
decode_estimate_gib=0.0; available_ram_gib=None
|
||||
if not latent_only: decode_estimate_gib,available_ram_gib=_check_decode_memory_budget(width=width,height=height,chunks=chunks,chunk_seconds=chunk_seconds)
|
||||
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)
|
||||
sequence_identity_hash=reference_assets.combined_hash if reference_assets is not None else assets.identity_hash
|
||||
visual_identity_hash=reference_assets.combined_hash if reference_assets is not None else assets.identity_hash
|
||||
sequence_identity_hash=combine_reference_audio_identity(visual_identity_hash,reference_audio_source)
|
||||
sequence_identity_hash=combine_timeline_video_identity(sequence_identity_hash,timeline_video_source)
|
||||
current_model_fingerprint=model_fingerprint(model,extra_wrapper_keys=("h3_continuum_join.apply_model.v1",))
|
||||
if storage_controller is not None:
|
||||
stored_session=storage_controller.prepare(model=model,model_fingerprint_value=current_model_fingerprint,clip=clip,video_vae=video_vae,sampler=sampler,sigmas=sigmas,prompt_plan=plan,width=width,height=height,chunk_seconds=chunk_seconds,continuity=continuity,audio_continuity=audio_continuity,base_seed=base_seed,reroll_from_chunk=reroll_from_chunk,reroll_nonce=reroll_nonce,first_frame_hash=assets.first_frame_hash,last_frame_hash=assets.last_frame_hash,identity_hash=sequence_identity_hash,strict_compatibility=strict_compatibility,existing_session=session,reference_contract=reference_assets.contract if reference_assets is not None else None,conditioning_mode=conditioning_mode)
|
||||
stored_session=storage_controller.prepare(model=model,model_fingerprint_value=current_model_fingerprint,clip=clip,video_vae=video_vae,sampler=sampler,sigmas=sigmas,prompt_plan=plan,width=width,height=height,chunk_seconds=chunk_seconds,continuity=continuity,audio_continuity=audio_continuity,base_seed=base_seed,reroll_from_chunk=reroll_from_chunk,reroll_nonce=reroll_nonce,first_frame_hash=assets.first_frame_hash,last_frame_hash=assets.last_frame_hash,identity_hash=sequence_identity_hash,strict_compatibility=strict_compatibility,existing_session=session,reference_contract=reference_assets.contract if reference_assets is not None else None,conditioning_mode=conditioning_mode,reference_audio_contract=reference_audio_source.contract if reference_audio_source is not None else None,reference_audio_vae=reference_audio_vae,timeline_video_contract=timeline_video_source.contract if timeline_video_source is not None else None)
|
||||
reroll_nonce=storage_controller.effective_reroll_nonce
|
||||
if stored_session is not None: session=stored_session
|
||||
accelerators=accelerator_summary(model)
|
||||
@@ -114,7 +126,13 @@ def run_sequence(*,model:Any,clip:Any,video_vae:Any,audio_vae:Any,sampler:Any,si
|
||||
preserved,reuse_notes=_preserved_prefix(session=session,prompt_hashes=prompt_hashes,chunks=chunks,reroll_from_chunk=effective_reroll_from_chunk,width=width,height=height,chunk_seconds=chunk_seconds,identity_hash=sequence_identity_hash)
|
||||
if reference_assets is not None:
|
||||
reuse_notes.insert(0,f"Reference conditioning: {reference_assets.count} image(s), size={reference_assets.size_mode}; persistent across all chunks.")
|
||||
if reference_warning: reuse_notes.append("Warning: "+reference_warning)
|
||||
if reference_warning: reuse_notes.append(reference_warning)
|
||||
if reference_audio_source is not None:
|
||||
reuse_notes.insert(0,"Reference Audio 1 conditioning: persistent across all chunks.")
|
||||
if reference_audio_warning: reuse_notes.append(reference_audio_warning)
|
||||
if timeline_video_source is not None:
|
||||
reuse_notes.insert(0,f"Timeline Video conditioning: chunk-local slices, size={timeline_video_source.size_mode}, resolved={timeline_video_source.target_width}x{timeline_video_source.target_height}.")
|
||||
if timeline_video_warning: reuse_notes.append(timeline_video_warning)
|
||||
if session is not None:
|
||||
old_fingerprint=str(session.get("model_fingerprint",""))
|
||||
if old_fingerprint and old_fingerprint!=current_model_fingerprint: reuse_notes.append("model/accelerator fingerprint differs from the saved session; accepted chunks were kept")
|
||||
@@ -124,7 +142,12 @@ def run_sequence(*,model:Any,clip:Any,video_vae:Any,audio_vae:Any,sampler:Any,si
|
||||
if reference_assets is not None:
|
||||
from ..reference import encode_reference_latents
|
||||
reference_assets=encode_reference_latents(video_vae,reference_assets)
|
||||
cache=_conditioning_cache(clip=clip,prompts=prompts,assets=assets,final_has_last_frame=last_frame is not None,reference_assets=reference_assets)
|
||||
reference_audio_assets=None
|
||||
if reference_audio_source is not None:
|
||||
from ..reference_audio import encode_reference_audio
|
||||
reference_audio_assets=encode_reference_audio(reference_audio_vae,reference_audio_source)
|
||||
if timeline_video_source is None:
|
||||
cache=_conditioning_cache(clip=clip,prompts=prompts,assets=assets,final_has_last_frame=last_frame is not None,reference_assets=reference_assets,reference_audio_assets=reference_audio_assets)
|
||||
entries=preserved[:]; previous_state=None
|
||||
if entries: previous_state=entry_to_state(entries[-1])
|
||||
elif initial_state is not None:
|
||||
@@ -133,12 +156,18 @@ def run_sequence(*,model:Any,clip:Any,video_vae:Any,audio_vae:Any,sampler:Any,si
|
||||
initial_frame_count=align_frame_count_up(int(round(chunk_seconds*FPS))); retained_frames=sum(int(entry["plan"]["net_frames"]) for entry in entries); sampling_reports=[]
|
||||
for sequence_index in range(len(entries),chunks):
|
||||
prompt=prompts[sequence_index]; prompt_hash_value=prompt_hashes[sequence_index]; is_final=sequence_index==chunks-1; effective_reroll_nonce=int(reroll_nonce) if int(reroll_from_chunk)>0 and sequence_index+1>=int(reroll_from_chunk) else 0; seed=derive_chunk_seed(base_seed,sequence_index,effective_reroll_nonce); motion_score=0.0; video_context=None; audio_context=None; context_before=None
|
||||
timeline_video_assets=None
|
||||
chunk_cache=cache
|
||||
if timeline_video_source is not None:
|
||||
from ..timeline_video import encode_timeline_video_chunk
|
||||
timeline_video_assets=encode_timeline_video_chunk(video_vae,timeline_video_source,sequence_index)
|
||||
chunk_cache=_conditioning_cache(clip=clip,prompts=[prompt],assets=assets,final_has_last_frame=bool(last_frame is not None and is_final),reference_assets=reference_assets,reference_audio_assets=reference_audio_assets,timeline_video_assets=timeline_video_assets)
|
||||
if previous_state is None:
|
||||
total_frames=initial_frame_count; latent=empty_h3_latent(width,height,total_frames); conditioning=attach_keyframes(cache[(prompt,bool(last_frame is not None and is_final))],frame_count=total_frames,first_latent=assets.first_latent,last_latent=assets.last_latent if is_final else None); clip_index=1; context_frames=0
|
||||
total_frames=initial_frame_count; latent=empty_h3_latent(width,height,total_frames); conditioning=attach_keyframes(chunk_cache[(prompt,bool(last_frame is not None and is_final))],frame_count=total_frames,first_latent=assets.first_latent,last_latent=assets.last_latent if is_final else None); clip_index=1; context_frames=0
|
||||
chunk_plan=make_plan(continuation=False,clip_index=clip_index,total_frames=total_frames,trim_frames=0,width=width,height=height,context_frames=5,state_capacity_frames=largest_context_capacity(total_frames),requested_extend_seconds=chunk_seconds,debug=debug); reason="initial clip"
|
||||
else:
|
||||
context_frames,motion_score,reason=choose_context_frames(continuity,previous_state); desired_cumulative=int(round((sequence_index+1)*chunk_seconds*FPS)); requested_new_frames=max(1,desired_cumulative-retained_frames); shape=make_extension_shape(context_frames,requested_new_frames/FPS); latent=empty_h3_latent(width,height,shape.total_frames)
|
||||
base_conditioning=attach_keyframes(cache[(prompt,bool(last_frame is not None and is_final))],frame_count=shape.total_frames,first_latent=assets.first_latent,last_latent=assets.last_latent if is_final else None)
|
||||
base_conditioning=attach_keyframes(chunk_cache[(prompt,bool(last_frame is not None and is_final))],frame_count=shape.total_frames,first_latent=assets.first_latent,last_latent=assets.last_latent if is_final else None)
|
||||
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)
|
||||
@@ -149,11 +178,14 @@ def run_sequence(*,model:Any,clip:Any,video_vae:Any,audio_vae:Any,sampler:Any,si
|
||||
if storage_controller is not None: storage_controller.commit_chunk(entry, position=sequence_index)
|
||||
retained_frames+=int(chunk_plan["net_frames"])
|
||||
sampling_reports.append(f"chunk {sequence_index+1}/{chunks}: seed={seed}, frames={chunk_plan['total_frames']}, trim={chunk_plan['trim_frames']}, retained_total={retained_frames}, context={context_frames} ({reason}), motion={motion_score:.6f}, "+(f"interop=emitted actual_prefix={CONTINUUM_ACTUAL_PREFIX_STEPS} consumer=not_observable" if context_before is not None else "interop=not_emitted"))
|
||||
del sampled,latent,conditioning,chunk_model
|
||||
del sampled,latent,conditioning,chunk_model,chunk_cache
|
||||
if timeline_video_assets is not None: del timeline_video_assets
|
||||
if len(entries)!=chunks: raise SequenceRuntimeError(f"internal sequence length mismatch: expected {chunks}, got {len(entries)}")
|
||||
if latent_only:
|
||||
last_state=entry_to_state(entries[-1]); parent_id=session.get("session_id") if session is not None else None
|
||||
settings={"continuity":continuity,"audio_continuity":bool(audio_continuity),"exact_total_duration":False,"prompt_mode":plan["mode"],"conditioning_mode":conditioning_mode,"base_seed":int(base_seed),"reroll_nonce":int(reroll_nonce),"diagnostics_mode":diagnostics_mode,"initial_state_source":initial_state is not None,"latent_first":True,"first_frame_hash":assets.first_frame_hash,"last_frame_hash":assets.last_frame_hash,"reference_contract":reference_assets.contract if reference_assets is not None else None}
|
||||
if reference_audio_source is not None: settings["reference_audio_contract"]=reference_audio_source.contract
|
||||
if timeline_video_source is not None: settings["timeline_video_contract"]=timeline_video_source.contract
|
||||
new_session=make_session(chunks=entries,width=width,height=height,chunk_seconds=chunk_seconds,identity_hash=sequence_identity_hash,model_fingerprint_value=current_model_fingerprint,parent_session_id=parent_id,reroll_from_chunk=int(reroll_from_chunk),settings=settings)
|
||||
report_lines=[f"H3 Continuum V3 {PACKAGE_VERSION}",f"Conditioning mode: {conditioning_mode_label(conditioning_mode)}.",prompt_plan_report(plan),"Decode: external ComfyUI Core VAE nodes; full raw AV chunks retained.",accelerators,"Execution: conditioning precomputed; single call-local MODEL clone per chunk; no internal VAE decode.",*reuse_notes]
|
||||
if diagnostics_mode!=DIAGNOSTICS_OFF: report_lines.extend(sampling_reports)
|
||||
|
||||
Reference in New Issue
Block a user