Views
No views yet
pip install sdnq1import torch
2import diffusers
3from diffusers.pipelines.ltx2.export_utils import encode_video
4from sdnq import SDNQConfig # import sdnq to register it into diffusers and transformers
5from sdnq.common import use_torch_compile as triton_is_available
6from sdnq.loader import apply_sdnq_options_to_model
7
8pipe = diffusers.LTX2Pipeline.from_pretrained("Disty0/LTX-2-SDNQ-4bit-dynamic", torch_dtype=torch.bfloat16)
9
10# Enable INT8 MatMul for AMD, Intel ARC and Nvidia GPUs:
11if triton_is_available and (torch.cuda.is_available() or torch.xpu.is_available()):
12 pipe.transformer = apply_sdnq_options_to_model(pipe.transformer, use_quantized_matmul=True)
13 pipe.text_encoder = apply_sdnq_options_to_model(pipe.text_encoder, use_quantized_matmul=True)
14 # pipe.transformer = torch.compile(pipe.transformer) # optional for faster speeds
15
16pipe.vae.enable_tiling()
17pipe.enable_model_cpu_offload()
18
19prompt = "A close-up of a cheerful girl puppet with curly auburn yarn hair and wide button eyes, holding a small red umbrella above her head. Rain falls gently around her. She looks upward and begins to sing with joy in English: \"It's raining, it's raining, I love it when its raining.\" Her fabric mouth opening and closing to a melodic tune. Her hands grip the umbrella handle as she sways slightly from side to side in rhythm. The camera holds steady as the rain sparkles against the soft lighting. Her eyes blink occasionally as she sings."
20negative_prompt = "blurry, low quality, still frame, frames, watermark, overlay, titles, has blurbox, has subtitles"
21
22frame_rate = 25.0
23video, audio = pipe(
24 prompt=prompt,
25 negative_prompt=negative_prompt,
26 width=768,
27 height=512,
28 num_frames=121,
29 frame_rate=frame_rate,
30 num_inference_steps=40,
31 guidance_scale=4.0,
32 generator=torch.manual_seed(10),
33 output_type="np",
34 return_dict=False,
35)
36video = (video * 255).round().astype("uint8")
37video = torch.from_numpy(video)
38
39
40encode_video(
41 video[0],
42 fps=frame_rate,
43 audio=audio[0].float().cpu(),
44 audio_sample_rate=pipe.vocoder.config.output_sampling_rate, # should be 24000
45 output_path="ltx2_t2v_sdnq-4bit-dynamic.mp4",
46)