Spaces:
Runtime error
Runtime error
IceClear commited on
Commit ·
67c0e7b
1
Parent(s): 25e6160
update
Browse filesFiles changed (2)
60 unmodified lines6162636465666768156 unmodified lines225226227226228229230231112 unmodified lines3443453463453473483473493503493503513523533543551 unmodified line3573583593583603613623632 unmodified lines36636736836736937037160 unmodified linesfrom urllib.parse import urlparsefrom torch.hub import download_url_to_file, get_dirimport shleximport uuid
os.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' output_dir = 'output/' + uuid.uuid4() + '.mp4' def _build_pos_and_neg_prompt(): # read positive prompt positive_text = "Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, \112 unmodified lines input_videos = cond_latents cond_latents = [cut_videos(video, sp_size) for video in cond_latents]
runner.dit.to("cpu") # runner.dit.to("cpu") print(f"Encoding videos: {list(map(lambda x: x.size(), cond_latents))}") runner.vae.to(torch.device("cuda")) # runner.vae.to(torch.device("cuda")) cond_latents = runner.vae_encode(cond_latents) runner.vae.to("cpu") runner.dit.to(torch.device("cuda")) # 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 line text_embeds["texts_neg"][i] = emb.to(torch.device("cuda"))
samples = generation_step(runner, text_embeds, cond_latents=cond_latents) runner.dit.to("cpu") # 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 fix input = ( rearrange(input[:, None], "c t h w -> t c h w")40 unmodified lines4142434445464728 unmodified lines76777878798081798084818283844 unmodified lines89909195969792939440 unmodified linesclass VideoDiffusionInfer(): def __init__(self, config: DictConfig): self.config = config self.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. 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): 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 lines print(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:,}")app.py+8-7
projects/video_diffusion_sr/infer.py+2-8