Skip to content

Commit af5a827

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

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 dataclasses import dataclass, field
@@ -52,7 +51,6 @@
5251
# Baseline BF16 peak memory ~75 GiB, saving BF16 weights snapshot total ~108 GiB.
5352
_BF16_WEIGHTS_SNAPSHOT_FREE_MEMORY_THRESHOLD_GIB = 115.0
5453
_QKV_SUFFIXES = (".to_q", ".to_k", ".to_v")
55-
_DISABLE_OVERLAP_LORA_LOAD_ENV = "TRTLLM_LTX2_DISABLE_OVERLAP_LORA_LOAD"
5654

5755

5856
# ---------------------------------------------------------------------------
@@ -999,8 +997,7 @@ def load_standard_components(
999997

1000998
lora_executor = None
1001999
lora_future = None
1002-
disable_overlap_lora_load = os.getenv(_DISABLE_OVERLAP_LORA_LOAD_ENV, "0") == "1"
1003-
if distilled_lora_path and not disable_overlap_lora_load:
1000+
if distilled_lora_path:
10041001
logger.info(f"Starting distilled LoRA pre-compute from {distilled_lora_path}...")
10051002
lora_executor = ThreadPoolExecutor(max_workers=1)
10061003
lora_future = lora_executor.submit(
@@ -1024,7 +1021,6 @@ def load_standard_components(
10241021
spatial_upsampler_path,
10251022
distilled_lora_path,
10261023
lora_future,
1027-
disable_overlap_lora_load,
10281024
)
10291025
finally:
10301026
if lora_executor is not None:
@@ -1037,7 +1033,6 @@ def _load_two_stage_components(
10371033
spatial_upsampler_path: str,
10381034
distilled_lora_path: str,
10391035
lora_future,
1040-
disable_overlap_lora_load: bool,
10411036
) -> None:
10421037
# --- Spatial upsampler ---
10431038
if spatial_upsampler_path:
@@ -1079,18 +1074,10 @@ def _load_two_stage_components(
10791074
self._distilled_lora_deltas: Dict[str, torch.Tensor] = {}
10801075
self._distilled_lora_weight_cache: Optional[_PersistentLoRAWeightCache] = None
10811076
if distilled_lora_path:
1082-
if disable_overlap_lora_load:
1083-
logger.info(f"Loading distilled LoRA from {distilled_lora_path}...")
1084-
self._distilled_lora_deltas = _load_lora_deltas(
1085-
distilled_lora_path,
1086-
self.transformer,
1087-
self._TRANSFORMER_PREFIX,
1088-
)
1089-
else:
1090-
logger.info("Waiting for distilled LoRA pre-compute...")
1091-
if lora_future is None:
1092-
raise RuntimeError("Distilled LoRA pre-compute was not started.")
1093-
self._distilled_lora_deltas = lora_future.result()
1077+
logger.info("Waiting for distilled LoRA pre-compute...")
1078+
if lora_future is None:
1079+
raise RuntimeError("Distilled LoRA pre-compute was not started.")
1080+
self._distilled_lora_deltas = lora_future.result()
10941081
logger.info(
10951082
f"Distilled LoRA ready: {len(self._distilled_lora_deltas)} parameter deltas"
10961083
)

tests/unittest/_torch/visual_gen/test_ltx2_pipeline.py

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

962962

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

0 commit comments

Comments
 (0)