Spaces:
Runtime error
Runtime error
IceClear commited on
Commit ·
67c0e7b
1
Parent(s): 25e6160
update
Browse filesFiles changed (2)
60 unmodified lines616263646566156 unmodified lines223224225226227228229112 unmodified lines3423433443453463473483493503513523531 unmodified line3553563573583593603612 unmodified lines36436536636736836937060 unmodified linesfrom urllib.parse import urlparsefrom torch.hub import download_url_to_file, get_dirimport shlexos.environ["MASTER_ADDR"] = "127.0.0.1"os.environ["MASTER_PORT"] = "12355"156 unmodified lines@spaces.GPU(duration=120)def generation_loop(video_path='./test_videos', seed=666, fps_out=12, batch_size=1, cfg_scale=1.0, cfg_rescale=0.0, sample_steps=1, res_h=1280, res_w=720, sp_size=1):runner = configure_runner(1)output_dir = 'output/out.mp4'def _build_pos_and_neg_prompt():# read positive promptpositive_text = "Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, \112 unmodified linesinput_videos = cond_latentscond_latents = [cut_videos(video, sp_size) for video in cond_latents]runner.dit.to("cpu")print(f"Encoding videos: {list(map(lambda x: x.size(), cond_latents))}")runner.vae.to(torch.device("cuda"))cond_latents = runner.vae_encode(cond_latents)runner.vae.to("cpu")runner.dit.to(torch.device("cuda"))for i, emb in enumerate(text_embeds["texts_pos"]):text_embeds["texts_pos"][i] = emb.to(torch.device("cuda"))1 unmodified linetext_embeds["texts_neg"][i] = emb.to(torch.device("cuda"))samples = generation_step(runner, text_embeds, cond_latents=cond_latents)runner.dit.to("cpu")del cond_latents# dump samples to the output directory2 unmodified lines):if ori_length < sample.shape[0]:sample = sample[:ori_length]filename = os.path.join(tgt_path, os.path.basename(path))# color fixinput = (rearrange(input[:, None], "c t h w -> t c h w")60 unmodified lines6162636465666768156 unmodified lines225226227228229230231112 unmodified lines3443453463473483493503513523533543551 unmodified line3573583593603613623632 unmodified lines36636736836937037160 unmodified linesfrom urllib.parse import urlparsefrom torch.hub import download_url_to_file, get_dirimport shleximport uuidos.environ["MASTER_ADDR"] = "127.0.0.1"os.environ["MASTER_PORT"] = "12355"156 unmodified lines@spaces.GPU(duration=120)def generation_loop(video_path='./test_videos', seed=666, fps_out=12, batch_size=1, cfg_scale=1.0, cfg_rescale=0.0, sample_steps=1, res_h=1280, res_w=720, sp_size=1):runner = configure_runner(1)output_dir = 'output/' + uuid.uuid4() + '.mp4'def _build_pos_and_neg_prompt():# read positive promptpositive_text = "Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, \112 unmodified linesinput_videos = cond_latentscond_latents = [cut_videos(video, sp_size) for video in cond_latents]# runner.dit.to("cpu")print(f"Encoding videos: {list(map(lambda x: x.size(), cond_latents))}")# runner.vae.to(torch.device("cuda"))cond_latents = runner.vae_encode(cond_latents)# runner.vae.to("cpu")# runner.dit.to(torch.device("cuda"))for i, emb in enumerate(text_embeds["texts_pos"]):text_embeds["texts_pos"][i] = emb.to(torch.device("cuda"))1 unmodified linetext_embeds["texts_neg"][i] = emb.to(torch.device("cuda"))samples = generation_step(runner, text_embeds, cond_latents=cond_latents)# runner.dit.to("cpu")del cond_latents# dump samples to the output directory2 unmodified lines):if ori_length < sample.shape[0]:sample = sample[:ori_length]# color fixinput = (rearrange(input[:, None], "c t h w -> t c h w")
40 unmodified lines41424344454628 unmodified lines757677787980818283848586874 unmodified lines929394959697989910040 unmodified linesclass VideoDiffusionInfer():def __init__(self, config: DictConfig):self.config = configdef get_condition(self, latent: Tensor, latent_blur: Tensor, task: str) -> Tensor:t, h, w, c = latent.shape28 unmodified lines# For fast init & resume,# when training from scratch, rank0 init DiT on cpu, then sync to other ranks with FSDP.# otherwise, all ranks init DiT on meta device, then load_state_dict with assign=True.if self.config.dit.get("init_with_meta_device", False):init_device = "cpu" if get_global_rank() == 0 and checkpoint is None else "meta"else:init_device = "cpu"# Create dit model.with torch.device(init_device):self.dit = create_object(self.config.dit.model)self.dit.set_gradient_checkpointing(self.config.dit.gradient_checkpoint)4 unmodified linesprint(f"Loading info: {loading_info}")self.dit = meta_non_persistent_buffer_init_fn(self.dit)if device in [get_device(), "cuda"]:self.dit.to(get_device())# Print model size.num_params = sum(p.numel() for p in self.dit.parameters() if p.requires_grad)print(f"DiT trainable parameters: {num_params:,}")40 unmodified lines4142434445464728 unmodified lines7677787980818283844 unmodified lines89909192939440 unmodified linesclass VideoDiffusionInfer():def __init__(self, config: DictConfig):self.config = configself.device = "cuda" if torch.cuda.is_available() else "cpu"def get_condition(self, latent: Tensor, latent_blur: Tensor, task: str) -> Tensor:t, h, w, c = latent.shape28 unmodified lines# For fast init & resume,# when training from scratch, rank0 init DiT on cpu, then sync to other ranks with FSDP.# otherwise, all ranks init DiT on meta device, then load_state_dict with assign=True.# Create dit model.with torch.device(self.device):self.dit = create_object(self.config.dit.model)self.dit.set_gradient_checkpointing(self.config.dit.gradient_checkpoint)4 unmodified linesprint(f"Loading info: {loading_info}")self.dit = meta_non_persistent_buffer_init_fn(self.dit)# Print model size.num_params = sum(p.numel() for p in self.dit.parameters() if p.requires_grad)print(f"DiT trainable parameters: {num_params:,}")
app.py+8-7
projects/video_diffusion_sr/infer.py+2-8