Enhancing Cross-Tokenizer Knowledge Distillation with Contextual Dynamical Mapping

Yijie Chen, Yijin Liu, Fandong Meng, Yufeng Chen, Jinan Xu, Jie Zhou

Abstract

Knowledge Distillation (KD) is a cornerstone technique for compressing Large Language Models (LLMs), yet it typically necessitates that the teacher and student models share an identical tokenizer. This requirement limits the transfer of knowledge between heterogeneous model architectures. This paper introduces Contextual Dynamic Mapping (CDM), a framework designed to bridge the gap between disparate tokenizers. By leveraging contextual information to align both token sequences and vocabularies, CDM significantly enhances the efficacy of cross-architecture knowledge transfer.

Introduction

Standard Knowledge Distillation works by training a smaller "student" model to mimic the output probability distributions (logits) of a larger "teacher" model. This process is mathematically straightforward when both models utilize the same tokenizer, as their output vocabularies and sequence lengths align perfectly. However, the landscape of LLMs is diverse; distilling knowledge from a model like Llama-3 into a student like Qwen2 introduces the challenge of Cross-Tokenizer KD (CTKD).

CTKD presents two primary obstacles:

  1. Sequence Misalignment: Different tokenizers segment the same text differently. For example, one model might tokenize "apple" as a single unit ["apple"], while another splits it into sub-words like ["ap", "ple"].
  2. Vocabulary Mismatch: Models often have different vocabulary sizes and semantic mappings, making direct logit comparison impossible.

Existing solutions often rely on character-level similarity or optimal transport to force alignment. However, these methods ignore the semantic context of the sentence, frequently resulting in nonsensical mappings (e.g., mapping "e" to "a" based solely on edit distance) that introduce noise into the distillation process.

Methodology: Contextual Dynamic Mapping (CDM)

To address these limitations, the authors propose Contextual Dynamic Mapping (CDM), which utilizes contextual cues to perform alignment at both the sequence and vocabulary levels.

Sequence Alignment via Entropy-Weighted DTW

Traditional methods use Dynamic Time Warping (DTW) based on string edit distance to align sequences. CDM enhances this by introducing an entropy-based weight. The framework calculates the entropy of the model's predictions at each position; high entropy typically indicates uncertainty, often occurring on ambiguous or short tokens like punctuation. By weighting the DTW cost function with this entropy, CDM prioritizes alignment on highly informative, semantically dense tokens while suppressing the influence of noisy, forced alignments.

Vocabulary Mapping via Contextual Top-K

Rather than relying on a static, offline dictionary, CDM employs a dynamic approach. At each sequence position, it extracts the Top-K predicted tokens from both the teacher and student. If an exact match is not found, CDM searches for the most similar token within that specific Top-K context using a length-normalized edit distance. This ensures that the mapping is semantically relevant to the current sentence rather than a generic character-level guess.

Dual Mapping and Masking

To further refine the signal, CDM performs a two-way alignment (teacher-to-student and student-to-teacher). Any tokens that cannot be confidently matched are masked out, preventing the student from learning from low-quality or ambiguous teacher signals.

Experimental Setup

The researchers evaluated CDM across five major model families—Llama-3, Phi3, Gemma-2, OPT, and Qwen2—configured into various teacher-student pairs. The evaluation spanned three critical task categories:

  • Instruction Following: Trained on Dolly-15K; evaluated on Dolly, Self-Inst, Vicuna, S-NI, and UnNI.
  • Code Generation: Trained on CodeM; evaluated on HumanEval+ and MBPP+.
  • Mathematics: Trained and evaluated on GSM-8K.

Key Insights and Results

Performance Gains

CDM demonstrated consistent improvements over standard Supervised Fine-Tuning (SFT) and existing CTKD baselines. For a Qwen2-0.5B student distilled from a Phi3-mini-3.8B teacher, CDM achieved performance gains of 4.27% in instruction following, 12.19% in code generation, and 3.34% in mathematics.

Comparison with State-of-the-Art

CDM outperformed established methods such as Unified Logits Distance (ULD) and MinED. For instance, on a Gemma-2-2B student, CDM reached an average instruction-following score of 23.55, surpassing ULD’s 23.23. Furthermore, CDM improved sequence alignment accuracy from 78.31% (using pure edit distance) to 82.20% and increased vocabulary mapping coverage from 65% to 87%.

The Importance of Context and Entropy

The study highlights that context is essential for alignment; without it, algorithms are prone to "semantic hallucinations" where fragments are mapped incorrectly across languages or sub-words. Additionally, the use of entropy as a noise filter allows the model to anchor its learning on semantically significant words, leading to a cleaner distillation signal.

Conclusion and Future Work

Contextual Dynamic Mapping (CDM) provides a robust framework for distilling knowledge between models with different tokenizers, effectively overcoming the hurdles of sequence and vocabulary misalignment. While the method introduces some computational overhead due to dynamic Top-K and entropy calculations, the performance benefits are substantial.

Future research will focus on scaling CDM to models exceeding 10B parameters and exploring multi-teacher environments, where a student might simultaneously ensemble knowledge from several teachers with diverse tokenization strategies.

Summary updated

BibTeX
@inproceedings{chen2025enhancing,
  author = {Yijie Chen and Yijin Liu and Fandong Meng and Yufeng Chen and Jinan Xu and Jie Zhou},
  title = {{Enhancing Cross-Tokenizer Knowledge Distillation with Contextual Dynamical Mapping}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure