Introduction
In the ideal world of software engineering, a model trained in one environment should behave identically in another. However, deep learning (DL) frameworks like TensorFlow, PyTorch, CNTK, and MXNet rely on different low-level implementations and mathematical libraries. This paper presents a comprehensive empirical study revealing that DL models are not "framework-agnostic." Even with identical weights and configurations, models behave differently across frameworks and face significant accuracy and performance regressions when migrated to mobile or web platforms.
Methodology
The researchers conducted a systematic study involving over ten man-months of effort to address two major gaps: development divergence and deployment decay.
The approach included:
- Cross-Framework Comparison: Training 7 popular DNN architectures (e.g., ResNet-20, GRU) across 4 major frameworks.
- Weight-Sharing Tests: Using the MMDNN tool to isolate framework differences by sharing exact weights and biases.
- Multi-Platform Deployment: Migrating models to 6 real-world mobile devices (Android and iOS) and 3 web browsers.
- Quantization Analysis: Testing the impact of 8-bit and 16-bit quantization on speed and accuracy.
The study utilized benchmarks including MNIST, CIFAR-10, and IMDb, along with 106,000 mutated samples generated via TensorFuzz and DeepHunter to test reliability.
Key Insights: Development Divergence
The study identified a "Deep Divergence" effect: while initial layers might produce similar outputs, tiny numerical differences amplify as data moves deeper into the network, potentially leading to different final classifications.
Key findings during development include:
- PyTorch Stability: PyTorch exhibited more stable training behavior and generally achieved higher training accuracy.
- CNTK Robustness: Models trained in Microsoft’s CNTK were consistently more robust against adversarial attacks compared to PyTorch or MXNet.
Key Results: Deployment Decay
Migrating models from powerful PCs to resource-constrained environments reveals significant hurdles:
- Accuracy Loss: Converting a ResNet-20 model from TensorFlow to CNTK caused an accuracy drop from 82.66% to 74.35%, despite identical weights.
- Web Resource Intensity: Running ResNet-20 on Safari consumed over 4GB of system memory. Web platforms also showed a compatibility issue, with accuracy dropping by over 5% for certain models.
- Mobile Performance: Android devices generally outperformed iOS for simpler models like LeNet, while iOS showed advantages for complex models like ResNet and VGG.
- Quantization Paradox: On iOS (Core ML), quantization sometimes slowed down prediction speeds, contrary to its intended purpose.
- Bug Discovery: The study identified a real-world bug in TensorFlow.js related to WebGL handling of 1x1 Conv2D kernels, which was subsequently fixed.
Conclusion
The study warns developers that "state-of-the-art" results on a PC might not hold up on a smartphone or browser. Future work should focus on automated testing tools for migration bugs and more efficient cross-platform conversion tools to minimize the "Deep Divergence" effect.
Summary updated