Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[model] LTX Video 0.9.8 #12095

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
a-r-r-o-w wants to merge 12 commits into main
base: main
Choose a base branch
Loading
from integrations/ltx-098
Open

[model] LTX Video 0.9.8 #12095

a-r-r-o-w wants to merge 12 commits into main from integrations/ltx-098

Conversation

Copy link
Member

@a-r-r-o-w a-r-r-o-w commented Aug 7, 2025
edited
Loading

code
import torch
from diffusers import LTXConditionPipeline, LTXLatentUpsamplePipeline
from diffusers.pipelines.ltx.pipeline_ltx_condition import LTXVideoCondition
from diffusers.pipelines.ltx.modeling_latent_upsampler import LTXLatentUpsamplerModel
from diffusers.utils import export_to_video, load_video
pipeline = LTXConditionPipeline.from_pretrained("Lightricks/LTX-Video-0.9.8-13B-distilled", torch_dtype=torch.bfloat16)
upsampler = LTXLatentUpsamplerModel.from_pretrained("a-r-r-o-w/LTX-0.9.8-Latent-Upsampler", torch_dtype=torch.bfloat16)
pipe_upsample = LTXLatentUpsamplePipeline(vae=pipeline.vae, latent_upsampler=upsampler).to(torch.bfloat16)
pipeline.to("cuda")
pipe_upsample.to("cuda")
pipeline.vae.enable_tiling()
def round_to_nearest_resolution_acceptable_by_vae(height, width):
 height = height - (height % pipeline.vae_spatial_compression_ratio)
 width = width - (width % pipeline.vae_spatial_compression_ratio)
 return height, width
prompt = """The camera pans over a snow-covered mountain range, revealing a vast expanse of snow-capped peaks and valleys.The mountains are covered in a thick layer of snow, with some areas appearing almost white while others have a slightly darker, almost grayish hue. The peaks are jagged and irregular, with some rising sharply into the sky while others are more rounded. The valleys are deep and narrow, with steep slopes that are also covered in snow. The trees in the foreground are mostly bare, with only a few leaves remaining on their branches. The sky is overcast, with thick clouds obscuring the sun. The overall impression is one of peace and tranquility, with the snow-covered mountains standing as a testament to the power and beauty of nature."""
# prompt = """A woman walks away from a white Jeep parked on a city street at night, then ascends a staircase and knocks on a door. The woman, wearing a dark jacket and jeans, walks away from the Jeep parked on the left side of the street, her back to the camera; she walks at a steady pace, her arms swinging slightly by her sides; the street is dimly lit, with streetlights casting pools of light on the wet pavement; a man in a dark jacket and jeans walks past the Jeep in the opposite direction; the camera follows the woman from behind as she walks up a set of stairs towards a building with a green door; she reaches the top of the stairs and turns left, continuing to walk towards the building; she reaches the door and knocks on it with her right hand; the camera remains stationary, focused on the doorway; the scene is captured in real-life footage."""
negative_prompt = "bright colors, symbols, graffiti, watermarks, worst quality, inconsistent motion, blurry, jittery, distorted"
expected_height, expected_width = 480, 832
downscale_factor = 2 / 3
# num_frames = 161
num_frames = 361
# 1. Generate video at smaller resolution
downscaled_height, downscaled_width = int(expected_height * downscale_factor), int(expected_width * downscale_factor)
downscaled_height, downscaled_width = round_to_nearest_resolution_acceptable_by_vae(downscaled_height, downscaled_width)
latents = pipeline(
 prompt=prompt,
 negative_prompt=negative_prompt,
 width=downscaled_width,
 height=downscaled_height,
 num_frames=num_frames,
 timesteps=[1000, 993, 987, 981, 975, 909, 725, 0.03],
 decode_timestep=0.05,
 decode_noise_scale=0.025,
 image_cond_noise_scale=0.0,
 guidance_scale=1.0,
 guidance_rescale=0.7,
 generator=torch.Generator().manual_seed(0),
 output_type="latent",
).frames
# 2. Upscale generated video using latent upsampler with fewer inference steps
# The available latent upsampler upscales the height/width by 2x
upscaled_height, upscaled_width = downscaled_height * 2, downscaled_width * 2
upscaled_latents = pipe_upsample(
 latents=latents,
 adain_factor=1.0,
 tone_map_compression_ratio=0.6,
 output_type="latent"
).frames
# 3. Denoise the upscaled video with few steps to improve texture (optional, but recommended)
video = pipeline(
 prompt=prompt,
 negative_prompt=negative_prompt,
 width=upscaled_width,
 height=upscaled_height,
 num_frames=num_frames,
 denoise_strength=0.999, # Effectively, 4 inference steps out of 5
 timesteps=[1000, 909, 725, 421, 0],
 latents=upscaled_latents,
 decode_timestep=0.05,
 decode_noise_scale=0.025,
 image_cond_noise_scale=0.0,
 guidance_scale=1.0,
 guidance_rescale=0.7,
 generator=torch.Generator().manual_seed(0),
 output_type="pil",
).frames[0]
# 4. Downscale the video to the expected resolution
video = [frame.resize((expected_width, expected_height)) for frame in video]
export_to_video(video, "output.mp4", fps=24)
moutain.mp4
woman-door.mp4

ghunkins and tin2tin reacted with heart emoji

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Collaborator

@yiyixuxu yiyixuxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Copy link
Member Author

a-r-r-o-w commented Aug 8, 2025
edited
Loading

@yiyixuxu I forgot to clarify here. This PR is slightly incomplete -- we still need the autoregressive sampling I believe. I wrote more about it here: https://huggingface.slack.com/archives/C065E480NN9/p1754568827299629?thread_ts=1752682810.233009&cid=C065E480NN9

Let's not merge for now :) I was debugging a different PR of mine so still need to look for a bit at their comfy codebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@yiyixuxu yiyixuxu yiyixuxu approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /