### Full Training Configuration Example Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/configuration.md An example of a complete configuration for full training, including runners, project directory, launch settings, dataloaders, models, optimizers, schedulers, and training parameters. ```python config = dict( runners=['giga_world_0.GigaWorld0Trainer'], project_dir='./experiments/giga_world_0_video/full_training', launch=dict( gpu_ids=[0, 1, 2, 3, 4, 5, 6, 7], distributed_type='DEEPSPEED', deepspeed_config=dict( deepspeed_config_file='accelerate_configs/zero2.json', ), ), dataloaders=dict( train=dict( data_or_config=['/path/to/packed_data/'], batch_size_per_gpu=1, num_workers=6, transform=dict( type='GigaWorld0Transform', num_frames=61, height=480, width=640, fps=16, image_cfg=dict( mask_generator=dict( max_ref_frames=1, start=1, factor=4, ), ), ), ), ), models=dict( vae_model_path='/path/to/giga_world_0_video/vae', transformer_model_path='/path/to/giga_world_0_video/transformer', ), optimizers=dict( type='CAME8Bit', lr=2 ** (-14.5), ), schedulers=dict( type='ConstantScheduler', ), train=dict( resume=True, max_epochs=50, gradient_accumulation_steps=1, mixed_precision='bf16', checkpoint_interval=500, checkpoint_total_limit=5, checkpoint_strict=False, log_with='tensorboard', log_interval=10, with_ema=True, activation_checkpointing=True, activation_class_names=['TransformerBlock'], ), ) ``` -------------------------------- ### Prompt File Format Example Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/data-preparation.md Prompt files should be plain text, containing a single prompt describing the video. Aim for 20-100 tokens. ```text A robot arm reaching for a cube on a wooden table in a laboratory setting. The camera is positioned at a slight angle showing the gripper opening and closing. ``` -------------------------------- ### PyTorch Device String Examples Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/types.md Shows standard PyTorch string formats for specifying compute devices. Includes examples for multiple GPUs and the CPU. ```python device = 'cuda:0' # First GPU device = 'cuda:1' # Second GPU device = 'cpu' # CPU (slow for video models) ``` -------------------------------- ### Install GigaWorld-0 Dependencies Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/README.md Installs the necessary Python packages and clones the GigaModels repository for local setup. ```bash pip install giga-train giga-datasets giga-models natten git clone https://github.com/open-gigaai/giga-models.git cd giga-models && pip install -e . ``` -------------------------------- ### Development Configuration Example Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/INDEX.md A minimal Python configuration dictionary for development on a single GPU. Sets up basic training parameters and dataloader settings. ```python config = dict( launch=dict(gpu_ids=[0]), train=dict(max_epochs=1, mixed_precision='no'), dataloaders=dict(train=dict(batch_size_per_gpu=1, num_workers=0)), ) ``` -------------------------------- ### Data Preparation Workflow Example Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/COMPLETION_SUMMARY.txt Demonstrates the data preparation pipeline using pack_data() and download(). Covers raw data organization, dataset structure, and downloading pre-trained models. ```python from gigaworld0.data import pack_data, download # Pack raw data into the required dataset structure pack_data(raw_data_path='path/to/raw', output_path='path/to/dataset') # Download pre-trained models download(model_name='pretrained_model', save_path='path/to/models') ``` -------------------------------- ### Install GigaWorld-0 Dependencies Source: https://github.com/open-gigaai/giga-world-0/blob/main/README.md Installs the necessary GigaTrain, GigaDatasets, and GigaModels frameworks, along with natten. It's recommended to use a fresh conda environment. ```bash conda create -n giga_world_0 python=3.11.10 -y conda activate giga_world_0 pip3 install giga-train pip3 install giga-datasets pip3 install natten git clone https://github.com/open-gigaai/giga-models.git cd giga-models pip3 install -e . git clone git@github.com:open-gigaai/giga-world-0.git ``` -------------------------------- ### Metadata Format Example Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/data-preparation.md Each label file in the dataset contains the data index and the original text prompt. ```python { 'data_index': int, # Index in dataset (0-based) 'prompt': str, # Original text prompt } ``` -------------------------------- ### GigaWorld0Trainer Methods Example Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/COMPLETION_SUMMARY.txt Demonstrates the usage of get_models(), forward_step(), and forward_vae() methods of the GigaWorld0Trainer class. Useful for understanding the training process and model interactions. ```python from gigaworld0.trainer import GigaWorld0Trainer # Assuming trainer is an initialized GigaWorld0Trainer instance trainer = GigaWorld0Trainer(...) # Get models models = trainer.get_models() # Perform a forward step (e.g., during training) loss = trainer.forward_step(...) # Perform a VAE forward pass (e.g., for encoding/decoding) reconstruction = trainer.forward_vae(...) ``` -------------------------------- ### Complete Training Data Preparation Workflow Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/data-preparation.md A step-by-step command-line workflow for preparing training data. This includes organizing raw data, downloading models, packing data using `pack_data.py`, updating the configuration, and starting training. ```bash # 1. Organize raw data (done manually) # mkdir -p raw_data # Add videos and prompts to raw_data/ # 2. Download models once python scripts/download.py \ --model-name video_pretrain \ --save-dir /path/to/models/ # 3. Pack data (encode prompts, organize videos) python scripts/pack_data.py \ --video-dir /path/to/raw_data/ \ --save-dir /path/to/packed_data/ \ --text-encoder-model-path /path/to/models/text_encoder/ # 4. Update config with paths # Edit configs/giga_world_0_video.py: # dataloaders.train.data_or_config = ['/path/to/packed_data/'] # models.vae_model_path = '/path/to/models/vae/' # models.transformer_model_path = '/path/to/models/transformer/' # 5. Start training python scripts/train.py --config configs.giga_world_0_video.config ``` -------------------------------- ### Train Script Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/module-structure.md The train script serves as the entry point for launching the training process. It utilizes a configuration object to set up and start training. ```python scripts/train.py ``` -------------------------------- ### JSON Data Format Example Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/inference-api.md Illustrates the expected JSON format for input data, where each entry contains a text prompt and the path to a reference image. ```json [ { "prompt": "A robotic arm reaching for a cube on a table", "image": "input_images/frame_001.png" }, { "prompt": "A robot hand grasping an object", "image": "input_images/frame_002.png" } ] ``` -------------------------------- ### Single GPU Inference Example Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/inference-api.md Demonstrates how to use the `inference` function for single-GPU video generation. Ensure all specified model paths are valid and accessible. ```python from scripts.inference import inference inference( data_path='test_data.json', save_dir='./results/', transformer_model_path='/path/to/transformer/', text_encoder_model_path='/path/to/text_encoder/', vae_model_path='/path/to/vae/', gpu_ids=[0], num_inference_steps=30, num_frames=61, height=480, width=640, ) ``` -------------------------------- ### Negative Prompt Example Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/inference-api.md Provides an example of a fixed negative prompt used during inference to emphasize quality rejection and avoid undesirable visual artifacts. ```text "The video captures a series of frames showing ugly scenes, static with no motion, motion blur, over-saturation, shaky footage, low resolution, grainy texture, pixelated images, poorly lit areas, ..." ``` -------------------------------- ### Inference API Usage Example Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/COMPLETION_SUMMARY.txt Shows how to use the main inference() entry point for single-GPU and multi-GPU scenarios. Supports LoRA and sequence parallelism, with input/output in JSON or MP4 formats. ```python from gigaworld0.inference import inference # Example for single-GPU inference output = inference(input_data, device='cuda:0', use_lora=True) # Example for multi-GPU inference (requires setup for distributed workers) # output = inference(input_data, device='cuda', distributed=True) ``` -------------------------------- ### Multi-GPU Inference Example Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/inference-api.md Shows how to configure the `inference` function to utilize multiple GPUs for video generation. Adjust `gpu_ids` to match your available hardware. Max 8 GPUs recommended. ```python inference( data_path='test_data.json', save_dir='./results/', transformer_model_path='/path/to/transformer/', gpu_ids=[0, 1, 2, 3], # Use 4 GPUs num_inference_steps=30, ) ``` -------------------------------- ### GigaWorld0Transform and MaskGenerator Example Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/COMPLETION_SUMMARY.txt Illustrates the use of the GigaWorld0Transform class for data preprocessing and the MaskGenerator utility for creating masks. Essential for preparing data for model training. ```python from gigaworld0.transform import GigaWorld0Transform, MaskGenerator # Initialize transform and mask generator transformer = GigaWorld0Transform(...) mask_generator = MaskGenerator(...) # Preprocess data using the transformer processed_data = transformer.preprocess(...) # Generate a mask mask = mask_generator.generate_mask(...) ``` -------------------------------- ### Training Workflow: Pack Data, Download Models, and Train Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/README.md This snippet outlines the steps for preparing data, downloading pre-trained models, and initiating the training process using the GigaWorld-0 framework. Ensure data is organized and configuration files are updated before execution. ```bash # Step 1: Organize raw data raw_data/ ├── video_0.mp4 and video_0.txt ├── video_1.mp4 and video_1.txt ... # Step 2: Pack data python scripts/pack_data.py \ --video-dir raw_data/ \ --save-dir packed_data/ \ --device cuda # Step 3: Download models python scripts/download.py \ --model-name video_pretrain \ --save-dir models/ # Step 4: Update config and train # Edit configs/giga_world_0_video.py with paths python scripts/train.py --config configs.giga_world_0_video.config ``` -------------------------------- ### Load and Launch Training Configuration Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/module-structure.md Loads or constructs a configuration object and then launches the training process using the provided configuration. ```python from giga_world_0 import GigaWorld0Trainer from giga_train import launch_from_config # Load and launch training config = ... # Load or construct config launch_from_config(config) ``` -------------------------------- ### Initialize and Configure Model Components Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/gigaworld0-trainer.md Initializes VAE and transformer models, sets up LoRA if applicable, and configures the loss function. Use this method to prepare all necessary model components before training. ```python def get_models(self, model_config) -> ModuleDict: """Initialize and configure model components.""" ``` ```python from giga_world_0 import GigaWorld0Trainer import addict # Create trainer instance (inherited from Trainer) trainer = GigaWorld0Trainer(...) # Configure model paths model_config = addict.Dict({ 'vae_model_path': '/path/to/giga_world_0/vae', 'transformer_model_path': '/path/to/giga_world_0_video/transformer', 'train_mode': 'full', # or 'lora' 'lora_rank': 64, # required if train_mode='lora' 'fp8_ignore_modules': [] }) # Initialize models models = trainer.get_models(model_config) # Returns ModuleDict with initialized transformer and VAE configurations ``` -------------------------------- ### Run Training from Correct Directory Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/troubleshooting-and-faq.md Execute training scripts from the repository's root directory to ensure correct module imports for configurations. ```bash cd /path/to/giga-world-0/ python scripts/train.py --config configs.giga_world_0_video.config ``` -------------------------------- ### Inference Workflow: Prepare Data and Generate Videos Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/README.md This snippet demonstrates how to prepare test data in JSON format and then use the inference script to generate videos. Specify the data path, output directory, and model paths for the generation process. ```bash # Step 1: Prepare test data (JSON format) [ {"prompt": "A robot arm reaching", "image": "path/to/image.png"}, ... ] # Step 2: Generate videos python scripts/inference.py \ --data-path test_data.json \ --save-dir results/ \ --transformer-model-path models/transformer/ \ --gpu-ids 0 1 2 3 # Output: Videos saved to results/ ``` -------------------------------- ### Reduce Batch Size for CUDA OOM Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/troubleshooting-and-faq.md When encountering CUDA out of memory errors, reduce the batch size per GPU. Start with a value of 1. ```python config['dataloaders']['train']['batch_size_per_gpu'] = 1 # Start with 1 ``` -------------------------------- ### Dataloader Configuration with Sampler Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/configuration.md Sets up data loading, including the path to datasets, batch size, number of workers, transformations, and sampler settings. The sampler can be configured for shuffling. ```python dataloaders=dict( train=dict( data_or_config=['/path/to/packed_data/'], batch_size_per_gpu=1, num_workers=6, transform=dict(...), sampler=dict( type='DefaultSampler', shuffle=True, ), ), ) ``` -------------------------------- ### Verify Model Download Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/troubleshooting-and-faq.md After downloading, check the model directory to confirm that the expected model components are present. ```bash ls -la /path/to/models/ # Should see: GigaWorld-0-Video-Pretrain-2b, text_encoder, vae ``` -------------------------------- ### Prepare and Pack Video Data Source: https://github.com/open-gigaai/giga-world-0/blob/main/README.md Organizes raw video data and corresponding text prompts, then packs the data and extracts prompt embeddings for training. ```bash python scripts/pack_data.py \ --video-dir /path/to/raw_data/ \ --save-dir /path/to/packed_data/ ``` -------------------------------- ### Prepare Training Data Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/README.md Prepares raw video data into a packed format suitable for training. Ensure the 'raw_videos/' directory exists and contains your video files. ```python from scripts.pack_data import pack_data pack_data( video_dir='raw_videos/', save_dir='packed_data/', device='cuda' ) ``` -------------------------------- ### PyTorch Dtype Management in Training Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/types.md Demonstrates how to manage dtypes for the main compute, VAE, and mixed precision modes within a PyTorch training setup. Supports float32, bfloat16, and fp16. ```python # Trainer dtype (main compute dtype) self.dtype = torch.float32 or torch.bfloat16 # VAE dtype (typically lower precision) vae_dtype = model_config.get('vae_dtype', self.dtype) # Mixed precision mode self.mixed_precision = 'bf16' # From training config ``` -------------------------------- ### Initialize MaskGenerator Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/gigaworld0-transform.md Initializes the MaskGenerator class. Use `max_ref_frames=1` for a single reference frame or `max_ref_frames=9` for multiple reference frames. The `factor` parameter accounts for VAE compression, and `start` ensures at least one reference frame. ```python from giga_world_0.giga_world_0_transforms import MaskGenerator # Standard setup: single reference frame mask_gen = MaskGenerator(max_ref_frames=1, factor=8, start=1) # Multiple reference frames mask_gen = MaskGenerator(max_ref_frames=9, factor=8, start=1) ``` -------------------------------- ### Enable Training Resume Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/troubleshooting-and-faq.md Set this configuration option to true to automatically resume training from the latest checkpoint. ```python config['train']['resume'] = True ``` -------------------------------- ### Download Models Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/troubleshooting-and-faq.md Before loading models, ensure they are downloaded to the specified save directory. Use the `download.py` script. ```bash python scripts/download.py \ --model-name video_pretrain \ --save-dir /path/to/models/ ``` -------------------------------- ### GigaTrain Integration for Distributed Training Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/gigaworld0-trainer.md Launch GigaWorld0Trainer using GigaTrain's `launch_from_config` for multi-GPU training. Ensure the config file references GigaWorld0Trainer. ```python from giga_train import launch_from_config # config file references GigaWorld0Trainer config = dict( runners=['giga_world_0.GigaWorld0Trainer'], models=dict( vae_model_path='...', transformer_model_path='...', ), # ... other training configs ) launch_from_config(config) ``` -------------------------------- ### GigaWorld0Trainer.get_models() Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/gigaworld0-trainer.md Initializes and configures all model components required for training, including VAE and transformer models, and sets up the training mode (full or LoRA). ```APIDOC ## GigaWorld0Trainer.get_models() ### Description Initializes and configures model components, including VAE and transformer models, and sets up the training mode (full or LoRA). ### Method `get_models(self, model_config)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **model_config** (object) - Required - Configuration object containing model paths and training parameters. Must have `vae_model_path` and `transformer_model_path`. Optional: `train_mode`, `lora_rank`, `fp8_ignore_modules`. ### Request Example ```python from giga_world_0 import GigaWorld0Trainer import addict # Create trainer instance (inherited from Trainer) trainer = GigaWorld0Trainer(...) # Configure model paths model_config = addict.Dict({ 'vae_model_path': '/path/to/giga_world_0/vae', 'transformer_model_path': '/path/to/giga_world_0_video/transformer', 'train_mode': 'full', # or 'lora' 'lora_rank': 64, # required if train_mode='lora' 'fp8_ignore_modules': [] }) # Initialize models models = trainer.get_models(model_config) ``` ### Response #### Success Response (200) * **giga_train.ModuleDict** - Dictionary containing initialized models: `transformer` (GigaWorld0Transformer3DModel), and associated configurations. Models are moved to the appropriate device and dtype. #### Response Example ```json { "transformer": "", "vae": "" } ``` ### Throws * **AssertionError** - When LoRA rank parameter is missing or invalid * **RuntimeError** - When model files not found at specified paths ``` -------------------------------- ### Verify Model Loading and Properties Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/troubleshooting-and-faq.md Load a model using from_pretrained and check its parameter count, device, and data type to ensure correct loading. ```python from giga_models import GigaWorld0Transformer3DModel model = GigaWorld0Transformer3DModel.from_pretrained('path/') print(sum(p.numel() for p in model.parameters()) / 1e9) # Parameters in billions print(next(model.parameters()).device) # Check device print(next(model.parameters()).dtype) # Check dtype ``` -------------------------------- ### Download Pre-trained Models Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/data-preparation.md Command-line usage for downloading pre-trained models from HuggingFace. Specify the model name and the save directory. ```bash # Download pretrain model python scripts/download.py \ --model-name video_pretrain \ --save-dir /path/to/models/ # Download GR1 fine-tuned model python scripts/download.py \ --model-name video_gr1 \ --save-dir /path/to/models/ ``` -------------------------------- ### Train GigaWorld-0 Video Model Source: https://github.com/open-gigaai/giga-world-0/blob/main/README.md Initiates the training process for the GigaWorld-0 video model using a specified configuration file. Supports LoRA training by setting specific configuration parameters. ```bash python scripts/train.py --config configs.giga_world_0_video.config ``` -------------------------------- ### Check TensorBoard Logs Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/troubleshooting-and-faq.md Run TensorBoard with the --logdir flag pointing to your experiments directory to visualize training progress. ```bash tensorboard --logdir experiments/ ``` -------------------------------- ### Inspect Packed Dataset Sample Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/troubleshooting-and-faq.md Load a sample from the packed dataset and print the shape of the video tensor to verify consistency. ```python from giga_datasets import load_dataset dataset = load_dataset('/path/to/packed_data/') sample = dataset[0] print(sample['video'].shape) # Should be (T, H, W, 3) ``` -------------------------------- ### Command-Line Usage for pack_data() Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/data-preparation.md Execute the `pack_data` script from the command line. Use flags to specify directories and the device. The T5 model can be downloaded automatically or provided via a path. ```bash # Download T5 automatically, encode prompts python scripts/pack_data.py \ --video-dir /path/to/raw_data/ \ --save-dir /path/to/packed_data/ \ --device cuda ``` ```bash # Use existing T5 model python scripts/pack_data.py \ --video-dir /path/to/raw_data/ \ --save-dir /path/to/packed_data/ \ --text-encoder-model-path /path/to/t5-11b/ \ --device cuda ``` -------------------------------- ### Inference Data Preparation and Execution Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/data-preparation.md Prepare inference data by creating a JSON file with prompts and image paths, then run inference using `inference.py`. Ensure correct paths for data, save directory, and model components are provided. ```json [ { "prompt": "A robot arm reaching for a cube", "image": "path/to/image1.png" }, { "prompt": "A hand grasping a ball", "image": "path/to/image2.png" } ] ``` ```bash python scripts/inference.py \ --data-path test_data.json \ --save-dir ./results/ \ --transformer-model-path /path/to/transformer/ \ --gpu-ids 0 ``` -------------------------------- ### Download GigaWorld-0 Models Source: https://github.com/open-gigaai/giga-world-0/blob/main/README.md Scripts to download pre-trained video models, including text encoders and VAEs, for GigaWorld-0. ```bash python scripts/download.py --model-name video_pretrain --save-dir /path/to/giga_world_0_video_pretrain/ python scripts/download.py --model-name video_gr1 --save-dir /path/to/giga_world_0_video_gr1/ ``` -------------------------------- ### Create a Training Configuration Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/README.md Defines the configuration dictionary for training a GigaWorld model. Specify runners, dataloaders, models, optimizers, and training parameters. ```python config = dict( runners=['giga_world_0.GigaWorld0Trainer'], dataloaders=dict( train=dict( data_or_config=['/path/to/packed_data/'], batch_size_per_gpu=1, transform=dict( type='GigaWorld0Transform', num_frames=61, height=480, width=640, image_cfg=dict( mask_generator=dict( max_ref_frames=1, factor=4, ), ), ), ), ), models=dict( vae_model_path='...', transformer_model_path='...', ), optimizers=dict(type='CAME8Bit', lr=2**(-14.5)), train=dict(max_epochs=50, mixed_precision='bf16'), ) ``` -------------------------------- ### Initialize GigaWorld0Pipeline Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/model-architecture.md Instantiate the GigaWorld0Pipeline using pre-trained model paths. The pipeline integrates transformer, text encoder, and VAE components for generative tasks. LoRA can be optionally loaded and fused. ```python from giga_models import GigaWorld0Pipeline pipe = GigaWorld0Pipeline.from_pretrained( transformer_model_path='...', text_encoder_model_path='...', vae_model_path='...', lora_model_path=None, # Optional lora_fuse=False, # Optional ) ``` -------------------------------- ### Minimal GigaWorld-0 Configuration Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/configuration.md This is a minimal configuration dictionary for GigaWorld-0 training. It specifies the trainer, dataloader settings, model paths, optimizer, scheduler, and basic training parameters. ```python config = dict( runners=['giga_world_0.GigaWorld0Trainer'], dataloaders=dict( train=dict( data_or_config=['/path/to/packed_data/'], batch_size_per_gpu=1, num_workers=6, transform=dict( type='GigaWorld0Transform', num_frames=61, height=480, width=640, fps=16, image_cfg=dict( mask_generator=dict( max_ref_frames=1, start=1, factor=4, ), ), ), ), ), models=dict( vae_model_path='/path/to/vae/', transformer_model_path='/path/to/transformer/', ), optimizers=dict( type='CAME8Bit', lr=2 ** (-14.5), ), schedulers=dict( type='ConstantScheduler', ), train=dict( max_epochs=1, mixed_precision='bf16', ), ) ``` -------------------------------- ### GigaWorld0Transform Constructor Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/gigaworld0-transform.md Initializes the GigaWorld0Transform with specified video dimensions and transformation configurations. ```APIDOC ## __init__ __init__(self, num_frames: int, height: int, width: int, image_cfg: dict, fps: int = 16) ### Description Initialize the GigaWorld0Transform with target dimensions and transformation settings. ### Parameters #### Path Parameters - **num_frames** (int) - Required - Number of frames to sample from each video. Common values: 61 for standard, 49 for lower-compute setups. - **height** (int) - Required - Target height for output frames in pixels. Typical value: 480 - **width** (int) - Required - Target width for output frames in pixels. Typical value: 640 - **image_cfg** (dict) - Required - Configuration dictionary containing `mask_generator` settings. Example: `{'mask_generator': {'max_ref_frames': 1, 'factor': 8, 'start': 1}}` - **fps** (int) - Optional - Default: 16 - Frames per second metadata for output video sequences. ### Request Example ```python from giga_world_0 import GigaWorld0Transform transform = GigaWorld0Transform( num_frames=61, height=480, width=640, image_cfg=dict( mask_generator=dict( max_ref_frames=1, factor=8, start=1, ) ), fps=16 ) ``` ``` -------------------------------- ### Raw Data Organization Structure Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/data-preparation.md Organize video and prompt files in the specified directory structure. Ensure video and prompt files are paired by index. ```bash raw_data/ ├── 0.mp4 # Video file 0 ├── 0.txt # Text prompt for video 0 ├── 1.mp4 # Video file 1 ├── 1.txt # Text prompt for video 1 ├── 2.mp4 ├── 2.txt └── ... ``` -------------------------------- ### Project Directory Configuration Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/configuration.md Defines the output directory for experiments. Subdirectories for checkpoints, logs, and outputs are created automatically within this base directory. ```python project_dir='./experiments/giga_world_0_video/it2v' ``` -------------------------------- ### Constant Scheduler Configuration Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/configuration.md Configure a constant learning rate scheduler. ```python # Constant learning rate schedulers=dict( type='ConstantScheduler', ) ``` -------------------------------- ### Download Script Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/module-structure.md Use the download script to fetch pre-trained models from HuggingFace. It supports downloading the transformer, T5 text encoder, and VAE. ```python scripts/download.py ``` -------------------------------- ### Support Documentation Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/COMPLETION_SUMMARY.txt Offers guidance for troubleshooting errors and frequently asked questions. ```APIDOC ## Support Documentation Offers guidance for troubleshooting errors and frequently asked questions. ### Entry Points: - **troubleshooting-and-faq.md**: Errors and solutions ``` -------------------------------- ### LoRA Fine-tuning Workflow Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/README.md This snippet details the process for LoRA fine-tuning, including packing custom data, updating the configuration to specify LoRA parameters, and initiating the training. It also covers inference with the fine-tuned LoRA model. ```bash # Step 1: Pack custom data python scripts/pack_data.py --video-dir custom_data/ --save-dir custom_packed/ # Step 2: Update config config = dict( models=dict( ... train_mode='lora', lora_rank=64, ), ) # Step 3: Train python scripts/train.py --config custom_config.config # Step 4: Inference with LoRA python scripts/inference.py \ ... --lora-model-path /path/to/lora/ \ --gpu-ids 0 ``` -------------------------------- ### CAME8Bit Optimizer Configuration Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/configuration.md Configure the CAME8Bit optimizer for memory-efficient training. Set learning rate and weight decay. ```python # CAME8Bit optimizer (recommended, memory-efficient) optimizers=dict( type='CAME8Bit', lr=2 ** (-14.5), # = 0.0000450... weight_decay=0.0, ) ``` -------------------------------- ### Cosine Annealing Scheduler Configuration Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/configuration.md Configure a cosine annealing scheduler with linear warmup. Specify warmup steps and minimum learning rate ratio. ```python # Linear warmup + cosine decay schedulers=dict( type='CosineAnnealingScheduler', warmup_steps=1000, min_lr_ratio=0.1, ) ``` -------------------------------- ### Initialize GigaWorld0Transform Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/gigaworld0-transform.md Initializes the GigaWorld0Transform with target dimensions and transformation settings. Use this to set up the preprocessing pipeline for your video data. ```python def __init__(self, num_frames: int, height: int, width: int, image_cfg: dict, fps: int = 16): """Initialize the transform.""" ``` ```python from giga_world_0 import GigaWorld0Transform transform = GigaWorld0Transform( num_frames=61, height=480, width=640, image_cfg=dict( mask_generator=dict( max_ref_frames=1, factor=8, start=1, ) ), fps=16 ) ``` -------------------------------- ### Full Training Mode Configuration Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/gigaworld0-trainer.md Configuration for enabling full training mode, where all parameters of the transformer model are trained. Requires specifying VAE and transformer model paths. ```python model_config = dict( vae_model_path='...', transformer_model_path='...', train_mode='full', ) ``` -------------------------------- ### Image Transform Configuration Dictionary Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/types.md Configuration for GigaWorld0Transform initialization. Includes settings for mask generation like maximum reference frames and downsampling factor. ```python image_cfg = dict( mask_generator=dict( max_ref_frames: int, # Maximum reference frames (>0) factor: int = 8, # Downsampling factor start: int = 1, # Minimum reference latents ) ) ``` -------------------------------- ### Launch Configuration for Distributed Training Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/configuration.md Configures distributed training and hardware settings, including GPU IDs and the distribution backend. Specify the DeepSpeed config file path if using 'DEEPSPEED'. ```python launch=dict( gpu_ids=[0, 1, 2, 3, 4, 5, 6, 7], distributed_type='DEEPSPEED', deepspeed_config=dict( deepspeed_config_file='accelerate_configs/zero2.json', ), ) ``` -------------------------------- ### GigaWorld0 Trainer Configuration Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/gigaworld0-trainer.md Configuration dictionary for initializing the GigaWorld0 trainer. Specify paths to VAE and transformer models, and the training mode ('full' or 'lora'). ```python model_config = dict( vae_model_path='/path/to/giga_world_0/vae', transformer_model_path='/path/to/giga_world_0_video/transformer', train_mode='full', # 'full' or 'lora' lora_rank=64, # required if train_mode='lora' fp8_ignore_modules=[], # modules to exclude from FP8 conversion ) ``` -------------------------------- ### Verify Image File Type Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/troubleshooting-and-faq.md Use the 'file' command to check the format of an image file. ```bash file test_image.png # Should output: image/png ``` -------------------------------- ### Configure Mixed Precision Training (fp8) Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/model-architecture.md Configure mixed precision training to use 8-bit floating point (fp8). This offers extreme compression but requires careful scaling and may impact quality if not tuned properly. Specific modules can be ignored to maintain stability. ```python train=dict( mixed_precision='fp8', ), models=dict( fp8_ignore_modules=['input_layer', 'output_layer'], ) ``` -------------------------------- ### Reference Documentation Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/COMPLETION_SUMMARY.txt Provides detailed information on configuration options and data structures used within the GigaWorld system. ```APIDOC ## Reference Documentation Provides detailed information on configuration options and data structures used within the GigaWorld system. ### Entry Points: - **configuration.md**: All configuration options - **types.md**: Data structures and formats ``` -------------------------------- ### Runner Configuration Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/configuration.md Specifies the trainer class to be used for GigaWorld-0 training. Ensure 'giga_world_0.GigaWorld0Trainer' is used for video training. ```python runners=['giga_world_0.GigaWorld0Trainer'] ``` -------------------------------- ### Output Dataset Structure Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/data-preparation.md The packed dataset is organized into specific directories for labels, videos, and prompts, along with configuration files. ```bash save_dir/ ├── labels/ # Metadata for each sample │ ├── data_0.pkl # Metadata for sample 0 │ ├── data_1.pkl # Metadata for sample 1 │ └── config.json # Dataset configuration ├── videos/ # Encoded video files │ ├── data_0.bin # Video 0 │ ├── data_1.bin # Video 1 │ └── config.json ├── prompts/ # Prompt embeddings │ ├── data_0.safetensors # Embeddings for prompt 0 │ ├── data_1.safetensors # Embeddings for prompt 1 │ └── config.json └── config.json # Master dataset config ``` -------------------------------- ### Enable Exponential Moving Average (EMA) Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/troubleshooting-and-faq.md Set this configuration option to true to enable EMA, which keeps a smoothed version of weights and improves generation quality. ```python config['train']['with_ema'] = True ``` -------------------------------- ### Add Repository to Python Path Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/troubleshooting-and-faq.md Ensure the repository's root directory is in the Python path to allow importing configuration modules. ```python import sys sys.path.insert(0, '/path/to/repo/') from configs.giga_world_0_video import config ``` -------------------------------- ### Check Config File Existence Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/troubleshooting-and-faq.md Verify that the configuration Python file exists at the specified path to resolve `ModuleNotFoundError`. ```bash ls -la configs/giga_world_0_video.py ``` -------------------------------- ### Pack Raw Data for Training Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/module-structure.md Initiates the data packing process, which involves encoding prompts and preparing raw video data into a training dataset format. Specify the directories for raw videos and where to save the packed data. ```python from scripts.pack_data import pack_data pack_data( video_dir='raw_data/', save_dir='packed_data/', ) ``` -------------------------------- ### Verify Data Path Existence Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/troubleshooting-and-faq.md Before packing data, verify that the target directory for packed data exists and contains the expected subdirectories. ```bash ls -la /path/to/packed_data/ # Should see: labels, videos, prompts, config.json ``` -------------------------------- ### Initialize and Use T5TextEncoder Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/data-preparation.md Initializes the T5TextEncoder and encodes prompts into embeddings. Ensure the model path is correct and the device is set to 'cuda'. ```python from giga_models.models.diffusion.giga_world_0 import T5TextEncoder text_encoder = T5TextEncoder(model_path) text_encoder.to('cuda') # Encode single prompt embeddings = text_encoder.encode_prompts(prompt) # Returns (1, seq_len, 768) # Get embedding shape prompt_embeds = embeddings[0] # Remove batch dimension print(prompt_embeds.shape) # (seq_len, 768) ``` -------------------------------- ### Model Paths and Training Configuration Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/configuration.md Specify paths to VAE and transformer models, and configure training mode and LoRA parameters. ```python models=dict( vae_model_path='/path/to/vae/', transformer_model_path='/path/to/transformer/', train_mode='full', lora_rank=64, fp8_ignore_modules=[], ) ``` -------------------------------- ### Monitor GPU Utilization Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/troubleshooting-and-faq.md To diagnose slow training, continuously monitor GPU utilization using `watch -n 1 nvidia-smi` to identify potential bottlenecks. ```bash watch -n 1 nvidia-smi # Watch GPU usage ``` -------------------------------- ### Full Training Configuration Dictionary Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/types.md Comprehensive configuration for the GigaTrain training loop. Covers data loading, model parameters, optimizers, schedulers, and training parameters like epochs and mixed precision. ```python config = dict( runners=['giga_world_0.GigaWorld0Trainer'], dataloaders=dict( train=dict( data_or_config: List[str], # Paths to packed datasets batch_size_per_gpu: int, # Batch size per GPU num_workers: int, # DataLoader workers transform=dict( type='GigaWorld0Transform', num_frames: int, # Frames to sample height: int, # Target height width: int, # Target width fps: int, # Frames per second image_cfg: dict, # Transform config ), ), ), models=dict( vae_model_path: str, transformer_model_path: str, train_mode: str = 'full', lora_rank: int = 64, ), optimizers=dict( type: str, # Optimizer class name lr: float, # Learning rate weight_decay: float = None, ), schedulers=dict( type: str, # Scheduler class name ), train=dict( max_epochs: int, gradient_accumulation_steps: int = 1, mixed_precision: str, # 'fp16', 'bf16', 'fp8' checkpoint_interval: int, checkpoint_total_limit: int, log_interval: int, ), ) ``` -------------------------------- ### DefaultSampler Configuration Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/configuration.md Configure the data sampler. Use 'DefaultSampler' for standard behavior and set shuffle to True for training. ```python sampler=dict( type='DefaultSampler', shuffle=True, ) ``` -------------------------------- ### Load Pre-trained Model for Inference Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/README.md This Python snippet shows how to load a pre-trained GigaWorld0Pipeline for inference. Ensure the correct paths to the transformer, text encoder, and VAE models are provided, and move the pipeline to the appropriate device. ```python from giga_models import GigaWorld0Pipeline pipe = GigaWorld0Pipeline.from_pretrained( transformer_model_path='/path/to/transformer/', text_encoder_model_path='/path/to/text_encoder/', vae_model_path='/path/to/vae/', ) pipe.to('cuda:0') ``` -------------------------------- ### Set HuggingFace Cache Directory Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/troubleshooting-and-faq.md Configure the HuggingFace cache directory using the `HF_HOME` environment variable to manage downloaded models. ```bash export HF_HOME=/data/hf_cache/ ``` -------------------------------- ### Set Full Training Mode Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/troubleshooting-and-faq.md Configure the model to use full parameter training. ```python config['models']['train_mode'] = 'full' ``` -------------------------------- ### Command-Line Inference (Single GPU) Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/inference-api.md Executes inference using the command-line interface on a single GPU. Specify the GPU ID using `--gpu-ids 0`. ```bash python scripts/inference.py \ --data-path test_data.json \ --save-dir ./results/ \ --transformer-model-path /path/to/transformer/ \ --gpu-ids 0 ``` -------------------------------- ### pack_data() Function Source: https://github.com/open-gigaai/giga-world-0/blob/main/_autodocs/data-preparation.md Packs videos, prompts, and prompt embeddings into a dataset format suitable for training or evaluation. It handles model downloading, video discovery, prompt encoding, and dataset assembly. ```APIDOC ## pack_data() ### Description Packs videos, prompts, and prompt embeddings into a dataset for training or evaluation. This function automates the process of discovering video and prompt files, encoding prompts into embeddings using a T5 model, and assembling everything into a structured dataset. ### Function Signature ```python def pack_data( video_dir: str, save_dir: str, text_encoder_model_path: str | None = None, device: str = 'cuda', ) -> None: """Pack videos, prompts, and prompt embeddings into a dataset for training or evaluation.""" ``` ### Parameters #### Path Parameters - **video_dir** (str) - Required - Directory containing .mp4 videos and .txt prompt files. All files with matching indices are processed. - **save_dir** (str) - Required - Output directory where packed dataset will be saved. Created if not exists. #### Query Parameters - **text_encoder_model_path** (str | None) - Optional - Path to T5 text encoder model. If None, downloads google-t5/t5-11b from HuggingFace (~50GB). - **device** (str) - Optional - Device for text encoding ('cuda' or 'cpu'). GPU recommended for speed. Defaults to 'cuda'. ### Processing Pipeline 1. **Model Download** — Downloads T5-11b text encoder if path not provided 2. **Video Discovery** — Finds all .mp4 files in video_dir 3. **Iteration** — For each video: - Reads corresponding .txt prompt file - Encodes prompt to embeddings using T5 - Saves prompt embedding, video, and metadata 4. **Dataset Assembly** — Combines all outputs into single Dataset object 5. **Finalization** — Saves configuration and creates dataset index ### Output Dataset Structure ``` save_dir/ ├── labels/ # Metadata for each sample │ ├── data_0.pkl # Metadata for sample 0 │ ├── data_1.pkl # Metadata for sample 1 │ └── config.json # Dataset configuration ├── videos/ # Encoded video files │ ├── data_0.bin # Video 0 │ ├── data_1.bin # Video 1 │ └── config.json ├── prompts/ # Prompt embeddings │ ├── data_0.safetensors # Embeddings for prompt 0 │ ├── data_1.safetensors # Embeddings for prompt 1 │ └── config.json └── config.json # Master dataset config ``` ### Metadata Format Each label file contains: ```python { 'data_index': int, # Index in dataset (0-based) 'prompt': str, # Original text prompt } ``` ### Example Usage ```python from scripts.pack_data import pack_data # Basic usage with automatic model download pack_data( video_dir='/path/to/raw_data/', save_dir='/path/to/packed_data/', device='cuda' ) # Custom text encoder path pack_data( video_dir='/path/to/raw_data/', save_dir='/path/to/packed_data/', text_encoder_model_path='/path/to/t5-11b/', device='cuda' ) # CPU-based encoding (slower) pack_data( video_dir='/path/to/raw_data/', save_dir='/path/to/packed_data/', device='cpu' ) ``` ### Command-Line Usage ```bash # Download T5 automatically, encode prompts python scripts/pack_data.py \ --video-dir /path/to/raw_data/ \ --save-dir /path/to/packed_data/ \ --device cuda # Use existing T5 model python scripts/pack_data.py \ --video-dir /path/to/raw_data/ \ --save-dir /path/to/packed_data/ \ --text-encoder-model-path /path/to/t5-11b/ \ --device cuda ``` ```