Skip to content

Commit e417e26

Browse files
committed
add tests and remove env variable
Signed-off-by: Yibin Li <109242046+yibinl-nvidia@users.noreply.github.com>
1 parent 10acd6b commit e417e26

2 files changed

Lines changed: 65 additions & 18 deletions

File tree

tensorrt_llm/_torch/visual_gen/models/ltx2/pipeline_ltx2_two_stages.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import json
66
import math
7-
import os
87
import time
98
from concurrent.futures import ThreadPoolExecutor
109
from typing import Any, Dict, List, Optional, Union
@@ -42,7 +41,6 @@
4241
STAGE_2_DISTILLED_SIGMA_VALUES = [0.909375, 0.725, 0.421875, 0.0]
4342
_FP8_DTYPES = (torch.float8_e4m3fn, torch.float8_e5m2)
4443
_QKV_SUFFIXES = (".to_q", ".to_k", ".to_v")
45-
_DISABLE_OVERLAP_LORA_LOAD_ENV = "TRTLLM_LTX2_DISABLE_OVERLAP_LORA_LOAD"
4644

4745

4846
# ---------------------------------------------------------------------------
@@ -642,8 +640,7 @@ def load_standard_components(
642640

643641
lora_executor = None
644642
lora_future = None
645-
disable_overlap_lora_load = os.getenv(_DISABLE_OVERLAP_LORA_LOAD_ENV, "0") == "1"
646-
if distilled_lora_path and not disable_overlap_lora_load:
643+
if distilled_lora_path:
647644
logger.info(f"Starting distilled LoRA pre-compute from {distilled_lora_path}...")
648645
lora_executor = ThreadPoolExecutor(max_workers=1)
649646
lora_future = lora_executor.submit(
@@ -667,7 +664,6 @@ def load_standard_components(
667664
spatial_upsampler_path,
668665
distilled_lora_path,
669666
lora_future,
670-
disable_overlap_lora_load,
671667
)
672668
finally:
673669
if lora_executor is not None:
@@ -680,7 +676,6 @@ def _load_two_stage_components(
680676
spatial_upsampler_path: str,
681677
distilled_lora_path: str,
682678
lora_future,
683-
disable_overlap_lora_load: bool,
684679
) -> None:
685680
# --- Spatial upsampler ---
686681
if spatial_upsampler_path:
@@ -720,18 +715,10 @@ def _load_two_stage_components(
720715
# --- Distilled LoRA (pre-compute deltas) ---
721716
self._distilled_lora_deltas: Dict[str, torch.Tensor] = {}
722717
if distilled_lora_path:
723-
if disable_overlap_lora_load:
724-
logger.info(f"Loading distilled LoRA from {distilled_lora_path}...")
725-
self._distilled_lora_deltas = _load_lora_deltas(
726-
distilled_lora_path,
727-
self.transformer,
728-
self._TRANSFORMER_PREFIX,
729-
)
730-
else:
731-
logger.info("Waiting for distilled LoRA pre-compute...")
732-
if lora_future is None:
733-
raise RuntimeError("Distilled LoRA pre-compute was not started.")
734-
self._distilled_lora_deltas = lora_future.result()
718+
logger.info("Waiting for distilled LoRA pre-compute...")
719+
if lora_future is None:
720+
raise RuntimeError("Distilled LoRA pre-compute was not started.")
721+
self._distilled_lora_deltas = lora_future.result()
735722
logger.info(
736723
f"Distilled LoRA ready: {len(self._distilled_lora_deltas)} parameter deltas"
737724
)

tests/unittest/_torch/visual_gen/test_ltx2_pipeline.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,66 @@ def test_cache_dit_config_prevents_promotion_with_explicit_auxiliary_paths(
892892
assert LTX2Pipeline.resolve_variant(config) is LTX2Pipeline
893893

894894

895+
class TestTwoStageLoRALoadingOverlap:
896+
"""Test two-stage LoRA load orchestration without loading checkpoints."""
897+
898+
def test_load_standard_components_overlaps_lora_with_base_components(self, monkeypatch):
899+
from types import SimpleNamespace
900+
901+
from tensorrt_llm._torch.visual_gen.models.ltx2 import pipeline_ltx2_two_stages
902+
from tensorrt_llm._torch.visual_gen.models.ltx2.pipeline_ltx2 import LTX2Pipeline
903+
from tensorrt_llm._torch.visual_gen.models.ltx2.pipeline_ltx2_two_stages import (
904+
LTX2TwoStagesPipeline,
905+
)
906+
907+
events = []
908+
lora_deltas = {"linear.weight": torch.ones(1)}
909+
910+
class FakeFuture:
911+
def result(self):
912+
events.append("lora_result")
913+
return lora_deltas
914+
915+
class FakeExecutor:
916+
def __init__(self, max_workers):
917+
assert max_workers == 1
918+
919+
def submit(self, fn, *args):
920+
events.append("lora_submit")
921+
assert fn is pipeline_ltx2_two_stages._load_lora_deltas
922+
assert args == (
923+
"/fake/lora.safetensors",
924+
pipeline.transformer,
925+
pipeline._TRANSFORMER_PREFIX,
926+
)
927+
return FakeFuture()
928+
929+
def shutdown(self, wait=True):
930+
events.append(f"shutdown:{wait}")
931+
932+
def fake_base_load(self, checkpoint_dir, device, skip_components=None, **kwargs):
933+
events.append("base_load")
934+
assert checkpoint_dir == "/fake/checkpoint"
935+
assert device == torch.device("cpu")
936+
937+
monkeypatch.setattr(pipeline_ltx2_two_stages, "ThreadPoolExecutor", FakeExecutor)
938+
monkeypatch.setattr(LTX2Pipeline, "load_standard_components", fake_base_load)
939+
940+
pipeline = LTX2TwoStagesPipeline.__new__(LTX2TwoStagesPipeline)
941+
pipeline.model_config = SimpleNamespace(
942+
torch_dtype=torch.float32,
943+
extra_attrs={
944+
"distilled_lora_path": "/fake/lora.safetensors",
945+
},
946+
)
947+
pipeline.transformer = object()
948+
949+
pipeline.load_standard_components("/fake/checkpoint", torch.device("cpu"))
950+
951+
assert events == ["lora_submit", "base_load", "lora_result", "shutdown:True"]
952+
assert pipeline._distilled_lora_deltas is lora_deltas
953+
954+
895955
class TestTwoStageUpsamplerBuildingBlocks:
896956
"""Test upsampler components without checkpoints (random weights)."""
897957

0 commit comments

Comments
 (0)