Abstract
Adapting visual programming or prompting large language models (LLMs) to generate executable code for visual tasks like visual question answering (VQA) for specialized tasks or domains remains challenging due to high annotation and inference costs. We propose a low-cost visual program distillation method that can be used for models with at most 1 billion parameters and requires no human-generated program annotations. We achieve this through synthetic data augmentation based on decoupling programs into higher-level skills, called templates, and their corresponding arguments. Experimental results show that, with a relatively small amount of question/answer data, small language models can generate high-quality specialized visual programs with the added benefit of much faster inference.
1. Introduction
Visual programming has emerged as a powerful paradigm where a Language Model (LLM) acts as a central controller, generating code to invoke specialized vision tools—such as object detectors, classifiers, or spatial relationship modules—to solve complex, multi-step visual reasoning tasks. While state-of-the-art models like GPT-4 excel in this role, their deployment is often hindered by high latency and significant operational costs, making them unsuitable for real-time or edge applications.
Smaller, open-source models (under 1B parameters) typically struggle to generate these programs accurately without extensive fine-tuning. However, training such models usually requires thousands of human-written programs, which are expensive and time-consuming to annotate. This research addresses this bottleneck by introducing a high-efficiency distillation pipeline that creates specialized, lightweight visual programmers with zero human-annotated programs.
2. Methodology
The proposed distillation pipeline consists of three primary stages designed to maximize data efficiency and model performance.
2.1 Teacher Annotation via Auto-Context
Rather than relying on human labels, the method utilizes a teacher model (GPT-4o-Mini) to self-annotate a small subset of a dataset (e.g., 1,000 samples). To ensure quality, the teacher generates programs based on the question and the ground-truth answer. If the generated program, when executed, produces the correct answer, it is retained as a "gold" training example.
2.2 Template-Based Augmentation
The core innovation of this work is the decoupling of visual programs into reusable logic and specific concepts. The researchers observed that many visual tasks share identical reasoning structures but differ only in their subjects. Programs are decomposed into:
- Templates: The high-level logic (e.g.,
find(arg0), verify_property(arg1)). - Arguments: The specific concepts (e.g.,
arg0='chair',arg1='red').
By swapping arguments within both the question and the program (e.g., changing "red chairs" to "green bananas"), the system can synthetically generate hundreds of new, valid training pairs from a single teacher-generated example. This significantly increases the linguistic and conceptual diversity of the training set without requiring additional teacher calls.
2.3 Student Training
Finally, "tiny" student models—specifically Qwen2.5-Coder (0.5B), Llama-3.2 (1B), and CodeT5+ (770M)—are fine-tuned on this augmented synthetic dataset using Low-Rank Adaptation (LoRA). This allows the models to specialize in the specific program structures required for the target domain.
3. Experimental Evaluation
The method was evaluated across several prominent Vision-Language benchmarks, including GQA (compositional reasoning), VQAv2 (open-ended VQA), CV Bench (2D split), and VizWiz (real-world images from visually impaired users).
4. Results and Analysis
The experimental results demonstrate that small models can achieve remarkable performance through template-based distillation.
- Efficiency and Speed: The distilled student models achieved inference speeds up to 30.8x faster than their teacher models. As shown in Figure 1, the Qwen-0.5B model matched the answer accuracy of GPT-4o-Mini on the GQA dataset (~43%) while maintaining a significantly higher throughput.
- Data Frugality: Peak performance was reached using only 0.1% of the available training data (approximately 1,000 Q/A pairs), highlighting the power of the augmentation strategy.
- Logic vs. Execution: A key insight from the study is that "program accuracy" (the correctness of the generated code) often exceeds "answer accuracy." This indicates that errors in visual programming systems frequently arise from the underlying vision APIs rather than the LLM's reasoning capabilities.
5. Conclusion and Future Work
This work proves that it is possible to train competent, lightweight visual programmers without any human-written code. By decoupling logic from concepts, the template-based augmentation strategy allows tiny models to generalize effectively from minimal data.
However, limitations remain. These student models are currently "specialists" for specific datasets and lack the broad general-purpose reasoning of massive LLMs. Future research will explore scaling this approach to more complex, multi-step tasks and incorporating execution feedback to allow models to learn from their own mistakes during training.
Summary updated