Introduction
Optical neural networks (ONNs) represent a promising frontier for high-speed, low-power computing. By utilizing the amplitude and phase of light waves, these networks can perform vector-matrix multiplications at the speed of light with minimal energy consumption. Central to their operation are programmable Mach-Zehnder interferometers (MZIs), which must implement unitary weight matrices to maintain energy efficiency. However, a significant hurdle exists in the training phase: simulating and optimizing the phase parameters of these MZIs using standard automatic differentiation (AD) frameworks like PyTorch or TensorFlow is computationally expensive. The deep, complex-valued computational graphs inherent in "fine-layered" ONN structures lead to substantial memory and processing overhead, delaying deployment to physical hardware.
Methodology
To address these bottlenecks, this research introduces a custom C++ module designed to accelerate the training of fine-layered ONNs without compromising accuracy. The approach integrates three core innovations:
Component-Level Abstraction
Rather than treating an MZI as an indivisible matrix operation, the authors decompose it into its constituent optical elements: phase shifters (PS) and directional couplers (DC). This modularity allows the framework to accommodate diverse physical MZI architectures by treating them as sequences of these fundamental building blocks.
Custom Wirtinger Derivatives
Standard AD engines often struggle with complex-valued operations, frequently decomposing them into elementary real-valued functions, which adds unnecessary overhead. The authors manually derived analytical complex-valued gradients for PSDC and DCPS pairs using Wirtinger calculus. By hardcoding these derivatives, the system bypasses the granular tracking required by general-purpose AD.
Memory-Efficient C++ Implementation
The custom derivatives are implemented in a high-performance C++ module. A key optimization is "pointer rewiring": instead of performing costly memory copies of output data between successive fine layers, the module simply swaps memory pointers. This technique significantly reduces memory I/O overhead, which is particularly impactful in deep, fine-layered architectures.
Experimental Results
The proposed method was evaluated using the MNIST handwritten digit database, formatted as a pixel-by-pixel sequential task—a common benchmark for recurrent networks using unitary matrices.
The results demonstrate dramatic performance gains over conventional PyTorch-based AD. For a 4-layer network, the method achieved a 19x speedup, which scaled to a 53x speedup for a 20-layer network. Crucially, this acceleration does not come at the cost of precision; the custom method and standard AD converged to identical test accuracies. In time-constrained scenarios, the custom method reached over 0.92 accuracy within 3,000 seconds, while the standard AD approach lagged at 0.83.
Ablation studies revealed that while custom Python derivatives doubled the speed, the transition to C++ and the inclusion of pointer rewiring provided the most substantial performance multipliers.
Conclusion
By moving away from general-purpose automatic differentiation in favor of domain-specific analytical gradients and optimized memory management, this work provides a path toward rapid iteration and training of optical neural networks. While currently tested on CPUs, future work involves porting the C++ module to multi-GPU systems and exploring its utility in broader deep learning contexts that require unitary weight matrices for long-term memory retention.
Summary updated