From 1f446bc8ed7262bcd943e64df6535669059162e4 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Fri, 4 Apr 2025 08:21:29 -0400 Subject: [PATCH] progress use batch info Signed-off-by: Vladimir Mandic --- CHANGELOG.md | 7 ++++++ installer.py | 2 +- modules/processing.py | 4 ++-- modules/progress.py | 52 ++++++++++++++++++++++++++++++++++------- modules/shared_state.py | 4 ++++ wiki | 2 +- 6 files changed, 59 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4d8c91ba..e800e47ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log for SD.Next +## Update for 2025-04-04 + +- LoRA: obey configured device when performing calculations +- Video: add FasterCache and PAB support to WanDB and LTX models +- Progress: add additional fields to progress API +- Progress: use batch-count for progress + ## Update for 2025-04-03 ### Highlights for 2025-04-03 diff --git a/installer.py b/installer.py index 36c84e549..2e7ef987d 100644 --- a/installer.py +++ b/installer.py @@ -538,7 +538,7 @@ def check_diffusers(): t_start = time.time() if args.skip_all or args.skip_git or args.experimental: return - sha = 'e5c6027ef89ec1a2800c0421599da89d4820f2e4' # diffusers commit hash + sha = 'f10775b1b55cbebc58655b966b4ba3a6fc259ca3' # diffusers commit hash pkg = pkg_resources.working_set.by_key.get('diffusers', None) minor = int(pkg.version.split('.')[1] if pkg is not None else 0) cur = opts.get('diffusers_version', '') if minor > 0 else '' diff --git a/modules/processing.py b/modules/processing.py index b1a8bd548..2728903a2 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -294,14 +294,14 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed: ema_scope_context = p.sd_model.ema_scope if not shared.native else nullcontext if not shared.native: shared.state.job_count = p.n_iter + shared.state.batch_count = p.n_iter with devices.inference_context(), ema_scope_context(): t0 = time.time() if not hasattr(p, 'skip_init'): p.init(p.all_prompts, p.all_seeds, p.all_subseeds) debug(f'Processing inner: args={vars(p)}') for n in range(p.n_iter): - # if hasattr(p, 'skip_processing'): - # continue + shared.state.batch_no = n + 1 pag.apply(p) debug(f'Processing inner: iteration={n+1}/{p.n_iter}') p.iteration = n diff --git a/modules/progress.py b/modules/progress.py index 354c90032..6413e7188 100644 --- a/modules/progress.py +++ b/modules/progress.py @@ -47,44 +47,80 @@ class ProgressRequest(BaseModel): class InternalProgressResponse(BaseModel): job: str = Field(default=None, title="Job name", description="Internal job name") + textinfo: str = Field(default=None, title="Info text", description="Info text used by WebUI.") + # status fields active: bool = Field(title="Whether the task is being worked on right now") queued: bool = Field(title="Whether the task is in queue") paused: bool = Field(title="Whether the task is paused") completed: bool = Field(title="Whether the task has already finished") debug: bool = Field(title="Debug logging level") + # raw fields + step: int = Field(default=None, title="Current step", description="Current step of the task") + steps: int = Field(default=None, title="Total steps", description="Total number of steps") + batch_no: int = Field(default=None, title="Current batch", description="Current batch") + batch_count: int = Field(default=None, title="Total batches", description="Total number of batches") + # calculated fields progress: float = Field(default=None, title="Progress", description="The progress with a range of 0 to 1") eta: float = Field(default=None, title="ETA in secs") + # image fields live_preview: str = Field(default=None, title="Live preview image", description="Current live preview; a data: uri") id_live_preview: int = Field(default=None, title="Live preview image ID", description="Send this together with next request to prevent receiving same image") - textinfo: str = Field(default=None, title="Info text", description="Info text used by WebUI.") -def progressapi(req: ProgressRequest): +def api_progress(req: ProgressRequest): active = req.id_task == current_task queued = req.id_task in pending_tasks completed = req.id_task in finished_tasks paused = shared.state.paused step = max(shared.state.sampling_step, 0) steps = max(shared.state.sampling_steps, 1) - progress = round(min(1, abs(step / steps) if steps > 0 else 0), 2) + batch_no = max(shared.state.batch_no, 0) + batch_count = max(shared.state.batch_count, 0) + + current = step / steps if step > 0 and steps > 0 else 0 + batch = batch_no / batch_count if batch_no > 0 and batch_count > 0 else 1 + progress = round(min(1, current * batch), 2) + elapsed = time.time() - shared.state.time_start if shared.state.time_start is not None else 0 predicted = elapsed / progress if progress > 0 else None eta = predicted - elapsed if predicted is not None else None id_live_preview = req.id_live_preview live_preview = None + textinfo = shared.state.textinfo updated = shared.state.set_current_image() - debug_log(f'Preview: job={shared.state.job} active={active} progress={step}/{steps}/{progress} image={shared.state.current_image_sampling_step} request={id_live_preview} last={shared.state.id_live_preview} enabled={shared.opts.live_previews_enable} job={shared.state.preview_job} updated={updated} image={shared.state.current_image} elapsed={elapsed:.3f}') if not active: - return InternalProgressResponse(job=shared.state.job, active=active, queued=queued, paused=paused, completed=completed, id_live_preview=-1, debug=debug, textinfo="Queued..." if queued else "Waiting...") - if shared.opts.live_previews_enable and (shared.state.id_live_preview != id_live_preview) and (shared.state.current_image is not None): + id_live_preview = -1 + textinfo = "Queued..." if queued else "Waiting..." + + debug_log(f'Preview: job={shared.state.job} active={active} progress={step}/{steps}/{progress} image={shared.state.current_image_sampling_step} request={id_live_preview} last={shared.state.id_live_preview} enabled={shared.opts.live_previews_enable} job={shared.state.preview_job} updated={updated} image={shared.state.current_image} elapsed={elapsed:.3f}') + + if shared.opts.live_previews_enable and active and (shared.state.id_live_preview != req.id_live_preview) and (shared.state.current_image is not None): buffered = io.BytesIO() shared.state.current_image.save(buffered, format='jpeg') live_preview = f'data:image/jpeg;base64,{base64.b64encode(buffered.getvalue()).decode("ascii")}' + id_live_preview = shared.state.id_live_preview - res = InternalProgressResponse(job=shared.state.job, active=active, queued=queued, paused=paused, completed=completed, progress=progress, eta=eta, live_preview=live_preview, id_live_preview=id_live_preview, debug=debug, textinfo=shared.state.textinfo) + res = InternalProgressResponse( + job=shared.state.job, + textinfo=textinfo, + active=active, + queued=queued, + paused=paused, + completed=completed, + debug=debug, + progress=progress, + step=step, + steps=steps, + batch_no=batch_no, + batch_count=batch_count, + job_timestamp=shared.state.time_start, + eta=eta, + live_preview=live_preview, + id_live_preview=id_live_preview, + ) return res def setup_progress_api(): - shared.api.add_api_route("/internal/progress", progressapi, methods=["POST"], response_model=InternalProgressResponse) + shared.api.add_api_route("/internal/progress", api_progress, methods=["POST"], response_model=InternalProgressResponse) diff --git a/modules/shared_state.py b/modules/shared_state.py index b4c92bb65..ea4fb6433 100644 --- a/modules/shared_state.py +++ b/modules/shared_state.py @@ -19,6 +19,8 @@ class State: job = "" job_no = 0 job_count = 0 + batch_no = 0 + batch_count = 0 frame_count = 0 total_jobs = 0 job_timestamp = '0' @@ -145,6 +147,8 @@ class State: self.job = title self.job_count = 0 self.frame_count = 0 + self.batch_no = 0 + self.batch_count = 0 self.job_no = 0 self.job_timestamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S") self.paused = False diff --git a/wiki b/wiki index 9408b299f..7d2b46a48 160000 --- a/wiki +++ b/wiki @@ -1 +1 @@ -Subproject commit 9408b299fffbb8efaccae968b2ac64d9216326fb +Subproject commit 7d2b46a482d20febe8179b955ca160cc6936515f