Reasoning Trace Reconstruction for Small-Model Distillation and Curriculum-Based Fine-Tuning
This article explains how to distill reasoning ability from a teacher model into a smaller student model when the teacher only returns compressed answers. It covers why compressed outputs weaken distillation, how to reconstruct full step-by-step reasoning traces from conclusions, how to design a three-stage curriculum for supervised fine-tuning, and how to evaluate the results across accuracy, format compliance, and long-context performance.
1. Background: Why Reasoning Ability Deserves Dedicated Distillation
A large language model’s performance on mathematical derivation, code generation, and multi-step planning depends heavily on whether it can break a problem down into an ordered sequence of intermediate steps. For smaller models, the main bottleneck is training data. High-quality step-by-step reasoning samples are expensive to produce, manual annotation cycles are long, and the process is hard to scale. As a result, many teams turn to distillation: using a stronger teacher model to generate training data, then having the student model imitate its outputs.
The format of the teacher model’s output directly affects distillation quality. For reasons of cost, user experience, or policy, some services only return the final answer and a highly condensed summary, with intermediate reasoning compressed or hidden. If a student model is trained only on such outputs, it typically learns conclusion templates rather than a generalizable derivation process.
2. The Core Problem: Compressed Reasoning vs. Full Reasoning Chains
Compressed reasoning output is short, skips steps, and hides key transformations in the omitted portions. Take a two-step algebra problem: a compressed output might simply say “therefore x = 3”. A human reader can verify this conclusion, but for a student model, the intermediate path from equation manipulation to the solution is missing.
Training directly on such samples via supervised fine-tuning usually leads to three problems:
- Broken logic: The model learns the output format but jumps steps arbitrarily on problems requiring multi-step derivation.
- Weak generalization: The model performs reasonably well within the training distribution but degrades noticeably on structurally similar problems with different phrasing.
- Error amplification: Occasionally incorrect conclusions from the teacher are treated as ground truth, and the student reproduces those errors with even greater confidence.
The key factor, therefore, is whether the data retains a learnable derivation structure. Data volume is a secondary concern.
3. Reasoning Trace Reconstruction: Inferring Process from Conclusions
One feasible approach is to train a reverse-decoding model. Its input is the question, the compressed answer, and any necessary context; its output is a fully expanded step-by-step reasoning chain. The overall pipeline is:
Compressed answer → Reverse-decoding model → Full step-by-step reasoning → Recombined with the question and answer into a training sample
3.1 Data Construction Pipeline
The construction pipeline should include the following steps:
- Sample filtering: Remove samples that are too short, duplicated, or malformed.
- Trace reconstruction: Generate candidate reasoning chains for each sample, keeping multiple candidates for later selection.
- Consistency verification: Check whether the reasoning chain’s conclusion matches the original answer. For math problems, compare numeric results; for code, run unit tests.
- Format normalization: Place the reasoning content inside a unified marker block to simplify training and parsing.
Example code:
def build_sft_sample(prompt, compressed_answer, invert_fn, verify_fn):# 1. Reconstruct the full reasoning chaintrace = invert_fn(prompt=prompt, answer=compressed_answer)if not trace:return None# 2. Verify the trace conclusion matches the original answerif not verify_fn(trace, compressed_answer):return None# 3. Assemble the supervised sample in a unified formatresponse = f"<think>\n{trace}\n</think>\n{compressed_answer}"return {"prompt": prompt, "response": response}
The invert_fn and verify_fn functions must be implemented per task type. Open-ended QA has no definitive answer, so it relies more on manual spot checks or a scoring model.
3.2 Quality Control
Reconstructed reasoning chains are not guaranteed to be reliable. Common issues include reasoning steps disconnected from the conclusion, premises introduced that were absent from the original answer, and overly long traces that inflate training sequences. It is advisable to store the source, reconstruction version, and verification result for each sample so issues can be traced back. Sample ratios should also be controlled across difficulty levels; if the data concentrates on easy problems, gains on complex tasks will be limited.
4. Staged Curriculum-Based Supervised Fine-Tuning
Training directly on data with mixed lengths and difficulty levels often causes format collapse or interrupted reasoning in long contexts. Curriculum-based training increases sequence length and task difficulty progressively: stabilize the format first, then learn complex reasoning, and finally adapt to long contexts.
4.1 Three-Stage Design
Stage 1: Format stabilization. Use shorter sequences and focus on output structure, including the start and end markers of the reasoning block, the answer position, and the stop token. The goal is for the model to follow the same format in every output, providing a stable interface for downstream parsing and reinforcement learning.
Stage 2: Complexity expansion. Raise sequence length to a medium range and introduce multi-step math problems, multi-turn conversational reasoning, and simple tool-calling samples. A proportion of hard examples can be included, but the data should still be dominated by tasks with verifiable answers.
Stage 3: Long-context training. Extend sequence length further and mix in a small portion of data from the first two stages as replay. Replay reduces the risk of the model forgetting previously learned formats and capabilities.
Example configuration:
curriculum:stage_1:max_seq_len: 4096focus: formatstage_2:min_seq_len: 4096max_seq_len: 8192focus: moderate_reasoningstage_3:min_seq_len: 8192max_seq_len: 32768replay_ratio: 0.1focus: long_context
These values are design examples only. Actual settings should be adjusted based on hardware capacity, data distribution, and evaluation results.
4.2 Training Parameters and Engineering Efficiency
For medium-sized models, full-parameter fine-tuning is costly, so parameter-efficient methods such as Low-Rank Adaptation (LoRA) are commonly used. Key hyperparameters include adapter rank, learning rate, batch size, and gradient accumulation steps. Record the loss curve and format compliance rate separately for each stage. If loss decreases while format compliance drops, check the data mixture and marker integrity first.
Long-sequence training places high demands on GPU memory. Common techniques include gradient checkpointing, mixed-precision training, sequence packing, and distributed training. These are general engineering practices that can be combined according to available hardware and framework support.
5. Evaluation Design
5.1 Evaluation Dimensions
Evaluation should not rely on a single metric. It is recommended to cover at least the following dimensions:
- Mathematical reasoning: Measure accuracy on problem sets with standard answers.
- Code capability: Judge correctness through unit tests.
- Format compliance: Measure the completeness rate of reasoning markers and answer markers.
- Long context: Check whether information retrieval and reasoning ability degrade at different input lengths.
- Tool calling: Verify that function names, parameter structures, and return-value handling conform to the specification.
5.2 Comparative Experiments
When evaluating, fix the base model, data scale, and training steps, and change only one variable at a time. For example, comparing “training directly on compressed answers” against “training on reconstructed reasoning chains” clearly isolates the benefit of the reconstruction step.
5.3 Safety and Compliance
Reasoning-enhanced models require a dedicated safety evaluation. If the training data contains harmful content, the model may amplify it. If the training data comes from the output of third-party services, first confirm whether their terms of use permit training on that output, and keep records of data provenance.
6. Practical Recommendations
- Define the target task first, then decide on data scale. Math reasoning and general conversation require very different data structures.
- Run the full pipeline on a small dataset first; confirm that formatting, evaluation, and the replay mechanism all work before scaling up.
