Spaces:
Runtime error
Runtime error
update to 0.9.8 (#23)
Browse files- update to 0.9.8 (0135c48cef03cb1cbdefffc47d83a85095518e10)
- Update app.py (e1c8d1db758dbb5663f2b31af5be19c7aaf5b5c3)
- update code base with main (27e0be50ac121b4b63239a5b5dc6a11eddac9209)
- Update app.py (c3db712c6a92b978a2feb71ccfd70038b6ee3108)
- Update app.py (ab760cfbc5339b4551b6e5a02020981b4c8affe3)
Co-authored-by: Linoy Tsaban <linoyts@users.noreply.huggingface.co>
Files changed (12)
- app.py+5-5
- configs/ltxv-13b-0.9.8-dev-fp8.yamlAdded+34
- configs/ltxv-13b-0.9.8-dev.yamlAdded+34
- configs/ltxv-13b-0.9.8-distilled-fp8.yamlAdded+29
- configs/ltxv-13b-0.9.8-distilled.yamlAdded+29
- configs/ltxv-2b-0.9.8-distilled-fp8.yamlAdded+28
- configs/ltxv-2b-0.9.8-distilled.yamlAdded+28
- ltx_video/models/autoencoders/causal_video_autoencoder.py+2-7
- ltx_video/models/transformers/attention.py-1
- ltx_video/models/transformers/transformer3d.py+1-1
- ltx_video/pipelines/pipeline_ltx_video.py+113-63
- ltx_video/schedulers/rf.py+1-1
23 unmodified lines24252627282930343 unmodified lines37437537637737837938038122 unmodified lines4044054064074084094105 unmodified lines41641741841942042142223 unmodified linesfrom ltx_video.pipelines.pipeline_ltx_video import ConditioningItem, LTXMultiScalePipeline, LTXVideoPipelinefrom ltx_video.utils.skip_layer_strategy import SkipLayerStrategyconfig_file_path = "configs/ltxv-13b-0.9.7-distilled.yaml"with open(config_file_path, "r") as file:PIPELINE_CONFIG_YAML = yaml.safe_load(file)343 unmodified lines"""with gr.Blocks(css=css) as demo:gr.Markdown("# LTX Video 0.9.7 Distilled")gr.Markdown("Fast high quality video generation. [Model](https://huggingface.co/Lightricks/LTX-Video/blob/main/ltxv-13b-0.9.7-distilled.safetensors) [GitHub](https://github.com/Lightricks/LTX-Video) [Diffusers](https://huggingface.co/Lightricks/LTX-Video-0.9.7-distilled#diffusers-π§¨)")with gr.Row():with gr.Column():22 unmodified linesstep=0.1,info=f"Target video duration (0.3s to 8.5s)")improve_texture = gr.Checkbox(label="Improve Texture (multi-scale)", value=True, info="Uses a two-pass generation for better quality, but is slower. Recommended for final output.")with gr.Column():output_video = gr.Video(label="Generated Video", interactive=False)5 unmodified lineswith gr.Row():seed_input = gr.Number(label="Seed", value=42, precision=0, minimum=0, maximum=2**32-1)randomize_seed_input = gr.Checkbox(label="Randomize Seed", value=True)with gr.Row():guidance_scale_input = gr.Slider(label="Guidance Scale (CFG)", minimum=1.0, maximum=10.0, value=PIPELINE_CONFIG_YAML.get("first_pass", {}).get("guidance_scale", 1.0), step=0.1, info="Controls how much the prompt influences the output. Higher values = stronger influence.")with gr.Row():height_input = gr.Slider(label="Height", value=512, step=32, minimum=MIN_DIM_SLIDER, maximum=MAX_IMAGE_SIZE, info="Must be divisible by 32.")23 unmodified lines24252627282930343 unmodified lines37437537637737837938038122 unmodified lines4044054064074084094105 unmodified lines41641741841942042142223 unmodified linesfrom ltx_video.pipelines.pipeline_ltx_video import ConditioningItem, LTXMultiScalePipeline, LTXVideoPipelinefrom ltx_video.utils.skip_layer_strategy import SkipLayerStrategyconfig_file_path = "configs/ltxv-13b-0.9.8-distilled.yaml"with open(config_file_path, "r") as file:PIPELINE_CONFIG_YAML = yaml.safe_load(file)343 unmodified lines"""with gr.Blocks(css=css) as demo:gr.Markdown("# LTX Video 0.9.8 13B Distilled")gr.Markdown("Fast high quality video generation. [Model](https://huggingface.co/Lightricks/LTX-Video/blob/main/ltxv-13b-0.9.8-distilled.safetensors) [GitHub](https://github.com/Lightricks/LTX-Video) [Diffusers](https://huggingface.co/Lightricks/LTX-Video-0.9.8-13B-distilled#diffusers-π§¨)")with gr.Row():with gr.Column():22 unmodified linesstep=0.1,info=f"Target video duration (0.3s to 8.5s)")improve_texture = gr.Checkbox(label="Improve Texture (multi-scale)", value=True,visible=False, info="Uses a two-pass generation for better quality, but is slower. Recommended for final output.")with gr.Column():output_video = gr.Video(label="Generated Video", interactive=False)5 unmodified lineswith gr.Row():seed_input = gr.Number(label="Seed", value=42, precision=0, minimum=0, maximum=2**32-1)randomize_seed_input = gr.Checkbox(label="Randomize Seed", value=True)with gr.Row(visible=False):guidance_scale_input = gr.Slider(label="Guidance Scale (CFG)", minimum=1.0, maximum=10.0, value=PIPELINE_CONFIG_YAML.get("first_pass", {}).get("guidance_scale", 1.0), step=0.1, info="Controls how much the prompt influences the output. Higher values = stronger influence.")with gr.Row():height_input = gr.Slider(label="Height", value=512, step=32, minimum=MIN_DIM_SLIDER, maximum=MAX_IMAGE_SIZE, info="Must be divisible by 32.")
12345678910111213141516171819202122232425262728293031323334pipeline_type: multi-scalecheckpoint_path: "ltxv-13b-0.9.8-dev-fp8.safetensors"downscale_factor: 0.6666666spatial_upscaler_model_path: "ltxv-spatial-upscaler-0.9.8.safetensors"stg_mode: "attention_values" # options: "attention_values", "attention_skip", "residual", "transformer_block"decode_timestep: 0.05decode_noise_scale: 0.025text_encoder_model_name_or_path: "PixArt-alpha/PixArt-XL-2-1024-MS"precision: "float8_e4m3fn" # options: "float8_e4m3fn", "bfloat16", "mixed_precision"sampler: "from_checkpoint" # options: "uniform", "linear-quadratic", "from_checkpoint"prompt_enhancement_words_threshold: 120prompt_enhancer_image_caption_model_name_or_path: "MiaoshouAI/Florence-2-large-PromptGen-v2.0"prompt_enhancer_llm_model_name_or_path: "unsloth/Llama-3.2-3B-Instruct"stochastic_sampling: false
first_pass: guidance_scale: [1, 1, 6, 8, 6, 1, 1] stg_scale: [0, 0, 4, 4, 4, 2, 1] rescaling_scale: [1, 1, 0.5, 0.5, 1, 1, 1] guidance_timesteps: [1.0, 0.996, 0.9933, 0.9850, 0.9767, 0.9008, 0.6180] skip_block_list: [[], [11, 25, 35, 39], [22, 35, 39], [28], [28], [28], [28]] num_inference_steps: 30 skip_final_inference_steps: 3 cfg_star_rescale: true
second_pass: guidance_scale: [1] stg_scale: [1] rescaling_scale: [1] guidance_timesteps: [1.0] skip_block_list: [27] num_inference_steps: 30 skip_initial_inference_steps: 17 cfg_star_rescale: true12345678910111213141516171819202122232425262728293031323334pipeline_type: multi-scalecheckpoint_path: "ltxv-13b-0.9.8-dev.safetensors"downscale_factor: 0.6666666spatial_upscaler_model_path: "ltxv-spatial-upscaler-0.9.8.safetensors"stg_mode: "attention_values" # options: "attention_values", "attention_skip", "residual", "transformer_block"decode_timestep: 0.05decode_noise_scale: 0.025text_encoder_model_name_or_path: "PixArt-alpha/PixArt-XL-2-1024-MS"precision: "bfloat16"sampler: "from_checkpoint" # options: "uniform", "linear-quadratic", "from_checkpoint"prompt_enhancement_words_threshold: 120prompt_enhancer_image_caption_model_name_or_path: "MiaoshouAI/Florence-2-large-PromptGen-v2.0"prompt_enhancer_llm_model_name_or_path: "unsloth/Llama-3.2-3B-Instruct"stochastic_sampling: false
first_pass: guidance_scale: [1, 1, 6, 8, 6, 1, 1] stg_scale: [0, 0, 4, 4, 4, 2, 1] rescaling_scale: [1, 1, 0.5, 0.5, 1, 1, 1] guidance_timesteps: [1.0, 0.996, 0.9933, 0.9850, 0.9767, 0.9008, 0.6180] skip_block_list: [[], [11, 25, 35, 39], [22, 35, 39], [28], [28], [28], [28]] num_inference_steps: 30 skip_final_inference_steps: 3 cfg_star_rescale: true
second_pass: guidance_scale: [1] stg_scale: [1] rescaling_scale: [1] guidance_timesteps: [1.0] skip_block_list: [27] num_inference_steps: 30 skip_initial_inference_steps: 17 cfg_star_rescale: true1234567891011121314151617181920212223242526272829pipeline_type: multi-scalecheckpoint_path: "ltxv-13b-0.9.8-distilled-fp8.safetensors"downscale_factor: 0.6666666spatial_upscaler_model_path: "ltxv-spatial-upscaler-0.9.8.safetensors"stg_mode: "attention_values" # options: "attention_values", "attention_skip", "residual", "transformer_block"decode_timestep: 0.05decode_noise_scale: 0.025text_encoder_model_name_or_path: "PixArt-alpha/PixArt-XL-2-1024-MS"precision: "float8_e4m3fn" # options: "float8_e4m3fn", "bfloat16", "mixed_precision"sampler: "from_checkpoint" # options: "uniform", "linear-quadratic", "from_checkpoint"prompt_enhancement_words_threshold: 120prompt_enhancer_image_caption_model_name_or_path: "MiaoshouAI/Florence-2-large-PromptGen-v2.0"prompt_enhancer_llm_model_name_or_path: "unsloth/Llama-3.2-3B-Instruct"stochastic_sampling: false
first_pass: timesteps: [1.0000, 0.9937, 0.9875, 0.9812, 0.9750, 0.9094, 0.7250] guidance_scale: 1 stg_scale: 0 rescaling_scale: 1 skip_block_list: [42]
second_pass: timesteps: [0.9094, 0.7250, 0.4219] guidance_scale: 1 stg_scale: 0 rescaling_scale: 1 skip_block_list: [42] tone_map_compression_ratio: 0.61234567891011121314151617181920212223242526272829pipeline_type: multi-scalecheckpoint_path: "ltxv-13b-0.9.8-distilled.safetensors"downscale_factor: 0.6666666spatial_upscaler_model_path: "ltxv-spatial-upscaler-0.9.8.safetensors"stg_mode: "attention_values" # options: "attention_values", "attention_skip", "residual", "transformer_block"decode_timestep: 0.05decode_noise_scale: 0.025text_encoder_model_name_or_path: "PixArt-alpha/PixArt-XL-2-1024-MS"precision: "bfloat16"sampler: "from_checkpoint" # options: "uniform", "linear-quadratic", "from_checkpoint"prompt_enhancement_words_threshold: 120prompt_enhancer_image_caption_model_name_or_path: "MiaoshouAI/Florence-2-large-PromptGen-v2.0"prompt_enhancer_llm_model_name_or_path: "unsloth/Llama-3.2-3B-Instruct"stochastic_sampling: false
first_pass: timesteps: [1.0000, 0.9937, 0.9875, 0.9812, 0.9750, 0.9094, 0.7250] guidance_scale: 1 stg_scale: 0 rescaling_scale: 1 skip_block_list: [42]
second_pass: timesteps: [0.9094, 0.7250, 0.4219] guidance_scale: 1 stg_scale: 0 rescaling_scale: 1 skip_block_list: [42] tone_map_compression_ratio: 0.612345678910111213141516171819202122232425262728pipeline_type: multi-scalecheckpoint_path: "ltxv-2b-0.9.8-distilled-fp8.safetensors"downscale_factor: 0.6666666spatial_upscaler_model_path: "ltxv-spatial-upscaler-0.9.8.safetensors"stg_mode: "attention_values" # options: "attention_values", "attention_skip", "residual", "transformer_block"decode_timestep: 0.05decode_noise_scale: 0.025text_encoder_model_name_or_path: "PixArt-alpha/PixArt-XL-2-1024-MS"precision: "float8_e4m3fn" # options: "float8_e4m3fn", "bfloat16", "mixed_precision"sampler: "from_checkpoint" # options: "uniform", "linear-quadratic", "from_checkpoint"prompt_enhancement_words_threshold: 120prompt_enhancer_image_caption_model_name_or_path: "MiaoshouAI/Florence-2-large-PromptGen-v2.0"prompt_enhancer_llm_model_name_or_path: "unsloth/Llama-3.2-3B-Instruct"stochastic_sampling: false
first_pass: timesteps: [1.0000, 0.9937, 0.9875, 0.9812, 0.9750, 0.9094, 0.7250] guidance_scale: 1 stg_scale: 0 rescaling_scale: 1 skip_block_list: [42]
second_pass: timesteps: [0.9094, 0.7250, 0.4219] guidance_scale: 1 stg_scale: 0 rescaling_scale: 1 skip_block_list: [42]12345678910111213141516171819202122232425262728pipeline_type: multi-scalecheckpoint_path: "ltxv-2b-0.9.8-distilled.safetensors"downscale_factor: 0.6666666spatial_upscaler_model_path: "ltxv-spatial-upscaler-0.9.8.safetensors"stg_mode: "attention_values" # options: "attention_values", "attention_skip", "residual", "transformer_block"decode_timestep: 0.05decode_noise_scale: 0.025text_encoder_model_name_or_path: "PixArt-alpha/PixArt-XL-2-1024-MS"precision: "bfloat16"sampler: "from_checkpoint" # options: "uniform", "linear-quadratic", "from_checkpoint"prompt_enhancement_words_threshold: 120prompt_enhancer_image_caption_model_name_or_path: "MiaoshouAI/Florence-2-large-PromptGen-v2.0"prompt_enhancer_llm_model_name_or_path: "unsloth/Llama-3.2-3B-Instruct"stochastic_sampling: false
first_pass: timesteps: [1.0000, 0.9937, 0.9875, 0.9812, 0.9750, 0.9094, 0.7250] guidance_scale: 1 stg_scale: 0 rescaling_scale: 1 skip_block_list: [42]
second_pass: timesteps: [0.9094, 0.7250, 0.4219] guidance_scale: 1 stg_scale: 0 rescaling_scale: 1 skip_block_list: [42]234 unmodified lines235236237238239240241366 unmodified lines608609610611612613614688 unmodified lines13031304130513061307130813091310131113121313131413151316131713181319132013211322234 unmodified lines"compress_time","compress_all","compress_all_res","compress_space_res",]])366 unmodified linesblock_params = block_params if isinstance(block_params, dict) else {}if block_name == "res_x_y":output_channel = output_channel * block_params.get("multiplier", 2)if block_name == "compress_all":output_channel = output_channel * block_params.get("multiplier", 1)self.conv_in = make_conv_nd(688 unmodified linesencoder_blocks = [("res_x", {"num_layers": 2}),("compress_space_res", {"multiplier": 2}),("res_x", {"num_layers": 2}),("compress_time_res", {"multiplier": 2}),("res_x", {"num_layers": 1}),("compress_all_res", {"multiplier": 2}),("res_x", {"num_layers": 1}),("compress_all_res", {"multiplier": 2}),("res_x", {"num_layers": 1}),]decoder_blocks = [("res_x", {"num_layers": 2, "inject_noise": False}),("compress_all", {"residual": True, "multiplier": 2}),("res_x", {"num_layers": 2, "inject_noise": False}),("compress_all", {"residual": True, "multiplier": 2}),("res_x", {"num_layers": 2, "inject_noise": False}),("compress_all", {"residual": True, "multiplier": 2}),("res_x", {"num_layers": 2, "inject_noise": False}),]234 unmodified lines235236237238239240241366 unmodified lines608609610611612613614688 unmodified lines130313041305130613071308130913101311131213131314131513161317234 unmodified lines"compress_time","compress_all","compress_all_res","compress_time_res",]])366 unmodified linesblock_params = block_params if isinstance(block_params, dict) else {}if block_name == "res_x_y":output_channel = output_channel * block_params.get("multiplier", 2)if block_name.startswith("compress"):output_channel = output_channel * block_params.get("multiplier", 1)self.conv_in = make_conv_nd(688 unmodified linesencoder_blocks = [("res_x", {"num_layers": 2}),("compress_space_res", {"multiplier": 2}),("compress_time_res", {"multiplier": 2}),("compress_all_res", {"multiplier": 2}),("compress_all_res", {"multiplier": 2}),("res_x", {"num_layers": 1}),]decoder_blocks = [("res_x", {"num_layers": 2, "inject_noise": False}),("compress_all", {"residual": True, "multiplier": 2}),("compress_all", {"residual": True, "multiplier": 2}),("compress_all", {"residual": True, "multiplier": 2}),("res_x", {"num_layers": 2, "inject_noise": False}),]
204 unmodified lines205206207208209210211204 unmodified linestimestep: Optional[torch.LongTensor] = None,cross_attention_kwargs: Dict[str, Any] = None,class_labels: Optional[torch.LongTensor] = None,added_cond_kwargs: Optional[Dict[str, torch.Tensor]] = None,skip_layer_mask: Optional[torch.Tensor] = None,skip_layer_strategy: Optional[SkipLayerStrategy] = None,) -> torch.FloatTensor:204 unmodified lines205206207208209210204 unmodified linestimestep: Optional[torch.LongTensor] = None,cross_attention_kwargs: Dict[str, Any] = None,class_labels: Optional[torch.LongTensor] = None,skip_layer_mask: Optional[torch.Tensor] = None,skip_layer_strategy: Optional[SkipLayerStrategy] = None,) -> torch.FloatTensor:
267 unmodified lines268269270271272273274267 unmodified linesfor key, value in state_dict.items()if key.startswith("model.diffusion_model.")}super().load_state_dict(state_dict, **kwargs)@classmethoddef from_pretrained(267 unmodified lines268269270271272273274267 unmodified linesfor key, value in state_dict.items()if key.startswith("model.diffusion_model.")}super().load_state_dict(state_dict, *args, **kwargs)@classmethoddef from_pretrained(
44 unmodified lines4546474849505152535455739 unmodified lines79579679779879980075 unmodified lines87687787887988088196 unmodified lines9789799809819829839849859869876 unmodified lines99499599699799899910001001100210031004100510061007100810095 unmodified lines1015101610171018101910201021102210231024102510261027102810291030103123 unmodified lines105510561057105810591060106111 unmodified lines107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410952 unmodified lines109810991100110111021103110413 unmodified lines111811191120112111221123112411251126112711281129113011312 unmodified lines1134113511361137113811391140114152 unmodified lines1194119511961197119811991200120112021203120412051206120712081209105 unmodified lines131513161317131813191320415 unmodified lines17361737173817391740174144 unmodified lines)try:import torch_xla.distributed.spmd as xsexcept ImportError:xs = Nonelogger = logging.get_logger(__name__) # pylint: disable=invalid-name739 unmodified linestext_encoder_max_tokens: int = 256,stochastic_sampling: bool = False,media_items: Optional[torch.Tensor] = None,**kwargs,) -> Union[ImagePipelineOutput, Tuple]:"""75 unmodified linesIf set to `True`, the sampling is stochastic. If set to `False`, the sampling is deterministic.media_items ('torch.Tensor', *optional*):The input media item used for image-to-image / video-to-video.Examples:Returns:96 unmodified linesguidance_scale[guidance_mapping[i]] for i in range(len(timesteps))]# For simplicity, we are using a constant num_conds for all timesteps, so we need to zero# out cases where the guidance scale should not be applied.guidance_scale = [x if x > 1.0 else 0.0 for x in guidance_scale]if not isinstance(stg_scale, List):stg_scale = [stg_scale] * len(timesteps)else:6 unmodified linesrescaling_scale[guidance_mapping[i]] for i in range(len(timesteps))]do_classifier_free_guidance = any(x > 1.0 for x in guidance_scale)do_spatio_temporal_guidance = any(x > 0.0 for x in stg_scale)do_rescaling = any(x != 1.0 for x in rescaling_scale)num_conds = 1if do_classifier_free_guidance:num_conds += 1if do_spatio_temporal_guidance:num_conds += 1# Normalize skip_block_list to always be None or a list of lists matching timestepsif skip_block_list is not None:# Convert single list to list of lists if needed5 unmodified linesnew_skip_block_list.append(skip_block_list[guidance_mapping[i]])skip_block_list = new_skip_block_list# Prepare skip layer masksskip_layer_masks: Optional[List[torch.Tensor]] = Noneif do_spatio_temporal_guidance:if skip_block_list is not None:skip_layer_masks = [self.transformer.create_skip_layer_mask(batch_size, num_conds, num_conds - 1, skip_blocks)for skip_blocks in skip_block_list]if enhance_prompt:self.prompt_enhancer_image_caption_model = (self.prompt_enhancer_image_caption_model.to(self._execution_device)23 unmodified linesnegative_prompt_attention_mask,) = self.encode_prompt(prompt,do_classifier_free_guidance,negative_prompt=negative_prompt,num_images_per_prompt=num_images_per_prompt,device=device,11 unmodified linesprompt_embeds_batch = prompt_embedsprompt_attention_mask_batch = prompt_attention_maskif do_classifier_free_guidance:prompt_embeds_batch = torch.cat([negative_prompt_embeds, prompt_embeds], dim=0)prompt_attention_mask_batch = torch.cat([negative_prompt_attention_mask, prompt_attention_mask], dim=0)if do_spatio_temporal_guidance:prompt_embeds_batch = torch.cat([prompt_embeds_batch, prompt_embeds], dim=0)prompt_attention_mask_batch = torch.cat([prompt_attention_mask_batch,prompt_attention_mask,],dim=0,)# 4. Prepare the initial latents using the provided media and conditioning items# Prepare the initial latents tensor, shape = (b, c, f, h, w)2 unmodified linesmedia_items=media_items,timestep=timesteps[0],latent_shape=latent_shape,dtype=prompt_embeds_batch.dtype,device=device,generator=generator,vae_per_channel_normalize=vae_per_channel_normalize,13 unmodified lines)init_latents = latents.clone() # Used for image_cond_noise_updatepixel_coords = torch.cat([pixel_coords] * num_conds)orig_conditioning_mask = conditioning_maskif conditioning_mask is not None and is_video:assert num_images_per_prompt == 1conditioning_mask = torch.cat([conditioning_mask] * num_conds)fractional_coords = pixel_coords.to(torch.float32)fractional_coords[:, 0] = fractional_coords[:, 0] * (1.0 / frame_rate)# 6. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipelineextra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)2 unmodified lineslen(timesteps) - num_inference_steps * self.scheduler.order, 0)with self.progress_bar(total=num_inference_steps) as progress_bar:for i, t in enumerate(timesteps):if conditioning_mask is not None and image_cond_noise_scale > 0.0:latents = self.add_noise_to_image_conditioning_latents(t,52 unmodified linesnoise_pred = self.transformer(latent_model_input.to(self.transformer.dtype),indices_grid=fractional_coords,encoder_hidden_states=prompt_embeds_batch.to(self.transformer.dtype),encoder_attention_mask=prompt_attention_mask_batch,timestep=current_timestep,skip_layer_mask=(skip_layer_masks[i]if skip_layer_masks is not Noneelse None),skip_layer_strategy=skip_layer_strategy,return_dict=False,)[0]105 unmodified lines)else:decode_timestep = Noneimage = vae_decode(latents,self.vae,415 unmodified linesnum_frames = (num_frames - 1) // scale_factor * scale_factor + 1return num_framesdef adain_filter_latent(latents: torch.Tensor, reference_latents: torch.Tensor, factor=1.044 unmodified lines454647484950739 unmodified lines79079179279379479579675 unmodified lines87287387487587687787887996 unmodified lines9769779789799809816 unmodified lines9889899909919929935 unmodified lines9991000100110021003100423 unmodified lines102810291030103110321033103411 unmodified lines10461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210732 unmodified lines107610771078107910801081108213 unmodified lines1096109710981099110011012 unmodified lines1104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115352 unmodified lines120612071208120912101211121212131214121512161217105 unmodified lines1323132413251326132713281329415 unmodified lines1745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179144 unmodified lines)logger = logging.get_logger(__name__) # pylint: disable=invalid-name739 unmodified linestext_encoder_max_tokens: int = 256,stochastic_sampling: bool = False,media_items: Optional[torch.Tensor] = None,tone_map_compression_ratio: float = 0.0,**kwargs,) -> Union[ImagePipelineOutput, Tuple]:"""75 unmodified linesIf set to `True`, the sampling is stochastic. If set to `False`, the sampling is deterministic.media_items ('torch.Tensor', *optional*):The input media item used for image-to-image / video-to-video.tone_map_compression_ratio: compression ratio for tone mapping, defaults to 0.0.If set to 0.0, no tone mapping is applied. If set to 1.0 - full compression is applied.Examples:Returns:96 unmodified linesguidance_scale[guidance_mapping[i]] for i in range(len(timesteps))]if not isinstance(stg_scale, List):stg_scale = [stg_scale] * len(timesteps)else:6 unmodified linesrescaling_scale[guidance_mapping[i]] for i in range(len(timesteps))]# Normalize skip_block_list to always be None or a list of lists matching timestepsif skip_block_list is not None:# Convert single list to list of lists if needed5 unmodified linesnew_skip_block_list.append(skip_block_list[guidance_mapping[i]])skip_block_list = new_skip_block_listif enhance_prompt:self.prompt_enhancer_image_caption_model = (self.prompt_enhancer_image_caption_model.to(self._execution_device)23 unmodified linesnegative_prompt_attention_mask,) = self.encode_prompt(prompt,True,negative_prompt=negative_prompt,num_images_per_prompt=num_images_per_prompt,device=device,11 unmodified linesprompt_embeds_batch = prompt_embedsprompt_attention_mask_batch = prompt_attention_masknegative_prompt_embeds = (torch.zeros_like(prompt_embeds)if negative_prompt_embeds is Noneelse negative_prompt_embeds)negative_prompt_attention_mask = (torch.zeros_like(prompt_attention_mask)if negative_prompt_attention_mask is Noneelse negative_prompt_attention_mask)prompt_embeds_batch = torch.cat([negative_prompt_embeds, prompt_embeds, prompt_embeds], dim=0)prompt_attention_mask_batch = torch.cat([negative_prompt_attention_mask,prompt_attention_mask,prompt_attention_mask,],dim=0,)# 4. Prepare the initial latents using the provided media and conditioning items# Prepare the initial latents tensor, shape = (b, c, f, h, w)2 unmodified linesmedia_items=media_items,timestep=timesteps[0],latent_shape=latent_shape,dtype=prompt_embeds.dtype,device=device,generator=generator,vae_per_channel_normalize=vae_per_channel_normalize,13 unmodified lines)init_latents = latents.clone() # Used for image_cond_noise_update# 6. Prepare extra step kwargs. TODO: Logic should ideally just be moved out of the pipelineextra_step_kwargs = self.prepare_extra_step_kwargs(generator, eta)2 unmodified lineslen(timesteps) - num_inference_steps * self.scheduler.order, 0)orig_conditioning_mask = conditioning_mask# Befor compiling this code please be aware:# This code might generate different input shapes if some timesteps have no STG or CFG.# This means that the codes might need to be compiled mutliple times.# To avoid that, use the same STG and CFG values for all timesteps.with self.progress_bar(total=num_inference_steps) as progress_bar:for i, t in enumerate(timesteps):do_classifier_free_guidance = guidance_scale[i] > 1.0do_spatio_temporal_guidance = stg_scale[i] > 0do_rescaling = rescaling_scale[i] != 1.0num_conds = 1if do_classifier_free_guidance:num_conds += 1if do_spatio_temporal_guidance:num_conds += 1if do_classifier_free_guidance and do_spatio_temporal_guidance:indices = slice(batch_size * 0, batch_size * 3)elif do_classifier_free_guidance:indices = slice(batch_size * 0, batch_size * 2)elif do_spatio_temporal_guidance:indices = slice(batch_size * 1, batch_size * 3)else:indices = slice(batch_size * 1, batch_size * 2)# Prepare skip layer masksskip_layer_mask: Optional[torch.Tensor] = Noneif do_spatio_temporal_guidance:if skip_block_list is not None:skip_layer_mask = self.transformer.create_skip_layer_mask(batch_size, num_conds, num_conds - 1, skip_block_list[i])batch_pixel_coords = torch.cat([pixel_coords] * num_conds)conditioning_mask = orig_conditioning_maskif conditioning_mask is not None and is_video:assert num_images_per_prompt == 1conditioning_mask = torch.cat([conditioning_mask] * num_conds)fractional_coords = batch_pixel_coords.to(torch.float32)fractional_coords[:, 0] = fractional_coords[:, 0] * (1.0 / frame_rate)if conditioning_mask is not None and image_cond_noise_scale > 0.0:latents = self.add_noise_to_image_conditioning_latents(t,52 unmodified linesnoise_pred = self.transformer(latent_model_input.to(self.transformer.dtype),indices_grid=fractional_coords,encoder_hidden_states=prompt_embeds_batch[indices].to(self.transformer.dtype),encoder_attention_mask=prompt_attention_mask_batch[indices],timestep=current_timestep,skip_layer_mask=skip_layer_mask,skip_layer_strategy=skip_layer_strategy,return_dict=False,)[0]105 unmodified lines)else:decode_timestep = Nonelatents = self.tone_map_latents(latents, tone_map_compression_ratio)image = vae_decode(latents,self.vae,415 unmodified linesnum_frames = (num_frames - 1) // scale_factor * scale_factor + 1return num_frames@staticmethoddef tone_map_latents(latents: torch.Tensor,compression: float,) -> torch.Tensor:"""Applies a non-linear tone-mapping function to latent values to reduce their dynamic rangein a perceptually smooth way using a sigmoid-based compression.This is useful for regularizing high-variance latents or for conditioning outputsduring generation, especially when controlling dynamic behavior with a `compression` factor.Parameters:----------latents : torch.TensorInput latent tensor with arbitrary shape. Expected to be roughly in [-1, 1] or [0, 1] range.compression : floatCompression strength in the range [0, 1].- 0.0: No tone-mapping (identity transform)- 1.0: Full compression effectReturns:-------torch.TensorThe tone-mapped latent tensor of the same shape as input."""if not (0 <= compression <= 1):raise ValueError("Compression must be in the range [0, 1]")# Remap [0-1] to [0-0.75] and apply sigmoid compression in one shotscale_factor = compression * 0.75abs_latents = torch.abs(latents)# Sigmoid compression: sigmoid shifts large values toward 0.2, small values stay ~1.0# When scale_factor=0, sigmoid term vanishes, when scale_factor=0.75, full effectsigmoid_term = torch.sigmoid(4.0 * scale_factor * (abs_latents - 1.0))scales = 1.0 - 0.8 * scale_factor * sigmoid_termfiltered = latents * scalesreturn filtereddef adain_filter_latent(latents: torch.Tensor, reference_latents: torch.Tensor, factor=1.0
313 unmodified lines314315316317318319320313 unmodified lines"""Predict the sample from the previous timestep by reversing the SDE. This function propagates the diffusionprocess from the learned model outputs (most often the predicted noise).z_{t_1} = z_t - \Delta_t * vThe method finds the next timestep that is lower than the input timestep(s) and denoises the latentsto that level. The input timestep(s) are not required to be one of the predefined timesteps.313 unmodified lines314315316317318319320313 unmodified lines"""Predict the sample from the previous timestep by reversing the SDE. This function propagates the diffusionprocess from the learned model outputs (most often the predicted noise).z_{t_1} = z_t - Delta_t * vThe method finds the next timestep that is lower than the input timestep(s) and denoises the latentsto that level. The input timestep(s) are not required to be one of the predefined timesteps.
app.py+5-5
configs/ltxv-13b-0.9.8-dev-fp8.yamlAdded+34
configs/ltxv-13b-0.9.8-dev.yamlAdded+34
configs/ltxv-13b-0.9.8-distilled-fp8.yamlAdded+29
configs/ltxv-13b-0.9.8-distilled.yamlAdded+29
configs/ltxv-2b-0.9.8-distilled-fp8.yamlAdded+28
configs/ltxv-2b-0.9.8-distilled.yamlAdded+28
ltx_video/models/autoencoders/causal_video_autoencoder.py+2-7
ltx_video/models/transformers/attention.py-1
ltx_video/models/transformers/transformer3d.py+1-1
ltx_video/pipelines/pipeline_ltx_video.py+113-63
ltx_video/schedulers/rf.py+1-1