**Source:** arXiv:2412.01885
Scanned 9/11/2026
Install to Claude Code
npx -y skills add hiyenwong/ai_collection --skill reasoning-memory-llm --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Reasoning Memory Llm?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hiyenwong-reasoning-memory-llm)More formats (shields.io, HTML) on the badges page.
---
name: reasoning-memory-in-llms-optimizing-sampling-infer
description: **Source:** arXiv:2412.01885
---
# Reasoning Memory in LLMs: Optimizing Sampling Inference
**Source:** arXiv:2412.01885
**Utility:** 0.93
**Created:** 2026-03-25
## Activation Keywords
- reasoning memory
- LLM sampling optimization
- KV cache reasoning
- inference time optimization
- tree-structured reasoning
- memory-efficient reasoning
## Description
A memory optimization technique for LLM reasoning that reduces memory consumption during sampling-based inference (tree search, beam search) by identifying and pruning unreachable branches using reachability analysis.
## Core Methodology
### 1. Problem: Memory Explosion in Sampling Inference
**Challenge:**
- Tree search methods (MCTS, ToT) maintain multiple reasoning paths
- KV cache grows linearly with number of branches
- Limits depth and breadth of reasoning
**Solution:** Identify and prune unreachable states using reachability analysis
### 2. Key Insight
**Observation:** During tree search, many branches become unreachable due to:
- Pruning by search algorithm
- Dead ends from failed reasoning
- Completed branches
**Memory can be recovered by detecting and removing unreachable KV cache entries**
### 3. Reachability Analysis
**Algorithm:**
1. Maintain a "live set" of currently active reasoning paths
2. For each path, track which KV cache entries are needed
3. Identify entries not in any live path
4. Safely evict unreachable entries
### 4. Integration with Search Algorithms
- Works with any tree-structured reasoning method
- Minimal overhead
- Maintains correctness guarantees
## Implementation Framework
```python
# Conceptual implementation
class ReasoningMemoryManager:
"""
Manages KV cache memory during tree-structured reasoning
"""
def __init__(self, model, max_memory_gb):
self.model = model
self.max_memory = max_memory_gb * 1e9
self.kv_cache = {}
self.live_paths = set()
self.path_to_kv_entries = {}
def add_path(self, path_id, kv_entries):
"""
Add a new reasoning path with its KV cache entries
Args:
path_id: Unique identifier for this reasoning path
kv_entries: Set of KV cache entry IDs this path uses
"""
self.live_paths.add(path_id)
self.path_to_kv_entries[path_id] = kv_entries
# Mark entries as in-use
for entry_id in kv_entries:
if entry_id not in self.kv_cache:
self.kv_cache[entry_id] = self._allocate_entry(entry_id)
def remove_path(self, path_id):
"""
Remove a completed/pruned path
Does NOT immediately free memory (may be needed by other paths)
"""
self.live_paths.discard(path_id)
def compute_reachable_entries(self):
"""
Compute which KV entries are reachable from live paths
"""
reachable = set()
for path_id in self.live_paths:
reachable.update(self.path_to_kv_entries.get(path_id, set()))
return reachable
def evict_unreachable(self):
"""
Remove KV cache entries not reachable from any live path
Returns number of entries evicted
"""
reachable = self.compute_reachable_entries()
all_entries = set(self.kv_cache.keys())
unreachable = all_entries - reachable
for entry_id in unreachable:
del self.kv_cache[entry_id]
return len(unreachable)
def get_memory_usage(self):
"""Current memory usage in bytes"""
return sum(entry.size for entry in self.kv_cache.values())
def check_and_evict(self):
"""
Check memory and evict if needed
"""
if self.get_memory_usage() > self.max_memory:
evicted = self.evict_unreachable()
return evicted
return 0
class TreeSearchWithMemory:
"""
Tree search with automatic memory management
"""
def __init__(self, model, memory_budget_gb=4):
self.memory_manager = ReasoningMemoryManager(model, memory_budget_gb)
self.path_counter = 0
def expand_node(self, parent_path_id, action):
"""
Expand a node in the search tree
Returns new path_id
"""
# Generate new KV entries
new_kv_entries = self._generate_kv_entries(parent_path_id, action)
# Register new path
new_path_id = self.path_counter
self.path_counter += 1
# Add to memory manager
self.memory_manager.add_path(new_path_id, new_kv_entries)
# Check memory and evict if needed
self.memory_manager.check_and_evict()
return new_path_id
def prune_branch(self, path_id):
"""
Prune a branch from search
"""
self.memory_manager.remove_path(path_id)
# Memory will be recovered on next eviction check
```
## Applications
### 1. Tree of Thoughts (ToT)
- Enables deeper reasoning trees
- More parallel branches within memory budget
### 2. Monte Carlo Tree Search (MCTS)
- More rollouts within memory budget
- Better exploration
### 3. Beam Search
- Larger beam widths
- Better quality outputs
## Performance Benefits
| Metric | Without Optimization | With Optimization |
|--------|---------------------|------------------|
| Memory usage | Linear in tree size | Bounded by live paths |
| Tree depth | Limited by memory | Can go deeper |
| Branching factor | Limited | Can explore more |
| Memory reduction | - | Up to 50% |
## When to Use
- Tree-structured reasoning methods
- When memory limits reasoning depth/breadth
- Long reasoning chains
- Multiple parallel reasoning paths
## Tools Used
- `read` - Read documentation and references
- `web_search` - Search for related information
- `web_fetch` - Fetch paper or documentation
## Instructions for Agents
Follow these steps when applying this skill:
### Step 1: Understand the Request
### Step 2: Search for Information
### Step 3: Apply the Framework
### Step 4: Provide Results
### Step 5: Verify Accuracy
### When to Apply
- Tree-structured reasoning methods
- When memory limits reasoning depth/breadth
- Long reasoning chains
## Examples
### Example 1: Basic Application
**User:** I need to apply Reasoning Memory in LLMs: Optimizing Sampling Inference to my analysis.
**Agent:** I'll help you apply reasoning-memory-llm. First, let me understand your specific use case...
**Context:** Problem: Memory Explosion in Sampling Inference
### Example 2: Advanced Scenario
**User:** Tree-structured reasoning methods
**Agent:** Based on the methodology, I'll guide you through the advanced application...
### Example 2: Advanced Application
**User:** What are the key considerations for reasoning-memory-llm?
**Agent:** Let me search for the latest research and best practices...
## Related Skills
- `llm-kv-cache-compression` - KV cache compression techniques
- `tree-of-thoughts` - ToT reasoning framework
- `monte-carlo-tree-search` - MCTS for reasoning
## References
- Chen et al. "Reasoning Memory: Enabling Efficient Tree-Structured Reasoning with Memory Management." arXiv:2412.01885 (2024)
- Tree of Thoughts framework
- KV cache management in transformersIs this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!