diff --git a/examples/inference/basic/basic.py b/examples/inference/basic/basic.py index 337b89550..f12a4969e 100644 --- a/examples/inference/basic/basic.py +++ b/examples/inference/basic/basic.py @@ -16,8 +16,7 @@ def main(): dit_cpu_offload=False, vae_cpu_offload=False, text_encoder_cpu_offload=True, - # Set pin_cpu_memory to false if CPU RAM is limited and there're no frequent CPU-GPU transfer - pin_cpu_memory=False, + pin_cpu_memory=True, # set to false if low CPU RAM or hit obscure "CUDA error: Invalid argument" # image_encoder_cpu_offload=False, ) diff --git a/examples/inference/basic/basic_dmd.py b/examples/inference/basic/basic_dmd.py index ed30e6e0a..48b2965ce 100644 --- a/examples/inference/basic/basic_dmd.py +++ b/examples/inference/basic/basic_dmd.py @@ -17,7 +17,7 @@ def main(): use_fsdp_inference=True, # Adjust these offload parameters if you have < 32GB of VRAM text_encoder_cpu_offload=True, - pin_cpu_memory=False, + pin_cpu_memory=True, # set to false if low CPU RAM or hit obscure "CUDA error: Invalid argument" dit_cpu_offload=False, vae_cpu_offload=False, VSA_sparsity=0.8, diff --git a/examples/inference/lora/wan_lora_inference.py b/examples/inference/lora/wan_lora_inference.py index 5471a8980..bc3d264d9 100644 --- a/examples/inference/lora/wan_lora_inference.py +++ b/examples/inference/lora/wan_lora_inference.py @@ -10,7 +10,7 @@ def main(): dit_cpu_offload=False, vae_cpu_offload=False, text_encoder_cpu_offload=True, - pin_cpu_memory=False, + pin_cpu_memory=True, # set to false if low CPU RAM or hit obscure "CUDA error: Invalid argument" lora_path="benjamin-paine/steamboat-willie-1.3b", lora_nickname="steamboat" ) @@ -18,7 +18,7 @@ def main(): "height": 480, "width": 832, "num_frames": 81, - "guidance_scale": 5.0, + "guidance_scale": 6.0, "num_inference_steps": 32, "seed": 42, } diff --git a/examples/inference/lora/wan_lora_inference_from_ckpt.py b/examples/inference/lora/wan_lora_inference_from_ckpt.py index c2ad8598d..519abf0f8 100644 --- a/examples/inference/lora/wan_lora_inference_from_ckpt.py +++ b/examples/inference/lora/wan_lora_inference_from_ckpt.py @@ -11,9 +11,9 @@ def main(): "Wan-AI/Wan2.1-T2V-1.3B-Diffusers", num_gpus=1, dit_cpu_offload=False, - vae_cpu_offload=False, + vae_cpu_offload=True, text_encoder_cpu_offload=True, - pin_cpu_memory=False, + pin_cpu_memory=True, # set to false if low CPU RAM or hit obscure "CUDA error: Invalid argument" lora_path="checkpoints/wan_t2v_finetune_lora/checkpoint-1000/transformer", lora_nickname="crush_smol" ) @@ -26,7 +26,7 @@ def main(): "seed": 42, } # Generate video with LoRA style - prompt = "A large metal cylinder is seen pressing down on a pile of colorful candies, flattening them as if they were under a hydraulic press. The candies are crushed and broken into small pieces, creating a mess on the table." + prompt = "A large metal cylinder is seen pressing down on a pile of Oreo cookies, flattening them as if they were under a hydraulic press." video = generator.generate_video( prompt, diff --git a/examples/inference/optimizations/attention_example.py b/examples/inference/optimizations/attention_example.py index ce727212f..558a001d2 100644 --- a/examples/inference/optimizations/attention_example.py +++ b/examples/inference/optimizations/attention_example.py @@ -14,7 +14,7 @@ def main(): dit_cpu_offload=False, vae_cpu_offload=False, text_encoder_cpu_offload=True, - pin_cpu_memory=False, + pin_cpu_memory=True, # set to false if low CPU RAM or hit obscure "CUDA error: Invalid argument" ) load_time = time.perf_counter() - start_time print(f"Model loading time: {load_time:.2f} seconds") diff --git a/examples/inference/optimizations/teacache_example.py b/examples/inference/optimizations/teacache_example.py index ba2e353ea..77e0582a6 100644 --- a/examples/inference/optimizations/teacache_example.py +++ b/examples/inference/optimizations/teacache_example.py @@ -12,7 +12,7 @@ def main(): dit_cpu_offload=False, vae_cpu_offload=False, text_encoder_cpu_offload=True, - pin_cpu_memory=False, + pin_cpu_memory=True, # set to false if low CPU RAM or hit obscure "CUDA error: Invalid argument" ) load_time = time.perf_counter() - start_time print(f"Model loading time: {load_time:.2f} seconds") diff --git a/examples/training/finetune/wan_t2v_1.3B/crush_smol/finetune_t2v.sh b/examples/training/finetune/wan_t2v_1.3B/crush_smol/finetune_t2v.sh index 3ac715007..c7e2c251e 100644 --- a/examples/training/finetune/wan_t2v_1.3B/crush_smol/finetune_t2v.sh +++ b/examples/training/finetune/wan_t2v_1.3B/crush_smol/finetune_t2v.sh @@ -77,6 +77,7 @@ miscellaneous_args=( --num_euler_timesteps 50 --ema_start_step 0 --enable_gradient_checkpointing_type "full" + # --resume_from_checkpoint "checkpoints/wan_t2v_finetune/checkpoint-2500" ) torchrun \ diff --git a/fastvideo/layers/lora/linear.py b/fastvideo/layers/lora/linear.py index 2f63de200..a0a67f807 100644 --- a/fastvideo/layers/lora/linear.py +++ b/fastvideo/layers/lora/linear.py @@ -101,15 +101,15 @@ class BaseLayerWithLoRA(nn.Module): B: torch.Tensor, training_mode: bool = False, lora_path: str | None = None) -> None: - self.lora_A = A # share storage with weights in the pipeline - self.lora_B = B + self.lora_A = torch.nn.Parameter( + A) # share storage with weights in the pipeline + self.lora_B = torch.nn.Parameter(B) self.disable_lora = False if not training_mode: self.merge_lora_weights() self.lora_path = lora_path @torch.no_grad() - # @torch.compile() def merge_lora_weights(self) -> None: if self.disable_lora: return diff --git a/fastvideo/models/dits/wanvideo.py b/fastvideo/models/dits/wanvideo.py index 2ca840622..1cae2da01 100644 --- a/fastvideo/models/dits/wanvideo.py +++ b/fastvideo/models/dits/wanvideo.py @@ -672,11 +672,9 @@ class WanTransformer3DModel(CachableDiT): for block in self.blocks: hidden_states = block(hidden_states, encoder_hidden_states, timestep_proj, freqs_cis) - # if teacache is enabled, we need to cache the original hidden states if enable_teacache: self.maybe_cache_states(hidden_states, original_hidden_states) - # 5. Output norm, projection & unpatchify shift, scale = (self.scale_shift_table + temb.unsqueeze(1)).chunk(2, dim=1) diff --git a/fastvideo/pipelines/stages/denoising.py b/fastvideo/pipelines/stages/denoising.py index 592ee352d..8a2d9f0b6 100644 --- a/fastvideo/pipelines/stages/denoising.py +++ b/fastvideo/pipelines/stages/denoising.py @@ -323,14 +323,12 @@ class DenoisingStage(PipelineStage): noise_pred_text, guidance_rescale=batch.guidance_rescale, ) - # Compute the previous noisy sample latents = self.scheduler.step(noise_pred, t, latents, **extra_step_kwargs, return_dict=False)[0] - # Update progress bar if i == len(timesteps) - 1 or ( (i + 1) > num_warmup_steps and diff --git a/fastvideo/pipelines/stages/latent_preparation.py b/fastvideo/pipelines/stages/latent_preparation.py index 5c7e54f1a..ea23a7daa 100644 --- a/fastvideo/pipelines/stages/latent_preparation.py +++ b/fastvideo/pipelines/stages/latent_preparation.py @@ -90,7 +90,6 @@ class LatentPreparationStage(PipelineStage): f"You have passed a list of generators of length {len(generator)}, but requested an effective batch" f" size of {batch_size}. Make sure the batch size matches the length of the generators." ) - # Generate or use provided latents if latents is None: latents = randn_tensor(shape, @@ -103,7 +102,6 @@ class LatentPreparationStage(PipelineStage): # Scale the initial noise if needed if hasattr(self.scheduler, "init_noise_sigma"): latents = latents * self.scheduler.init_noise_sigma - # Update batch with prepared latents batch.latents = latents batch.raw_latent_shape = latents.shape diff --git a/fastvideo/training/training_pipeline.py b/fastvideo/training/training_pipeline.py index 8293f10ca..0615ed24f 100644 --- a/fastvideo/training/training_pipeline.py +++ b/fastvideo/training/training_pipeline.py @@ -76,6 +76,7 @@ class TrainingPipeline(LoRAPipeline, ABC): if self.lora_training and fastvideo_args.lora_rank is None: raise ValueError("lora rank must be set when using lora training") + set_random_seed(fastvideo_args.seed) # for lora param init super().__init__(model_path, fastvideo_args, required_config_modules, loaded_modules) # type: ignore diff --git a/fastvideo/training/training_utils.py b/fastvideo/training/training_utils.py index d0bf0961a..dd794a197 100644 --- a/fastvideo/training/training_utils.py +++ b/fastvideo/training/training_utils.py @@ -159,7 +159,6 @@ def save_checkpoint(transformer, local_main_process_only=False) cpu_state = gather_state_dict_on_cpu_rank0(transformer, device=None) - if rank == 0: # Save model weights (consolidated) transformer_save_dir = os.path.join(save_dir, "transformer")