diff --git a/examples/inference/gradio/gradio_frontend.py b/examples/inference/gradio/gradio_frontend.py index ea17862d6..fcbc1da06 100644 --- a/examples/inference/gradio/gradio_frontend.py +++ b/examples/inference/gradio/gradio_frontend.py @@ -486,7 +486,7 @@ def main(): help="URL of the Ray Serve backend") parser.add_argument("--t2v_model_path", type=str, - default="Wan-AI/Wan2.2-TI2V-5B-Diffusers", + default="FastVideo/FastWan2.1-T2V-1.3B-Diffusers", help="Path to the T2V model (for default parameters)") parser.add_argument("--i2v_model_path", type=str, @@ -505,18 +505,18 @@ def main(): # Load default parameters from the models # try: - # default_params = SamplingParam.from_pretrained(args.t2v_model_path) + default_params = SamplingParam.from_pretrained(args.t2v_model_path) # except Exception as e: # print(f"Warning: Could not load default parameters from {args.t2v_model_path}: {e}") # print("Using fallback default parameters...") # # Create fallback default parameters - default_params = SamplingParam() - default_params.height = 448 - default_params.width = 832 - default_params.num_frames = 21 - default_params.guidance_scale = 7.5 - default_params.num_inference_steps = 20 - default_params.seed = 1024 + # default_params = SamplingParam() + # default_params.height = 448 + # default_params.width = 832 + # default_params.num_frames = 21 + # default_params.guidance_scale = 7.5 + # default_params.num_inference_steps = 20 + # default_params.seed = 1024 # Create and launch the interface demo = create_gradio_interface(args.backend_url, default_params) diff --git a/examples/inference/gradio/ray_serve_backend.py b/examples/inference/gradio/ray_serve_backend.py index bfc192523..c7c237756 100644 --- a/examples/inference/gradio/ray_serve_backend.py +++ b/examples/inference/gradio/ray_serve_backend.py @@ -167,7 +167,7 @@ class FastVideoAPI: print("✅ I2V model initialized successfully") @app.post("/generate_video", response_model=VideoGenerationResponse) - @limiter.limit("2/minute") # Allow 2 requests per minute per IP + @limiter.limit("50/minute") # Allow 2 requests per minute per IP async def generate_video(self, request: Request, video_request: VideoGenerationRequest) -> VideoGenerationResponse: try: # Select the appropriate model and parameters based on model_type @@ -183,15 +183,15 @@ class FastVideoAPI: # Update parameters with request values params.prompt = video_request.prompt # Only override negative prompt if user explicitly opts in - # if video_request.use_negative_prompt: - # params.negative_prompt = video_request.negative_prompt + if video_request.use_negative_prompt: + params.negative_prompt = video_request.negative_prompt - # params.seed = video_request.seed - # params.guidance_scale = video_request.guidance_scale - # params.num_frames = video_request.num_frames - # params.height = video_request.height - # params.width = video_request.width - # params.num_inference_steps = video_request.num_inference_steps + params.seed = video_request.seed + params.guidance_scale = video_request.guidance_scale + params.num_frames = video_request.num_frames + params.height = video_request.height + params.width = video_request.width + params.num_inference_steps = video_request.num_inference_steps # Handle seed randomization if video_request.randomize_seed: @@ -297,7 +297,7 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(description="FastVideo Ray Serve Backend") parser.add_argument("--t2v_model_path", type=str, - default="Wan-AI/Wan2.2-TI2V-5B-Diffusers", + default="FastVideo/FastWan2.1-T2V-1.3B-Diffusers", help="Path to the T2V model") parser.add_argument("--i2v_model_path", type=str, diff --git a/fastvideo/pipelines/stages/denoising.py b/fastvideo/pipelines/stages/denoising.py index 4141ca718..3542381b2 100644 --- a/fastvideo/pipelines/stages/denoising.py +++ b/fastvideo/pipelines/stages/denoising.py @@ -10,7 +10,6 @@ from collections.abc import Iterable from typing import Any import torch -import torchvision.transforms.functional as TF from einops import rearrange from tqdm.auto import tqdm @@ -31,8 +30,7 @@ from fastvideo.pipelines.stages.base import PipelineStage from fastvideo.pipelines.stages.validators import StageValidators as V from fastvideo.pipelines.stages.validators import VerificationResult from fastvideo.platforms import AttentionBackendEnum -from fastvideo.utils import dict_to_3d_list, masks_like, best_output_size -from PIL import Image +from fastvideo.utils import dict_to_3d_list, masks_like try: from fastvideo.attention.backends.sliding_tile_attn import ( @@ -200,12 +198,11 @@ class DenoisingStage(PipelineStage): logger.info(f"z shape: {z.shape}") logger.info(f"latent_model_input shape: {latent_model_input.shape}") latent_model_input = latent_model_input.squeeze(0) - mask1, mask2 = masks_like([latent_model_input], - zero=True) + mask1, mask2 = masks_like([latent_model_input], zero=True) # logger.info(f"mask1 shape: {mask1.shape}") # logger.info(f"mask2 shape: {mask2.shape}") - latent_model_input = ( - 1. - mask2[0]) * z + mask2[0] * latent_model_input + latent_model_input = (1. - + mask2[0]) * z + mask2[0] * latent_model_input # latent_model_input = latent_model_input.unsqueeze(0) latent_model_input = latent_model_input.to(get_local_torch_device()) latents = latent_model_input @@ -213,9 +210,10 @@ class DenoisingStage(PipelineStage): temporal_scale = fastvideo_args.pipeline_config.vae_config.arch_config.scale_factor_temporal spatial_scale = fastvideo_args.pipeline_config.vae_config.arch_config.scale_factor_spatial patch_size = fastvideo_args.pipeline_config.dit_config.arch_config.patch_size - seq_len = ((F - 1) // temporal_scale + 1) * ( - batch.height // spatial_scale) * (batch.width // spatial_scale) // ( - patch_size[1] * patch_size[2]) + seq_len = ((F - 1) // temporal_scale + + 1) * (batch.height // spatial_scale) * ( + batch.width // spatial_scale) // (patch_size[1] * + patch_size[2]) import math seq_len = int(math.ceil(seq_len / sp_world_size)) * sp_world_size logger.info("latents shape: %s", latents.shape) @@ -239,11 +237,14 @@ class DenoisingStage(PipelineStage): if fastvideo_args.pipeline_config.ti2v_task and batch.pil_image is not None: logger.info(f"before ti2v timestep: {t}") timestep = [t] - timestep = torch.stack(timestep).to(get_local_torch_device()) + timestep = torch.stack(timestep).to( + get_local_torch_device()) logger.info(f"mask2 shape: {mask2[0].shape}") logger.info(f"mask[0][0] shape: {mask2[0][0].shape}") - logger.info(f"mask[0][0][:, ::2, ::2] shape: {mask2[0][0][:, ::2, ::2].shape}") + logger.info( + f"mask[0][0][:, ::2, ::2] shape: {mask2[0][0][:, ::2, ::2].shape}" + ) temp_ts = (mask2[0][0][:, ::2, ::2] * timestep).flatten() logger.info(f"temp_ts: {temp_ts}") logger.info(f"temp_ts shape: {temp_ts.shape}") @@ -257,8 +258,8 @@ class DenoisingStage(PipelineStage): t = timestep # else: t_expand = t.repeat(latent_model_input.shape[0]) - logger.info(f"t_expand shape: {t_expand.shape}") - logger.info(f"t_expand: {t_expand}") + # logger.info(f"t_expand shape: {t_expand.shape}") + # logger.info(f"t_expand: {t_expand}") assert torch.isnan(latent_model_input).sum() == 0 latent_model_input = self.scheduler.scale_model_input( diff --git a/fastvideo/worker/multiproc_executor.py b/fastvideo/worker/multiproc_executor.py index 1d770d322..97bcb90cd 100644 --- a/fastvideo/worker/multiproc_executor.py +++ b/fastvideo/worker/multiproc_executor.py @@ -40,7 +40,8 @@ class MultiprocExecutor(Executor): logger.info("Using provided master port: %s", self.master_port) else: # Auto-find available port - for port in range(29503, 65535): + import random + for port in range(29503 + random.randint(0, 10000), 65535): with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: if s.connect_ex(('localhost', port)) != 0: self.master_port = port