Turaco: Complexity-Guided Data Sampling for Training Neural Surrogates of Programs

Alex Renda, Yi Ding, Michael Carbin · DOI

Abstract

Training neural networks to act as surrogates for complex programs is a critical technique for accelerating simulations and enabling gradient-based optimization of non-differentiable code. However, standard data sampling techniques often fail to capture the underlying mathematical complexity of diverse execution paths. We present Turaco, a methodology and domain-specific language that uses static program analysis to measure the sample complexity of individual execution paths. By allocating training data based on both path frequency and mathematical complexity, Turaco significantly improves surrogate accuracy and execution efficiency across a variety of domains, including financial modeling, physics simulations, and 3D rendering.

Introduction

Surrogate programming involves replacing computationally expensive or non-differentiable programs with fast neural network approximations. While this approach offers significant speedups, the quality of the surrogate is heavily dependent on the training data. Traditional methods rely on uniform sampling or frequency-based sampling (sampling based on real-world input distributions). These methods overlook a fundamental property of software: programs are stratified. Different inputs trigger different execution paths, and these paths vary significantly in their mathematical complexity. A simple linear path may require very few examples to learn, whereas a path involving high-order transcendental functions requires a much higher density of data points to achieve the same level of accuracy.

Methodology

Turaco introduces a systematic approach to data allocation through four key components:

1. Stratified Modeling

Turaco treats programs as piecewise functions where each "stratum" corresponds to a unique execution path. This allows the system to analyze the complexity of specific logic branches independently rather than treating the program as a monolithic black box.

2. Complexity Analysis via Tilde Calculus

The core innovation of Turaco is the use of static analysis to calculate an upper bound on the "sample complexity" of each path. The authors utilize a mathematical framework called "tilde calculus" to quantify how "wiggly" or high-order a function is. For instance, a path performing simple arithmetic has low complexity, while one involving exp() or sin() operations is assigned a higher complexity value.

3. Dual-Number Execution

To propagate these complexity bounds through the program's logic, Turaco employs a technique similar to automatic differentiation. Complexity values are tracked alongside standard values during a symbolic execution phase, ensuring that assignments and operations correctly accumulate the total complexity of a path.

4. Optimal Data Allocation

Turaco provides a closed-form optimization (Theorem 2) to determine the ideal distribution of a fixed data budget. The formula balances the probability of a path occurring (frequency) with the difficulty of learning that path (complexity). This ensures that complex, high-impact paths are not starved of data even if they occur relatively infrequently.

Evaluation and Benchmarks

The effectiveness of Turaco was evaluated across several diverse benchmarks:

  • Financial/Numerical: BlackScholes (option pricing) and Huber (robust loss function).
  • Physics/Engineering: EQuake (earthquake simulation) and Jmeint (3D triangle intersection).
  • Graphics: Luminance (brightness calculation) and Camera (color temperature conversion).
  • Case Study: A large-scale 3D renderer translated from C++/GLSL, representing a high-stakes real-world application.

Key Results

Accuracy and Efficiency

Across all benchmarks, complexity-guided sampling improved empirical error by an average of 5% compared to frequency-based baselines and 5.4% compared to uniform sampling. While a 5% error reduction may seem modest, it has a disproportionate impact on performance: the authors found that this improvement allowed for the use of smaller, faster neural networks, resulting in up to a 28% improvement in execution speed while maintaining the required error threshold.

Perceptual Quality in Rendering

In the 3D renderer case study, Turaco-guided surrogates achieved 17% to 44% lower error. Qualitatively, this eliminated visual glitches in complex materials and shadows. Frequency-based sampling often ignored rare but complex paths (like smoke particles), leading to artifacts that Turaco successfully mitigated by oversampling those specific high-complexity regions.

Predictive Reliability

The study demonstrated a strong correlation ($r=0.86$) between the predicted error decrease calculated by Turaco’s static analysis and the actual empirical improvements observed during training. This suggests that the complexity bounds, while theoretical, serve as a highly reliable guide for real-world data engineering.

Limitations and Future Work

Despite its success, Turaco has several constraints. It is currently optimized for analytic functions (smooth functions like polynomials and exponentials) and struggles with highly discontinuous logic. Additionally, the system only supports fixed-length or bounded loops; unbounded while loops break the path-based analysis. The complexity bounds are also "sound but loose," occasionally overestimating complexity in cases where mathematical simplifications (like $x + (-x)$) are not recognized. Finally, the method assumes the input distribution is known beforehand; if the distribution shifts, the sampling strategy must be recomputed.

Conclusion

Turaco demonstrates that data sampling for neural surrogates should not be a blind process. By incorporating the mathematical complexity of code paths into the data generation pipeline, developers can create surrogates that are both more accurate and significantly faster than those trained on uniform or frequency-only datasets.

Summary updated

BibTeX
@article{renda2023turaco,
  author = {Alex Renda and Yi Ding and Michael Carbin},
  title = {{Turaco: Complexity-Guided Data Sampling for Training Neural Surrogates of Programs}},
  journal = {Proc. ACM Program. Lang.},
  year = {2023},
  doi = {10.1145/3622856},
}
Figure