Visual Contrastive Self-Distillation
By Yijun Liang, Yunjie Tian, Yijiang Li, Yuqi Jia, Furong Huang, Tianyi Zhou, Di Fu
"VCSD improves on-policy self-distillation for VLMs by contrasting teacher distributions conditioned on original vs. content-erased images, boosting performance without external teachers or privileged signals."
Abstract
On-policy self-distillation (OPSD) is promising as it removes the external teacher required by on-policy distillation (OPD), yet it still needs asymmetric information between teacher and student to ensure that the self-teacher provides a stronger learning signal than the student. Existing methods create this asymmetry either through privileged answers or visual evidence. We ask whether both can be removed, yielding a simpler form of OPSD driven purely by input conditioning. For this purpose, we propose Visual Contrastive Self-Distillation, namely VCSD, which converts image-content removal into an on-policy self-distillation signal. At each student-generated response prefix, the EMA teacher produces two next-token distributions under the same prompt and prefix -- one conditioned on the original image and the other on a content-erased control. Their token-wise log-probability difference highlights candidates whose likelihood is specifically increased by the instance-level visual content. We use this contrast to sharpen the teacher's original-image distribution within its plausible support, and distill the resulting full-distribution target into the student. Using ViRL39K dataset, VCSD consistently outperforms matched OPSD across Qwen3-VL and Qwen3.5 models. For example, on Qwen3-VL, it improves the seven-benchmark aggregate from $62.27\% \rightarrow 67.04\%$ at 2B, $71.30\% \rightarrow 73.16\%$ at 4B, and $72.51\% \rightarrow 76.26\%$ at 8B. Furthermore, VCSD requires no external teacher, privileged answers, visual evidence signals, reasoning traces, or additional inference-time cost.
Technical Analysis & Implementation
Technical Breakdown of VCSD§
Core Methodology§
Visual Contrastive Self-Distillation (VCSD) is an on-policy self-distillation method for vision-language models (VLMs). It eliminates the need for external teachers, privileged answers, or visual evidence by creating asymmetry purely through input conditioning. The key idea is to use an Exponential Moving Average (EMA) teacher that generates two next-token distributions for each student-generated prefix: one conditioned on the original image ($p_{\text{orig}}$) and one on a content-erased control image ($p_{\text{erased}}$). The token-wise log-probability difference $\Delta = \log p_{\text{orig}} - \log p_{\text{erased}}$ highlights candidates whose likelihood is specifically increased by the actual visual content. This contrastive signal sharpens the teacher's original-image distribution within its plausible support (e.g., top-$k$ tokens):
$$\tilde{p}(y_t) = \text{softmax}\left( \log p_{\text{orig}}(y_t) + \alpha \cdot \Delta(y_t) \right) \cdot \mathbb{1}_{y_t \in \text{support}}$$
where $\alpha$ is a scaling hyperparameter. The resulting distribution $\tilde{p}$ serves as the distillation target, and the student is trained by minimizing the KL divergence between its own logits and this target.
Implementation Details§
- EMA Teacher: Updated as $\theta_{\text{EMA}} \leftarrow \tau \theta_{\text{EMA}} + (1-\tau) \theta_{\text{student}}$.
- Content Erasure: Images are processed to remove instance-level visual content while preserving layout and low-level features (e.g., using random masking or a pretrained erasure module).
- Training Procedure: For each (image, prompt) pair, the student generates a response prefix (on-policy). At each token position, the teacher computes logits under both conditions. The contrastive target is constructed, and the student is updated via KL divergence.
- Evaluation: On ViRL39K benchmark, VCSD improves aggregate scores across 7 benchmarks for Qwen3-VL (e.g., 2B: 62.27% -> 67.04%) and Qwen3.5 models, without additional inference cost.
PyTorch-style Code Snippet§
def train_step(student, ema_teacher, image_orig, image_erased, prompt):
# Student generates response prefix (on-policy)
with torch.no_grad():
prefix = student.generate_prefix(prompt, image_orig)
# Teacher produces distributions for both conditions
with torch.no_grad():
logits_orig = ema_teacher(prompt, image_orig, prefix) # (batch, vocab)
logits_erased = ema_teacher(prompt, image_erased, prefix)
# Compute contrastive difference
log_probs_orig = F.log_softmax(logits_orig, dim=-1)
log_probs_erased = F.log_softmax(logits_erased, dim=-1)
delta = log_probs_orig - log_probs_erased # (batch, vocab)
# Build support: top-k tokens from original distribution
support_probs, support_ids = torch.topk(log_probs_orig.softmax(-1), k=50, dim=-1)
# Add contrastive signal and renormalize
target_logits = logits_orig.gather(-1, support_ids) + alpha * delta.gather(-1, support_ids)
target_probs = F.softmax(target_logits, dim=-1)
# Student logits on same prefix
student_logits = student(prompt, image_orig, prefix)
student_log_probs = F.log_softmax(student_logits, dim=-1)
kl_loss = F.kl_div(student_log_probs.gather(-1, support_ids), target_probs, reduction='batchmean')
return kl_lossKey Advantages§
- Removes external teacher, privileged answers, and visual evidence signals.
- Simple contrastive mechanism relies only on input conditioning asymmetry.
- Consistent gains across model scales and architectures without extra inference cost.
Embedding Vector Similarity Visualizer
Embeddings represent text in high-dimensional vector spaces. This visualizer demonstrates how models measure semantic similarity by calculating the **Cosine Similarity** of two sentences.
Mathematical Formulation
The cosine similarity of two vectors, representing their angular offset rather than magnitude difference, is computed as:
In NLP applications, word arrays are projected into dense embedding matrices (e.g. 1536 dimensions). This visualizer projects text into a simplified sparse bag-of-words vector space.