Skip to content

perf(control): cache upscaled cond_hint across sliding context steps - #259

Open
neverbiasu wants to merge 1 commit into
Kosinkadink:mainfrom
neverbiasu:perf/cache-cond-hint-sliding-context
Open

perf(control): cache upscaled cond_hint across sliding context steps#259
neverbiasu wants to merge 1 commit into
Kosinkadink:mainfrom
neverbiasu:perf/cache-cond-hint-sliding-context

Conversation

@neverbiasu

Copy link
Copy Markdown

Description

  • Cache upscaled cond_hint tensor in ControlNetAdvanced
  • Slice sub_idxs directly from cached tensor during sliding context steps
  • Add guarded cache invalidation (check reference, shape, device, dtype)
  • Explicitly release cached tensor in cleanup_advanced()
  • Verify exact tensor parity and run test suite

Fixes the TODO in adv_control/control.py (L66).

Previously, sliding_get_control re-ran common_upscale (tensor interpolation) on every single sampling step whenever sub_idxs was present. For video or AnimateDiff workflows, this meant tens of redundant upscale calls on identical input tensors.

This PR caches the full upscaled tensor in self._cached_cond_hint. During sliding context steps, self.cond_hint is sliced directly via _cached_cond_hint[sub_idxs].

Cache invalidation handles changes to cond_hint_original identity, batch size, spatial latent size, device, or dtype.

Verification

  • Tests: python -m unittest discover -s tests (16/16 passed).
  • Benchmark: Upscale calls reduced from 40 down to 1 across a 20-step 2-window sampling run.
  • Parity: Tensor outputs are bitwise identical (diff = 0.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant