Case study · Paper reproduction in PyTorch

Reproducing a Chain-of-Thought Paper

Towards Revealing the Mystery behind Chain of Thought (Feng et al., 2023) argues that small transformers can't solve some math tasks directly, but can once they write out intermediate steps. The official code expects Linux and four GPUs. I ported it to a single 4 GB GPU on Windows and re-ran the experiments to see whether the claim holds.

95.3%arithmetic accuracy with Chain-of-Thought
12.2%same model answering directly
7.8×more accurate with CoT
1/10of the paper's training data (100K vs 1M)
01Question

Papers are usually run on lab clusters. Does the central result survive on hardware a student actually has? If Chain-of-Thought really changes what a small transformer can compute, the gap between "show your work" and "answer directly" should still be there with less data, fewer epochs and one small GPU.

02Approach

Make distributed training run on Windows

Swapped the Linux-only NCCL backend for gloo, disabled libuv, bypassed torchrun by setting the distributed environment variables by hand, and set num_workers=0 to stop zombie data-loader processes.

Device-agnostic code

Replaced hard-coded .cuda() calls with a detected device, and loaded checkpoints with map_location so they work on any machine.

Faster training

Added Automatic Mixed Precision (autocast + GradScaler) to get more out of a small GPU.

Scaled to a 4 GB budget

Batch size 256 to fill VRAM, datasets cut from 1,000,000 to 100,000 examples, and epochs cut from 100 to 50 (15 for LIS).

# train.py: the core of the Windows port
os.environ["USE_LIBUV"] = "0"
dist.init_process_group(backend="gloo")
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = GPT(args).to(device)
Generate100K / 20KTrain / test problems per task
Train twiceCoT vs directSame 3-layer architecture
TestHeld-out setExact-answer accuracy
DocumentTroubleshooting logEvery code change and command
03Findings

One result held, one didn't (at my budget)

Test accuracy from my runs.

Test accuracy, CoT vs direct

Same model size for both, only the training format differs.

Arithmetic · CoT95.3%
Arithmetic · direct12.2%
LIS · CoT23.1%
LIS · direct40.4%

Arithmetic: length 4, 50 epochs. LIS: length 20, 15 epochs.

Arithmetic replicated

With CoT the model scored 95.3% vs 12.2% answering directly, a 7.8× gap, using a tenth of the data and half the epochs.

LIS didn't, at 15 epochs

The CoT model scored below the direct one (23.1% vs 40.4%). Its sequences are almost twice as long (45 vs 24 tokens), so the likely cause is too little training: the paper used 100 epochs.

Reproducible on a laptop GPU

The troubleshooting log in the repo lists every change and command, so anyone on Windows can re-run it.