Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .cursor/rules/ltx2-patch-reverify.mdc
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ globs: backend/pyproject.toml
alwaysApply: false
---

# LTX-2 bump → re-check `services.patches`
# LTX-2 bump → re-check CUDA patches in `inference.apply_patches`

Delete-first. If this change updates `ltx-core` or `ltx-pipelines` (version pin, git tag, or `tool.uv.dependency-metadata`), treat every module imported from `backend/services/patches/` in `backend/ltx2_server.py` as suspect, plus any out-of-directory swap of an upstream symbol.
Delete-first. If this change updates `ltx-core` or `ltx-pipelines` (version pin, git tag, or `tool.uv.dependency-metadata`), treat every module imported from `backend/inference/patches/` in `backend/inference/apply_patches.py` as suspect, plus Darwin leftovers imported from `backend/services/patches/` in `backend/ltx2_server.py`, and any out-of-directory swap of an upstream symbol.

Those patches rebind private upstream symbols. A bump can rename the target (import-time assert should fail) or change the contract (assert still passes, behavior is wrong). Default is **delete** the patch; keep only what still fails on the new revision.

For each patch:

1. Read the module's "Remove once ..." docstring. If upstream now includes the fix, delete the patch, its `ltx2_server.py` import, and its tests.
1. Read the module's "Remove once ..." docstring. If upstream now includes the fix, delete the patch, its `apply_patches.py` (CUDA) or `ltx2_server.py` (Darwin) import, and its tests.
2. Cautionary example: `diffvae_mps_tiling_budget` asserted `DiffusionVideoDecoder.recommended_tiling_config`, which 1.3.0 removed. Keeping it made the backend unable to boot. `safetensors_metadata_fix` is the opposite kind of patch (Windows 1455 / never-`safe_open` the 46GB distilled-1.1 checkpoint) — keep until that contract is upstream.
3. Otherwise diff the upstream function against the replacement and keep the contract identical. Re-earn; do not copy blindly.
4. Run that patch's tests (`backend/tests/test_<patch>.py`) plus the patch import-smoke test.
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:

- name: Install Python dev dependencies
working-directory: backend
run: uv sync --frozen --extra dev
run: uv sync --frozen --extra desktop --extra dev

- name: Pyright type check
working-directory: backend
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:

- &install-backend
name: Install dependencies
run: uv sync --frozen --extra test --extra dev
run: uv sync --frozen --extra desktop --extra test --extra dev

# The full suite runs on Linux. Windows only runs tests that call the
# real Win32 DLL APIs. `--` keeps `-m` from being read as a uv flag.
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Key patterns:
- Python 3.13+ (per `.python-version`), managed with `uv`
- Pyright strict mode (`backend/pyrightconfig.json`)
- Dependencies in `backend/pyproject.toml`
- Bumping `ltx-core` / `ltx-pipelines`: re-verify every `services.patches` import in `backend/ltx2_server.py` (private upstream monkey-patches). Drop a patch only if upstream now includes the fix.
- Bumping `ltx-core` / `ltx-pipelines`: re-verify every CUDA patch in `backend/inference/patches/` (imported from `backend/inference/apply_patches.py`), plus the Darwin leftovers in `backend/services/patches/` (imported from `backend/ltx2_server.py`). These are private upstream monkey-patches. Drop a patch only if upstream now includes the fix.

## Key File Locations

Expand Down
4 changes: 2 additions & 2 deletions backend/api_model_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
WarnedFastAspectCell,
WarnedFastCell,
)
from frame_math import compute_num_frames
from inference.frame_math import compute_num_frames
from keyframe_request import validate_keyframe_inputs
from runtime_config.fast_chunking import job_window_count
from inference.fast_chunking import job_window_count
from runtime_config.ltx_capabilities import (
CanvasMode,
LtxOfferingCapabilities,
Expand Down
61 changes: 24 additions & 37 deletions backend/api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import re
from typing import Annotated, Literal, NamedTuple, Self, TypeAlias, cast, get_args
from typing import Annotated, Literal, Self, TypeAlias, cast, get_args

from pydantic import (
BaseModel,
Expand Down Expand Up @@ -51,7 +51,7 @@
LoraEntry as LoraEntry,
)
from assistant_limits import ASSISTANT_LIMITS
from frame_math import compute_num_frames
from inference.frame_math import compute_num_frames
from runtime_config.eta import EtaBasis, EtaFeature
from runtime_config.reject_reasons import (
BudgetMode,
Expand All @@ -64,21 +64,31 @@
WarnedCellTier,
)
from runtime_config.ic_lora_stage_mode import IcLoraStageMode, ic_lora_stage_mode
from runtime_config.ic_lora_tiling import (
from inference.ic_lora_tiling import (
MAX_TILE_OVERLAP,
MIN_CARRY_FRAMES,
MIN_TILE_OVERLAP,
MIN_WINDOW_FRAMES,
IcLoraTileSize,
IcLoraTiling,
)
from runtime_config.nag_limits import (
from inference.nag_limits import (
MAX_ALPHA as NAG_MAX_ALPHA,
MAX_SCALE as NAG_MAX_SCALE,
MAX_TAU as NAG_MAX_TAU,
NEGATIVE_PROMPT_MAX_LENGTH,
)

from inference.types import (
DEFAULT_EDIT_CONTEXT_MODE,
EditContextMode,
ExtendMode,
ImageConditioningInput as ImageConditioningInput,
LTXLocalModelId,
REFERENCE_STILL_FRAME_IDX as REFERENCE_STILL_FRAME_IDX,
RetakeMode,
)

NonEmptyPrompt = Annotated[str, StringConstraints(strip_whitespace=True, min_length=1)]
LocalAssistantModel = Literal["qwen3.5:9b"]

Expand Down Expand Up @@ -140,24 +150,10 @@ class AssistantModelsResponse(BaseModel):
"gemma-4-e2b-it",
"z-image-turbo",
]
LTXLocalModelId = Literal[
"ltx-2.5-22b-distilled",
"ltx-2.3-22b-distilled-1.1",
"ltx-2.3-22b-distilled",
]
# T2V/I2V/A2V/LoRA create-body `params.model`. Not a GenSpace pipeline (`fast`)
# and not a checkpoint id. Future API rows (`ltx-2.5-pro`, …) join this union.
OfferingId = Literal["ltx-2.3-fast", "ltx-2.5-fast"]


class ImageConditioningInput(NamedTuple):
"""Image conditioning triplet used by all video pipelines."""

path: str
frame_idx: int
strength: float


JsonObject: TypeAlias = dict[str, object]
VideoCameraMotion = Literal[
"none",
Expand Down Expand Up @@ -253,9 +249,6 @@ class FeatureFlags(BaseModel):
# Show a "Negative prompt:" line under each result's meta bar, for every feature
# that stores a negative prompt. For comparing runs with and without one. Off by default.
showGenerationNegativePrompt: bool = False
# Offer the Keyframes feature on Home. The backend refuses the create route while it is
# off, and Home hides the feature. GenSpace multi-keyframe has no flag. Off by default.
keyframes: bool = False


class UiPreferences(BaseModel):
Expand All @@ -274,7 +267,6 @@ class FeatureFlagsPatch(BaseModel):
highResVideoToVideo: bool | None = None
createWithAi: bool | None = None
showGenerationNegativePrompt: bool | None = None
keyframes: bool | None = None


class GenerationProgressResponse(BaseModel):
Expand Down Expand Up @@ -1068,10 +1060,6 @@ def _validate_input_image_mode(self) -> "SuggestGapPromptRequest":
return self


RetakeMode: TypeAlias = Literal[
"replace_audio_and_video", "replace_video", "replace_audio"
]

# ltxv-api /v2/retake and /v2/extend accept ltx-2-pro / ltx-2-3-pro. Desktop maps
# those to pipeline "pro" — narrower than LTXVideoGenPipeline on purpose.
RetakeExtendModel: TypeAlias = Literal["pro"]
Expand Down Expand Up @@ -1101,9 +1089,6 @@ class RetakeRequest(BaseModel):
model: RetakeExtendModel = "pro"


ExtendMode: TypeAlias = Literal["start", "end"]


class ExtendRequest(BaseModel):
model_config = ConfigDict(strict=True)

Expand Down Expand Up @@ -1143,12 +1128,6 @@ class IcLoraExtractRequest(BaseModel):
frame_time: float = 0


# The frame index of a reference still (the look still of Layout To Render). Upstream
# rejects a negative index, so the pipeline keeps the still apart from the clip frames.
# Only a catalog entry can pin it (``reference_image_frame``). A request cannot send it.
REFERENCE_STILL_FRAME_IDX = -1


class IcLoraImageInput(BaseModel):
model_config = ConfigDict(strict=True)

Expand Down Expand Up @@ -2673,6 +2652,9 @@ class RetakeParams(NagParams):
startTime: float = Field(ge=0, allow_inf_nan=False)
duration: float = Field(ge=2, allow_inf_nan=False)
mode: RetakeMode = "replace_audio_and_video"
# "short" keeps about 2 s of context on each side of the selection instead of filling the
# window to the cap (see continuation_context_frames).
contextMode: EditContextMode = DEFAULT_EDIT_CONTEXT_MODE
resolution: TargetResolution | None = None
seed: int | None = None
# Accepted so the shared Home form can submit provenance like every other
Expand Down Expand Up @@ -2717,6 +2699,9 @@ class ExtendParams(NagParams):
model: OfferingId
duration: float = Field(ge=2, le=20, allow_inf_nan=False)
mode: ExtendMode = "end"
# "short" conditions on only the last frames of the clip (see
# CONTINUATION_CONTEXT_FRAMES) instead of the whole encode window.
contextMode: EditContextMode = DEFAULT_EDIT_CONTEXT_MODE
resolution: TargetResolution | None = None
seed: int | None = None
# Accepted so the shared Home form can submit provenance like every other
Expand Down Expand Up @@ -2771,8 +2756,9 @@ class EditPreflightRequest(BaseModel):
presets, retake minimum) so every candidate has an exact resolution-level
verdict; callers add the durations they display (extend presets, retake
current selection) for exact per-cell messages. ``startTime`` only affects
retake windowing, ``mode`` only extend stitching; both default so each
feature sends what it needs.
retake windowing, ``mode`` only extend stitching and ``contextMode`` only how
much of the clip an extend keeps as context (which sets the window it is
priced at); all default so each feature sends what it needs.
"""

model_config = ConfigDict(strict=True, extra="forbid")
Expand All @@ -2781,6 +2767,7 @@ class EditPreflightRequest(BaseModel):
assetId: str = Field(min_length=1)
startTime: float = Field(default=0, ge=0, allow_inf_nan=False)
mode: ExtendMode = "end"
contextMode: EditContextMode = DEFAULT_EDIT_CONTEXT_MODE
candidates: list[EditPreflightCandidate] = Field(min_length=1, max_length=8)
durations: list[float] = Field(min_length=1, max_length=32)

Expand Down
20 changes: 8 additions & 12 deletions backend/app_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@
from handlers.base import resolve_models_dir
from handlers.assistant_models_handler import AssistantModelsHandler
from runtime_config.runtime_config import RuntimeConfig
from inference.a2v_pipeline.a2v_pipeline import A2VPipeline
from inference.fast_video_pipeline.fast_video_pipeline import FastVideoPipeline
from inference.ic_lora_pipeline.ic_lora_pipeline import IcLoraPipeline
from inference.retake_pipeline.retake_pipeline import RetakePipeline
from services.interfaces import (
A2VPipeline,
DepthProcessorPipeline,
FastVideoPipeline,
ZitAPIClient,
ImageGenerationPipeline,
GpuCleaner,
GpuInfo,
HTTPClient,
IcLoraPipeline,
LTXAPIClient,
ModelDownloader,
PoseProcessorPipeline,
PromptEnhancerPipeline,
RetakePipeline,
TaskRunner,
TextEncoder,
VideoProcessor,
Expand Down Expand Up @@ -553,9 +553,6 @@ def _queued_enhancement_policy(self, generation: GenerationRecord) -> QueuedEnha
def _high_res_video_to_video_enabled(self) -> bool:
return self.feature_flags.get_flags().highResVideoToVideo

def _keyframes_enabled(self) -> bool:
return self.feature_flags.get_flags().keyframes

def _lane_runner(self, store: Store, lane: LaneSpec) -> QueueRunner:
if lane.id == LOCAL_LANE:
return QueueRunner(
Expand Down Expand Up @@ -618,7 +615,6 @@ def _bind_store(self, store: Store) -> None:
preflight_ic_lora_tile_sizes=self.ic_lora.preflight_recipe_tile_sizes,
preflight_queued_synthesized_ic_lora=self.ic_lora.preflight_queued_synthesized_job,
high_res_enabled=self._high_res_video_to_video_enabled,
keyframes_enabled=self._keyframes_enabled,
should_use_local_encoding=self.text.should_use_local_encoding,
image_generation_status=self.image_generation.get_status,
)
Expand Down Expand Up @@ -669,18 +665,18 @@ class ServiceBundle:

def build_default_service_bundle(config: RuntimeConfig) -> ServiceBundle:
"""Build real runtime services with lazy heavy imports isolated from tests."""
from services.fast_video_pipeline.ltx_fast_video_pipeline import LTXFastVideoPipeline
from inference.fast_video_pipeline.ltx_fast_video_pipeline import LTXFastVideoPipeline
from services.zit_api_client.zit_api_client_impl import ZitAPIClientImpl
from services.gpu_cleaner.torch_cleaner import TorchCleaner
from services.gpu_info.gpu_info_impl import GpuInfoImpl
from services.http_client.http_client_impl import HTTPClientImpl
from services.a2v_pipeline.ltx_a2v_pipeline import LTXa2vPipeline
from inference.a2v_pipeline.ltx_a2v_pipeline import LTXa2vPipeline
from services.depth_processor_pipeline.midas_dpt_pipeline import MidasDPTPipeline
from services.ic_lora_pipeline.ltx_ic_lora_pipeline import LTXIcLoraPipeline
from inference.ic_lora_pipeline.ltx_ic_lora_pipeline import LTXIcLoraPipeline
from services.image_generation_pipeline.zit_image_generation_pipeline import ZitImageGenerationPipeline
from services.ltx_api_client.ltx_api_client_impl import LTXAPIClientImpl
from services.model_downloader.hugging_face_downloader import HuggingFaceDownloader
from services.retake_pipeline.ltx_retake_pipeline import LTXRetakePipeline
from inference.retake_pipeline.ltx_retake_pipeline import LTXRetakePipeline
from services.prompt_enhancer_pipeline.ltx_prompt_enhancer_pipeline import LtxPromptEnhancerPipeline
from services.pose_processor_pipeline.dw_pose_pipeline import DWPosePipeline
from services.task_runner.threading_runner import ThreadingRunner
Expand Down
10 changes: 9 additions & 1 deletion backend/handlers/assistant_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@
- For a style no recipe covers, make it concrete: "low quality retro" becomes film
grain, soft focus and faded colour. Keep every subject, setting and wording the user specified.
- For image-to-video, describe motion consistent with the attached image. For
extensions and retakes, describe how the clip continues.
extensions and retakes, describe how the clip continues, and always write that
prompt. When one changes or adds speech, put the exact words in quotes in the prompt:
the video model says only what the prompt quotes.
- Extensions and retakes use the clip as context: contextMode "long" (the default)
keeps as much of it as fits, "short" keeps about 2 seconds (next to the new part
for an extension, on each side of the selection for a retake). Short is faster, but
the new part may drift from the rest of the clip. Leave contextMode out unless the
user asks for short, less context or a faster run, and say so in the reply when you
set it.
- When the request refers to something in an attached image, describe its visible
details in the prompt: colour, material, pattern and shape.
- Style and motion recipes add their own trigger phrases; describe the scene only.
Expand Down
19 changes: 17 additions & 2 deletions backend/handlers/assistant_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@
LTXLocalA2VResolution, LTXQueuedAspectRatio, LTXVideoGenAspectRatio, LTXVideoGenFps,
NonEmptyPrompt, OfferingId, PromptProvenance, RETAKE_MAX_DURATION_SECONDS, RetakeMode, TargetResolution, VideoCameraMotion,
)
from inference.types import DEFAULT_EDIT_CONTEXT_MODE, EditContextMode

# Small models skip an optional field, and the video model says only what the prompt quotes.
EDIT_PROMPT_DESCRIPTION = (
"Write it: how the new part looks and sounds, in one paragraph. "
"When the user says what someone should say, put those exact words in quotes here"
)

# Long is the default, so a request that does not name a context mode never sets one.
CONTEXT_MODE_DESCRIPTION = (
'"long" (default) keeps as much of the clip as fits as context. "short" keeps about 2 seconds of it: '
"faster, but the result may drift from the rest of the clip. Set short only when the user asks for it"
)

# The model repeats its tool schema as capabilities, so offer only what local models run.
# list_video_models still decides which combinations a model supports.
Expand Down Expand Up @@ -67,13 +80,14 @@ class AudioParams(AssistantParams):


class ExtensionParams(AssistantParams):
prompt: str = ""
prompt: str = Field(default="", description=EDIT_PROMPT_DESCRIPTION)
negativePrompt: str = ""
model: OfferingId
# Two names because "duration" means clip length in every other tool.
added_seconds: float | None = Field(default=None, ge=2, le=20, allow_inf_nan=False, description='"Add 3 seconds"')
total_seconds: float | None = Field(default=None, gt=0, allow_inf_nan=False, description='"Extend it to 10 seconds": the final length')
mode: ExtendMode = "end"
contextMode: EditContextMode = Field(default=DEFAULT_EDIT_CONTEXT_MODE, description=CONTEXT_MODE_DESCRIPTION)
resolution: TargetResolution | None = Field(default=None, description="Omit to keep the source size; set only when the user asks")


Expand Down Expand Up @@ -105,12 +119,13 @@ class IngredientsParams(AssistantParams):


class ReplacementParams(AssistantParams):
prompt: str = ""
prompt: str = Field(default="", description=EDIT_PROMPT_DESCRIPTION)
negativePrompt: str = ""
model: OfferingId
startTime: float = Field(ge=0, allow_inf_nan=False)
duration: float = Field(ge=2, le=RETAKE_MAX_DURATION_SECONDS, allow_inf_nan=False)
mode: RetakeMode = "replace_audio_and_video"
contextMode: EditContextMode = Field(default=DEFAULT_EDIT_CONTEXT_MODE, description=CONTEXT_MODE_DESCRIPTION)
# No resolution: a retake keeps the source's frame size, and small models fill it in from earlier clips.


Expand Down
Loading
Loading