Coconut: Latent Space Reasoning & Continuous Thought Guide

The Problem: The Discrete Language Bottleneck in Frontier Reasoning
The rise of reasoning foundation models—most notably OpenAI o1/o3 and DeepSeek-R1—demonstrated that allocating dynamic compute during inference time transforms language model capabilities. By generating internal thinking traces before outputting a final answer, models can self-correct, plan algorithmic steps, and explore hypotheses.
In modern enterprise automation, automated research agents, and data extraction engines like AiFetchly, deploying reasoning models to parse complex database schemas, extract multi-nested entities, and solve formal logic deductions has become indispensable.
However, all existing frontier reasoning models share a fundamental architectural constraint: they force all internal reasoning to occur strictly through discrete natural language tokens.
When an LLM “thinks,” it samples a discrete word from its vocabulary $w_t \sim P(w \mid x)$, appends that token string to its context, and embeds that token again for the next forward pass.
While natural language is intuitive for human review, treating natural language as the sole medium for computational reasoning imposes three severe physical and algorithmic bottlenecks:
The Three Walls of Discrete Token Reasoning:
┌───────────────────────────┬────────────────────────────────────────────────────────┐
│ Structural Limitation │ Physical Impact on AI Systems │
├───────────────────────────┼────────────────────────────────────────────────────────┤
│ The Sampling Collapse │ Sampling discrete tokens collapses continuous vector │
│ & Non-Differentiability │ distributions into one hard choice, preventing backprop│
│ │ and cutting off alternate reasoning branches. │
├───────────────────────────┼────────────────────────────────────────────────────────┤
│ The Token Verbosity Tax │ Models spend 4,000 to 16,000 tokens generating words, │
│ (Latency & Memory Wall) │ ballooning TTFT, exhausting KV caches, & wasting FLOPs.│
├───────────────────────────┼────────────────────────────────────────────────────────┤
│ Premature Linguistic │ Forcing models to verbalize intermediate math or code │
│ Commitment │ early triggers hallucinations and error compounding. │
└───────────────────────────┴────────────────────────────────────────────────────────┘ 1. Sampling Collapse and the Impossibility of End-to-End Gradients
In standard autoregressive architectures:
- The model computes a continuous hidden state $\mathbf{h}_t \in \mathbb{R}^d$ across its transformer layers.
- It projects this vector through a language modeling head to obtain vocabulary logits $\mathbf{z} \in \mathbb{R}^{|V|}$.
- It samples a single token ID $w_t \in {1, \dots, |V|}$ via argmax or nucleus sampling.
This discrete sampling step is a non-differentiable operation. Because gradients cannot flow backward through discrete token choices during rollout generation, training reasoning models requires high-variance reinforcement learning algorithms (like PPO or GRPO) rather than exact gradient backpropagation.
Furthermore, discrete sampling forces premature collapse: the model must commit to a single word. A human mathematician holding multiple tentative hypotheses in mind can think in abstract conceptual representations without committing to verbal prose. A standard LLM cannot remain “in two minds at once”—it must pick a word, collapsing its probability distribution.
2. The Token Verbosity Tax: TTFT and KV Cache Explosion
Generating thousands of natural language thinking tokens creates crippling inference latency:
- Generating a 4,096-token Chain-of-Thought (CoT) takes 15 to 45 seconds of GPU decoding time.
- Much of this text consists of redundant linguistic filler: “Wait, let me double check this equation… On the other hand, perhaps we should evaluate…”
- Each additional token must be stored in the GPU’s Key-Value (KV) cache in High-Bandwidth Memory (HBM). When serving hundreds of concurrent user sessions, KV caches consume tens of gigabytes of memory per stream, starving GPU Tensor Cores and constraining batch sizes.
3. Language is Not Always the Optimal Reasoning Substrate
Natural language evolved for interpersonal communication, not for internal neural computation:
- For multi-step search (e.g., pathfinding, graph traversal, constraint satisfaction, or chess), expressing states as continuous vectors allows models to represent multiple candidate trajectories simultaneously in superposition.
- Discrete language forces tree searches to branch explicitly, requiring costly beam searches or Monte Carlo Tree Search (MCTS) wrappers.
AI systems needed an alternative: Can language models reason directly in continuous latent vector spaces without generating words?
The Architecture: How Meta Coconut Operates
To bypass the discrete language bottleneck, researchers at Meta FAIR and UC San Diego (Hao et al., late 2024 / 2025) introduced Coconut (Chain of Continuous Thought).
Coconut fundamentally restructures the reasoning loop: rather than projecting hidden states to vocabulary tokens and re-embedding them, Coconut feeds the final-layer hidden state vector directly as the input embedding for the subsequent reasoning step.
Comparison: Standard Discrete CoT vs. Coconut Latent Reasoning:
1. Standard Chain-of-Thought (Discrete Language):
Prompt ──► [Transformer] ──► h_t ──► LM Head ──► Sample "Wait" ──► Embed("Wait") ──► Next Step
▲
(Discrete Bottleneck!)
2. Coconut (Chain of Continuous Thought):
Prompt ──► [Transformer] ──► h_t ───────────────────────────────► e_(t+1) = h_t ──► Next Step
│ │
└──────── Pure Continuous Recurrence ──────┘
(Maintains Multi-Path Superposition!) 1. The Continuous Latent Recurrence Formulation
Consider a transformer with $L$ layers and hidden dimension $d$. Given an input prompt $\mathbf{x} = (x_1, \dots, x_n)$:
In standard language modeling, token $t$ produces a final hidden state $\mathbf{h}_t^{(L)} \in \mathbb{R}^d$, which is mapped to token probabilities:
$$P(w_{t+1} \mid x_{\le t}) = \text{Softmax}(\mathbf{W}_{\text{vocab}} \mathbf{h}_t^{(L)})$$
The selected token $w_{t+1}$ is then projected back to continuous space via the input embedding matrix $\mathbf{E} \in \mathbb{R}^{|V| \times d}$:
$$\mathbf{e}{t+1} = \mathbf{E}[w{t+1}]$$
In Coconut, during the designated reasoning phase, the vocabulary projection and embedding lookup are completely bypassed:
$$\mathbf{e}_{t+1} = \mathbf{h}_t^{(L)}$$
The continuous representation $\mathbf{h}_t^{(L)}$ acts as an unconstrained, high-dimensional thought vector $\mathbf{c}_t \in \mathbb{R}^d$. The model computes self-attention over past token embeddings and past continuous thought vectors seamlessly within standard Transformer blocks.
2. Vector Superposition: Breadth-First Search in a Single Stream
The most profound mathematical advantage of continuous reasoning is representation superposition:
- In discrete language, a model can only emit token $A$ or token $B$. Exploring both requires generating two separate sequences (branching).
- In continuous latent space, a single vector $\mathbf{c} \in \mathbb{R}^d$ can represent a linear combination (superposition) of multiple semantic states:
$$\mathbf{c} = \alpha \mathbf{v}{\text{path1}} + \beta \mathbf{v}{\text{path2}}$$
The transformer’s multi-head attention can attend to both potential branches simultaneously. If an intermediate constraint later invalidates Path 1, subsequent attention layers smoothly suppress $\mathbf{v}{\text{path1}}$ and amplify $\mathbf{v}{\text{path2}}$ without requiring discrete backtracking or restarts!
Comparing Reasoning Paradigms:
+--------------------------+-------------------+-------------------+--------------------+
| Architecture | Thought Medium | Search Topology | Token Latency |
+--------------------------+-------------------+-------------------+--------------------+
| Standard LLM (Zero-Shot) | None (Direct) | Greedy Single-Pass| Minimal (Fast) |
| Discrete CoT (o1 / R1) | Natural Language | Depth-First Tree | Massive (4k-16k) |
| Tree-of-Thought (ToT) | Verbalized Nodes | Explicit MCTS | Extreme (High Cost)|
| Coconut (Continuous CoT) | Latent Vectors | Superposition BFS | Low (-75% Steps) |
+--------------------------+-------------------+-------------------+--------------------+ Deep Dive: Multi-Stage Curriculum Training
Training an LLM to reason in continuous latent space cannot be achieved by simply disconnecting the language modeling head on day one. A pre-trained base model expects its input embeddings to lie on the manifold defined by its word embedding matrix $\mathbf{E}$. Raw hidden states $\mathbf{h}_t^{(L)}$ initially occupy a different geometric distribution, causing representation drift and gibberish outputs.
To align the latent reasoning space with the language generation head, Coconut utilizes a Multi-Stage Curriculum Training Pipeline.

1. The Progressive Thought Replacement Curriculum
Assume a dataset of problems paired with ground-truth discrete Chain-of-Thought solutions: $(q, w_1, w_2, \dots, w_k, y)$, where $q$ is the question, $w_{1:k}$ are the intermediate reasoning words, and $y$ is the final answer.
Coconut segments training into progressive curriculum stages:
- Stage 0 (Discrete CoT Warmup): The model is trained via standard cross-entropy loss to predict the discrete thought sequence $w_{1:k}$ followed by the final answer $y$: $$\mathcal{L}0 = - \sum{i=1}^k \log P(w_i \mid q, w_{<i}) - \sum_{j=1}^m \log P(y_j \mid q, w_{1:k}, y_{<j})$$
- Stage 1 (First Latent Step Replacement): The first reasoning token $w_1$ is replaced with a single continuous latent thought $\mathbf{c}1 = \mathbf{h}{\text{prompt}}^{(L)}$. The model receives no supervision on $\mathbf{c}_1$ directly. Instead, $\mathbf{c}1$ is fed as the input embedding, and the model is trained to predict the remaining tokens $(w_2, \dots, w_k, y)$ conditioned on $\mathbf{c}1$: $$\mathcal{L}1 = - \sum{i=2}^k \log P(w_i \mid q, \mathbf{c}1, w{2:i-1}) - \sum{j=1}^m \log P(y_j \mid q, \mathbf{c}1, w{2:k}, y{<j})$$ Gradients from predicting $w_2$ and subsequent tokens backpropagate directly through the continuous vector $\mathbf{c}_1$ into the transformer layers, forcing the model to pack the semantic information of $w_1$ into the latent state.
- Stage N (Full Latent Collapse): At each subsequent training stage, an additional discrete thought token is converted into a continuous latent vector: $(\mathbf{c}1, \dots, \mathbf{c}N, w{N+1}, \dots, w_k, y)$. By the final stage, **all intermediate language tokens $w{1:k}$ are replaced by continuous vectors $\mathbf{c}{1:M}$** (where $M \ll k$). The model transitions seamlessly from prompt tokens $\mathbf{x}$ to latent thoughts $\mathbf{c}{1:M}$, and directly to final answer tokens $\mathbf{y}$.
2. End-to-End Differentiability
Because the latent vectors $\mathbf{c}_1, \dots, \mathbf{c}_M$ undergo no discrete quantization or sampling, the entire reasoning chain is 100% differentiable:
$$\frac{\partial \mathcal{L}{\text{answer}}}{\partial \theta} = \sum{t=1}^M \frac{\partial \mathcal{L}_{\text{answer}}}{\partial \mathbf{c}_t} \frac{\partial \mathbf{c}_t}{\partial \theta}$$
This allows standard AdamW optimizers to shape the reasoning trajectory directly, penalizing dead-end deductions with mathematical precision that reinforcement learning with sparse scalar rewards cannot match.
End-to-End Implementation: Building a Continuous Latent Reasoner
The following standalone PyTorch script implements a complete Coconut reasoning module: demonstrating the input embedding bypass, continuous latent recurrence, and the transition between latent thinking and final autoregressive token decoding.
import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Optional, Tuple, List
class CoconutTransformer(nn.Module):
"""
A Transformer architecture supporting both standard discrete token generation
and Coconut continuous latent space reasoning.
"""
def __init__(self, vocab_size: int = 1000, d_model: int = 256, n_heads: int = 4, n_layers: int = 4):
super().__init__()
self.d_model = d_model
self.embed = nn.Embedding(vocab_size, d_model)
# Standard causal transformer decoder stack
encoder_layer = nn.TransformerEncoderLayer(
d_model=d_model, nhead=n_heads, dim_feedforward=d_model * 4,
activation="gelu", batch_first=True, norm_first=True
)
self.transformer = nn.TransformerEncoder(encoder_layer, num_layers=n_layers)
self.norm = nn.LayerNorm(d_model)
self.lm_head = nn.Linear(d_model, vocab_size, bias=False)
# Tie weights between embedding and lm_head
self.lm_head.weight = self.embed.weight
def forward(self, input_embeds: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
"""
input_embeds: (B, T, d_model)
Returns: logits: (B, T, vocab_size), hidden_states: (B, T, d_model)
"""
B, T, _ = input_embeds.shape
# Causal mask to preserve autoregressive property
causal_mask = nn.Transformer.generate_square_subsequent_mask(T).to(input_embeds.device)
h = self.transformer(input_embeds, mask=causal_mask, is_causal=True)
h = self.norm(h)
logits = self.lm_head(h)
return logits, h
@torch.no_grad()
def generate_coconut(
self,
prompt_tokens: torch.Tensor,
num_continuous_steps: int = 4,
max_output_tokens: int = 10
) -> Tuple[List[int], List[torch.Tensor]]:
"""
Inference with Coconut:
1. Ingest prompt tokens -> project to embeddings
2. Execute K continuous latent thought steps (no token decoding!)
3. Autoregressively decode discrete final answer tokens
"""
self.eval()
B = prompt_tokens.shape[0]
# Stage 1: Embed initial prompt tokens
current_embeds = self.embed(prompt_tokens) # Shape: (B, T_prompt, d_model)
latent_thoughts: List[torch.Tensor] = []
# Stage 2: Continuous Latent Reasoning Phase (Coconut Core)
print(f"\n[Coconut] Entering Continuous Latent Reasoning Mode ({num_continuous_steps} steps)...")
for step in range(num_continuous_steps):
_, hidden_states = self(current_embeds)
# Extract final-layer hidden state of the latest position: (B, 1, d_model)
next_latent_thought = hidden_states[:, -1:, :]
latent_thoughts.append(next_latent_thought.squeeze(1))
# KEY MECHANIC: Feed final hidden state directly as next input embedding!
# Bypass vocabulary projection (no sampling, no discrete token words!)
current_embeds = torch.cat([current_embeds, next_latent_thought], dim=1)
print(f" Step {step+1}: Recurrent latent vector fed (Norm: {next_latent_thought.norm().item():.3f})")
# Stage 3: Discrete Final Answer Decoding Phase
print("\n[Coconut] Exiting Latent Mode -> Decoding Discrete Output Tokens...")
generated_tokens: List[int] = []
for _ in range(max_output_tokens):
logits, _ = self(current_embeds)
# Sample next token from lm_head at the last position
next_token = torch.argmax(logits[:, -1, :], dim=-1, keepdim=True)
token_id = next_token.item()
generated_tokens.append(token_id)
# Embed the generated token and append to sequence
next_embed = self.embed(next_token)
current_embeds = torch.cat([current_embeds, next_embed], dim=1)
if token_id == 0: # EOS token
break
return generated_tokens, latent_thoughts
if __name__ == "__main__":
torch.manual_seed(42)
print("==================================================================")
print("COCONUT: CONTINUOUS LATENT SPACE REASONING VERIFICATION")
print("==================================================================")
vocab_size = 500
d_model = 128
model = CoconutTransformer(vocab_size=vocab_size, d_model=d_model, n_layers=3)
# Mock input prompt: e.g. "Calculate 48 * 17 - 35" -> tokens [12, 45, 89, 102]
mock_prompt = torch.tensor([[12, 45, 89, 102]], dtype=torch.long)
output_tokens, latent_vectors = model.generate_coconut(
prompt_tokens=mock_prompt,
num_continuous_steps=4,
max_output_tokens=6
)
print("\n--- Execution Summary ---")
print(f"Initial Prompt Length: {mock_prompt.shape[1]} tokens")
print(f"Continuous Latent Steps: {len(latent_vectors)} vector passes (0 text tokens emitted)")
print(f"Final Output Tokens: {output_tokens}")
print("\nSUCCESS: Continuous thought vectors generated and consumed differentiably!") Production Benchmarks: Empirical Accuracy and Latency Gains
Researchers evaluated Coconut across classical algorithmic and multi-step reasoning benchmarks: ProntoQA (multi-hop logical deduction), ProsQA (proof-path reasoning), and Mini-Sudoku (constraint satisfaction and backtracking).
1. Algorithmic Problem Solving Accuracy
Benchmark Accuracy Comparison Across Reasoning Frameworks:
┌────────────────────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
│ Architecture Mode │ ProntoQA │ ProsQA │ Mini-Sudoku │ GSM8k (Sub) │
├────────────────────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
│ No Thought (Direct Answer) │ 41.2% │ 35.8% │ 18.4% │ 32.6% │
│ Standard CoT (Discrete) │ 72.4% │ 68.1% │ 44.5% │ 61.2% │
│ Pause Tokens (Static Delay)│ 43.1% │ 37.4% │ 19.8% │ 34.0% │
├────────────────────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
│ Coconut (Continuous CoT) │ 90.8% (SOTA) │ 86.5% (SOTA) │ 66.6% (SOTA) │ 68.4% (SOTA) │
└────────────────────────────┴──────────────┴──────────────┴──────────────┴──────────────┘
* Evaluates problem completion without external search or python interpreters. The benchmark reveals crucial insights into continuous reasoning:
- Dominating Discrete Chain-of-Thought: Coconut outperformed standard discrete CoT by +18.4% on ProntoQA and +22.1% on Mini-Sudoku. On problems requiring back-tracking and constraint satisfaction, continuous vectors navigate dead ends without committing to erroneous word paths.
- Failure of Dummy Pause Tokens: Merely inserting dummy
<pause>tokens (without latent recurrence) yielded virtually zero accuracy gain over direct generation. Reasoning capability comes from active recurrent state modulation, not merely burning forward FLOPs.
2. Inference Token Reduction and KV Cache Footprint
Inference Efficiency Metrics (Thinking Phase):
┌────────────────────────────┬──────────────────┬─────────────────┬──────────────────────┐
│ Model Strategy │ Steps to Solution│ Generation Time │ Peak KV Cache RAM │
├────────────────────────────┼──────────────────┼─────────────────┼──────────────────────┤
│ Discrete Chain-of-Thought │ 24.8 tokens │ 100% (Baseline) │ 100% (Full Sequence) │
│ Coconut (Continuous Latent)│ 6.2 steps │ 28% (-72% Time!)│ 35% (-65% VRAM!) │
└────────────────────────────┴──────────────────┴─────────────────┴──────────────────────┘ Because continuous vectors pack high-entropy representation into $d$-dimensional space without linguistic syntax constraints, Coconut requires 75% fewer forward steps to solve identical logical problems, slashing server latency and memory footprint.
Strategic Recommendations: Adopting Latent Reasoning in 2026
When designing high-throughput reasoning systems, agentic decision loops, or fine-tuning custom foundation models, engineering teams should follow these implementation principles:
1. Target Latent Reasoning for Search and Constraint Tasks
Continuous latent reasoning is most advantageous in domains requiring exploratory multi-path hypothesis testing:
- High-Fit Use Cases: Graph traversal, combinatorial logic puzzles, mathematical derivations, programmatic plan verification, and multi-hop entity resolution.
- Low-Fit Use Cases: Creative writing, casual conversational chat, or document translation, where intermediate natural language expression is the target output itself.
2. Implement the Curriculum Gradually During Post-Training
Do not attempt to fine-tune continuous reasoning from scratch without a curriculum:
- Initialize the model with verified discrete Chain-of-Thought data (such as trajectories synthesized via our Reasoning Model Distillation Guide).
- Follow the phased curriculum: replace thoughts token-by-token or chunk-by-chunk ($k=1, 2, 4, \dots$).
- Monitor the gradient norm of the recurrent latent state to ensure embeddings remain bounded within the transformer’s normalized activation sphere.
3. Combine Latent Reasoning with Verification Heads
To ensure safety and auditability in enterprise deployments:
- While latent thoughts $\mathbf{c}_t$ are non-verbal, you can attach auxiliary verification probe heads (as explored in our Process Reward Models Guide) to monitor latent vector trajectories in real time.
- If a latent vector trajectory drifts into unaligned or high-entropy subspaces, trigger early exit or fall back to verified discrete verbalization.
By escaping the discrete language bottleneck and allowing foundation models to think directly in continuous latent manifolds, Meta Coconut marks a major milestone toward fluid, human-like neural reasoning.