Skip to content

Commit 2c2f177

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

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
@@ -757,6 +757,66 @@ def test_resolve_variant_requires_both_paths(self):
757757
assert result is LTX2Pipeline
758758

759759

760+
class TestTwoStageLoRALoadingOverlap:
761+
"""Test two-stage LoRA load orchestration without loading checkpoints."""
762+
763+
def test_load_standard_components_overlaps_lora_with_base_components(self, monkeypatch):
764+
from types import SimpleNamespace
765+
766+
from tensorrt_llm._torch.visual_gen.models.ltx2 import pipeline_ltx2_two_stages
767+
from tensorrt_llm._torch.visual_gen.models.ltx2.pipeline_ltx2 import LTX2Pipeline
768+
from tensorrt_llm._torch.visual_gen.models.ltx2.pipeline_ltx2_two_stages import (
769+
LTX2TwoStagesPipeline,
770+
)
771+
772+
events = []
773+
lora_deltas = {"linear.weight": torch.ones(1)}
774+
775+
class FakeFuture:
776+
def result(self):
777+
events.append("lora_result")
778+
return lora_deltas
779+
780+
class FakeExecutor:
781+
def __init__(self, max_workers):
782+
assert max_workers == 1
783+
784+
def submit(self, fn, *args):
785+
events.append("lora_submit")
786+
assert fn is pipeline_ltx2_two_stages._load_lora_deltas
787+
assert args == (
788+
"/fake/lora.safetensors",
789+
pipeline.transformer,
790+
pipeline._TRANSFORMER_PREFIX,
791+
)
792+
return FakeFuture()
793+
794+
def shutdown(self, wait=True):
795+
events.append(f"shutdown:{wait}")
796+
797+
def fake_base_load(self, checkpoint_dir, device, skip_components=None, **kwargs):
798+
events.append("base_load")
799+
assert checkpoint_dir == "/fake/checkpoint"
800+
assert device == torch.device("cpu")
801+
802+
monkeypatch.setattr(pipeline_ltx2_two_stages, "ThreadPoolExecutor", FakeExecutor)
803+
monkeypatch.setattr(LTX2Pipeline, "load_standard_components", fake_base_load)
804+
805+
pipeline = LTX2TwoStagesPipeline.__new__(LTX2TwoStagesPipeline)
806+
pipeline.model_config = SimpleNamespace(
807+
torch_dtype=torch.float32,
808+
extra_attrs={
809+
"distilled_lora_path": "/fake/lora.safetensors",
810+
},
811+
)
812+
pipeline.transformer = object()
813+
814+
pipeline.load_standard_components("/fake/checkpoint", torch.device("cpu"))
815+
816+
assert events == ["lora_submit", "base_load", "lora_result", "shutdown:True"]
817+
assert pipeline._distilled_lora_deltas is lora_deltas
818+
819+
760820
class TestTwoStageUpsamplerBuildingBlocks:
761821
"""Test upsampler components without checkpoints (random weights)."""
762822

0 commit comments

Comments
 (0)