Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix([issue-739]): restore --image-strength on v0.14.x + address review
[._.]/ Adam Eivy8b05a420c941
diff --git a/scripts/generate_ltx2.py b/scripts/generate_ltx2.pyindex 3df6638fc9..9b61850ba2 100644--- a/scripts/generate_ltx2.py+++ b/scripts/generate_ltx2.py@@ -29,8 +29,8 @@ Pin compatibility — class renames + frame_rate:switched the output-rate keyword from `fps` to `frame_rate`. PortOS pins aspecific commit (see scripts/setup-image-video.sh LTX2_PIN), but installsupgrade on their own schedule, so this bridge resolves both the pipeline- class (_resolve_pipeline / _resolve_pipeline_with_method) and the rate- keyword (_rate_kwargs) from the live API — old and new pins both work.+ class (_resolve_pipeline) and the rate keyword (_rate_kwargs) from the live+ API — old and new pins both work.Output: writes the rendered .mp4 to --output. Emits a final JSON line onstdout ({"video_path": "<output>"}) so the Node parent can read the result@@ -160,6 +160,20 @@ def _rate_kwargs(func, fps: float) -> dict:return {name: fps} if name else {}+def _import_image_conditioning_input():+ """v0.14.x ImageConditioningInput (per-image strength field), or None on old pins.++ Pre-rename pins have no ltx_pipelines_mlx.utils.args module; image strength+ there is injected via the legacy VideoConditionByLatentIndex monkey-patch+ instead (see _image_conditioning_kwargs / _apply_legacy_image_strength).+ """+ try:+ from ltx_pipelines_mlx.utils.args import ImageConditioningInput+ except ImportError:+ return None+ return ImageConditioningInput++_EXTEND_TC_CONFIG: dict | None = None_A2V_TC_CONFIG: dict | None = None_EXTEND_TC_PATCH_OK = False@@ -364,28 +378,19 @@ def bind_output_fps(pipe, fps: float) -> None:pipe._decode_and_save_video = decode_with_fps-def configure_image_strength(image_strength: float | None) -> None:- """Thread PortOS' I2V strength into ltx-2-mlx conditioning constructors.+def _apply_legacy_image_strength(image_strength: float) -> bool:+ """Inject I2V strength on pre-rename pins; return True if the hook applied.Pre-rename pins drive first-frame conditioning through a module-level- `VideoConditionByLatentIndex` symbol on ti2vid_one_stage that we subclass to- inject the requested strength. v0.14.x reworked image conditioning and no- longer exposes that hook, so on those pins we surface a clear notice and- leave strength at the pipeline default rather than silently pretending the- value applied (distinguish "applied" from "couldn't apply").+ `VideoConditionByLatentIndex` symbol on ti2vid_one_stage (and ti2vid_two_stages)+ that we subclass to bake in the strength — replaced wholesale, not appended.+ v0.14.x reworked image conditioning and no longer exposes that hook (strength+ is carried by ImageConditioningInput instead — see _image_conditioning_kwargs),+ so this returns False there and the caller surfaces a clear notice."""- if image_strength is None:- return- if image_strength < 0.0 or image_strength > 1.0:- raise SystemExit("--image-strength must be between 0.0 and 1.0")-from ltx_pipelines_mlx import ti2vid_one_stageif not hasattr(ti2vid_one_stage, "VideoConditionByLatentIndex"):- emit_status(- "--image-strength not supported at this ltx-2-mlx pin "- "(reworked image conditioning) — using pipeline default"- )- return+ return Falsefrom ltx_core_mlx.conditioning.types.latent_cond import VideoConditionByLatentIndex as BaseCondition@@ -400,7 +405,52 @@ def configure_image_strength(image_strength: float | None) -> None:ti2vid_two_stages.VideoConditionByLatentIndex = PortOSVideoConditionexcept ImportError:pass- emit_status(f"Using image strength {image_strength:g}")+ return True+++def _image_conditioning_kwargs(generate_and_save, image: str | None,+ image_strength: float | None) -> dict:+ """I2V image kwarg(s) for generate_and_save, honoring --image-strength on both pins.++ Returns {} when there's no source image. With no strength override we pass a+ bare `image=` on every pin — unchanged behavior. With a strength override:++ - v0.14.x carries per-image strength as a first-class field on+ ImageConditioningInput passed through `images=[...]` (passing+ `images=[ImageConditioningInput(path, 0, 1.0)]` is exactly what the+ pipeline builds from a bare `image=` internally, so this only changes+ the strength); and+ - pre-rename pins take a bare `image=` and get strength from the legacy+ VideoConditionByLatentIndex monkey-patch, applied here just before+ generate reads it. If even that hook is absent we surface a notice and+ fall back to the pipeline default rather than silently dropping it.++ Pin selection is by the live API: the new path needs both an `images`+ parameter on generate_and_save AND an importable ImageConditioningInput.+ """+ if not image:+ return {}+ if image_strength is None:+ return {"image": image}+ if image_strength < 0.0 or image_strength > 1.0:+ raise SystemExit("--image-strength must be between 0.0 and 1.0")++ ImageConditioningInput = _import_image_conditioning_input()+ if ImageConditioningInput is not None and \+ "images" in inspect.signature(generate_and_save).parameters:+ emit_status(f"Using image strength {image_strength:g}")+ return {"images": [ImageConditioningInput(+ path=image, frame_idx=0, strength=image_strength,+ )]}++ if _apply_legacy_image_strength(image_strength):+ emit_status(f"Using image strength {image_strength:g}")+ else:+ emit_status(+ "--image-strength not supported at this ltx-2-mlx pin "+ "(reworked image conditioning) — using pipeline default"+ )+ return {"image": image}def _one_stage_kwargs(args: argparse.Namespace, **extra) -> dict:@@ -442,7 +492,6 @@ def run_two_stage(args: argparse.Namespace, image: str | None = None) -> str:return pipe.generate_and_save(prompt=args.prompt,output_path=args.output,- image=image,height=args.height,width=args.width,num_frames=args.num_frames,@@ -450,6 +499,7 @@ def run_two_stage(args: argparse.Namespace, image: str | None = None) -> str:stage1_steps=args.steps if args.steps is not None else 30,stage2_steps=args.stage2_steps,cfg_scale=args.cfg_scale if args.cfg_scale is not None else 3.0,+ **_image_conditioning_kwargs(pipe.generate_and_save, image, args.image_strength),**_rate_kwargs(pipe.generate_and_save, args.fps),)@@ -471,13 +521,13 @@ def run_text(args: argparse.Namespace) -> str:def run_image(args: argparse.Namespace) -> str:- configure_image_strength(args.image_strength)- if args.cfg_scale is not None:- if not args.image:- raise SystemExit("--image is required for image mode")- return run_two_stage(args, image=args.image)if not args.image:raise SystemExit("--image is required for image mode")+ # --image-strength is threaded into generate_and_save via+ # _image_conditioning_kwargs (per-pipe, since the new/old pins carry it+ # differently); both the two-stage and one-stage paths below pick it up.+ if args.cfg_scale is not None:+ return run_two_stage(args, image=args.image)OneStagePipeline = _resolve_pipeline("TI2VidOneStagePipeline", "ImageToVideoPipeline")emit_status(f"Loading I2V pipeline ({args.model})…")emit_stage(1, 0, 1, "Loading model")@@ -485,8 +535,11 @@ def run_image(args: argparse.Namespace) -> str:bind_output_fps(pipe, args.fps)emit_stage(1, 1, 1, "Loaded")emit_status("Generating I2V…")+ image_kwargs = _image_conditioning_kwargs(+ pipe.generate_and_save, args.image, args.image_strength+ )return pipe.generate_and_save(- **_one_stage_kwargs(args, image=args.image),+ **_one_stage_kwargs(args, **image_kwargs),**_rate_kwargs(pipe.generate_and_save, args.fps),)@@ -592,10 +645,11 @@ def run_extend(args: argparse.Namespace) -> str:"""global _EXTEND_TC_CONFIGfrom ltx_core_mlx.utils.memory import aggressive_cleanup- # Pre-rename pins: ExtendPipeline.extend_from_video; v0.14.x folds extend- # into RetakePipeline.extend_from_video (and deletes the extend module).+ # v0.14.x: RetakePipeline.extend_from_video; pre-rename pins: ExtendPipeline.+ # New name first (the resolver contract) — and on the old pin RetakePipeline+ # lacks extend_from_video, so method-presence still selects ExtendPipeline.ExtendPipeline = _resolve_pipeline(- "ExtendPipeline", "RetakePipeline", method="extend_from_video"+ "RetakePipeline", "ExtendPipeline", method="extend_from_video")if not args.extend_from_video:raise SystemExit("--extend-from-video is required for extend mode")diff --git a/scripts/generate_ltx2_teacache_test.py b/scripts/generate_ltx2_teacache_test.pyindex 2c08df21e9..089d320abf 100644--- a/scripts/generate_ltx2_teacache_test.py+++ b/scripts/generate_ltx2_teacache_test.py@@ -85,6 +85,156 @@ class GenerateLtx2TeaCacheTest(unittest.TestCase):"guided_denoise_loop_with_a2v_teacache",)+ def test_resolve_pipeline_prefers_new_name_then_falls_back(self):+ root = sys.modules["ltx_pipelines_mlx"]++ class NewCls:+ pass++ class LegacyCls:+ pass++ root.NewCls = NewCls+ root.LegacyCls = LegacyCls+ # New name present → wins over the legacy fallback.+ self.assertIs(self.helper._resolve_pipeline("NewCls", "LegacyCls"), NewCls)+ # New name absent → fall back to the legacy name (pre-rename pin).+ self.assertIs(self.helper._resolve_pipeline("MissingNew", "LegacyCls"), LegacyCls)++ def test_resolve_pipeline_method_presence_skips_class_without_method(self):+ root = sys.modules["ltx_pipelines_mlx"]++ class NoMethod:+ pass++ class WithMethod:+ def extend_from_video(self):+ pass++ # Both names resolve, but only the second defines the method — the+ # extend path must pick it (mirrors ExtendPipeline-without-method on a+ # pin where the method moved to RetakePipeline).+ root.NoMethod = NoMethod+ root.WithMethod = WithMethod+ chosen = self.helper._resolve_pipeline(+ "NoMethod", "WithMethod", method="extend_from_video"+ )+ self.assertIs(chosen, WithMethod)++ def test_resolve_pipeline_raises_when_no_name_resolves(self):+ with self.assertRaises(SystemExit):+ self.helper._resolve_pipeline("Nope1", "Nope2")++ def test_rate_kwarg_name_prefers_frame_rate_over_fps(self):+ def both(a, frame_rate=1, fps=2):+ pass++ def fps_only(a, fps=2):+ pass++ def kwargs_only(a, **kwargs):+ pass++ self.assertEqual(self.helper._rate_kwarg_name(both), "frame_rate")+ self.assertEqual(self.helper._rate_kwarg_name(fps_only), "fps")+ # A bare **kwargs must NOT be treated as accepting the rate.+ self.assertIsNone(self.helper._rate_kwarg_name(kwargs_only))+ self.assertEqual(self.helper._rate_kwargs(kwargs_only, 24.0), {})+ self.assertEqual(self.helper._rate_kwargs(fps_only, 24.0), {"fps": 24.0})++ def test_one_stage_kwargs_omits_num_steps_when_steps_unset(self):+ args = SimpleNamespace(+ prompt="p", output="o.mp4", height=480, width=704,+ num_frames=97, seed=42, steps=None,+ )+ kwargs = self.helper._one_stage_kwargs(args)+ self.assertNotIn("num_steps", kwargs)+ self.assertEqual(kwargs["output_path"], "o.mp4")++ args.steps = 20+ kwargs = self.helper._one_stage_kwargs(args, image="i.png")+ self.assertEqual(kwargs["num_steps"], 20)+ self.assertEqual(kwargs["image"], "i.png")++ def test_image_conditioning_empty_without_image(self):+ def gen(image=None, images=None):+ pass++ self.assertEqual(self.helper._image_conditioning_kwargs(gen, None, None), {})++ def test_image_conditioning_bare_image_when_no_strength(self):+ # No strength override → plain image= on every pin (unchanged behavior).+ def gen(image=None, images=None):+ pass++ self.assertEqual(+ self.helper._image_conditioning_kwargs(gen, "i.png", None),+ {"image": "i.png"},+ )++ def test_image_conditioning_validates_strength_range(self):+ def gen(image=None, images=None):+ pass++ with self.assertRaises(SystemExit):+ self.helper._image_conditioning_kwargs(gen, "i.png", 1.5)++ def test_image_conditioning_uses_images_with_strength_on_new_pin(self):+ # New pin: generate_and_save accepts images= AND ImageConditioningInput+ # is importable → per-image strength is carried as a field.+ args_mod = types.ModuleType("ltx_pipelines_mlx.utils.args")++ class FakeImageConditioningInput(tuple):+ def __new__(cls, path, frame_idx, strength, crf=33):+ obj = super().__new__(cls, (path, frame_idx, strength, crf))+ obj.path, obj.frame_idx, obj.strength = path, frame_idx, strength+ return obj++ args_mod.ImageConditioningInput = FakeImageConditioningInput+ utils_mod = types.ModuleType("ltx_pipelines_mlx.utils")+ saved = {+ name: sys.modules.get(name)+ for name in ("ltx_pipelines_mlx.utils", "ltx_pipelines_mlx.utils.args")+ }+ sys.modules["ltx_pipelines_mlx.utils"] = utils_mod+ sys.modules["ltx_pipelines_mlx.utils.args"] = args_mod+ try:+ def gen(prompt=None, image=None, images=None, frame_rate=None):+ pass++ out = self.helper._image_conditioning_kwargs(gen, "i.png", 0.4)+ self.assertIn("images", out)+ self.assertNotIn("image", out)+ self.assertEqual(len(out["images"]), 1)+ ici = out["images"][0]+ self.assertEqual((ici.path, ici.frame_idx, ici.strength), ("i.png", 0, 0.4))+ finally:+ for name, module in saved.items():+ if module is None:+ sys.modules.pop(name, None)+ else:+ sys.modules[name] = module++ def test_image_conditioning_degrades_when_no_images_param_and_no_hook(self):+ # No images= param AND no legacy VideoConditionByLatentIndex hook →+ # graceful fallback to bare image= (neither pin's strength mechanism is+ # available, so we use the default rather than dropping it silently).+ one_stage = types.ModuleType("ltx_pipelines_mlx.ti2vid_one_stage")+ saved = sys.modules.get("ltx_pipelines_mlx.ti2vid_one_stage")+ sys.modules["ltx_pipelines_mlx.ti2vid_one_stage"] = one_stage+ sys.modules["ltx_pipelines_mlx"].ti2vid_one_stage = one_stage+ try:+ def gen(image=None):+ pass++ out = self.helper._image_conditioning_kwargs(gen, "i.png", 0.4)+ self.assertEqual(out, {"image": "i.png"})+ finally:+ if saved is None:+ sys.modules.pop("ltx_pipelines_mlx.ti2vid_one_stage", None)+ else:+ sys.modules["ltx_pipelines_mlx.ti2vid_one_stage"] = saved+def test_extend_patch_builds_stage1_teacache_from_sigmas(self):self.helper._EXTEND_TC_CONFIG = self.helper._teacache_config(True, True, 30)@@ -175,5 +325,80 @@ class GenerateLtx2TeaCacheTest(unittest.TestCase):sys.modules[name] = module+class GenerateLtx2NewPinTeaCacheTest(unittest.TestCase):+ """v0.14.x deletes the `extend` module and runs extend through `retake`.++ The TeaCache patch must follow the guided_denoise_loop call site to the+ retake module via _first_module_with_attr — otherwise TeaCache silently+ no-ops on the new pin. This fakes the new-pin module shape (no `extend`,+ `retake` carries the loop) and asserts the patch lands on retake.+ """++ def setUp(self):+ self.module_name = "generate_ltx2_newpin_under_test"+ self.original_modules = {+ name: sys.modules.get(name)+ for name in [+ self.module_name,+ "ltx_pipelines_mlx",+ "ltx_pipelines_mlx.extend",+ "ltx_pipelines_mlx.retake",+ "ltx_pipelines_mlx.a2vid_two_stage",+ "ltx_pipelines_mlx.ti2vid_two_stages",+ ]+ }+ for name in self.original_modules:+ sys.modules.pop(name, None)++ root = types.ModuleType("ltx_pipelines_mlx")+ root.__path__ = []+ retake = types.ModuleType("ltx_pipelines_mlx.retake")+ a2v = types.ModuleType("ltx_pipelines_mlx.a2vid_two_stage")+ two_stages = types.ModuleType("ltx_pipelines_mlx.ti2vid_two_stages")++ def retake_loop(*args, teacache=None, **kwargs):+ return {"caller": "retake", "teacache": teacache, "kwargs": kwargs}++ def a2v_loop(*args, teacache=None, **kwargs):+ return {"caller": "a2v", "teacache": teacache, "kwargs": kwargs}++ retake.guided_denoise_loop = retake_loop+ a2v.guided_denoise_loop = a2v_loop+ two_stages._build_teacache_controller = lambda num_steps, thresh: {+ "num_steps": num_steps, "thresh": thresh,+ }++ sys.modules["ltx_pipelines_mlx"] = root+ # No ltx_pipelines_mlx.extend — exactly as v0.14.x ships.+ sys.modules["ltx_pipelines_mlx.retake"] = retake+ sys.modules["ltx_pipelines_mlx.a2vid_two_stage"] = a2v+ sys.modules["ltx_pipelines_mlx.ti2vid_two_stages"] = two_stages+ self.retake = retake+ self.a2v = a2v++ spec = importlib.util.spec_from_file_location(self.module_name, HELPER_PATH)+ self.helper = importlib.util.module_from_spec(spec)+ sys.modules[self.module_name] = self.helper+ spec.loader.exec_module(self.helper)++ def tearDown(self):+ for name, module in self.original_modules.items():+ if module is None:+ sys.modules.pop(name, None)+ else:+ sys.modules[name] = module++ def test_patch_follows_extend_loop_to_retake_when_extend_module_gone(self):+ self.assertTrue(self.helper._EXTEND_TC_PATCH_OK)+ self.assertEqual(+ self.retake.guided_denoise_loop.__name__,+ "guided_denoise_loop_with_extend_teacache",+ )+ self.assertEqual(+ self.a2v.guided_denoise_loop.__name__,+ "guided_denoise_loop_with_a2v_teacache",+ )++if __name__ == "__main__":unittest.main()