[Feat] LTX Standard Two-Stage Pipeline (#5500)
Signed-off-by: mglyn <1203789601@qq.com>
This commit is contained in:
1 parent
4b66f62e10
commit
83d1f11449
29 files changed
+2644
-371
No files matched your search
@@ -13,13 +13,21 @@ import pytest
|
||||
import torch
|
||||
|
||||
from vllm_omni.diffusion.data import DiffusionOutput
|
||||
from vllm_omni.diffusion.models.ltx2 import ltx2_components
|
||||
from vllm_omni.diffusion.models.ltx2 import (
|
||||
ltx2_components,
|
||||
ltx2_transformer,
|
||||
)
|
||||
from vllm_omni.diffusion.models.ltx2.ltx2_components import (
|
||||
LTX2_COMPONENT_PROFILE,
|
||||
LTX2_DISTILLED_COMPONENT_PROFILE,
|
||||
LTX2_TWO_STAGE_COMPONENT_PROFILE,
|
||||
LTX23_COMPONENT_PROFILE,
|
||||
LTX23_DISTILLED_COMPONENT_PROFILE,
|
||||
LTX23_TWO_STAGE_COMPONENT_PROFILE,
|
||||
_install_connector_attention,
|
||||
detect_ltx_model_version,
|
||||
resolve_ltx_artifact,
|
||||
resolve_ltx_component_profile,
|
||||
)
|
||||
from vllm_omni.diffusion.models.ltx2.ltx2_conditioning import LTXI2VConditioningMixin
|
||||
from vllm_omni.diffusion.models.ltx2.ltx2_denoise import (
|
||||
@@ -33,6 +41,7 @@ from vllm_omni.diffusion.models.ltx2.ltx2_guidance import (
|
||||
LTXGuidancePlan,
|
||||
LTXGuidanceSpec,
|
||||
LTXModalityGuidance,
|
||||
_repeat_batch,
|
||||
build_perturbation_kwargs,
|
||||
combine_guided_x0,
|
||||
)
|
||||
@@ -40,18 +49,29 @@ from vllm_omni.diffusion.models.ltx2.ltx2_latents import LTXAVState
|
||||
from vllm_omni.diffusion.models.ltx2.ltx2_recipes import (
|
||||
LTX2_DISTILLED_TWO_STAGE_RECIPE,
|
||||
LTX2_ONE_STAGE_RECIPE,
|
||||
LTX2_TWO_STAGE_RECIPE,
|
||||
LTX23_DISTILLED_TWO_STAGE_RECIPE,
|
||||
LTX23_ONE_STAGE_RECIPE,
|
||||
LTX23_TWO_STAGE_RECIPE,
|
||||
LTX_DEFAULT_NEGATIVE_PROMPT,
|
||||
LTX_POSITIVE_ONLY_RECIPE,
|
||||
resolve_ltx_pipeline_recipe,
|
||||
)
|
||||
from vllm_omni.diffusion.models.ltx2.ltx2_request import (
|
||||
LTXRequestInputs,
|
||||
validate_ltx_checkpoint,
|
||||
validate_pipeline_request,
|
||||
)
|
||||
from vllm_omni.diffusion.models.ltx2.ltx2_request import LTXRequestInputs, validate_pipeline_request
|
||||
from vllm_omni.diffusion.models.ltx2.ltx2_runtime import LTXRuntime
|
||||
from vllm_omni.diffusion.models.ltx2.pipeline_ltx2 import (
|
||||
LTX2I2VDMD2Pipeline,
|
||||
LTX2Pipeline,
|
||||
LTX2T2VDMD2Pipeline,
|
||||
)
|
||||
from vllm_omni.diffusion.models.ltx2.pipeline_ltx2_two_stage import LTX2DistilledPipeline
|
||||
from vllm_omni.diffusion.models.ltx2.pipeline_ltx2_two_stage import (
|
||||
LTX2DistilledPipeline,
|
||||
LTX2TwoStagePipeline,
|
||||
)
|
||||
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu]
|
||||
|
||||
@@ -104,10 +124,22 @@ def test_ltx_public_entries_share_runtime_and_keep_recipe_boundaries():
|
||||
)
|
||||
|
||||
assert issubclass(LTX2Pipeline, LTXRuntime)
|
||||
assert issubclass(LTX2TwoStagePipeline, LTXRuntime)
|
||||
assert issubclass(LTX2DistilledPipeline, LTXRuntime)
|
||||
assert LTX2Pipeline.component_profile is LTX2_COMPONENT_PROFILE
|
||||
assert LTX2Pipeline.pipeline_recipe is LTX2_ONE_STAGE_RECIPE
|
||||
assert LTX2TwoStagePipeline.component_profile is LTX2_TWO_STAGE_COMPONENT_PROFILE
|
||||
assert LTX2TwoStagePipeline.pipeline_recipe is LTX2_TWO_STAGE_RECIPE
|
||||
assert LTX2DistilledPipeline.component_profile is LTX2_DISTILLED_COMPONENT_PROFILE
|
||||
for pipeline_cls, profile in (
|
||||
(LTX2Pipeline, LTX2_COMPONENT_PROFILE),
|
||||
(LTX2TwoStagePipeline, LTX2_TWO_STAGE_COMPONENT_PROFILE),
|
||||
(LTX2DistilledPipeline, LTX2_DISTILLED_COMPONENT_PROFILE),
|
||||
):
|
||||
assert pipeline_cls._dit_modules == list(profile.dit_modules)
|
||||
assert pipeline_cls._encoder_modules == list(profile.encoder_modules)
|
||||
assert pipeline_cls._vae_modules == list(profile.vae_modules)
|
||||
assert pipeline_cls._resident_modules == list(profile.resident_modules)
|
||||
assert LTX2_COMPONENT_PROFILE.video_vae_cls is DistributedAutoencoderKLLTX2Video
|
||||
assert LTX23_COMPONENT_PROFILE.video_vae_cls is DistributedAutoencoderKLLTX2Video
|
||||
|
||||
@@ -123,6 +155,72 @@ def test_ltx_checkpoint_version_detection_uses_metadata(tmp_path):
|
||||
assert detect_ltx_model_version(str(tmp_path)) == "2"
|
||||
|
||||
|
||||
def test_ltx_artifact_falls_back_to_unpinned_hub_download(tmp_path, monkeypatch):
|
||||
filename = "ltx-sidecar.safetensors"
|
||||
calls = []
|
||||
|
||||
def fake_download(**kwargs):
|
||||
calls.append(kwargs)
|
||||
return "/cache/ltx-sidecar.safetensors"
|
||||
|
||||
monkeypatch.setattr(ltx2_components, "hf_hub_download", fake_download)
|
||||
|
||||
assert (
|
||||
resolve_ltx_artifact(str(tmp_path / "model"), "Lightricks/test", filename) == "/cache/ltx-sidecar.safetensors"
|
||||
)
|
||||
assert calls == [{"repo_id": "Lightricks/test", "filename": filename}]
|
||||
|
||||
|
||||
def test_ltx_artifact_prefers_model_root(tmp_path, monkeypatch):
|
||||
filename = "ltx-sidecar.safetensors"
|
||||
expected = tmp_path / filename
|
||||
expected.write_bytes(b"sidecar")
|
||||
monkeypatch.setattr(ltx2_components, "hf_hub_download", lambda **_kwargs: pytest.fail("unexpected Hub lookup"))
|
||||
|
||||
assert resolve_ltx_artifact(str(tmp_path), "Lightricks/test", filename) == str(expected)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("expected_kind", "scheduler_config"),
|
||||
[
|
||||
("regular", {"use_dynamic_shifting": True, "shift_terminal": 0.1}),
|
||||
("distilled", {"use_dynamic_shifting": False, "shift_terminal": None}),
|
||||
],
|
||||
)
|
||||
def test_ltx_checkpoint_validation_accepts_matching_scheduler_metadata(expected_kind, scheduler_config):
|
||||
validate_ltx_checkpoint(
|
||||
scheduler_config,
|
||||
expected_kind=expected_kind,
|
||||
pipeline_name="TestLTXPipeline",
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("expected_kind", "scheduler_config", "error"),
|
||||
[
|
||||
("regular", {"use_dynamic_shifting": False, "shift_terminal": None}, "regular non-distilled"),
|
||||
("distilled", {"use_dynamic_shifting": True, "shift_terminal": 0.1}, "merged distilled"),
|
||||
],
|
||||
)
|
||||
def test_ltx_checkpoint_validation_rejects_mismatched_scheduler_metadata(expected_kind, scheduler_config, error):
|
||||
with pytest.raises(ValueError, match=error):
|
||||
validate_ltx_checkpoint(
|
||||
scheduler_config,
|
||||
expected_kind=expected_kind,
|
||||
pipeline_name="TestLTXPipeline",
|
||||
)
|
||||
|
||||
|
||||
def test_ltx_rejects_advanced_uaa_before_component_initialization():
|
||||
od_config = SimpleNamespace(
|
||||
model="unused",
|
||||
parallel_config=SimpleNamespace(ulysses_mode="advanced_uaa"),
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="does not support ulysses_mode='advanced_uaa'"):
|
||||
LTX2Pipeline(od_config=od_config)
|
||||
|
||||
|
||||
def test_ltx23_checkpoint_selects_version_specific_one_stage_profile(tmp_path, monkeypatch):
|
||||
from vllm_omni.diffusion.models.ltx2 import ltx2_runtime
|
||||
|
||||
@@ -144,16 +242,104 @@ def test_ltx23_checkpoint_selects_version_specific_one_stage_profile(tmp_path, m
|
||||
assert pipe.reports_stage_durations
|
||||
|
||||
|
||||
def test_ltx_one_stage_entry_exposes_batch_image_and_distributed_decode_contracts():
|
||||
def test_ltx_multistage_rejects_cache_dit_before_component_initialization(tmp_path, monkeypatch):
|
||||
from vllm_omni.diffusion.models.ltx2 import ltx2_runtime
|
||||
|
||||
(tmp_path / "model_index.json").write_text(json.dumps({"vocoder": ["ltx2", "LTX2Vocoder"]}))
|
||||
initialized = False
|
||||
|
||||
def stub_components(*_args, **_kwargs):
|
||||
nonlocal initialized
|
||||
initialized = True
|
||||
|
||||
monkeypatch.setattr(ltx2_runtime, "initialize_pipeline_components", stub_components)
|
||||
|
||||
with pytest.raises(ValueError, match="only one-stage LTX recipes"):
|
||||
LTX2TwoStagePipeline(
|
||||
od_config=SimpleNamespace(
|
||||
model=str(tmp_path),
|
||||
cache_backend="cache_dit",
|
||||
)
|
||||
)
|
||||
|
||||
assert not initialized
|
||||
|
||||
|
||||
def test_ltx23_checkpoint_selects_version_specific_two_stage_profiles(tmp_path, monkeypatch):
|
||||
from vllm_omni.diffusion.models.ltx2 import ltx2_runtime
|
||||
|
||||
(tmp_path / "model_index.json").write_text(json.dumps({"vocoder": ["ltx2", "LTX2VocoderWithBWE"]}))
|
||||
|
||||
def stub_components(pipe, od_config):
|
||||
pipe.od_config = od_config
|
||||
pipe.vae_spatial_compression_ratio = 32
|
||||
|
||||
monkeypatch.setattr(ltx2_runtime, "initialize_pipeline_components", stub_components)
|
||||
monkeypatch.setattr(LTXRuntime, "setup_diffusion_pipeline_profiler", lambda *_args, **_kwargs: None)
|
||||
monkeypatch.setattr(ltx2_runtime, "build_ltx_phase_adapter", lambda *_args: SimpleNamespace())
|
||||
pipe = LTX2TwoStagePipeline(
|
||||
od_config=SimpleNamespace(
|
||||
model=str(tmp_path),
|
||||
enable_diffusion_pipeline_profiler=False,
|
||||
lora_path=None,
|
||||
model_config={},
|
||||
)
|
||||
)
|
||||
|
||||
assert pipe.model_version == "2.3"
|
||||
assert pipe.component_profile is LTX23_TWO_STAGE_COMPONENT_PROFILE
|
||||
assert pipe.pipeline_recipe is LTX23_TWO_STAGE_RECIPE
|
||||
|
||||
|
||||
def test_ltx23_checkpoint_selects_full_distilled_profile_and_recipe(tmp_path, monkeypatch):
|
||||
from vllm_omni.diffusion.models.ltx2 import ltx2_runtime
|
||||
|
||||
(tmp_path / "model_index.json").write_text(json.dumps({"vocoder": ["ltx2", "LTX2VocoderWithBWE"]}))
|
||||
|
||||
def stub_components(pipe, od_config):
|
||||
pipe.od_config = od_config
|
||||
pipe.vae_spatial_compression_ratio = 32
|
||||
|
||||
monkeypatch.setattr(ltx2_runtime, "initialize_pipeline_components", stub_components)
|
||||
monkeypatch.setattr(LTXRuntime, "setup_diffusion_pipeline_profiler", lambda *_args, **_kwargs: None)
|
||||
|
||||
pipe = LTX2DistilledPipeline(
|
||||
od_config=SimpleNamespace(
|
||||
model=str(tmp_path),
|
||||
enable_diffusion_pipeline_profiler=False,
|
||||
)
|
||||
)
|
||||
|
||||
assert pipe.model_version == "2.3"
|
||||
assert pipe.component_profile is LTX23_DISTILLED_COMPONENT_PROFILE
|
||||
assert pipe.pipeline_recipe is LTX23_DISTILLED_TWO_STAGE_RECIPE
|
||||
assert pipe._phase_adapter is None
|
||||
assert pipe.preserve_sp_padded_audio_duration
|
||||
assert pipe.reports_stage_durations
|
||||
|
||||
|
||||
def test_ltx_entries_expose_batch_image_and_distributed_decode_contracts():
|
||||
assert LTX2Pipeline.supports_request_batch
|
||||
assert LTX2Pipeline.support_image_input
|
||||
assert LTX2Pipeline.unified_text_image_entry
|
||||
assert LTX2Pipeline.distributed_video_decode
|
||||
assert not LTX2TwoStagePipeline.supports_request_batch
|
||||
assert LTX2TwoStagePipeline.support_image_input
|
||||
assert LTX2TwoStagePipeline.unified_text_image_entry
|
||||
assert not LTX2DistilledPipeline.supports_request_batch
|
||||
assert LTX2DistilledPipeline.support_image_input
|
||||
assert LTX2DistilledPipeline.unified_text_image_entry
|
||||
|
||||
|
||||
def test_ltx_two_stage_resolves_request_embedded_images():
|
||||
pipe = object.__new__(LTX2TwoStagePipeline)
|
||||
request_inputs = SimpleNamespace(latents=None)
|
||||
image = torch.zeros(3, 8, 8)
|
||||
req = SimpleNamespace(prompts=[{"prompt": "image conditioned", "multi_modal_data": {"image": image}}])
|
||||
|
||||
assert pipe._resolve_request_image(req, None, request_inputs) is image
|
||||
|
||||
|
||||
def test_ltx_dmd2_entries_retain_their_task_boundaries():
|
||||
assert not LTX2T2VDMD2Pipeline.support_image_input
|
||||
assert LTX2I2VDMD2Pipeline.support_image_input
|
||||
@@ -330,6 +516,15 @@ def test_ltx_guidance_uses_official_close_to_disabled_semantics():
|
||||
assert LTXGuidancePlan.build(LTXGuidanceSpec(video=guidance)).names == ("cond",)
|
||||
|
||||
|
||||
def test_ltx_positive_only_guidance_preserves_token_major_layout():
|
||||
tensor = torch.arange(24).view(1, 3, 8).transpose(1, 2).contiguous().transpose(1, 2)
|
||||
|
||||
repeated = _repeat_batch(tensor, 1)
|
||||
|
||||
assert repeated is tensor
|
||||
assert repeated.stride() == tensor.stride()
|
||||
|
||||
|
||||
def test_ltx_guidance_rescale_is_invariant_to_request_batching():
|
||||
cond = torch.tensor(
|
||||
[
|
||||
@@ -380,6 +575,32 @@ def test_ltx_guidance_rescale_handles_zero_variance_prediction():
|
||||
torch.testing.assert_close(actual, torch.zeros_like(cond))
|
||||
|
||||
|
||||
def test_ltx_audio_guidance_rescale_ignores_sp_padding_tokens():
|
||||
logical_cond = torch.tensor([[[1.0, 2.0], [3.0, 5.0]]])
|
||||
logical_uncond = torch.tensor([[[0.5, -1.0], [2.0, 1.0]]])
|
||||
guidance = LTXModalityGuidance(cfg_scale=3.0, rescale_scale=1.0)
|
||||
expected = combine_guided_x0(
|
||||
cond=logical_cond,
|
||||
uncond_text=logical_uncond,
|
||||
uncond_perturbed=0.0,
|
||||
uncond_modality=0.0,
|
||||
guidance=guidance,
|
||||
)
|
||||
padded_cond = torch.cat([logical_cond, torch.tensor([[[1000.0, -1000.0]]])], dim=1)
|
||||
padded_uncond = torch.cat([logical_uncond, torch.tensor([[[-500.0, 500.0]]])], dim=1)
|
||||
|
||||
actual = combine_guided_x0(
|
||||
cond=padded_cond,
|
||||
uncond_text=padded_uncond,
|
||||
uncond_perturbed=0.0,
|
||||
uncond_modality=0.0,
|
||||
guidance=guidance,
|
||||
rescale_token_count=2,
|
||||
)
|
||||
|
||||
torch.testing.assert_close(actual[:, :2], expected)
|
||||
|
||||
|
||||
def test_ltx_guidance_builds_per_sample_stg_and_modality_masks():
|
||||
plan = LTXGuidancePlan.build(LTX23_ONE_STAGE_RECIPE.request_guidance)
|
||||
perturbations = build_perturbation_kwargs(plan, batch_size=2, reference=torch.ones(8, 1, 1))
|
||||
@@ -547,11 +768,19 @@ def test_ltx_connector_attention_dispatches_through_omni_kernel(has_learned_regi
|
||||
|
||||
def test_ltx2_distilled_pipeline_shares_recipe_runtime():
|
||||
assert issubclass(LTX2DistilledPipeline, LTXI2VConditioningMixin)
|
||||
assert issubclass(LTX2DistilledPipeline, LTX2Pipeline)
|
||||
assert not issubclass(LTX2DistilledPipeline, LTX2Pipeline)
|
||||
assert LTX2DistilledPipeline._run_recipe is LTXRuntime._run_recipe
|
||||
assert "_forward_request" not in LTX2DistilledPipeline.__dict__
|
||||
|
||||
|
||||
def test_ltx_two_stage_entry_is_a_thin_pipeline_variant():
|
||||
assert "_run_recipe" not in LTX2TwoStagePipeline.__dict__
|
||||
assert "_forward_request" not in LTX2TwoStagePipeline.__dict__
|
||||
assert "load_weights" not in LTX2TwoStagePipeline.__dict__
|
||||
assert issubclass(LTX2TwoStagePipeline, LTXI2VConditioningMixin)
|
||||
assert not issubclass(LTX2TwoStagePipeline, LTX2Pipeline)
|
||||
|
||||
|
||||
def test_ltx_variants_share_denoise_loop_and_i2v_conditioning():
|
||||
assert "_denoise_loop" not in LTX2Pipeline.__dict__
|
||||
assert issubclass(LTX2Pipeline, LTXI2VConditioningMixin)
|
||||
@@ -594,7 +823,8 @@ def test_denoise_executor_owns_progress_and_interrupt():
|
||||
torch.testing.assert_close(state.audio, torch.tensor(11.0))
|
||||
|
||||
|
||||
def test_ltx2_distilled_two_stage_executes_declarative_phase_plan():
|
||||
@pytest.mark.parametrize("pipeline_cls", [LTX2TwoStagePipeline, LTX2DistilledPipeline])
|
||||
def test_ltx_two_stage_executes_declarative_i2v_phase_plan(pipeline_cls):
|
||||
request_inputs = LTXRequestInputs(
|
||||
prompt="prompt",
|
||||
negative_prompt="",
|
||||
@@ -671,12 +901,15 @@ def test_ltx2_distilled_two_stage_executes_declarative_phase_plan():
|
||||
return latents.repeat_interleave(2, dim=-2).repeat_interleave(2, dim=-1)
|
||||
|
||||
prompt_context_sentinel = prompt_context
|
||||
pipeline = object.__new__(LTX2DistilledPipeline)
|
||||
pipeline = object.__new__(pipeline_cls)
|
||||
torch.nn.Module.__init__(pipeline)
|
||||
pipeline.device = torch.device("cpu")
|
||||
pipeline.vae_spatial_compression_ratio = 32
|
||||
pipeline.vae_temporal_compression_ratio = 8
|
||||
pipeline.latent_upsampler = FakeUpsampler()
|
||||
activated_slots = []
|
||||
if pipeline_cls is LTX2TwoStagePipeline:
|
||||
pipeline._phase_adapter = SimpleNamespace(activate=activated_slots.append)
|
||||
object.__setattr__(pipeline, "_resolve_request_inputs", resolve_request_inputs)
|
||||
object.__setattr__(pipeline, "run_phase", run_phase)
|
||||
object.__setattr__(pipeline, "decode_phase", decode_phase)
|
||||
@@ -686,14 +919,18 @@ def test_ltx2_distilled_two_stage_executes_declarative_phase_plan():
|
||||
|
||||
assert len(phase_calls) == 2
|
||||
assert phase_calls[1][2] is prompt_context_sentinel
|
||||
if pipeline_cls is LTX2TwoStagePipeline:
|
||||
assert activated_slots == [None, "ltx_distilled"]
|
||||
torch.testing.assert_close(output.output[0], torch.full((1, 128, 1, 2, 2), 3.0))
|
||||
torch.testing.assert_close(output.output[1], torch.full((1, 8, 1, 2), 4.0))
|
||||
expected_audio = 2.0 if pipeline_cls is LTX2TwoStagePipeline else 4.0
|
||||
torch.testing.assert_close(output.output[1], torch.full((1, 8, 1, 2), expected_audio))
|
||||
|
||||
|
||||
def test_ltx2_distilled_stage2_reapplies_final_resolution_i2v_conditioning():
|
||||
@pytest.mark.parametrize("pipeline_cls", [LTX2TwoStagePipeline, LTX2DistilledPipeline])
|
||||
def test_ltx_two_stage_stage2_reapplies_final_resolution_i2v_conditioning(pipeline_cls):
|
||||
from vllm_omni.diffusion.models.ltx2 import ltx2_latents
|
||||
|
||||
pipeline = object.__new__(LTX2DistilledPipeline)
|
||||
pipeline = object.__new__(pipeline_cls)
|
||||
torch.nn.Module.__init__(pipeline)
|
||||
pipeline.vae_spatial_compression_ratio = 32
|
||||
pipeline.vae_temporal_compression_ratio = 8
|
||||
@@ -750,6 +987,18 @@ def test_ltx2_distilled_two_stage_recipe_is_fixed_positive_only():
|
||||
assert (LTX2_DISTILLED_TWO_STAGE_RECIPE.height, LTX2_DISTILLED_TWO_STAGE_RECIPE.width) == (1024, 1536)
|
||||
|
||||
|
||||
def test_ltx23_full_distilled_route_uses_merged_weights_without_lora():
|
||||
assert resolve_ltx_component_profile("distilled_two_stage", "2.3") is LTX23_DISTILLED_COMPONENT_PROFILE
|
||||
assert resolve_ltx_pipeline_recipe("distilled_two_stage", "2.3") is LTX23_DISTILLED_TWO_STAGE_RECIPE
|
||||
assert LTX23_DISTILLED_TWO_STAGE_RECIPE is LTX2_DISTILLED_TWO_STAGE_RECIPE
|
||||
assert all(phase.adapter_slot is None for phase in LTX23_DISTILLED_TWO_STAGE_RECIPE.phases)
|
||||
assert LTX23_DISTILLED_COMPONENT_PROFILE.distilled_lora_filename is None
|
||||
assert LTX23_DISTILLED_COMPONENT_PROFILE.vocoder_cls is LTX23_COMPONENT_PROFILE.vocoder_cls
|
||||
assert LTX23_DISTILLED_COMPONENT_PROFILE.latent_upsampler_filename == (
|
||||
"ltx-2.3-spatial-upscaler-x2-1.1.safetensors"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("request_inputs", "error"),
|
||||
[
|
||||
@@ -958,6 +1207,98 @@ def test_ltx_custom_sigmas_bypass_scheduler_shifting():
|
||||
torch.testing.assert_close(timesteps, expected[:-1] * scheduler.config.num_train_timesteps)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("recipe", "steps", "stg_block"),
|
||||
[
|
||||
(LTX2_TWO_STAGE_RECIPE, 40, 29),
|
||||
(LTX23_TWO_STAGE_RECIPE, 30, 28),
|
||||
],
|
||||
)
|
||||
def test_ltx_official_two_stage_recipes_only_vary_by_model_defaults(recipe, steps, stg_block):
|
||||
stage1, stage2 = recipe.phases
|
||||
assert (recipe.width, recipe.height) == (1536, 1024)
|
||||
assert recipe.num_inference_steps == steps
|
||||
assert stage1.spatial_downscale == 2
|
||||
assert stage1.adapter_slot is None
|
||||
assert stage1.guidance.video.stg_blocks == (stg_block,)
|
||||
assert stage1.guidance.audio.stg_blocks == (stg_block,)
|
||||
assert stage2.input_transform == "spatial_upsample"
|
||||
assert stage2.adapter_slot == "ltx_distilled"
|
||||
assert stage2.guidance == LTXGuidanceSpec.positive_only()
|
||||
assert stage2.num_inference_steps == 3
|
||||
assert stage2.sigmas == (0.909375, 0.725, 0.421875, 0.0)
|
||||
# Official Stage 2 refines video only; its audio result is discarded.
|
||||
assert (recipe.video_output_phase, recipe.audio_output_phase) == (1, 0)
|
||||
|
||||
|
||||
def test_ltx_two_stage_entries_select_the_official_adapter_slots():
|
||||
phase_switches = []
|
||||
ordinary_pipeline = object.__new__(LTX2TwoStagePipeline)
|
||||
ordinary_pipeline._phase_adapter = SimpleNamespace(activate=phase_switches.append)
|
||||
for phase in LTX2_TWO_STAGE_RECIPE.phases:
|
||||
ordinary_pipeline._enter_phase(phase)
|
||||
assert phase_switches == [None, "ltx_distilled"]
|
||||
|
||||
distilled_pipeline = object.__new__(LTX2DistilledPipeline)
|
||||
for phase in LTX2_DISTILLED_TWO_STAGE_RECIPE.phases:
|
||||
distilled_pipeline._enter_phase(phase)
|
||||
|
||||
|
||||
def test_ltx23_gate_projection_declares_its_global_column_parallel_layout(monkeypatch):
|
||||
class FakeColumn(torch.nn.Module):
|
||||
def __init__(
|
||||
self,
|
||||
input_size,
|
||||
output_size,
|
||||
*,
|
||||
bias,
|
||||
gather_output,
|
||||
return_bias,
|
||||
quant_config,
|
||||
prefix,
|
||||
):
|
||||
super().__init__()
|
||||
self.input_size = input_size
|
||||
self.output_size = output_size
|
||||
self.bias_enabled = bias
|
||||
self.gather_output = gather_output
|
||||
self.return_bias = return_bias
|
||||
self.quant_config = quant_config
|
||||
self.prefix = prefix
|
||||
|
||||
class FakeRow(torch.nn.Module):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__()
|
||||
|
||||
class FakeAttention(torch.nn.Module):
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__()
|
||||
|
||||
monkeypatch.setattr(ltx2_transformer, "ColumnParallelLinear", FakeColumn)
|
||||
monkeypatch.setattr(ltx2_transformer, "RowParallelLinear", FakeRow)
|
||||
monkeypatch.setattr(ltx2_transformer, "_LTX2ParallelAttention", FakeAttention)
|
||||
monkeypatch.setattr(ltx2_transformer, "get_tensor_model_parallel_world_size", lambda: 2)
|
||||
|
||||
attention = ltx2_transformer.LTX2Attention(
|
||||
query_dim=16,
|
||||
heads=4,
|
||||
dim_head=4,
|
||||
qk_norm="rms_norm",
|
||||
apply_gated_attention=True,
|
||||
pack_qkv=False,
|
||||
prefix="transformer_blocks.0.attn1",
|
||||
)
|
||||
|
||||
gate = attention.to_gate_logits
|
||||
assert isinstance(gate, FakeColumn)
|
||||
assert gate.input_size == 16
|
||||
assert gate.output_size == 4
|
||||
assert gate.gather_output is False
|
||||
assert gate.return_bias is False
|
||||
assert gate.quant_config is None
|
||||
assert gate.prefix == "transformer_blocks.0.attn1.to_gate_logits"
|
||||
|
||||
|
||||
class TestLTXRequestParsing:
|
||||
def test_request_resolves_official_and_explicit_negative_prompts_per_sample(self):
|
||||
from vllm_omni.diffusion.request import OmniDiffusionRequest
|
||||
@@ -1432,6 +1773,7 @@ class TestPipelineComponents:
|
||||
|
||||
def test_distilled_profile_keeps_upsampler_in_managed_resident_components(self):
|
||||
assert LTX2_DISTILLED_COMPONENT_PROFILE.resident_modules == ("vocoder", "latent_upsampler")
|
||||
assert LTX23_DISTILLED_COMPONENT_PROFILE.resident_modules == ("vocoder", "latent_upsampler")
|
||||
|
||||
|
||||
class TestLTX23DecodeConditioning:
|
||||
@@ -1477,6 +1819,11 @@ class TestRegistryIntegration:
|
||||
from vllm_omni.diffusion.registry import _DIFFUSION_MODELS
|
||||
|
||||
assert _DIFFUSION_MODELS["LTX2Pipeline"] == ("ltx2", "pipeline_ltx2", "LTX2Pipeline")
|
||||
assert _DIFFUSION_MODELS["LTX2TwoStagePipeline"] == (
|
||||
"ltx2",
|
||||
"pipeline_ltx2_two_stage",
|
||||
"LTX2TwoStagePipeline",
|
||||
)
|
||||
assert _DIFFUSION_MODELS["LTX2DistilledPipeline"] == (
|
||||
"ltx2",
|
||||
"pipeline_ltx2_two_stage",
|
||||
@@ -1488,6 +1835,9 @@ class TestRegistryIntegration:
|
||||
"LTX23ImageToVideoPipeline",
|
||||
"LTX2TwoStagesPipeline",
|
||||
"LTX2ImageToVideoTwoStagesPipeline",
|
||||
"LTX2ImageToVideoTwoStagePipeline",
|
||||
"LTX23TwoStagePipeline",
|
||||
"LTX23ImageToVideoTwoStagePipeline",
|
||||
}
|
||||
assert removed_entries.isdisjoint(_DIFFUSION_MODELS)
|
||||
|
||||
@@ -1497,6 +1847,7 @@ class TestRegistryIntegration:
|
||||
|
||||
expected = [
|
||||
"LTX2Pipeline",
|
||||
"LTX2TwoStagePipeline",
|
||||
"LTX2DistilledPipeline",
|
||||
"LTX2T2VDMD2Pipeline",
|
||||
"LTX2I2VDMD2Pipeline",
|
||||
@@ -1509,6 +1860,7 @@ class TestRegistryIntegration:
|
||||
"model_class_name",
|
||||
[
|
||||
"LTX2Pipeline",
|
||||
"LTX2TwoStagePipeline",
|
||||
"LTX2DistilledPipeline",
|
||||
"LTX2T2VDMD2Pipeline",
|
||||
"LTX2I2VDMD2Pipeline",
|
||||
|
||||
Reference in new issue
Block a user