Mutation-Based Deep Learning Framework Testing Method in JavaScript Environment

Yinglong Zou, Juan Zhai, Chunrong Fang, Jiawei Liu, Tao Zheng, Zhenyu Chen · DOI

Abstract

As deep learning (DL) moves to the edge, JavaScript (JS) has become a primary language for running models directly in web browsers. However, the aggressive optimizations required for resource-constrained browser environments—such as cache reuse and inference acceleration—introduce unique stability and correctness issues. This paper presents DLJSFuzzer, the first mutation-based testing tool specifically designed for JS DL frameworks. By targeting these JS-specific optimization paths, DLJSFuzzer uncovered 147 unique bugs in TensorFlow.js, significantly outperforming general-purpose DL testing tools in both efficiency and detection rates.

Introduction

Deep learning execution in web browsers faces much stricter resource constraints, including limited memory and slower execution speeds, compared to server-side environments. To maintain performance, JS DL frameworks implement specialized optimizations:

  1. Cache Reuse: Recycling memory buffers to avoid the overhead of frequent re-allocations.
  2. Inference Acceleration: Utilizing techniques like node optimization, operator reordering, and operator fusion to streamline model execution.

Existing framework testing tools (e.g., Muffin, Gandalf) were primarily designed for Python/C++ desktop environments. These tools often utilize fixed tensor shapes and simple model structures that fail to trigger complex JS-specific optimization logic. Consequently, many "browser-only" bugs, such as crashes or numerical inconsistencies, remain undetected by traditional fuzzing methods.

Methodology

DLJSFuzzer addresses these gaps through a dual-pronged mutation strategy combined with heuristic guidance and differential testing.

The DLJSFuzzer workflow includes seed generation, mutation, and differential testing for bug detection.

Mutation Strategies

  • Tensor Mutation (13 Rules): Instead of static inputs, the fuzzer dynamically alters tensor shapes and data types (e.g., switching between float32 and bfloat16). This specifically targets cache reuse logic, testing whether the framework incorrectly identifies distinct tensors as identical or fails to handle varying dimensions during buffer recycling.
  • Model Mutation (8 Rules): The tool generates diverse architectures by applying mutations that mimic inference acceleration strategies. For example, it may insert equivalent but complex operator sequences to verify if the framework's fusion logic correctly simplifies them without introducing errors.
Operator fusion mutation combines Convolution, BatchNorm, and ReLU layers into a single CBR block to test framework optimization logic.

Heuristic Guidance and Differential Testing

The fuzzer employs a "fitness" score based on previous bug-finding success to prioritize seed models and mutation rules. To detect bugs, DLJSFuzzer executes the same model on TensorFlow.js (within Chrome and Edge) and compares the output against "ground truth" frameworks like Python-based TensorFlow or PyTorch. Significant output divergences (Inconsistency) or execution failures (Crashes) are flagged as bugs.

Key Results

DLJSFuzzer was evaluated against TensorFlow.js using seven data sources, including standard vision datasets (MNIST, ImageNet) and synthetic tensors. It was compared to three state-of-the-art baselines: LEMON, Muffin, and Gandalf.

  • Bug Detection: DLJSFuzzer identified 21 unique crashes and 126 unique NaN/Inconsistency bugs. The most effective baseline, Muffin, only identified 11 crashes and 2 numerical bugs.
  • Developer Confirmation: At the time of publication, 12 of the reported crashes had been confirmed by TensorFlow.js developers.
  • Efficiency: The tool improved model generation efficiency by over 47% and bug detection efficiency by over 91% compared to all tested baselines.
  • Optimization as a Bug Vector: Analysis revealed that over 57% of crashes were rooted in the cache reuse mechanism, confirming that performance-oriented features are a primary source of instability in JS DL frameworks.

Conclusion

DLJSFuzzer demonstrates that specialized mutation strategies targeting browser-side optimizations are essential for securing the JavaScript deep learning ecosystem. The tool's success in identifying nearly 150 unique bugs highlights the fragility of current JS-specific optimization implementations. Future work will expand the tool's scope to other JS frameworks and additional optimization strategies, such as Dead Code Elimination.

Summary updated

BibTeX
@inproceedings{zou2024mutation,
  author = {Yinglong Zou and Juan Zhai and Chunrong Fang and Jiawei Liu and Tao Zheng and Zhenyu Chen},
  title = {{Mutation-Based Deep Learning Framework Testing Method in JavaScript Environment}},
  booktitle = {ASE},
  year = {2024},
  doi = {10.1145/3691620.3695478},
}
Figure