Coconut trains in stages, and checkpoints are selected manually
Training Large Language Model to Reason in a Continuous Latent Space
At a glance
- What is it?
- Coconut is the MIT licensed reference implementation for training a language model to reason in a continuous latent space rather than in text, from Facebook Research. Everything about a run lives in a YAML config, and reproducing the published GSM8K results takes four A100 80GB GPUs and a staged training sequence.
- Who is it for?
- Coconut is worth reading if you are experimenting with reasoning that does not emit text, and it is not a drop-in training script: the default configuration assumes four A100 80GB GPUs, a Weights and Biases login before any run, and a two-phase sequence in which a chain of thought checkpoint is selected manually as the initialisation for the Coconut stage.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 129 days ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 6, 2026, and from our analysis. They are not legal advice.
Star history
- facebookresearch/coconut1,743 ★ · +18
| Repository | 2026-10-16 | 2026-11-06 |
|---|---|---|
| facebookresearch/coconut | 1.7k | 1.7k |
18 Stars in the last 21 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
A four-GPU assumption baked into every command
The reproduction instructions state their hardware assumption up front: all commands assume four A100 GPUs with 80GB each, and the README says you may change batch_size_training, gradient_accumulation_steps and nproc_per_node in the config to adapt to your resources. That is an honest warning rather than a hidden default.
Training runs through torchrun, and the pattern repeats for every experiment in the README. The stage 0 chain of thought run on GSM8K is a four process launch of run.py against args/gsm_cot.yaml, and the same shape is used for Coconut training and for evaluation. The only difference between runs is the YAML file and, sometimes, a checkpoint path edited into it.
Setup is conda plus pip. The environment is created with Python 3.12, and the requirements file pins exact versions rather than ranges:
conda create --name coconut python=3.12
conda activate coconut
pip install -r requirements.txtThe pinned set is torch 2.5.1, transformers 4.46.2, datasets 3.1.0, wandb 0.18.7, numpy 2.1.3 and tqdm 4.67.0.
wandb is not optional, unless you set debug
The README states that the code relies on wandb for logging and asks you to log in to your wandb account before running any experiments. There is no offline mode documented and no alternative logger.
The escape hatch is the debug flag in the config, and it is a genuine dry run rather than a logging change. If debug is true, there is no wandb and no model saving, and a subset of the data is used. That is the setting to use for checking that your data file parses and your model identifier loads before committing four GPUs to a run.
The rest of the general settings are straightforward. project names the wandb project, save_path is where checkpoints go, and only_eval loads a model and tests on the data from val_path instead of training. The README is careful about only_eval: it must be used together with load_model_path, otherwise there is nothing to load.
The model itself comes from a Huggingface identifier, with openai-community/gpt2 given as the example, which is the quickest way to confirm your setup end to end.
The method argument selects the experiment, not the model
One field decides which of four experiments you are running, and misreading it costs a full training run.
Setting coconut trains the Coconut model. Setting cot trains a chain of thought model, which is the baseline and, as the reproduction steps make clear, stage 0 of the Coconut training rather than an unrelated experiment. Setting no_thoughts trains a Coconut model without thoughts, and no_cot trains a no chain of thought model. The four together form the ablation set that a paper needs, which is why they are one argument rather than four scripts.
The training shape is governed by three fields. c_thought is the number of continuous thoughts per reasoning step. epochs_per_stage is how many epochs each stage gets. max_latent_stage is the maximum number of training stages in addition to the initial one, and pad_latent_to_max decides whether the number of continuous thoughts is padded when the reasoning steps run out before the current stage index.
Two flags change experiment character rather than performance. uniform_prob is the probability of mixing in data from other stages, set to 0 for the standard experiment and 0.3 for the analysis experiment. save_only_improve keeps only the best validation accuracy checkpoint, and the README recommends setting it to False for Coconut training because otherwise the checkpoints in the last stage might not get saved.
The evaluation checkpoint is chosen by hand, not by the script
The reproduction workflow is where the practical friction lives, and it is a three step loop repeated for every dataset.
For GSM8K you preprocess first with bash preprocessing/gsm_icot.bash, then train a chain of thought model, then pick a checkpoint as the initialisation for Coconut. The README gives the selection criterion as a validation accuracy around 40 percent, which tells you whether your stage 0 run reproduced correctly before you build on it. You then replace load_model_path in args/gsm_coconut.yaml with that checkpoint and run the Coconut config.
Then evaluation repeats the pattern. Find the checkpoint with the best validation accuracy, put its path into load_model_path in args/gsm_coconut_eval.yaml, and run that file. Nothing in the pipeline picks the checkpoint for you.
Two more paths are documented. ProntoQA is not shipped, so you clone the official repository at a pinned commit and generate a raw dataset with run_experiment.py using specific arguments, then copy the 5hop_0shot_random.json file into the data directory and preprocess it with python preprocessing/prontoqa.py. ProsQA needs no preprocessing at all, since the dataset is already in data/prosqa_*.json.
There is also load_model_path used for a second purpose beyond evaluation: initialising Coconut from a chain of thought tuned model. That dual use is why the field appears in both the training and the evaluation configs.
A flat repository with three data files as the only schema
The repository root is small enough to read in a minute: run.py is the entry point, coconut.py holds the model, dataset.py the loading, utils.py the helpers, plus args/, preprocessing/, data/ and assets/.
The data format is the contract anyone reusing this will care about most. Training and evaluation data is a JSON file containing a list of data points, and each data point has three string fields: a question, an answer, and a list of steps where each step is itself a string. Nothing else is accepted, and nothing in the code is described as normalising it.
That means the chain of thought supervision is data you must already have. The GSM8K path handles it by pointing at augmented training and validation sets from another repository, and ProntoQA by generating a synthetic dataset with a generation script. There is no documented path for your own task, so the practical scope of this code is the three datasets it documents.
Code of conduct and contributing files sit at the root alongside the MIT licence in LICENSE. The last push was on 2026-07-02 and there are no GitHub releases, so the commit history rather than the tag list is the version history.
Editorial conclusion
Coconut is worth reading if you are experimenting with reasoning that does not emit text, and it is not a drop-in training script: the default configuration assumes four A100 80GB GPUs, a Weights and Biases login before any run, and a two-phase sequence in which a chain of thought checkpoint is selected manually as the initialisation for the Coconut stage. Before starting, read args/gsm_cot.yaml and args/gsm_coconut.yaml side by side, because the second only makes sense after the first has produced a checkpoint with the validation accuracy the README expects.
Frequently asked questions
How do I set up the Coconut environment?
Create a conda environment with Python 3.12, activate it, and run pip install -r requirements.txt, which pins torch 2.5.1, transformers 4.46.2, datasets 3.1.0 and wandb 0.18.7.
What hardware does reproducing the Coconut paper results need?
The README states that all the reproduction commands assume four A100 GPUs with 80GB each, and that batch_size_training, gradient_accumulation_steps and nproc_per_node can be changed to fit other resources.
What data format does Coconut expect?
A JSON file holding a list of data points, each with a question string, an answer string and a list of steps where every step is a string.
Which Coconut config should I use for GSM8K?
Train a chain of thought model first with args/gsm_cot.yaml, select a checkpoint with validation accuracy around 40 percent, put its path in load_model_path in args/gsm_coconut.yaml, then run that config.
Can I run Coconut without Weights and Biases?
Only in debug mode. The README says that if debug is true there is no wandb and no model saving, and a subset of the data will be used.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/facebookresearch-coconut)Star history chart for your README
[](https://hysenlabs.com/projects/facebookresearch-coconut)Was this useful?