Latent Knowledge in LLMs and Data Selection for Continued Pretraining (GRAFT)

14 minute read

Published:

阅读中文

Motivation

Many approaches to interpreting large language models (LLMs) ask how internal activations influence the output logits. Sparse autoencoders (SAEs) are one prominent example [1]. Transcoders extend this approach [2] and have been used to trace reasoning circuits inside language models [3], [4].

This line of work suggests that MLP up-projection activations carry rich information and that later tokens can aggregate information from earlier in a sequence. Training additional interpretability modules and measuring how changes to activations affect logits can require considerable data and computation. That led us to ask whether we could use the information already present in the model’s MLP activations to identify knowledge it could gain from continued pretraining.

We explore what a model’s latent knowledge space might look like, how to use it for selecting training data, and whether image tokens show similar behavior.

Latent knowledge in LLMs

We think of an LLM’s reasoning process as finding a path through a large space of possible steps [5]. A path can lead to a correct or incorrect answer. Multiple paths form a graph, giving us a way to study properties of what we call the latent knowledge space.

This perspective gives us three questions:

  1. How can we connect explicit knowledge in data to latent representations?
  2. Can the model find the correct path in its reasoning space?
  3. Does that space contain the path the model needs?

Connecting knowledge to the latent space

There is no simple mapping from a knowledge structure in the data to individual neurons. In our earlier work, we also found that the structure of the data and the structure a model uses to reason can differ substantially [6]. Knowledge graphs suggest a working definition in terms of entities and the relationships that give them meaning [7]. To apply that intuition to hidden states, we need to define the graph’s nodes and edges.

What is a node?

A node can represent an entity or a semantic unit. As information moves through a causal language model, later tokens can accumulate meaning from earlier tokens. By the time we inspect a relationship, some of an entity’s information may already have moved to a later position [4], [6]. This makes punctuation such as periods and commas plausible anchors for sentence representations, and related work has found special tokens carrying intermediate reasoning information [6], [12], [13].

Why would punctuation become an anchor during pretraining? One clue is the diversity of contexts that precede a token [8]. When a token follows many different combinations of earlier words, its representation may be a useful place to look for aggregated context. We score candidate tokens by exponentiating the entropy of their predecessor distribution within a window.

The predecessor window is:

In the initial implementation, a window of one token already identified punctuation such as periods and commas. These punctuation tokens are a practical shortcut. After a forward pass, we use the MLP up-projection activations at the selected positions as representations of their corresponding sentences.

What is an edge?

Connected sentences often share information needed to follow a train of thought. We use cosine similarity between two anchor activations as a proxy for such a connection. In these experiments, we add an edge when the similarity exceeds 0.7. This is an operational definition of a latent relationship.

Measuring branching across layers

To inspect how a model uses this space while reasoning, we picture a trajectory as part of a directed acyclic graph that branches from earlier steps to later ones.

Reasoning paths through latent subspaces
Correct and incorrect paths diverge as they move through latent subspaces.

For reasoning paths generated by the model, we focus on the degree structure of the resulting graph. We measure it with the Branch Fraction (BF) at layer $l$:

A smaller BF suggests fewer branching opportunities and a more restricted set of candidate paths. A larger BF suggests more possible continuations. The score can be computed with batched matrix operations on a GPU, which makes large-scale data scoring more practical than computing path measures such as shortest paths.

We ran Qwen3.5-2B-Instruct ten times per question on the MMLU development set. The figure groups questions by the number of correct responses and shows mean BF across decoder layers.

Qwen3.5-2B mean Branch Fraction by layer and number of correct answers
Mean BF by layer for Qwen3.5-2B-Instruct, grouped by correct answers across ten runs on MMLU dev.

Questions answered consistently, whether correctly or incorrectly, showed less branching than questions with a more even split between correct and incorrect responses. BF was most informative in intermediate layers. Toward the first and last layers, scores were closer to one and separated the groups less clearly.

Knowledge-guided data selection

How GRAFT selects documents

The earlier analysis looks at connections the model has already formed. For continued pretraining, we want to find documents whose concepts the model has yet to connect well. A low BF is our signal: it can indicate sparse links between contexts or even isolated semantic units. Training on these documents may help the model build those missing connections.

Intermediate layers appear useful, but the best layer is hard to choose in advance. In GRAFT, each eligible layer votes for a document when its BF meets the selection criterion. We select documents using a chosen range of vote counts. Late layers can be excluded when their votes appear to reflect instruction or output format more than missing knowledge.

GRAFT workflow from subset sampling through threshold verification to final selection
GRAFT samples a subset, checks graph scores and voting thresholds, then scores and selects documents from the full pool.

Results and analysis

We use Nemotron Specialized v1.2 as a candidate pool. The tables compare methods across the same ten benchmarks on SmolLM2-1.7B, Qwen2.5-3B, and Qwen3-8B. GRAFT achieves the highest macro average in these comparisons, although the best method varies by task.

Table 1. SmolLM2-1.7B and Qwen2.5-3B after 3B tokens of continued pretraining. Macro is the unweighted mean over ten tasks. Bold marks the best result and underlining marks second best within each model.

MethodMMLUARC-EARC-CCSQAQASCMMLU-ProPIQAOpenBookAGIEvalHellaMacroAvg. Rank
SmolLM2-1.7B
Base 20.75 ±0.03 32.38 ±0.16 26.24 ±0.09 17.22 ±0.08 14.47 ±0.12 6.83 ±0.04 26.59 ±0.19 25.60 ±0.37 14.28 ±0.08 8.23 ±0.09 19.26 ±0.03 6.50
Random 37.53 ±0.08 54.57 ±0.12 44.94 ±0.19 26.78 ±0.07 22.81 ±0.41 17.72 ±0.13 51.10 ±0.24 49.65 ±0.62 39.64 ±0.16 35.60 ±0.15 38.03 ±0.02 4.90
DCLM 16.37 ±0.06 20.21 ±0.16 19.22 ±0.11 13.76 ±0.20 9.23 ±0.22 13.08 ±0.12 34.09 ±0.34 37.55 ±0.44 29.39 ±0.08 29.02 ±0.12 22.19 ±0.06 6.50
QuRating 44.23 ±0.05 68.48 ±0.16 55.95 ±0.32 44.90 ±0.27 36.96 ±0.31 22.21 ±0.18 63.49 ±0.23 59.65 ±0.70 45.57 ±0.00 37.47 ±0.19 47.89 ±0.08 2.50
PPL 45.14 ±0.07 77.62 ±0.11 58.94 ±0.49 46.66 ±0.14 40.42 ±0.22 19.36 ±0.18 64.84 ±0.20 51.60 ±0.59 40.31 ±0.24 35.13 ±0.10 48.00 ±0.04 2.60
Attn-Inf 45.35 ±0.04 72.00 ±0.17 56.29 ±0.26 39.56 ±0.40 34.61 ±0.31 20.58 ±0.06 61.28 ±0.21 58.35 ±0.34 44.15 ±0.00 41.76 ±0.26 47.39 ±0.09 2.50
GRAFT 43.54 ±0.04 70.24 ±0.25 57.17 ±0.35 49.00 ±0.22 40.52 ±0.27 20.34 ±0.06 63.64 ±0.24 56.45 ±1.12 43.20 ±0.00 36.71 ±0.25 48.08 ±0.13 2.50
Qwen2.5-3B
Base 43.93 ±0.04 69.16 ±0.15 57.85 ±0.09 48.46 ±0.09 44.85 ±0.16 32.27 ±0.09 67.30 ±0.19 61.13 ±1.55 57.38 ±0.24 57.66 ±0.28 54.00 ±0.12 5.70
Random 55.17 ±0.05 80.51 ±0.15 69.48 ±0.13 65.93 ±0.08 60.01 ±0.41 41.58 ±0.12 76.24 ±0.16 71.60 ±1.00 44.88 ±0.97 53.80 ±0.37 61.92 ±0.07 4.30
DCLM 43.81 ±0.02 64.73 ±0.11 58.87 ±0.09 61.37 ±0.05 53.42 ±0.06 38.84 ±0.12 70.89 ±0.24 59.40 ±1.74 39.24 ±0.16 52.49 ±0.29 54.31 ±0.15 6.50
QuRating 62.09 ±0.07 92.44 ±0.09 81.80 ±0.18 71.09 ±0.14 71.89 ±0.12 42.75 ±0.07 78.40 ±0.30 81.60 ±0.00 49.58 ±0.51 57.68 ±0.15 68.93 ±0.05 2.00
PPL 53.61 ±0.10 82.67 ±0.11 74.54 ±0.18 68.50 ±0.13 68.14 ±0.29 42.29 ±0.07 78.80 ±0.08 79.00 ±0.69 43.72 ±0.80 57.48 ±0.29 64.87 ±0.10 3.40
Attn-Inf 51.57 ±0.04 68.80 ±0.02 64.39 ±0.26 64.84 ±0.13 55.29 ±0.60 43.21 ±0.02 78.78 ±0.20 65.40 ±1.04 41.88 ±0.97 56.38 ±0.21 59.05 ±0.13 4.70
GRAFT 62.63 ±0.05 91.67 ±0.04 81.11 ±0.26 72.07 ±0.08 70.48 ±0.06 43.60 ±0.04 79.63 ±0.14 81.13 ±0.83 58.18 ±0.78 59.83 ±0.05 70.03 ±0.06 1.40

Table 2. Qwen3-8B after 1B tokens of continued pretraining. Δ Base is the change in Macro relative to the base model. Bold marks the best result and underlining marks second best.

MethodMMLUARC-EARC-CCSQAQASCMMLU-ProPIQAOpenBookAGIEvalHellaMacroAvg. RankΔ Base
Qwen3-8B
Base 69.02 ±0.09 92.76 ±0.08 88.65 ±0.09 79.42 ±0.17 79.27 ±0.39 56.13 ±0.09 83.22 ±0.11 87.93 ±0.50 73.52 ±0.87 77.19 ±0.20 78.71 ±0.10 4.50 —
Random 75.35 ±0.01 96.93 ±0.04 92.58 ±0.15 80.51 ±0.00 81.25 ±0.16 59.95 ±0.08 86.42 ±0.30 89.13 ±0.31 76.74 ±0.27 69.48 ±0.16 80.83 ±0.00 2.90 +2.12 ±0.11
DCLM 72.93 ±0.07 97.14 ±0.04 92.63 ±0.10 78.95 ±0.00 80.31 ±0.06 63.30 ±0.05 88.05 ±0.08 89.00 ±0.20 78.59 ±0.40 68.89 ±0.16 80.98 ±0.05 3.10 +2.27 ±0.06
QuRating 76.16 ±0.07 96.63 ±0.04 91.64 ±0.09 79.69 ±0.08 83.01 ±0.16 64.29 ±0.07 86.76 ±0.13 90.53 ±0.76 76.48 ±0.80 69.13 ±0.46 81.43 ±0.16 2.90 +2.72 ±0.07
GRAFT 76.47 ±0.09 97.28 ±0.06 92.15 ±0.09 80.32 ±0.13 83.12 ±0.06 64.47 ±0.09 86.80 ±0.13 90.13 ±1.21 79.48 ±0.51 74.51 ±0.16 82.47 ±0.10 1.60 +3.76 ±0.19

How knowledge becomes connected

We compare the model before and after continued pretraining on a physics example. We group sentences around frequently occurring content words and calculate cosine similarities using their representations at layer 23 of Qwen2.5-3B. The graphs show additional links between concepts after training.

Physics concepts and their connections before and after continued pretraining
A physics-domain graph before and after continued pretraining. Orange edges show newly formed links.

Which layers carry useful selection signals?

Low-BF votes for the selected documents tend to occur in intermediate layers. Selecting documents with individual intermediate layers also works in our experiments and covers more benchmarks than using layers near the ends of the model.

Low-BF hit rates by layer and exact number of votes
Layer-wise low-BF hit rates conditioned on the exact number of votes.
Benchmark accuracy for data selected using layers 10, 20, 22, or 30
Downstream accuracy when selecting data with individual layers.

Later experiments suggest that late-layer scores are sensitive to data format. If the model has already seen some of the data and we want to train on the same pool again, we recommend trying a voting range that excludes the later layers, such as layers after 25 in Qwen2.5-3B.

Choosing thresholds and the training order

In our sweep, promising settings are in the upper left of the heatmap, with low BF and a restrained number of votes. Settings toward the bottom right can lead to sharp drops in performance. The plotted sweep used up to 0.1 billion tokens per setting. If resources allow, a small pilot of around 1 billion tokens can help identify damaging subsets before a larger run.

Accuracy heatmap over Branch Fraction intervals and vote-count bands
Parameter sweep across BF intervals and vote counts, with up to 0.1B training tokens per setting.

Data order also matters. In our runs, training on a weaker subset first made it difficult to recover even when a stronger subset was added later.

Benchmark scores before and after an additional one billion tokens of training
Benchmark scores after a single 1B-token injection and after an additional 1B tokens.

Image tokens in vision-language models

Can we use the same idea for images? We asked whether some image tokens carry enough semantic information to distinguish image labels. Text token types are discrete, while image token embeddings are continuous. We therefore cluster the image embeddings first, then compute how often cluster $j$ precedes cluster $k$ within a window of $W$ positions.

Here $M$ is the number of clusters and $W$ is the number of preceding positions considered.

We tested Qwen3.5-9B, Qwen3.5-27B, and Gemma4-31B on CIFAR-100. We looked at coverage across images and at whether the selected representations were informative enough to use as features for classification. The figures compare coverage and classification accuracy across diversity ranks, including the top 1–30 and 91–120 clusters.

Coverage and accuracy gaps across image-token diversity settings on CIFAR-100
CIFAR-100 coverage and accuracy differences across predecessor windows and cluster counts.
CIFAR-100 linear probe accuracy for the top 1–30 and 91–120 image token clusters
CIFAR-100 test accuracy for features from the top 1–30 and 91–120 clusters by predecessor diversity.

Image tokens do retain useful information, but the difference across diversity ranks appears less pronounced than it is for text. The behavior also depends on the model’s vision encoder, so it can vary substantially across architectures. Image tokens remain an interesting direction for further study.

Conclusion

This work explores a graph-based definition of latent knowledge and uses it to select data for continued pretraining. We saw gains on open benchmarks, but the useful voting layers depend on the model and its training history. A small training run can help validate a selection rule before applying it to a large corpus. Cosine similarity is a starting point for constructing edges, and other ways of identifying semantic alignment are worth investigating.

How to cite

Download BibTeX

@misc{dai2026graft,
  author = {Dai, Xinnan and Gao, Bryan and Luo, Cheng and Zhang, Yifan
            and Zhou, Xiaohuan and Yu, Yifeng and Zeng, Shenglai and Guo, Kai
            and Tang, Jiliang and Feng, Weiguo and Liu, Fengze},
  title  = {{GRAFT}: Growing Missing Knowledge through Topology-Guided Data Selection},
  year   = {2026},
  month  = {December},
  url    = {https://ddigimon.github.io/posts/2026/12/graft/}
}

References

  1. Robert Huben, Hoagy Cunningham, Logan Smith, Aidan Ewart, and Lee Sharkey. (2024). Sparse Autoencoders Find Highly Interpretable Features in Language Models. ICLR 2024.
  2. Jacob Dunefsky, Philippe Chlenski, and Neel Nanda. (2024). Transcoders Find Interpretable LLM Feature Circuits. NeurIPS 2024, 37: 24375–24410.
  3. Emmanuel Ameisen et al. (2025). Circuit Tracing: Revealing Computational Graphs in Language Models. Transformer Circuits Thread.
  4. Jack Lindsey et al. (2025). On the Biology of a Large Language Model. Transformer Circuits Thread.
  5. Gouki Minegishi, Hiroki Furuta, Takeshi Kojima, Yusuke Iwasawa, and Yutaka Matsuo. (2025). Topology of Reasoning: Understanding Large Reasoning Models through Reasoning Graph Properties. NeurIPS 2025, 38: 13907–13938.
  6. Xinnan Dai et al. (2025). GraphGhost: Tracing Structures Behind Large Language Models. arXiv:2510.08613.
  7. Robyn Speer, Joshua Chin, and Catherine Havasi. (2017). ConceptNet 5.5: An Open Multilingual Graph of General Knowledge. AAAI 2017, 31(1).
  8. Xinnan Dai, Kai Yang, Cheng Luo, Shenglai Zeng, Kai Guo, and Jiliang Tang. (2026). When Do Hallucinations Arise? A Graph Perspective on the Evolution of Path Reuse and Path Compression. ICML 2026, PMLR 306: 22617–22632.
  9. Minyoung Huh, Brian Cheung, Tongzhou Wang, and Phillip Isola. (2024). Position: The Platonic Representation Hypothesis. ICML 2024, PMLR 235: 20617–20642.
  10. Wes Gurnee et al. (2026). Verbalizable Representations Form a Global Workspace in Language Models. Transformer Circuits Thread.
  11. Ross Murphy and Gabriel Brostow. (2026). The Platonic Representation Hypothesis in Jacobian-Space: Language and Vision Models Agree Approximately Up to a Rotation. arXiv:2611.33304.
  12. Anton Razzhigaev et al. (2025). LLM-Microscope: Uncovering the Hidden Role of Punctuation in Context Memory of Transformers. Findings of NAACL 2025, 7772–7779.
  13. Jinu Lee et al. (2026). ReasoningFlow: Discourse Structures for Understanding LLM Reasoning Traces. EMNLP 2026, 15430–15463.