Created by a consortium of academic institutions and incubated at the Apache Software Foundation, MXNet (or “mix-net”) was designed to blend the advantages of different programming approaches to deep learning model development—imperative, which specifies exactly “how” computation is performed, and declarative or symbolic, which focuses on “what” should be performed.
Image reference: https://www.cs.cmu.edu/~muli/file/mxnet-learning-sys.pdf
Imperative Programming Mode
MXNet’s NDArray, with imperative programming, is MXNet’s primary tool for storing and transforming data. NDArray is used to represent and manipulate the inputs and outputs of a model as multi-dimensional arrays. NDArray is similar to NumPy’s ndarrays, but they can run on GPUs to accelerate computing.
Imperative programming has the advantage that it’s familiar to developers with procedural programming backgrounds, it’s more natural for parameter updates and interactive debugging.
Symbolic Programming Mode
Neural networks transform input data by applying layers of nested functions to input parameters. Each layer consists of a linear function followed by a nonlinear transformation. The goal of deep learning is to optimize these parameters (consisting of weights and biases) by computing their partial derivatives (gradients) with respect to a loss metric. In forward propagation, the neural network takes the input parameters and outputs a confidence score to the nodes in the next layer until the output layer is reached where the error of the score is calculated. With backpropagation inside of a process called gradient descent, the errors are sent back through the network again and the weights are adjusted, improving the model.
Graphs are data structures consisting of connected nodes (called vertices) and edges. Every modern framework for deep learning is based on the concept of graphs, where neural networks are represented as a graph structure of computations.
MXNet symbolic programming allows functions to be defined abstractly through computation graphs. With symbolic programming, complex functions are first expressed in terms of placeholder values. Then these functions can be executed by binding them to real values. Symbolic programming also provides predefined neural network layers allowing to express large models concisely with less repetitive work and better performance.
Image reference: https://www.cs.cmu.edu/~muli/file/mxnet-learning-sys.pdf
Symbolic programming has the following advantages:
- The clear boundaries of a computation graph provide more optimization opportunities by the backend MXNet executor
- It’s easier to specify the computation graph for neural network configurations
Hybrid Programming Mode with the Gluon API
One of the key advantages of MXNet is its included hybrid programming interface, Gluon, which bridges the gap between the imperative and symbolic interfaces while keeping the capabilities and advantages of both. Gluon is an easy-to-learn language that produces fast portable models. With the Gluon API, you can prototype your model imperatively using NDArray. Then you can switch to symbolic mode with the hybridize command for faster model training and inference. In symbolic mode, the model runs faster as an optimized graph with the backend MXNet executor and can be easily exported for inference in different language bindings like java or C++.