Removed: 13 extra diagnostic hooks (18→5), scene transition tracking,
per-scene capture buffers, cross-scene similarity reporting, _prev_sigma,
_scene_snapped, _scene_cur_ref/_sca refs in hook remover.
Back to 5 hooks on IDENTITY_BLOCKS only. Diagnostic data collected,
analysis complete - no longer needed in production path.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The i2v hidden state injection only produces meaningful results alongside
carry_i2v_guides in the Scene Chain Sampler. Without it the injection
has no reliable reference to anchor from (proven through testing).
New Studio Refiner setting: "Reference injection" toggle (default off).
Hint explains it should be enabled together with carry_i2v_guides.
Passing reference_latent=None to build_enhancements when disabled so
the entire injection path is skipped cleanly.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Data from 5-scene run showed:
- b14:0.609, b33:0.581, b34:0.551, b30:0.542, b21:0.538 (most consistent)
- b26:0.403, b27:0.437 (least consistent - scene-specific, removed)
New IDENTITY_BLOCKS = [14, 21, 30, 33, 34] replacing [21, 26, 31].
Also fixes phantom scene count: only save a scene snapshot on transition
if the previous scene was properly snapped (filters model init passes
that triggered false scene transitions, overcounting by 1).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Performance: hooks now only capture when sigma in [0.85, 0.95] - one
step per scene instead of every step. Eliminates the 2x overhead and
5x slowdown on step 6.
Report timing: fires in sigma tracker when sigma < 0.5 AND scene is
snapped AND ≥2 scenes captured. Covers the last sigma=0.421875 step
which was below the old hook_remover threshold of 0.05.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Detects scene transitions via sigma resets (sigma jumping back up = new
scene). At mid-sigma in each scene, snapshots ALL candidate blocks
(14, 19, 20-35). After the run completes, computes pairwise cosine
similarity across scenes and prints ranked results:
Cross-scene block consistency (3 scenes):
b27:0.89 b31:0.84 b24:0.81 ... b14:0.21
-> Candidate identity blocks (sim>=0.70): [24, 27, 29, 31]
-> Scene-specific blocks (sim<=0.40): [14, 19, 20]
Blocks with high similarity = consistent character features across
different scene compositions. Use these as actual injection targets.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Registers capture-only hooks on ALL candidate blocks (14, 19, 20-35).
After each run, saves their hidden states at sigma~0.91 to a diagnostic
file. On the second run, compares per-block cosine similarity against the
first run and prints ranked results:
Block similarity (high=character-consistent, low=scene-specific):
b27:0.89 b31:0.84 b24:0.81 b19:0.43 b14:0.21 ...
Blocks with high similarity across different scenes of the same character
are the true identity blocks. Blocks with low similarity are scene-specific.
Requires refinement_key to be set. Runs silently (no output) on first
generation, reports on second.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
With schedules like [1.0, 0.99, 0.98, ..., 0.725, 0.421, 0.0] the old
snapshot threshold of sigma<0.6 fired on the last step, leaving zero
steps for injection. Changed to sigma<0.95 to snapshot after the
high-noise plateau, giving injection during the two steps that actually
form character identity (sigma 0.725 and 0.421875).
Widened identity injection gate from (0.25, 0.42) to (0.35, 0.80) to
cover those steps. Strength stays at 2%.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
4% was still causing spatial content from reference to ghost into new
scenes. Dropped to 2% and narrowed the injection window to 0.25-0.42
(late identity formation, after coarse composition is already set),
reducing scene composition interference from the reference.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Anchor blocks (14, 19) encode scene composition/structure - injecting
from the reference frame bled the entire reference scene into new
generations. Disabled anchor injection for i2v entirely.
Identity block strength reduced from 10% to 4% - hidden states encode
the full scene context, not just character features, so even a light
touch at 10% was too strong. 4% applies a gentle bias toward the
reference character without overriding scene-specific content.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
patches_replace["dit"] never fires for LTXAV - both capture and inject
must use forward hooks. Each hook now handles both:
- Capture: always writes block output to capture_buf (for blessed maps)
- Inject: when lazy_inject is populated, lerps the block output toward
the reference tensor at the appropriate sigma-gated strength, then
returns the modified output so the model sees the adjusted hidden state
Reference snapshot moved from step 1 (sigma_max, very noisy) to first
time sigma drops below 0.6, giving cleaner reference maps for fine
details like character features. Snapshot only fires once len(cap_buf)
covers all injection blocks.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
LTXAV transformer blocks receive transformer_options correctly but never
check patches_replace["dit"], so capture/inject via that mechanism is a
no-op. Switch to nn.Module forward hooks registered directly on the
transformer blocks.
Finds transformer block list via model.model.diffusion_model using common
attribute names (transformer_blocks, blocks, joint_blocks, layers).
Handles dict/tuple/tensor output formats from blocks.
Hooks are removed via a cleanup wrapper once sigma drops below 0.05.
Prints "Registered N forward hooks" if successful, warns if block list
not found.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two bugs:
1. capture_buf was None when refinement_key was empty, so block replacements
never captured anything and the lazy inject snapshot check always failed
silently. capture_buf is now always created when has_i2v is True.
2. _model_ref=model was left in the sigma tracker closure from a previous
refactor - a direct model reference sitting inside model.model_options,
causing the "potential memory leak" warning. Removed.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Running apply_fn with a different x tensor causes shape mismatches because
the conditioning in args["c"] was prepared for the actual generation's
input shape, not our reference tensor.
New approach: no separate forward pass. The block capture already runs
during every denoising step. After the first actual step completes,
snapshot capture_buf into the lazy inject objects. From step 2 onwards
injection is active with the step-1 reference maps.
This is shape-safe, model-type agnostic, and requires zero extra inference.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ModelPatcherDynamic (dynamic VRAM loading) has no apply_model method.
Use apply_fn from the wrapper instead - it's the base model function
and works with all patcher types.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
LTX i2v sets the image frame mask to (1 - strength), e.g. 0.3 at
strength=0.7. Our threshold of < 0.1 was too tight and missed all
real-world i2v latents. Changed to < 0.95 - any frame below 1.0
indicates a reference image is present.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The previous approach called model.apply_model with empty conditioning {},
which fails silently for LTX2 (text conditioning required). Reference maps
were never actually populated.
New approach:
- _LazyInject holder: blocks receive a placeholder that starts empty and gets
populated on the first denoising step. No injection until maps are ready.
- _run_reference_extraction: called from _sigma_tracker on the first model
call, where args["c"] contains the real conditioning. Temporarily installs
capture patches, calls model.apply_model at sigma=0.03 with actual
conditioning, collects hidden states, populates lazy inject objects, then
restores all patches.
- Generation proceeds normally from step 1 with injection active.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When an i2v reference is connected, old blessed maps from prior runs
(which may represent a completely different character) must not inject.
If reference map extraction fails, injection is simply skipped rather
than falling back to stale appearance data.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When an i2v latent is connected (noise_mask with protected first frame),
FunPack now automatically extracts hidden state maps from the reference
image at blocks 14, 19, 21, 26, 31 via a single forward pass at sigma=0.03.
These maps are injected during generation to anchor character appearance
without requiring any prior rated runs.
Priority: reference maps from i2v > blessed maps from prior rated run.
T2v latents (no noise_mask or mask=1 throughout) are detected and skipped
cleanly - no injection happens and generation is unaffected.
Reference map injection uses fixed moderate strength (anchor 22%, identity
10%) since there is no reward signal to scale against. Blessed maps continue
to scale with reward as before.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Extends the attention anchor system with three representative blocks from
the concept-formation/identity zone (20-35) which handles character
appearance, body proportions, and distinguishing visual traits.
- IDENTITY_BLOCKS = [21, 26, 31]: evenly spaced across the identity zone
- sigma gate (0.2, 0.55): mid-sigma window where identity is being formed,
slightly later than semantic anchors (0.2, 0.5)
- max inject strength 12% (vs 28% for semantic anchors): lighter touch to
preserve appearance without overriding scene-specific action/composition
- Same blessed map file, same capture/bless/inject infrastructure
- _sigma_gated_strength now takes configurable sigma_high/sigma_low params
- _build_block_replacement takes sigma_gate tuple per block
Fix pre-existing test failures from single-word transition removal:
"suddenly" replaced with "cut to" in transition-related test prompts.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Audio continuation chunks mix real latents (overlap context from prev
scene, low std) with template noise (new frames, std ~1). The model
denoises new frames anchored by the low-amplitude context, producing
quieter audio in every scene after the first.
After sampling each continuation scene, measure the RMS of the overlap
audio frames (known good amplitude from previous scene) and the RMS of
the newly generated frames. If the discrepancy is >10%, rescale the new
frames to match the overlap RMS before blending.
Scene 1 is unaffected (no overlap, no adjustment). Video latents are
never touched.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Injection from blessed maps (Perfect/Loved it runs) at blocks 14 and 19
now concentrates in the anatomy/physics formation phase:
- sigma >= 0.5: full inject_strength (early structure steps)
- 0.2 <= sigma < 0.5: linear fade to zero
- sigma < 0.2: no injection (detail refinement phase, leave alone)
A lightweight sigma_tracker wrapper updates shared sigma_state before
each model call so block replacements always have the current timestep.
The tracker is only installed when blessed maps exist (zero overhead
otherwise).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
New placement option 'silent': the transition phrase marks the scene
boundary but is stripped from the output entirely. Neither the previous
nor the next segment contains it. Available globally and as a per-entry
override on custom transitions.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Trailing \b after a non-word character (like '.') never matches since
\b requires a word char on one side. Custom triggers ending with
punctuation now use (?=\s|$) as the end boundary instead, so
"Scene cut." correctly splits prompts.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Global setting in Studio Refiner tab: "Transition placement" (start/end).
start = transition opens the new segment (existing default behavior).
end = transition closes the previous segment instead.
- Per-entry placement override in Transitions tab (global/start/end).
Custom transitions can pin their placement regardless of the global setting.
- transition items gain a placement field (global/start/end, defaults to global).
- load_custom_transition_triggers returns {trigger_lower: placement|None} so
the split function can do per-trigger lookups efficiently.
- refine_v2 and Studio.run() wired with split_transition_placement parameter.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The [a-z][\w-]* alternative matched any word after "scene", turning
"scene proceeds", "scene features", "scene shows" etc. into false
transition split points. Removed the over-broad alternative - the
pattern now only matches numbered scenes (scene 1, scene -2) and
"scene minus <label>" forms.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Single words like "next", "suddenly", "later", "finally" etc. fire on
normal prompt text and cause spurious scene splits. Removed the entire
single-word temporal markers block. Shortest triggers are now two words
minimum. Also removes "and suddenly" and "and next" which were similarly
too vague.
Stray article-comma cleanup ("the, next" -> "the next") also applied when
building transition segments to handle commas left by the split.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When the stacking fix merges a pure-transition segment into the next one,
it now uses a space instead of ", " if the segment ends with an article
(a/an/the). This prevents "the scene then cuts to the, next view" when
"next" is also a transition word and the segments get merged mid-phrase.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
If a prompt ends with a transition phrase plus nothing (or just a lone
article like "the"), the last segment is now dropped rather than kept
as a near-empty scene. Covers cases like "...K/DA Kai'Sa, the scene
then cuts to the" where the user did not complete the transition.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Shortcuts and Transitions: saved entries collapse to a summary row (name +
on/off badge); click to expand, Collapse button to close without saving
- Transition summary also shows trigger phrase in italic next to the name
- Shortcuts: replacement is no longer required; blank/missing defaults to [""]
which removes the matched phrase (same as explicit empty replacement)
- Shortcuts: name falls back to first activation word when left blank
- New summary row CSS: badge-on/badge-off, label, trigger styles
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Shortcuts: allow empty string as a valid replacement to remove matched phrases
from prompts; post-pass cleans up orphaned commas/spaces left by removals
- Shortcuts: add cross-shortcut longer-phrase-wins test confirming ordered
alternation handles multiple shortcuts with overlapping triggers correctly
- Transitions: new user-editable transition word list stored in transitions.json;
custom triggers extend the built-in split pattern at runtime, keyed by name
- Transitions: Studio JS gets a dedicated Transitions tab (name, trigger, enabled)
with Add/Refresh/Import/Export toolbar
- Transitions: four API routes mirroring shortcuts (GET, export, save/delete, import)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>