Skip to content

Commit af700c8

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

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
# ---------------------------------------------------------------------------
@@ -637,8 +635,7 @@ def load_standard_components(
637635

638636
lora_executor = None
639637
lora_future = None
640-
disable_overlap_lora_load = os.getenv(_DISABLE_OVERLAP_LORA_LOAD_ENV, "0") == "1"
641-
if distilled_lora_path and not disable_overlap_lora_load:
638+
if distilled_lora_path:
642639
logger.info(f"Starting distilled LoRA pre-compute from {distilled_lora_path}...")
643640
lora_executor = ThreadPoolExecutor(max_workers=1)
644641
lora_future = lora_executor.submit(
@@ -662,7 +659,6 @@ def load_standard_components(
662659
spatial_upsampler_path,
663660
distilled_lora_path,
664661
lora_future,
665-
disable_overlap_lora_load,
666662
)
667663
finally:
668664
if lora_executor is not None:
@@ -675,7 +671,6 @@ def _load_two_stage_components(
675671
spatial_upsampler_path: str,
676672
distilled_lora_path: str,
677673
lora_future,
678-
disable_overlap_lora_load: bool,
679674
) -> None:
680675
# --- Spatial upsampler ---
681676
if spatial_upsampler_path:
@@ -715,18 +710,10 @@ def _load_two_stage_components(
715710
# --- Distilled LoRA (pre-compute deltas) ---
716711
self._distilled_lora_deltas: Dict[str, torch.Tensor] = {}
717712
if distilled_lora_path:
718-
if disable_overlap_lora_load:
719-
logger.info(f"Loading distilled LoRA from {distilled_lora_path}...")
720-
self._distilled_lora_deltas = _load_lora_deltas(
721-
distilled_lora_path,
722-
self.transformer,
723-
self._TRANSFORMER_PREFIX,
724-
)
725-
else:
726-
logger.info("Waiting for distilled LoRA pre-compute...")
727-
if lora_future is None:
728-
raise RuntimeError("Distilled LoRA pre-compute was not started.")
729-
self._distilled_lora_deltas = lora_future.result()
713+
logger.info("Waiting for distilled LoRA pre-compute...")
714+
if lora_future is None:
715+
raise RuntimeError("Distilled LoRA pre-compute was not started.")
716+
self._distilled_lora_deltas = lora_future.result()
730717
logger.info(
731718
f"Distilled LoRA ready: {len(self._distilled_lora_deltas)} parameter deltas"
732719
)

tests/unittest/_torch/visual_gen/test_ltx2_pipeline.py

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

880880

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

0 commit comments

Comments
 (0)