Skip to content

Commit 22444f6

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

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
@@ -44,7 +43,6 @@
4443
# Baseline BF16 peak memory ~75 GiB, saving BF16 weights snopshot total ~108 GiB.
4544
_BF16_WEIGHTS_SNAPSHOT_FREE_MEMORY_THRESHOLD_GIB = 115.0
4645
_QKV_SUFFIXES = (".to_q", ".to_k", ".to_v")
47-
_DISABLE_OVERLAP_LORA_LOAD_ENV = "TRTLLM_LTX2_DISABLE_OVERLAP_LORA_LOAD"
4846

4947

5048
# ---------------------------------------------------------------------------
@@ -681,8 +679,7 @@ def load_standard_components(
681679

682680
lora_executor = None
683681
lora_future = None
684-
disable_overlap_lora_load = os.getenv(_DISABLE_OVERLAP_LORA_LOAD_ENV, "0") == "1"
685-
if distilled_lora_path and not disable_overlap_lora_load:
682+
if distilled_lora_path:
686683
logger.info(f"Starting distilled LoRA pre-compute from {distilled_lora_path}...")
687684
lora_executor = ThreadPoolExecutor(max_workers=1)
688685
lora_future = lora_executor.submit(
@@ -706,7 +703,6 @@ def load_standard_components(
706703
spatial_upsampler_path,
707704
distilled_lora_path,
708705
lora_future,
709-
disable_overlap_lora_load,
710706
)
711707
finally:
712708
if lora_executor is not None:
@@ -719,7 +715,6 @@ def _load_two_stage_components(
719715
spatial_upsampler_path: str,
720716
distilled_lora_path: str,
721717
lora_future,
722-
disable_overlap_lora_load: bool,
723718
) -> None:
724719
# --- Spatial upsampler ---
725720
if spatial_upsampler_path:
@@ -759,18 +754,10 @@ def _load_two_stage_components(
759754
# --- Distilled LoRA (pre-compute deltas) ---
760755
self._distilled_lora_deltas: Dict[str, torch.Tensor] = {}
761756
if distilled_lora_path:
762-
if disable_overlap_lora_load:
763-
logger.info(f"Loading distilled LoRA from {distilled_lora_path}...")
764-
self._distilled_lora_deltas = _load_lora_deltas(
765-
distilled_lora_path,
766-
self.transformer,
767-
self._TRANSFORMER_PREFIX,
768-
)
769-
else:
770-
logger.info("Waiting for distilled LoRA pre-compute...")
771-
if lora_future is None:
772-
raise RuntimeError("Distilled LoRA pre-compute was not started.")
773-
self._distilled_lora_deltas = lora_future.result()
757+
logger.info("Waiting for distilled LoRA pre-compute...")
758+
if lora_future is None:
759+
raise RuntimeError("Distilled LoRA pre-compute was not started.")
760+
self._distilled_lora_deltas = lora_future.result()
774761
logger.info(
775762
f"Distilled LoRA ready: {len(self._distilled_lora_deltas)} parameter deltas"
776763
)

tests/unittest/_torch/visual_gen/test_ltx2_pipeline.py

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

951951

952+
class TestTwoStageLoRALoadingOverlap:
953+
"""Test two-stage LoRA load orchestration without loading checkpoints."""
954+
955+
def test_load_standard_components_overlaps_lora_with_base_components(self, monkeypatch):
956+
from types import SimpleNamespace
957+
958+
from tensorrt_llm._torch.visual_gen.models.ltx2 import pipeline_ltx2_two_stages
959+
from tensorrt_llm._torch.visual_gen.models.ltx2.pipeline_ltx2 import LTX2Pipeline
960+
from tensorrt_llm._torch.visual_gen.models.ltx2.pipeline_ltx2_two_stages import (
961+
LTX2TwoStagesPipeline,
962+
)
963+
964+
events = []
965+
lora_deltas = {"linear.weight": torch.ones(1)}
966+
967+
class FakeFuture:
968+
def result(self):
969+
events.append("lora_result")
970+
return lora_deltas
971+
972+
class FakeExecutor:
973+
def __init__(self, max_workers):
974+
assert max_workers == 1
975+
976+
def submit(self, fn, *args):
977+
events.append("lora_submit")
978+
assert fn is pipeline_ltx2_two_stages._load_lora_deltas
979+
assert args == (
980+
"/fake/lora.safetensors",
981+
pipeline.transformer,
982+
pipeline._TRANSFORMER_PREFIX,
983+
)
984+
return FakeFuture()
985+
986+
def shutdown(self, wait=True):
987+
events.append(f"shutdown:{wait}")
988+
989+
def fake_base_load(self, checkpoint_dir, device, skip_components=None, **kwargs):
990+
events.append("base_load")
991+
assert checkpoint_dir == "/fake/checkpoint"
992+
assert device == torch.device("cpu")
993+
994+
monkeypatch.setattr(pipeline_ltx2_two_stages, "ThreadPoolExecutor", FakeExecutor)
995+
monkeypatch.setattr(LTX2Pipeline, "load_standard_components", fake_base_load)
996+
997+
pipeline = LTX2TwoStagesPipeline.__new__(LTX2TwoStagesPipeline)
998+
pipeline.model_config = SimpleNamespace(
999+
torch_dtype=torch.float32,
1000+
extra_attrs={
1001+
"distilled_lora_path": "/fake/lora.safetensors",
1002+
},
1003+
)
1004+
pipeline.transformer = object()
1005+
1006+
pipeline.load_standard_components("/fake/checkpoint", torch.device("cpu"))
1007+
1008+
assert events == ["lora_submit", "base_load", "lora_result", "shutdown:True"]
1009+
assert pipeline._distilled_lora_deltas is lora_deltas
1010+
1011+
9521012
class TestTwoStageUpsamplerBuildingBlocks:
9531013
"""Test upsampler components without checkpoints (random weights)."""
9541014

0 commit comments

Comments
 (0)