Skip to content
Back to skills

Sleep Like Consolidation Llm

ASecurity

Sleep-like consolidation mechanism for LLMs that converts recent context into persistent fast weights before clearing KV cache, enabling long-horizon reasoning with preserved inference latency.

  • 3 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 11, 2026
code-qualitypythongoperformance

Works with

  • cli

Security analysis

A100/100

Scanned September 11, 2026

npx -y skills add hiyenwong/ai_collection --skill sleep-like-consolidation-llm --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Sleep Like Consolidation Llm?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Sleep Like Consolidation Llm
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hiyenwong-sleep-like-consolidation-llm/badge)](https://www.skillsdirectory.com/skills/hiyenwong-sleep-like-consolidation-llm)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: sleep-like-consolidation-llm
category: ai_collection
version: 1.0
created: 2026-05-26
source: arXiv:2605.26099
authors: Sangyun Lee, Sean McLeish, Tom Goldstein, Giulia Fanti
description: Sleep-like consolidation mechanism for LLMs that converts recent context into persistent fast weights before clearing KV cache, enabling long-horizon reasoning with preserved inference latency.
tags: [llm, memory, consolidation, fast-weights, ssm, context-length, sleep]
activation: sleep consolidation, fast weights, context compression, state-space model, SSM, long context, offline processing, memory management, recurrent passes, cache clearing
---

# Sleep-Like Consolidation for LLMs

## Overview

Methodology from arXiv:2605.26099 (May 2026). Transformer-based LLMs suffer from poor context length scaling due to attention mechanism's O(n²) complexity. This paper introduces a **sleep-like consolidation mechanism** that periodically converts recent context into persistent fast weights before clearing the KV cache.

## Core Mechanism

### 1. Wake Phase
- Model processes input tokens normally with attention + SSM blocks
- Context accumulates in KV cache as usual
- No additional computation overhead during inference

### 2. Sleep Phase (Triggered When)
- KV cache reaches a predefined threshold (e.g., 80% capacity)
- Or periodically after N tokens processed
- Model performs **N offline recurrent passes** over accumulated context
- Updates **fast weights** in state-space model (SSM) blocks via learned local rule
- KV cache is cleared after consolidation

### 3. Inference After Sleep
- Fast weights carry consolidated knowledge from past context
- Wake-time prediction latency is preserved
- Model can handle effectively unlimited context by cycling sleep/wake

## Key Findings

- **Increasing sleep duration N improves performance**
- Largest gains on examples requiring **deeper reasoning**
- Regular transformers and SSM-attention hybrids **fail** on multi-hop graph retrieval and math reasoning tasks that this method solves
- Works on controlled synthetic tasks (cellular automata, multi-hop graph retrieval) and realistic math reasoning

## Implementation Patterns

### Pattern 1: Fast Weight Update Rule
```
For each sleep pass k = 1..N:
  For each position i in context:
    h_i^{k+1} = h_i^k + η · ∇_fast_weights L(context, h_i^k)
  Fast weights W_fast ← update(W_fast, {h_i^N})
```

### Pattern 2: KV Cache Management
```python
if len(kv_cache) > threshold:
    # Enter sleep phase
    for _ in range(num_sleep_passes):
        fast_weights = recurrent_pass(context, fast_weights, local_rule)
    kv_cache.clear()
    # Resume inference with consolidated fast weights
```

### Pattern 3: Hybrid Attention-SSM Architecture
- Use attention for immediate context (wake phase)
- Use SSM with fast weights for long-term memory (consolidated)
- Shift computation to offline sleep to preserve inference latency

## When to Apply

- **Trigger words**: context length, KV cache, long-horizon tasks, memory compression, sleep consolidation, fast weights
- **Use cases**: Long-context LLM serving, agentic workflows, multi-step reasoning tasks
- **Benefits**: O(1) memory growth with context, preserved inference latency, improved deep reasoning

## Pitfalls

- Sleep phase requires careful tuning of N (number of passes) — too few loses information, too many wastes compute
- Fast weight update rule must be learned during pre-training, not added post-hoc
- Works best with SSM-attention hybrid architectures, not pure transformers
- Consolidation quality depends on the learned local rule — must be trained on diverse tasks

## Related Concepts

- Hebbian learning (biological inspiration for fast weight updates)
- Compressive transformers (alternative context compression)
- State-space models (SSMs like Mamba, RWKV)
- Working memory consolidation in neuroscience

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…