From d9f8e0d758351963585328d3cf9b26f8b33425eb Mon Sep 17 00:00:00 2001 From: "Tessa (livepeer-tessa)" Date: Sun, 12 Apr 2026 18:21:15 +0000 Subject: [PATCH] fix(longlive): add logger + warning when KV cache write is skipped (#921) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `if write_len > 0` guards in `CausalWanSelfAttention.forward()` already prevent the RuntimeError (empty tensor slice when write_start_index == local_end_index), but the skip was silent, making it impossible to diagnose cache-state drift from Grafana logs. Changes: - Add `import logging` and `logger = logging.getLogger(__name__)` - Add `else: logger.warning(...)` branch on both the roll_and_insert and direct_insert write paths so that stale-index events are surfaced as WARNING-level log entries (rather than ~310 silent skips/session) The WARNING includes write_start_index, local_end_index, and a reference to #921 to aid future investigation of cache index drift after rapid video↔text mode transitions. Fixes daydreamlive/scope#921 Signed-off-by: Tessa (livepeer-tessa) --- .../longlive/modules/causal_model.py | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/scope/core/pipelines/longlive/modules/causal_model.py b/src/scope/core/pipelines/longlive/modules/causal_model.py index 8607855bc..96e731484 100644 --- a/src/scope/core/pipelines/longlive/modules/causal_model.py +++ b/src/scope/core/pipelines/longlive/modules/causal_model.py @@ -1,5 +1,6 @@ # Modified from https://github.com/NVlabs/LongLive # SPDX-License-Identifier: CC-BY-NC-SA-4.0 +import logging import math import torch @@ -13,6 +14,7 @@ ) from scope.core.pipelines.wan2_1.modules.attention import attention + from .model import ( WAN_CROSSATTENTION_CLASSES, MLPProj, @@ -30,6 +32,8 @@ flex_attention, dynamic=False, mode="max-autotune-no-cudagraphs" ) +logger = logging.getLogger(__name__) + def causal_rope_apply(x, grid_sizes, freqs, start_frame=0): n, c = x.size(2), x.size(3) // 2 @@ -331,6 +335,15 @@ def qkv_fn(x): temp_v[:, write_start_index:local_end_index] = v[ :, roped_offset : roped_offset + write_len ] + else: + logger.warning( + "KV cache write skipped (roll_and_insert): " + "write_start_index (%d) >= local_end_index (%d) — " + "cache indices may be stale after a rapid mode transition. " + "(See daydreamlive/scope#921)", + write_start_index, + local_end_index, + ) # Save cache update info for later use cache_update_info = { @@ -377,6 +390,15 @@ def qkv_fn(x): temp_v[:, write_start_index:local_end_index] = v[ :, roped_offset : roped_offset + write_len ] + else: + logger.warning( + "KV cache write skipped (direct_insert): " + "write_start_index (%d) >= local_end_index (%d) — " + "cache indices may be stale after a rapid mode transition. " + "(See daydreamlive/scope#921)", + write_start_index, + local_end_index, + ) # Save cache update info for later use cache_update_info = {