Skip to content

laguna: windowed KV via make_cache() + strip language_model. prefix - #26

Open
pierre427 wants to merge 1 commit into
Blaizzy:pc/add-lgfrom
pierre427:pr/laguna-windowed-kv-sanitize
Open

pierre427 wants to merge 1 commit into
Blaizzy:pc/add-lgfrom
pierre427:pr/laguna-windowed-kv-sanitize

Conversation

@pierre427

Copy link
Copy Markdown

Hi @Blaizzy — the two small additions I mentioned on ml-explore#1223, as a ready-to-merge follow-up onto your branch (merging this updates the PR). Both are tested against your current pc/add-lg and black==25.1.0 clean.

1. make_cache() for the sliding-window layers. The sliding_attention layers (the majority) never attend beyond their window, so this returns a bounded RotatingKVCache(max_size=sliding_window) for them and a full KVCache only for the full_attention (global) layers. Without it, make_prompt_cache allocates a full cache on all 40 layers — storing/attending over history the sliding layers can't use. Measured ~2.7x decode and ~4 GB less KV at 32k on the 8-bit repack; bitwise-identical to a full cache at ≤ window context. Falls back to a full cache if a config omits sliding_window.

2. language_model. prefix strip in sanitize(). Some repacks (e.g. AtomicChat/Laguna-XS-2.1-MLX-8bit) wrap every tensor under a VLM-style language_model. prefix, so a stock load misses all weights. This strips it up front when present.

Verified locally: make_cache() returns the right cache type per layer_types, forward + single-step decode run with those caches, and sanitize() strips the prefix. Happy to adjust to your preferences, or drop it if you'd rather fold these in yourself.

Two small additions on top of the Laguna model:

- make_cache(): the sliding_attention layers (the majority) never attend
  beyond their window, so return a bounded RotatingKVCache(max_size=
  sliding_window) for them and a full KVCache only for the full_attention
  (global) layers. Without this, make_prompt_cache allocates a full cache on
  every layer, so long-context runs store and attend over history the sliding
  layers can't use (measured ~2.7x decode and ~4 GB less KV at 32k on the
  8-bit repack); bitwise-identical to a full cache at <= window context.

- sanitize(): strip the VLM-style `language_model.` prefix that some repacks
  (e.g. AtomicChat/Laguna-XS-2.1-MLX-8bit) put on every tensor, so a stock
  load finds the weights.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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