home/ atoms/ stochastic-similarity-filter

The Stochastic Similarity Filter skips GPU work probabilistically when consecutive frames are nearly identical

When a webcam or screen-capture source is nearly static, re-running the full diffusion pipeline every frame wastes GPU compute. StreamDiffusion’s Stochastic Similarity Filter (SSF) computes cosine similarity between the current input tensor and the previous one (flattened to a 1-D vector). If similarity exceeds a configurable threshold, it stochastically skips the frame: skip probability rises as similarity approaches 1.0. A max_skip_frame cap prevents indefinite skipping if the source freezes entirely. When a frame is skipped the pipeline returns the cached prev_image_result and sleeps for inference_time_ema seconds, matching output cadence. The filter reduces energy consumption by 2.39× on RTX 3060 (paper) and alleviates sustained GPU load during static moments in live performance.

Examples

stream.enable_similar_image_filter(
    similar_image_filter_threshold=0.98,  # 0.0–1.0; lower = skip more
    similar_image_filter_max_skip_frame=10,
)

With threshold=0.99 nearly identical camera feeds skip most frames; threshold=0.95 is stricter.

Assessment

Describe the mathematical criterion SSF uses to decide whether to skip a frame. Then predict what happens over time if the source is fully frozen and max_skip_frame=10.

“skip_prob = max(0, 1 - (1 - cos_sim) / (1 - self.threshold))”
corpus · streamdiffusion-pipeline-for-real-time-interactive-image-gen · chunk 53