From ad42bf3515c916b0f19325885d190da77f27c897 Mon Sep 17 00:00:00 2001 From: forLG Date: Thu, 9 Jul 2026 08:09:20 +0000 Subject: [PATCH 1/3] fix: LingBot KV metadata typing, honor full-KV - TeleFuser provides `global_end`/`local_end_index` as `int` metadata rather than array-like values. Now LingBot KV binding read and write them as scalars, See `cacheseek/reuse/exact_prefix/telefuser_lingbot.py`. - default Lingbot checkpoint needs full KV, but `examples/exact_prefix_reuse/e2e_telefuser_lingbot.py` initalize a rolling window config. Now when `local_attn_size=-1`, the config constructor will transfer from `make_rolling_config()` to `make_full_kv_config()`. See `examples/exact_prefix_reuse/e2e_telefuser_lingbot.py`. Further improvement: use a unified config constructor in `telefuser_lingbot.py`. --- cacheseek/reuse/exact_prefix/telefuser_lingbot.py | 6 +++--- .../exact_prefix_reuse/e2e_telefuser_lingbot.py | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cacheseek/reuse/exact_prefix/telefuser_lingbot.py b/cacheseek/reuse/exact_prefix/telefuser_lingbot.py index 15def69..f66553f 100644 --- a/cacheseek/reuse/exact_prefix/telefuser_lingbot.py +++ b/cacheseek/reuse/exact_prefix/telefuser_lingbot.py @@ -222,8 +222,8 @@ def set_resume_depth(self, depth: int) -> None: rt = self._rt global_end = (depth + 1) * rt.chunk_size * rt.frame_tokens for kv in rt.self_kv_cache: - kv["global_end_index"][0] = global_end - kv["local_end_index"][0] = self._local_end_tokens + kv["global_end_index"] = global_end + kv["local_end_index"] = self._local_end_tokens class LingBotWorldKVBinding: @@ -376,7 +376,7 @@ def on_chunk_finalized( # In rolling mode this chunk's clean KV sits at the physical tail # [local_end-ct : local_end] (logical position idx*ct holds only in # full-length mode); local_end was just advanced by the clean rewrite. - e = int(kv["local_end_index"][0]) + e = int(kv["local_end_index"]) s = e - ct payload.append( ( diff --git a/examples/exact_prefix_reuse/e2e_telefuser_lingbot.py b/examples/exact_prefix_reuse/e2e_telefuser_lingbot.py index 6cfbe8c..81e249a 100644 --- a/examples/exact_prefix_reuse/e2e_telefuser_lingbot.py +++ b/examples/exact_prefix_reuse/e2e_telefuser_lingbot.py @@ -69,6 +69,7 @@ from cacheseek.reuse.exact_prefix import NamespaceForest, WorldKVManager from cacheseek.reuse.exact_prefix.telefuser_lingbot import ( LingBotWorldKVBinding, + make_full_kv_config, make_rolling_config, ) from cacheseek.stores import InMemoryTierStore @@ -244,9 +245,19 @@ def make_store(): def fresh_stack(): forest = NamespaceForest() + if cfg.local_attn_size == -1: + world_kv_cfg = make_full_kv_config(break_even_k=1) + else: + world_kv_cfg = make_rolling_config( + local_attn_size=cfg.local_attn_size, + sink_size=cfg.sink_size, + chunk_size=3, + break_even_k=1 + ) + mgr = WorldKVManager( forest, shared_store, - make_rolling_config(local_attn_size=cfg.local_attn_size, sink_size=cfg.sink_size, chunk_size=3), + world_kv_cfg ) return forest, mgr From 5db34dfd6101781985db044134744300ea4775e6 Mon Sep 17 00:00:00 2001 From: forLG Date: Thu, 9 Jul 2026 09:07:28 +0000 Subject: [PATCH 2/3] refactor: merge redundant funtions into single one see `cacheseek/reuse/exact_reuse/telefuser_lingbot.py`, remove `make_rolling_config` and `make_full_kv_config`, add `make_world_kv_config` to unify them. --- .../reuse/exact_prefix/telefuser_lingbot.py | 37 ++++++++++++------- .../e2e_telefuser_lingbot.py | 19 +++------- tests/test_world_kv_telefuser_binding.py | 4 +- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/cacheseek/reuse/exact_prefix/telefuser_lingbot.py b/cacheseek/reuse/exact_prefix/telefuser_lingbot.py index f66553f..9a38205 100644 --- a/cacheseek/reuse/exact_prefix/telefuser_lingbot.py +++ b/cacheseek/reuse/exact_prefix/telefuser_lingbot.py @@ -50,27 +50,36 @@ from .types import ActionKey -def make_full_kv_config(*, break_even_k: int = 1) -> WorldKVConfig: - """Full-length KV (local_attn_size=-1) => materialization needs the entire - prefix.""" - return WorldKVConfig( - window_chunks=1_000_000, sink_chunks=1, break_even_k=break_even_k - ) - - -def make_rolling_config( +def make_world_kv_config( *, local_attn_size: int = 7, # latent frames, incl. sink (matches TeleFuser pipeline config) sink_size: int = 3, # latent frames chunk_size: int = 3, # latent frames per chunk break_even_k: int = 1, ) -> WorldKVConfig: - """Rolling window: materialization needs only the sink chunk plus the chunks - covering the most recent (L-S) frames -- O(W) rather than O(K).""" - recent_frames = max(local_attn_size - sink_size, 1) + """Build WorldKVConfig from TeleFuser LingBot KV geometry. + + Uses local_attn_size=-1 for full-length KV. Positive values for + rolling KV. + + Rolling window: materialization needs only the sink chunk plus the chunks + covering the most recent (L-S) frames -- O(W) rather than O(K). + """ + if local_attn_size == -1: + window_chunks = 1_000_000 + sink_chunks = 1 + elif local_attn_size > 0: + recent_frames = max(local_attn_size - sink_size, 1) + + window_chunks=-(-recent_frames // chunk_size) # ceil + sink_chunks=-(-sink_size // chunk_size) + else: + raise ValueError(f"local_attn_size must be -1 for full KV and positive " + f"for rolling, got {local_attn_size}") + return WorldKVConfig( - window_chunks=-(-recent_frames // chunk_size), # ceil - sink_chunks=-(-sink_size // chunk_size), + window_chunks=window_chunks, + sink_chunks=sink_chunks, break_even_k=break_even_k, ) diff --git a/examples/exact_prefix_reuse/e2e_telefuser_lingbot.py b/examples/exact_prefix_reuse/e2e_telefuser_lingbot.py index 81e249a..76318df 100644 --- a/examples/exact_prefix_reuse/e2e_telefuser_lingbot.py +++ b/examples/exact_prefix_reuse/e2e_telefuser_lingbot.py @@ -69,8 +69,7 @@ from cacheseek.reuse.exact_prefix import NamespaceForest, WorldKVManager from cacheseek.reuse.exact_prefix.telefuser_lingbot import ( LingBotWorldKVBinding, - make_full_kv_config, - make_rolling_config, + make_world_kv_config, ) from cacheseek.stores import InMemoryTierStore @@ -245,19 +244,13 @@ def make_store(): def fresh_stack(): forest = NamespaceForest() - if cfg.local_attn_size == -1: - world_kv_cfg = make_full_kv_config(break_even_k=1) - else: - world_kv_cfg = make_rolling_config( - local_attn_size=cfg.local_attn_size, - sink_size=cfg.sink_size, - chunk_size=3, - break_even_k=1 - ) - mgr = WorldKVManager( forest, shared_store, - world_kv_cfg + make_world_kv_config( + local_attn_size=cfg.local_attn_size, + sink_size=cfg.sink_size, + chunk_size=3 + ), ) return forest, mgr diff --git a/tests/test_world_kv_telefuser_binding.py b/tests/test_world_kv_telefuser_binding.py index b9bd011..aa3e84a 100644 --- a/tests/test_world_kv_telefuser_binding.py +++ b/tests/test_world_kv_telefuser_binding.py @@ -29,7 +29,7 @@ ) from cacheseek.reuse.exact_prefix.telefuser_lingbot import ( # noqa: E402 LingBotWorldKVBinding, - make_rolling_config, + make_world_kv_config, ) # Tiny geometry: chunk=3 frames, frame_tokens=2; window L=7 frames including @@ -159,7 +159,7 @@ def run_session(binding, runtime, session, *, snapshots: list | None = None): def make_stack(): forest = NamespaceForest() - cfg = make_rolling_config(local_attn_size=LOCAL_ATTN, sink_size=SINK, chunk_size=CHUNK_FRAMES) + cfg = make_world_kv_config(local_attn_size=LOCAL_ATTN, sink_size=SINK, chunk_size=CHUNK_FRAMES) return forest, WorldKVManager(forest, InMemoryTierStore(), cfg) From bb359db2becfa8ed6068e36cf8737baae903b2f0 Mon Sep 17 00:00:00 2001 From: forLG Date: Wed, 15 Jul 2026 05:52:40 +0000 Subject: [PATCH 3/3] fix(exact-reuse): assign `sample_shift=10` in SessionConfig for better generation quality. --- examples/exact_prefix_reuse/e2e_telefuser_lingbot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/exact_prefix_reuse/e2e_telefuser_lingbot.py b/examples/exact_prefix_reuse/e2e_telefuser_lingbot.py index 76318df..c84b8b6 100644 --- a/examples/exact_prefix_reuse/e2e_telefuser_lingbot.py +++ b/examples/exact_prefix_reuse/e2e_telefuser_lingbot.py @@ -147,6 +147,7 @@ def run_request(pipeline, binding, frame_num: int, poses, intrinsics, *, image_p control_mode="cam", frame_num=frame_num, seed=SEED, + sammple_shift=10, # better generation quality poses=poses, intrinsics=intrinsics, world_kv_binding=binding,