Latent Reasoning

March 26, 2026 · View on GitHub

Official code for the paper "Rethinking LLM Reasoning: From Explicit Trajectories to Latent Representations" (ICLR 2026).

Overview

Latent Reasoning replaces explicit Chain-of-Thought (CoT) tokens with a continuous latent trajectory generated by a lightweight reasoning network. Instead of producing long textual reasoning traces, the model:

  1. Encodes the prompt through the base LLM to obtain hidden states.
  2. A Reasoning Network (a small transformer, e.g. Qwen3-Embedding-0.6B) processes these hidden states together with learnable latent trajectory parameters to produce latent reasoning embeddings.
  3. These latent embeddings are concatenated with the prompt embeddings and fed back into the base LLM for decoding.

This achieves competitive reasoning performance while significantly reducing generation length.

Architecture

Architecture Diagram

The paper explores multiple reasoning network architectures (see modeling/reasoning_net.py):

  • MLPReasoningNet: Simple MLP-based reasoning network
  • TransformerReasoningNet: Uses a small pre-trained transformer as the reasoning backbone

The current training pipeline uses TransformerReasoningNet (see modeling/reason.py), which concatenates the full prompt hidden states with the latent trajectory before processing through the reasoning transformer, enabling richer context modeling.

Project Structure

├── sft.py                          # SFT training entry point
├── rft.py                          # RFT (GRPO) training entry point
├── modeling/
│   ├── reason.py                   # Core model: TransformerReasoningNet + LatentTransformerReasoningModel
│   └── reasoning_net.py            # Paper's original reasoning network variants (MLP, Transformer)
├── trainer/
│   └── grpo_trainer.py             # Custom GRPO trainer for latent reasoning
├── inference/
│   ├── run_inference.py            # Interactive inference script
│   └── run_inference.sh            # Inference launch script
├── utils/
│   ├── load_data.py                # Dataset loading utilities
│   └── reward_func.py              # Reward functions for RFT (accuracy, length penalty)
├── scripts/
│   ├── train_sft_1.5B.sh           # SFT training script for 1.5B model
│   ├── train_sft_7B.sh             # SFT training script for 7B model
│   ├── train_rft_1.5B.sh           # RFT training script for 1.5B model
│   └── train_rft_7B.sh             # RFT training script for 7B model
├── configs/                        # Accelerate / DeepSpeed / FSDP configs
│   ├── deepspeed_zero1.yaml
│   ├── deepspeed_zero2.yaml
│   ├── deepspeed_zero3.yaml
│   ├── single_gpu.yaml
│   ├── multi_gpu.yaml
│   └── ...
├── trl/                            # Modified TRL library
└── README.md

Quick Start

Installation

pip install -r requirements.txt

The training code supports loading datasets directly from the Hugging Face Hub. If you keep local cached or preprocessed copies under ./data/datasets, you can point the loader to that directory with LRT_DATA_ROOT=/path/to/data/datasets.

MATH-DATA is a local alias that expects a saved dataset at $LRT_DATA_ROOT/Deepseek-R1-Distill-Math-Reasoning.

SFT Training

Single-node multi-GPU training (1.5B model):

bash scripts/train_sft_1.5B.sh

Key SFT training arguments:

ArgumentDefaultDescription
--slow_thinking_model_pathdeepseek-ai/DeepSeek-R1-Distill-Qwen-1.5BBase LLM (frozen during training)
--reasoning_net_pathQwen/Qwen3-Embedding-0.6BReasoning network backbone
--latent_trajectory_length256Number of latent trajectory tokens
--dataset_nameopen-r1/OpenR1-Math-220kTraining dataset
--prompt_max_length1024Max prompt token length
--completion_max_length2048Max completion token length
--learning_rate3e-4Learning rate

RFT Training (GRPO)

After SFT, you can further improve the model with reinforcement fine-tuning using GRPO:

bash scripts/train_rft_1.5B.sh
# or
bash scripts/train_rft_7B.sh

Key RFT-specific arguments:

ArgumentDefaultDescription
--reward_metricaccuracyReward function to use
--beta0.0KL penalty coefficient (0 = no KL regularization)
--num_generations8Number of rollout generations per prompt
--temperature1.0Sampling temperature for rollout
--clip_eps_low0.2DAPO-style asymmetric clipping lower bound
--clip_eps_high0.28DAPO-style asymmetric clipping upper bound

Inference

bash inference/run_inference.sh

Datasets

The paper uses the following datasets for training:

Additional datasets supported in this codebase:

Models

The framework supports various base models and reasoning networks:

Base Models (frozen):

  • deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B
  • deepseek-ai/DeepSeek-R1-Distill-Qwen-7B

Reasoning Networks:

  • Qwen/Qwen3-Embedding-0.6B (default, recommended)

Training Pipeline

The training follows a multi-stage process:

  1. Stage 1 — Instruction Tuning (SFT): Train the reasoning network on general instruction-following data (e.g., stepfun-ai/Step-3.5-Flash-SFT). Note that the results reported in this paper do not include this training stage.
  2. Stage 2 — Math Reasoning (SFT): Fine-tune on math-specific datasets (e.g., open-r1/OpenR1-Math-220k)
  3. Stage 3 — Reinforcement Fine-Tuning (RFT): Further improve with GRPO using accuracy rewards (e.g., on BytedTsinghua-SIA/DAPO-Math-17k)

During training, only the reasoning network parameters are updated; the base LLM remains frozen.

Citation

If you find this work useful, please cite our paper:

@inproceedings{
jiang2026rethinking,
title={Rethinking LLM Reasoning: From Explicit Trajectories to Latent Representations},
author={Cong Jiang and Xiaofeng Zhang and Zheng Zhang and Fangzhi Zhu and XiaoWei Chen and Junxiong Zhu},
booktitle={The Fourteenth International Conference on Learning Representations},
year={2026},
url={https://openreview.net/forum?id=CbK7lYbmv8}
}

License

This project is released under the MIT License.