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

ChameleonAPI: Automatic and Efficient Customization of Neural Networks for ML Applications

Yuhan Liu, Chengcheng Wan, Kuntai Du, Henry Hoffmann, Junchen Jiang, Shan Lu, Michael MaireOSDI 2024

Abstract

Machine Learning-as-a-Service (MLaaS) providers typically offer generic, pre-trained models designed for broad utility. However, these "one-size-fits-all" models often fail to account for the specific decision-making logic of the applications that consume their outputs. This paper introduces ChameleonAPI, a framework that automatically customizes neural networks by analyzing an application's source code. By identifying critical errors—misclassifications that lead to incorrect application-level decisions—and retraining models with an application-specific loss function, ChameleonAPI reduces incorrect application decisions by 43% compared to leading commercial APIs.

Introduction

Current ML APIs, such as Google Vision or Amazon Rekognition, treat all misclassifications as equal. In practice, however, many model errors are benign at the application level, while others are catastrophic. For instance, a recycling application might group "Paper" and "Cardboard" into a single "Recycle" category. If a model confuses cardboard for paper, the application's final decision remains correct. Conversely, misidentifying a "Shirt" (Donate) as "Paper" (Recycle) constitutes a critical error. ChameleonAPI addresses this gap by aligning model performance with the specific requirements of the application logic.

The ChameleonAPI Framework

ChameleonAPI employs a three-step pipeline to customize ML models without requiring developers to modify their existing application code.

1. Logic Extraction

The framework uses symbolic execution and static analysis to parse the application's Python code. This process identifies how the application utilizes ML outputs, specifically focusing on:

  • Target Classes: How the application groups various labels into decision categories.
  • Decision Type: Whether the application logic follows a multi-choice or multi-select structure.
  • Matching Order: The priority or sequence in which the application evaluates labels.

2. Application-Specific Loss Function

The extracted logic is translated into a differentiable loss function. This function is designed to penalize three specific types of critical errors:

  • Type-1: The correct class is identified, but only after an incorrect class has already triggered a decision.
  • Type-2: The correct class is never matched by the model.
  • Type-3: An incorrect class is matched before the correct one in the application's priority sequence.

3. Model Retraining

ChameleonAPI takes an off-the-shelf model (e.g., TResNet for vision or BERT for language) and fine-tunes it using the custom loss function. This results in a model optimized specifically for the target application's control flow and predicates.

Experimental Evaluation

The authors evaluated ChameleonAPI using 57 real-world open-source applications from GitHub across various domains, including image classification, object detection, and sentiment analysis. To simulate the proprietary data used by commercial APIs, the researchers utilized standard datasets such as OpenImages, COCO, and Amazon reviews.

Key Insights

  • Equivalence Classes: The study found that applications treat an average of 4.7 different ML labels as a single equivalence class, providing significant "wiggle room" for model optimization.
  • Label Filtering: While commercial models are trained on thousands of labels, the average application in the study only required 7 target classes. Focusing the model on these specific classes significantly improves reliability.
  • Efficiency: The customization process is highly efficient. Fine-tuning a pre-trained model with the specialized loss function required less than 24 minutes on a consumer-grade GPU (RTX 3080).

Results

ChameleonAPI demonstrated a significant improvement over general-purpose models:

  • Decision Accuracy: The framework reduced incorrect application decisions by 43% compared to top-tier commercial ML APIs and by 48% compared to standard off-the-shelf models.
  • Cross-Task Consistency: Performance gains were consistent across vision and language tasks, proving the versatility of the application-aware approach.
  • Precision-Recall Optimization: Customized models achieved a superior precision-recall frontier for the specific target classes used by the applications, effectively learning the application's unique tolerance for noise.

Limitations and Future Work

While effective, ChameleonAPI's reliance on static analysis means it can struggle with highly complex code structures, such as deep recursion or indirect data dependencies. Additionally, the system assumes a stable input distribution; significant shifts in real-world data (concept drift) may necessitate re-customization. Future research will explore handling more complex ML tasks, such as video analytics, and developing methods to automatically detect when a model requires re-tuning due to changes in application logic or data distributions.

Conclusion

ChameleonAPI represents a shift from model-centric to application-centric machine learning. By bridging the gap between neural network training and application-level logic, the framework enables the deployment of more reliable and efficient ML-driven software.

Summary updated

BibTeX
@inproceedings{liu2024chameleonapi,
  author = {Yuhan Liu and Chengcheng Wan and Kuntai Du and Henry Hoffmann and Junchen Jiang and Shan Lu and Michael Maire},
  title = {{ChameleonAPI: Automatic and Efficient Customization of Neural Networks for ML Applications}},
  booktitle = {OSDI},
  year = {2024},
}

Loading related content...

Figure