NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

A Stepwise Distillation Learning Strategy for Non-differentiable Visual Programming Frameworks on Visual Reasoning Tasks

Wentao Wan, Nan Kang, Zeqing Wang, Zhuojie Yang, Liang Lin, Keze Wang

TL;DR

The proposed Stepwise Distillation learning strategy for Visual Programming (SDVP) enables the fine-tuning of non-differentiable Visual Programming (VProg) frameworks. By distilling knowledge from small, task-specific "teacher" models into the larger, general-purpose Vision-Language Models (VLMs) used as sub-modules, SDVP significantly boosts performance on target visual reasoning tasks while preserving cross-task generalization.

What Problem Does This Paper Address?

Visual Programming (VProg) frameworks like VisProg and ViperGPT are a powerful shift toward interpretable and modular AI. Instead of using a single end-to-end black-box network, VProg uses a Large Language Model (LLM) to parse a complex visual query into a Python program. This program then executes a sequence of discrete steps, calling specialized Vision-Language Models (VLMs) for sub-tasks like object detection or property verification.

While highly flexible and interpretable, VProg faces two major hurdles:

  1. The Performance Gap: General-purpose VLMs invoked by VProg often underperform on specific visual reasoning tasks compared to specialized networks trained end-to-end for those exact tasks.
  2. Non-Differentiability: Because VProg wraps neural networks inside discrete Python logic (like loops, conditionals, and string parsing), the framework as a whole is non-differentiable. You cannot simply backpropagate a loss from the final answer to fine-tune the underlying VLMs.

Replacing general VLMs with task-specific ones fixes the performance gap but triggers "catastrophic forgetting," destroying VProg's core strength: its ability to generalize across different tasks.

Methods

The authors introduce SDVP (Stepwise Distillation for Visual Programming) to optimize the differentiable sub-modules within an otherwise non-differentiable framework.

Fig. 2. The overview of our proposed SDVP pipeline. SDVP aims to fine-tune visual sub-modules to produce the correct predictions for visual sub-tasks, so as to access the correct final answer of the original question. The right part displays how our SDVP works. During the execution of the program, the visual sub-module “verify property” is called to verify whether the clothing in the image is red, and it answers “no” wrongly. To rectify it, we use the teacher model to answer the same question, then we let “verify property” learn it through distillation. After distillation, “verify property” gives a correct answer “yes”. Similarly, after distillation the visual sub-module “simple query” would answer “shirt” correctly instead of “dress”. Because of the correct reasoning of each sub-module, in the final step, we could get the correct answer “shirt” to the original question “Which kind of clothing is red ?” with the given image.

The pipeline consists of three main components:

  • The Adapter: Task-specific teacher models expect standard inputs (e.g., an image and a full question), whereas VProg sub-modules operate on cropped image patches and localized sub-questions. The Adapter uses an LLM to reformat VProg's intermediate code and parameters into a structure the teacher model can understand.
  • Pseudo-Label Generation: The specialized teacher model processes these adapted inputs to generate high-quality intermediate "pseudo-labels" for each step of the program execution.
  • Stepwise Distillation: Instead of end-to-end training, distillation happens step-by-step along the execution path. The general-purpose VLM (the student) is fine-tuned using cross-entropy loss to match the teacher's pseudo-labels on these atomic sub-tasks.

Datasets

The framework was evaluated using several prominent visual reasoning and grounding benchmarks:

  • GQA: A visual question answering dataset emphasizing multi-step spatial reasoning and compositional questions.
  • NLVRv2 (Natural Language Visual Reasoning): A dataset requiring joint reasoning over pairs of real-world images and a textual statement.
  • RefCOCO / RefCOCO+: Used as evaluation-only datasets to test whether the models maintained their general visual grounding capabilities after distillation.

Key Insights and Ideas

  • The Anti-Forgetting Power of Modularity: Traditional fine-tuning often causes catastrophic forgetting because of the massive domain gap between new and old tasks. However, VProg naturally breaks complex, diverse tasks down into similar, atomic sub-tasks (e.g., turning a complex query into simple "How many?" or "Is there?" questions). This decomposition narrows the input distribution gap, making the framework inherently resistant to forgetting.
  • Inverting the Distillation Paradigm: Standard knowledge distillation compresses a large, cumbersome model into a smaller student. SDVP flips this: it takes a small, highly specialized proprietary model and distills its niche expertise into a much larger, general-purpose VLM foundation model.

Key Results

SDVP was evaluated across two major VProg architectures (VisProg and ViperGPT) using BLIP and InternVL-1.5 as the underlying foundation models.

Fig. 1. Performance analysis of VisProg [18], a classical VProg framework, to invoke different visual models for the four VR tasks. Note that, the target VR task is on NLVRv2 [4]. Invoking the existing models trained on NLVRv2 to perform as the relevant visual sub-modules enables VisProg to perform superior on NLVRv2, but the capabilities of VisProg on other tasks significantly decline. Our SDVP, which distills the capabilities of models well-trained on NLVRv2 into the sub-modules of VisProg, allows VisProg to improve performance on NLVRv2, while essentially maintaining its capabilities on other tasks, thus preserving the cross-task generalization ability of VisProg.
  • GQA Improvements: When using BLIP, SDVP achieved a +2.4% accuracy boost for VisProg and a +6.5% boost for ViperGPT.
  • NLVRv2 Improvements: SDVP yielded a +6.2% improvement for VisProg and a +4.0% improvement for ViperGPT.
  • Preserving Generalization: Unlike baseline methods that crashed on non-target tasks when using task-specific models directly, models trained via SDVP maintained stable performance on unseen tasks like RefCOCO, proving that the multi-task generality of the foundation VLM remained intact.

Limitations and Future Work

The authors note a few key limitations:

  • Teacher Dependency: The performance ceiling of the fine-tuned VLM is strictly bounded by the accuracy and generalization capability of the task-specific teacher model providing the pseudo-labels.
  • LLM Vulnerabilities: Because SDVP relies on the visual programs generated by an LLM, it remains susceptible to any syntax or semantic errors inherent to the LLM's code generation.

Future work will focus on co-optimizing the visual sub-modules and the visual programs collaboratively, as well as exploring ways to bypass the teacher model entirely by learning directly from final outcome supervision.

Summary updated

BibTeX
@misc{wan2023stepwise,
  author = {Wentao Wan and Nan Kang and Zeqing Wang and Zhuojie Yang and Liang Lin and Keze Wang},
  title = {{A Stepwise Distillation Learning Strategy for Non-differentiable Visual Programming Frameworks on Visual Reasoning Tasks}},
  year = {2023},
  eprint = {2309.09809},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2309.09809},
}
Figure