forked from neggles/animatediff-cli
-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
progress bar improvements #132
Open
JCBrouwer
wants to merge
1
commit into
s9roll7:main
Choose a base branch
from
JCBrouwer:better-progress-bar
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -864,21 +864,34 @@ def interpolate_latents(self, latents: torch.Tensor, interpolation_factor:int, d | |
|
||
|
||
|
||
def decode_latents(self, latents: torch.Tensor): | ||
def decode_latents(self, latents: torch.Tensor, progress_bar: tqdm = None): | ||
video_length = latents.shape[2] | ||
latents = 1 / self.vae.config.scaling_factor * latents | ||
latents = rearrange(latents, "b c f h w -> (b f) c h w") | ||
# video = self.vae.decode(latents).sample | ||
video = [] | ||
|
||
if progress_bar is not None: # if we have a progress bar, we close it (rich doesn't support multiple progress bars) | ||
task_id = progress_bar._prog.add_task('Decoding latents...', start=True, total=latents.shape[0]) | ||
remove_task = True | ||
else: | ||
progress_bar = self.progress_bar(total=latents.shape[0], desc="Decoding latents...") | ||
task_id = progress_bar._task_id | ||
remove_task = False | ||
|
||
for frame_idx in range(latents.shape[0]): | ||
video.append( | ||
self.vae.decode(latents[frame_idx : frame_idx + 1].to(self.vae.device, self.vae.dtype)).sample.cpu() | ||
) | ||
latent = latents[frame_idx : frame_idx + 1].to(self.vae.device, self.vae.dtype) | ||
video.append(self.vae.decode(latent).sample.cpu()) | ||
progress_bar._prog.update(task_id, advance=1, refresh=True) | ||
|
||
video = torch.cat(video) | ||
video = rearrange(video, "(b f) c h w -> b c f h w", f=video_length) | ||
video = (video / 2 + 0.5).clamp(0, 1) | ||
# we always cast to float32 as this does not cause significant overhead and is compatible with bfloa16 | ||
video = video.float().numpy() | ||
|
||
if remove_task: | ||
progress_bar._prog.remove_task(task_id) | ||
|
||
return video | ||
|
||
def prepare_extra_step_kwargs(self, generator, eta): | ||
|
@@ -2533,7 +2546,7 @@ def get_controlnet_variable( | |
|
||
# 7. Denoising loop | ||
num_warmup_steps = len(timesteps) - num_inference_steps * self.scheduler.order | ||
with self.progress_bar(total=total_steps) as progress_bar: | ||
with self.progress_bar(total=len(timesteps), desc="Diffusing video...") as progress_bar: | ||
for i, t in enumerate(timesteps): | ||
stopwatch_start() | ||
|
||
|
@@ -2823,7 +2836,6 @@ def sample_to_device( sample ): | |
pred = pred.to(dtype=latents.dtype, device=latents.device) | ||
noise_pred[:, :, context] = noise_pred[:, :, context] + pred | ||
counter[:, :, context] = counter[:, :, context] + 1 | ||
progress_bar.update() | ||
|
||
# perform guidance | ||
noise_size = prompt_encoder.get_condi_size() | ||
|
@@ -2842,7 +2854,7 @@ def sample_to_device( sample ): | |
): | ||
denoised = latents - noise_pred | ||
denoised = self.interpolate_latents(denoised, interpolation_factor, device) | ||
video = torch.from_numpy(self.decode_latents(denoised)) | ||
video = torch.from_numpy(self.decode_latents(denoised, progress_bar=progress_bar)) | ||
callback(i, video) | ||
|
||
# compute the previous noisy sample x_t -> x_t-1 | ||
|
@@ -2886,6 +2898,7 @@ def sample_to_device( sample ): | |
tmp_latent = None | ||
|
||
stopwatch_stop("LOOP end") | ||
progress_bar.update() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not want to change the units of progress |
||
if c_ref_enable: | ||
self.unload_controlnet_ref_only( | ||
|
@@ -2921,7 +2934,7 @@ def sample_to_device( sample ): | |
|
||
return AnimationPipelineOutput(videos=video) | ||
|
||
def progress_bar(self, iterable=None, total=None): | ||
def progress_bar(self, iterable=None, total=None, desc=None): | ||
if not hasattr(self, "_progress_bar_config"): | ||
self._progress_bar_config = {} | ||
elif not isinstance(self._progress_bar_config, dict): | ||
|
@@ -2930,9 +2943,9 @@ def progress_bar(self, iterable=None, total=None): | |
) | ||
|
||
if iterable is not None: | ||
return tqdm(iterable, **self._progress_bar_config) | ||
return tqdm(iterable, desc=desc, **self._progress_bar_config) | ||
elif total is not None: | ||
return tqdm(total=total, **self._progress_bar_config) | ||
return tqdm(total=total, desc=desc, **self._progress_bar_config) | ||
else: | ||
raise ValueError("Either `total` or `iterable` has to be defined.") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically, don't delete the logs left in the code.
Most of the time, they are still being debugged or are left to investigate behavior that could be improved.