Upload ltx2_two_stage.py
Browse files- ltx2_two_stage.py +84 -0
ltx2_two_stage.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
python ltx2_two_stage.py \
|
| 3 |
+
--image "astronaut.jpg" 0 1.0 \
|
| 4 |
+
--prompt="An astronaut hatches from a fragile egg on the surface of the Moon, the shell cracking and peeling apart in gentle low-gravity motion. Fine lunar dust lifts and drifts outward with each movement, floating in slow arcs before settling back onto the ground. The astronaut pushes free in a deliberate, weightless motion, small fragments of the egg tumbling and spinning through the air. In the background, the deep darkness of space subtly shifts as stars glide with the camera's movement, emphasizing vast depth and scale. The camera performs a smooth, cinematic slow push-in, with natural parallax between the foreground dust, the astronaut, and the distant starfield. Ultra-realistic detail, physically accurate low-gravity motion, cinematic lighting, and a breath-taking, movie-like shot." \
|
| 5 |
+
--output_path="t2v_2.mp4" \
|
| 6 |
+
--gemma_root="google/gemma-3-12b-it-qat-q4_0-unquantized" \
|
| 7 |
+
--checkpoint_path="rc1/ltx-2-19b-dev-rc1.safetensors" \
|
| 8 |
+
--distilled_lora_path "rc1/ltx-2-19b-distilled-lora-384-rc1.safetensors" \
|
| 9 |
+
--spatial_upsampler_path "rc1/ltx-2-spatial-upscaler-x2-1.0-rc1.safetensors"
|
| 10 |
+
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
from huggingface_hub import hf_hub_download
|
| 14 |
+
from typing import Optional
|
| 15 |
+
from ltx_pipelines import utils
|
| 16 |
+
from ltx_pipelines.constants import DEFAULT_LORA_STRENGTH
|
| 17 |
+
from ltx_core.loader.primitives import LoraPathStrengthAndSDOps
|
| 18 |
+
from ltx_core.loader.sd_ops import LTXV_LORA_COMFY_RENAMING_MAP
|
| 19 |
+
from ltx_pipelines.ti2vid_two_stages import TI2VidTwoStagesPipeline
|
| 20 |
+
from ltx_core.tiling import TilingConfig
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def get_hub_or_local_checkpoint(repo_id: Optional[str] = None, filename: Optional[str] = None):
|
| 24 |
+
if repo_id is None and filename is None:
|
| 25 |
+
raise ValueError("Please supply at least one of `repo_id` or `filename`")
|
| 26 |
+
|
| 27 |
+
if repo_id is not None:
|
| 28 |
+
if filename is None:
|
| 29 |
+
raise ValueError("If repo_id is specified, filename must also be specified.")
|
| 30 |
+
ckpt_path = hf_hub_download(repo_id=repo_id, filename=filename)
|
| 31 |
+
else:
|
| 32 |
+
ckpt_path = filename
|
| 33 |
+
|
| 34 |
+
return ckpt_path
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def default_2_stage_arg_parser_mod():
|
| 38 |
+
parser = utils.default_2_stage_arg_parser()
|
| 39 |
+
parser.add_argument("--local_files_only", action="store_true")
|
| 40 |
+
parser.add_argument("--checkpoint_id", type=str, default="diffusers-internal-dev/new-ltx-model")
|
| 41 |
+
return parser
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def main() -> None:
|
| 45 |
+
parser = default_2_stage_arg_parser_mod()
|
| 46 |
+
args = parser.parse_args()
|
| 47 |
+
|
| 48 |
+
checkpoint_path = get_hub_or_local_checkpoint(args.checkpoint_id, args.checkpoint_path)
|
| 49 |
+
distilled_lora_path = get_hub_or_local_checkpoint(args.checkpoint_id, args.distilled_lora_path)
|
| 50 |
+
spatial_upsampler_path = get_hub_or_local_checkpoint(args.checkpoint_id, args.spatial_upsampler_path)
|
| 51 |
+
|
| 52 |
+
lora_strengths = (args.lora_strength + [DEFAULT_LORA_STRENGTH] * len(args.lora))[: len(args.lora)]
|
| 53 |
+
loras = [
|
| 54 |
+
LoraPathStrengthAndSDOps(lora, strength, LTXV_LORA_COMFY_RENAMING_MAP)
|
| 55 |
+
for lora, strength in zip(args.lora, lora_strengths, strict=True)
|
| 56 |
+
]
|
| 57 |
+
pipeline = TI2VidTwoStagesPipeline(
|
| 58 |
+
checkpoint_path=checkpoint_path,
|
| 59 |
+
distilled_lora_path=distilled_lora_path,
|
| 60 |
+
distilled_lora_strength=args.distilled_lora_strength,
|
| 61 |
+
spatial_upsampler_path=spatial_upsampler_path,
|
| 62 |
+
gemma_root=args.gemma_root,
|
| 63 |
+
loras=loras,
|
| 64 |
+
fp8transformer=args.enable_fp8,
|
| 65 |
+
local_files_only=args.local_files_only
|
| 66 |
+
)
|
| 67 |
+
pipeline(
|
| 68 |
+
prompt=args.prompt,
|
| 69 |
+
negative_prompt=args.negative_prompt,
|
| 70 |
+
output_path=args.output_path,
|
| 71 |
+
seed=args.seed,
|
| 72 |
+
height=args.height,
|
| 73 |
+
width=args.width,
|
| 74 |
+
num_frames=args.num_frames,
|
| 75 |
+
frame_rate=args.frame_rate,
|
| 76 |
+
num_inference_steps=args.num_inference_steps,
|
| 77 |
+
cfg_guidance_scale=args.cfg_guidance_scale,
|
| 78 |
+
images=args.images,
|
| 79 |
+
tiling_config=TilingConfig.default(),
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
if __name__ == "__main__":
|
| 84 |
+
main()
|