### Install LTX-Core from Repository Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-core/README.md Installs LTX-Core using uv sync for frozen dependencies, typically run from the repository root. ```bash uv sync --frozen ``` -------------------------------- ### Install Dependencies and Run Training Script Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/troubleshooting.md Ensure all dependencies are synchronized and use `uv run` to execute the training script from the repository root. ```bash # From the repository root uv sync cd packages/ltx-trainer uv run python scripts/train.py configs/ltx2_av_lora.yaml ``` -------------------------------- ### Clone Repository and Set Up Environment Source: https://github.com/lightricks/ltx-2/blob/main/README.md Clone the LTX-2 repository and set up the Python environment using uv. Ensure you have uv installed and then synchronize dependencies and activate the virtual environment. ```bash git clone https://github.com/Lightricks/LTX-2.git cd LTX-2 # Set up the environment uv sync --frozen source .venv/bin/activate ``` -------------------------------- ### Install LTX-2 Dependencies Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/quick-start.md Install the necessary dependencies for the LTX-2 trainer from the repository root. Navigate to the trainer package directory afterwards. ```bash # From the repository root uv sync cd packages/ltx-trainer ``` -------------------------------- ### Install LTX-Core as a Package Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-core/README.md Installs LTX-Core as an editable package using pip. ```bash pip install -e packages/ltx-core ``` -------------------------------- ### Running Training Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/CLAUDE.md Commands for initiating training, supporting both single-GPU and multi-GPU setups using Accelerate. ```bash # Single GPU uv run python scripts/train.py configs/ltx2_av_lora.yaml ``` ```bash # Multi-GPU with Accelerate uv run accelerate launch scripts/train.py configs/ltx2_av_lora.yaml ``` -------------------------------- ### Run Training (Single GPU) Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/AGENTS.md Starts the training process on a single GPU using a specified configuration file. ```bash # Single GPU uv run python scripts/train.py configs/ltx2_av_lora.yaml ``` -------------------------------- ### Start Multi-GPU LTX-2 Training Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/quick-start.md Launch LTX-2 training across multiple GPUs using the `accelerate` library. This command requires the `accelerate` package to be installed. ```bash uv run accelerate launch scripts/train.py configs/ltx2_av_lora.yaml ``` -------------------------------- ### Get Help for Scene Splitting Script Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/dataset-preparation.md View all available configuration options for scene detection, including detector algorithms, thresholds, and minimum scene lengths. ```bash uv run python scripts/split_scenes.py --help ``` -------------------------------- ### Start LTX-2 Training Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/quick-start.md Initiate the LTX-2 training process using a specified configuration YAML file. Ensure the configuration file is correctly set up with model paths, data paths, and output directories. ```bash uv run python scripts/train.py configs/ltx2_av_lora.yaml ``` -------------------------------- ### Install LTX-2 Pipelines Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-pipelines/README.md Install the LTX-2 Pipelines package from the repository root or as a standalone package using pip. ```bash uv sync --frozen ``` ```bash pip install -e packages/ltx-pipelines ``` -------------------------------- ### Clone LTX-2 Repository Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/quick-start.md Clone the LTX-2 repository to your local machine. This is the first step to installing the trainer. ```bash git clone https://github.com/Lightricks/LTX-2 ``` -------------------------------- ### CSV Dataset Format Example Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/dataset-preparation.md Example of a dataset formatted as a CSV file, with columns for caption and media path. ```csv caption,media_path "A cat playing with a ball of yarn","videos/cat_playing.mp4" "A dog running in the park","videos/dog_running.mp4" ``` -------------------------------- ### Dataset JSON Format with Reference Videos Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/dataset-preparation.md Example structure for a dataset using JSON format, including paths for both the main media and reference videos. ```json [ { "caption": "A cat playing with a ball of yarn", "media_path": "videos/cat_playing.mp4", "reference_path": "references/cat_playing_depth.mp4" } ] ``` -------------------------------- ### JSON Dataset Format Example Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/dataset-preparation.md Example of a dataset formatted as a JSON array of objects, each containing a caption and media path. ```json [ { "caption": "A cat playing with a ball of yarn", "media_path": "videos/cat_playing.mp4" }, { "caption": "A dog running in the park", "media_path": "videos/dog_running.mp4" } ] ``` -------------------------------- ### Example Sequence Length Calculation Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/dataset-preparation.md An example calculation of the sequence length for a 768x448x89 video, illustrating the application of the sequence length formula. ```plaintext (768/32) * (448/32) * ((89-1)/8 + 1) = 24 * 14 * 12 = 4,032 ``` -------------------------------- ### JSONL Dataset Format Example Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/dataset-preparation.md Example of a dataset formatted as JSON Lines (JSONL), where each line is a JSON object with caption and media path. ```jsonl {"caption": "A cat playing with a ball of yarn", "media_path": "videos/cat_playing.mp4"} {"caption": "A dog running in the park", "media_path": "videos/dog_running.mp4"} ``` -------------------------------- ### Dataset JSONL Format with Reference Videos Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/dataset-preparation.md Example structure for a dataset using JSONL format, with each line representing a record containing media and reference video paths. ```jsonl {"caption": "A cat playing with a ball of yarn", "media_path": "videos/cat_playing.mp4", "reference_path": "references/cat_playing_depth.mp4"} {"caption": "A dog running in the park", "media_path": "videos/dog_running.mp4", "reference_path": "references/dog_running_depth.mp4"} ``` -------------------------------- ### Example Inpainting Configuration File Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/custom-training-strategies.md This YAML file demonstrates the configuration structure for an inpainting LoRA training run. It specifies model paths, training mode, inpainting-specific parameters, LoRA settings, data paths, and optimization parameters. ```yaml # configs/ltx2_inpainting_lora.yaml model: model_path: "/path/to/ltx2.safetensors" text_encoder_path: "/path/to/gemma" training_mode: "lora" training_strategy: name: "inpainting" # Must match your Literal type mask_latents_dir: "mask_latents" mask_threshold: 0.5 lora: rank: 32 alpha: 32 target_modules: - "to_k" - "to_q" - "to_v" - "to_out.0" data: preprocessed_data_root: "/path/to/preprocessed/dataset" optimization: learning_rate: 1e-4 steps: 2000 batch_size: 1 # ... other config sections ... ``` -------------------------------- ### Video VAE Decoding Example Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-core/README.md Illustrates the input and output dimensions for the Video VAE decoder, showing the expansion of latent representations back to video pixels. Note the frame count relationship. ```text [B, 128, 5, 16, 16] → [B, 3, 33, 512, 512] ``` -------------------------------- ### Increase Training Steps Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/troubleshooting.md Set the total number of training steps. A value of 3000 is shown as an example. ```yaml optimization: steps: 3000 ``` -------------------------------- ### Video VAE Encoding Example Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-core/README.md Illustrates the input and output dimensions for the Video VAE encoder, showing the compression of video pixels to latent representations. Note the frame count constraint for input. ```text [B, 3, 33, 512, 512] → [B, 128, 5, 16, 16] ``` -------------------------------- ### Launch Training with torch.compile Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/troubleshooting.md Use `accelerate launch` with a DDP compile configuration file to enable `torch.compile` for potentially faster training. ```bash uv run accelerate launch --config_file configs/accelerate/ddp_compile.yaml \ scripts/train.py configs/ltx2_av_lora.yaml ``` -------------------------------- ### Configure Video and Audio Guiders Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-pipelines/README.md Set up parameters for video and audio guiders to control text guidance, structural coherence, and modality synchronization. Adjust scales based on desired prompt adherence and audio-visual sync. ```python from ltx_core.components.guiders import MultiModalGuiderParams # Video guider: moderate CFG, STG enabled, modality isolation video_guider_params = MultiModalGuiderParams( cfg_scale=3.0, stg_scale=1.0, rescale_scale=0.7, modality_scale=3.0, stg_blocks=[29], ) # Audio guider: higher CFG for stronger prompt adherence audio_guider_params = MultiModalGuiderParams( cfg_scale=7.0, stg_scale=1.0, rescale_scale=0.7, modality_scale=3.0, stg_blocks=[29], ) ``` -------------------------------- ### Image-to-Video Generation with TI2VidTwoStagesPipeline Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-pipelines/README.md Demonstrates initializing the TI2VidTwoStagesPipeline and generating a video from an input image. Requires specifying checkpoint paths, LoRA configurations, guider parameters, and generation settings. ```python from ltx_core.loader import LTXV_LORA_COMFY_RENAMING_MAP, LoraPathStrengthAndSDOps from ltx_pipelines.ti2vid_two_stages import TI2VidTwoStagesPipeline from ltx_core.components.guiders import MultiModalGuiderParams distilled_lora = [ LoraPathStrengthAndSDOps( "/path/to/distilled_lora.safetensors", 0.6, LTXV_LORA_COMFY_RENAMING_MAP ), ] pipeline = TI2VidTwoStagesPipeline( checkpoint_path="/path/to/checkpoint.safetensors", distilled_lora=distilled_lora, spatial_upsampler_path="/path/to/upsampler.safetensors", gemma_root="/path/to/gemma", loras=[], ) video_guider_params = MultiModalGuiderParams( cfg_scale=3.0, stg_scale=1.0, rescale_scale=0.7, modality_scale=3.0, skip_step=0, stg_blocks=[29], ) audio_guider_params = MultiModalGuiderParams( cfg_scale=7.0, stg_scale=1.0, rescale_scale=0.7, modality_scale=3.0, skip_step=0, stg_blocks=[29], ) # Generate video from image pipeline( prompt="A serene landscape with mountains in the background", output_path="output.mp4", seed=42, height=512, width=768, num_frames=121, frame_rate=25.0, num_inference_steps=40, video_guider_params=video_guider_params, audio_guider_params=audio_guider_params, images=[ImageConditioningInput("input_image.jpg", 0, 1.0, 33)], # Image at frame 0, strength 1.0, CRF 33 ) ``` -------------------------------- ### View Pipeline Help Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-pipelines/README.md Display all available command-line options and parameters for a specific pipeline module by using the --help flag. ```bash python -m ltx_pipelines.ti2vid_two_stages --help ``` -------------------------------- ### Run Training (Multi-GPU with Accelerate) Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/AGENTS.md Launches distributed training across multiple GPUs using the Accelerate library. ```bash # Multi-GPU with Accelerate uv run accelerate launch scripts/train.py configs/ltx2_av_lora.yaml ``` -------------------------------- ### Configure Hugging Face Accelerate Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/training-guide.md Run the interactive Accelerate wizard to set up your multi-GPU training environment, including DDP and FSDP configurations. This creates a default configuration file. ```bash uv run accelerate config ``` -------------------------------- ### Launch Distributed Training with Accelerate Configs Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/training-guide.md Launch training jobs using pre-defined Accelerate configuration files for DDP and FSDP, with or without torch.compile. Specify the Accelerate config file using `--config_file`. ```bash CUDA_VISIBLE_DEVICES=0,1 \ uv run accelerate launch --config_file configs/accelerate/ddp.yaml \ scripts/train.py configs/ltx2_av_lora.yaml ``` ```bash CUDA_VISIBLE_DEVICES=0,1 \ uv run accelerate launch --config_file configs/accelerate/ddp_compile.yaml \ scripts/train.py configs/ltx2_av_lora.yaml ``` ```bash CUDA_VISIBLE_DEVICES=0,1,2,3 \ uv run accelerate launch --config_file configs/accelerate/fsdp.yaml \ scripts/train.py configs/ltx2_av_lora.yaml ``` ```bash CUDA_VISIBLE_DEVICES=0,1,2,3 \ uv run accelerate launch --config_file configs/accelerate/fsdp_compile.yaml \ scripts/train.py configs/ltx2_av_lora.yaml ``` -------------------------------- ### Launch Training with Default Accelerate Config Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/training-guide.md Launch training jobs using your default Accelerate configuration. You can override the number of processes or select specific GPUs using command-line arguments. ```bash uv run accelerate launch scripts/train.py configs/ltx2_av_lora.yaml ``` ```bash uv run accelerate launch --num_processes 2 scripts/train.py configs/ltx2_av_lora.yaml ``` ```bash CUDA_VISIBLE_DEVICES=0,1 uv run accelerate launch scripts/train.py configs/ltx2_av_lora.yaml ``` -------------------------------- ### Run Two-Stage Text-to-Video Pipeline Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-pipelines/README.md Execute the two-stage text-to-video pipeline from the command line, specifying model paths, prompts, and output file. ```bash python -m ltx_pipelines.ti2vid_two_stages \ --checkpoint-path path/to/checkpoint.safetensors \ --distilled-lora path/to/distilled_lora.safetensors 0.8 \ --spatial-upsampler-path path/to/upsampler.safetensors \ --gemma-root path/to/gemma \ --prompt "A beautiful sunset over the ocean" \ --output-path output.mp4 ``` -------------------------------- ### Run Short Training Test Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/custom-training-strategies.md Execute a brief training run using a specified configuration file to quickly test the training pipeline's functionality. ```bash uv run python scripts/train.py configs/ltx2_inpainting_lora.yaml ``` -------------------------------- ### FP8 Scaled MM Calibration File Format Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-core/README.md Example JSON format for the calibration file used in static input quantization for FP8 Scaled MM. It specifies per-tensor scaling factors for quantization. ```json { "amax_values": { "transformer_blocks.0.attn.to_q.input_quantizer": 12.5, "transformer_blocks.0.attn.to_k.input_quantizer": 8.3, ... } } ``` -------------------------------- ### Preprocess Dataset with Reference Videos Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/dataset-preparation.md Command to preprocess a dataset that includes reference videos, using the `--reference-column` argument to specify the field containing reference paths. ```bash uv run python scripts/process_dataset.py dataset.json \ --resolution-buckets "960x544x49" \ --model-path /path/to/ltx-2-model.safetensors \ --text-encoder-path /path/to/gemma-model \ --reference-column "reference_path" ``` -------------------------------- ### Image-to-Video Inference with Conditioning Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/utility-scripts.md Generate video from a prompt, using a conditioning image for the first frame. Ensure the conditioning image is specified. ```bash uv run python scripts/inference.py --checkpoint /path/to/model.safetensors --text-encoder-path /path/to/gemma --prompt "A cat walking" --condition-image first_frame.png --output output.mp4 ``` -------------------------------- ### Text-to-Video Training Strategy Configuration Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/configuration-reference.md Configures the 'text_to_video' training strategy. Set 'with_audio' to true for joint audio-video training and specify the directory for audio latents. ```yaml training_strategy: name: "text_to_video" first_frame_conditioning_p: 0.1 with_audio: false audio_latents_dir: "audio_latents" ``` -------------------------------- ### Enable Gradient Checkpointing Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/troubleshooting.md Use this configuration to trade training speed for memory savings. Highly recommended for most training runs. ```yaml optimization: enable_gradient_checkpointing: true ``` -------------------------------- ### Multi-GPU Dataset Preprocessing Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/utility-scripts.md Launch dataset preprocessing across multiple GPUs using `accelerate launch`. Use `--overwrite` to force re-encoding if parameters have changed. ```bash # Multi-GPU preprocessing uv run accelerate launch --num_processes 4 scripts/process_dataset.py dataset.json \ --resolution-buckets "960x544x49" \ --model-path /path/to/ltx-2-model.safetensors \ --text-encoder-path /path/to/gemma-model # Force re-encoding of all items (e.g. after switching model or resolution) uv run accelerate launch --num_processes 4 scripts/process_dataset.py dataset.json \ --resolution-buckets "960x544x49" \ --model-path /path/to/ltx-2.3-model.safetensors \ --text-encoder-path /path/to/gemma-model \ --overwrite ``` -------------------------------- ### Acceleration Configuration Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/configuration-reference.md Set up hardware acceleration and compute optimization. 'bf16' mixed precision is recommended for modern GPUs. Enable 8-bit text encoder loading to reduce memory usage. ```yaml acceleration: mixed_precision_mode: "bf16" # "no", "fp16", or "bf16" quantization: null # Quantization options load_text_encoder_in_8bit: false # Load text encoder in 8-bit offload_optimizer_during_validation: false # Offload optimizer state to CPU during validation ``` -------------------------------- ### Multi-GPU Training with Specific Process Count Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/utility-scripts.md Execute distributed training with `accelerate launch`, explicitly setting the number of processes using `--num_processes`. ```bash uv run accelerate launch --num_processes 4 scripts/train.py configs/ltx2_av_lora.yaml ``` -------------------------------- ### Dataset Preprocessing with Audio Processing Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/dataset-preparation.md Enable audio-video training by including the `--with-audio` flag during dataset preprocessing. This computes and caches audio latents. ```bash uv run python scripts/process_dataset.py dataset.json \ --resolution-buckets "960x544x49" \ --model-path /path/to/ltx-2-model.safetensors \ --text-encoder-path /path/to/gemma-model \ --with-audio ``` -------------------------------- ### Running Tests Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/CLAUDE.md Navigate to the ltx-trainer package directory and run pytest to execute the test suite. ```bash cd packages/ltx-trainer uv run pytest ``` -------------------------------- ### Configure Standard LoRA Training (Video-Only) Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/training-modes.md Use this configuration for standard LoRA training when only video output is required. It requires significantly less memory and compute than full fine-tuning. ```yaml model: training_mode: "lora" training_strategy: name: "text_to_video" first_frame_conditioning_p: 0.1 with_audio: false # Video-only training ``` -------------------------------- ### Process Dataset with Scaled Reference Videos Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/training-modes.md Use this command to process target and reference videos at specified resolutions. Ensure the reference downscale factor matches the validation configuration. ```bash uv run python scripts/process_dataset.py dataset.json \ --resolution-buckets 768x768x25 \ --model-path /path/to/ltx2.safetensors \ --text-encoder-path /path/to/gemma \ --reference-column "reference_path" \ --reference-downscale-factor 2 ``` -------------------------------- ### Multi-GPU Dataset Preprocessing Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/dataset-preparation.md Run dataset preprocessing across multiple GPUs in parallel using 'accelerate launch'. Each process handles a slice of the dataset. Rerunning resumes automatically, skipping existing outputs. ```bash uv run accelerate launch --num_processes 4 scripts/process_dataset.py dataset.json \ --resolution-buckets "960x544x49" \ --model-path /path/to/ltx-2-model.safetensors \ --text-encoder-path /path/to/gemma-model ``` -------------------------------- ### Preprocess Dataset for Training Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/utility-scripts.md Processes videos and caches latents for training. Specify resolution buckets, model paths, and optionally enable audio processing. ```bash uv run python scripts/process_dataset.py dataset.json --resolution-buckets "960x544x49" --model-path /path/to/ltx-2-model.safetensors --text-encoder-path /path/to/gemma-model ``` ```bash uv run python scripts/process_dataset.py dataset.json --resolution-buckets "960x544x49" --model-path /path/to/ltx-2-model.safetensors --text-encoder-path /path/to/gemma-model --with-audio ``` -------------------------------- ### Basic Dataset Preprocessing Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/dataset-preparation.md Preprocess your dataset by resizing videos, computing latents, and generating text embeddings. Ensure you provide paths to the model and text encoder. ```bash uv run python scripts/process_dataset.py dataset.json \ --resolution-buckets "960x544x49" \ --model-path /path/to/ltx-2-model.safetensors \ --text-encoder-path /path/to/gemma-model ``` -------------------------------- ### Enable Model Quantization Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/troubleshooting.md Use quantization options like 'int8-quanto', 'int4-quanto', or 'fp8-quanto' to reduce memory usage. ```yaml acceleration: quantization: "int8-quanto" # Options: int8-quanto, int4-quanto, fp8-quanto ``` -------------------------------- ### Test Strategy Instantiation Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/custom-training-strategies.md Test if a training strategy can be successfully instantiated with its configuration. This checks if the strategy class and its associated configuration are correctly set up. ```bash uv run python -c " from ltx_trainer.training_strategies import get_training_strategy from ltx_trainer.training_strategies.inpainting import InpaintingConfig config = InpaintingConfig() strategy = get_training_strategy(config) print(f'Data sources: {strategy.get_data_sources()}') " ``` -------------------------------- ### Process Dataset with Multiple Resolution Buckets Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/utility-scripts.md Process the dataset using multiple resolution buckets, separated by semicolons. This allows for training with varied video resolutions. ```bash uv run python scripts/process_dataset.py dataset.json \ --resolution-buckets "960x544x49;512x512x81" \ --model-path /path/to/ltx-2-model.safetensors \ --text-encoder-path /path/to/gemma-model ``` -------------------------------- ### Validate Training Configuration Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/custom-training-strategies.md Verify that your training configuration file is valid by loading it with LtxTrainerConfig. Ensure the configuration is correctly parsed and accessible. ```bash uv run python -c " from ltx_trainer.config import LtxTrainerConfig import yaml with open('configs/ltx2_inpainting_lora.yaml') as f: config = LtxTrainerConfig(**yaml.safe_load(f)) print(f'Strategy: {config.training_strategy.name}') " ``` -------------------------------- ### Inference with Custom Guidance Settings Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/utility-scripts.md Customize inference by adjusting guidance scales and STG parameters. Use `--guidance-scale`, `--stg-scale`, and `--stg-blocks` to fine-tune the generation process. ```bash uv run python scripts/inference.py --checkpoint /path/to/model.safetensors --text-encoder-path /path/to/gemma --prompt "A cat playing with a ball" --guidance-scale 4.0 --stg-scale 1.0 --stg-blocks 29 --output output.mp4 ``` -------------------------------- ### Text-to-Video Inference Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/utility-scripts.md Run text-to-video inference using a trained model checkpoint. By default, it includes audio generation and uses specific CFG and STG scales. ```bash # Text-to-video inference (with audio by default) # By default, uses CFG scale 4.0 and STG scale 1.0 with block 29 uv run python scripts/inference.py \ --checkpoint /path/to/model.safetensors \ --text-encoder-path /path/to/gemma \ --prompt "A cat playing with a ball" \ --output output.mp4 ``` -------------------------------- ### Enable Weights & Biases Logging Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/training-guide.md Add this configuration to enable experiment tracking with Weights & Biases. Set your W&B username or team to 'entity'. ```yaml wandb: enabled: true project: "ltx-2-trainer" entity: null # Your W&B username or team tags: [ "ltx2", "lora" ] log_validation_videos: true ``` -------------------------------- ### Register Inpainting Strategy in __init__.py Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/custom-training-strategies.md Update the `__init__.py` file to import and register the new Inpainting strategy and its configuration. This involves adding imports, updating type aliases, and including a case in the `get_training_strategy` function. ```python # Add import for your strategy from ltx_trainer.training_strategies.inpainting import InpaintingConfig, InpaintingStrategy # Add to the TrainingStrategyConfig type alias TrainingStrategyConfig = TextToVideoConfig | VideoToVideoConfig | InpaintingConfig # Add to __all__ __all__ = [ # ... existing exports ... "InpaintingConfig", "InpaintingStrategy", ] # Add case in get_training_strategy() def get_training_strategy(config: TrainingStrategyConfig) -> TrainingStrategy: match config: # ... existing cases ... case InpaintingConfig(): strategy = InpaintingStrategy(config) ``` -------------------------------- ### Run Ruff Linting and Formatting Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/AGENTS.md Checks code for linting issues and formats code using Ruff. Run from the repository root. ```bash # Run ruff linting and formatting uv run ruff check . uv run ruff format . ``` -------------------------------- ### Configure Full Model Fine-tuning Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/training-modes.md Use this configuration for full model fine-tuning to update all base model parameters. This offers maximum flexibility but requires substantial computational resources and multiple GPUs. ```yaml model: training_mode: "full" training_strategy: name: "text_to_video" first_frame_conditioning_p: 0.1 ``` -------------------------------- ### WandbConfig Logging Settings Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/configuration-reference.md Configure Weights & Biases logging for your training runs. Set enabled, project, entity, tags, and whether to log validation videos. ```yaml wandb: enabled: false # Enable W&B logging project: "ltx-2-trainer" # W&B project name entity: null # W&B username or team tags: [ ] # Tags for the run log_validation_videos: true # Log validation videos to W&B ``` -------------------------------- ### TrainingStrategy Helper Methods Source: https://github.com/lightricks/ltx-2/blob/main/packages/ltx-trainer/docs/custom-training-strategies.md Reference for helper methods available in the base `TrainingStrategy` class, used for tasks like patching latents, generating position embeddings, and creating conditioning masks. ```markdown The base `TrainingStrategy` class provides these helper methods: | Method | Purpose | |----------------------------------------------|-------------------------------------------------| | `_video_patchifier.patchify(latents)` | Convert `[B, C, F, H, W]` → `[B, seq_len, C]` | | `_audio_patchifier.patchify(latents)` | Convert `[B, C, T, F]` → `[B, T, C*F]` | | `_get_video_positions(...)` | Generate position embeddings for video | | `_get_audio_positions(...)` | Generate position embeddings for audio | | `_create_per_token_timesteps(mask, sigma)` | Create timesteps with 0 for conditioning tokens | | `_create_first_frame_conditioning_mask(...)` | Create mask for first-frame conditioning | ```