Is Gluon going to replace Symbol?


Hello all! I am working on a machine learning project using MXNet, and I am currently using Symbol-based models from the MXNet Model Zoo. I’m wondering if I should switch over to Gluon models. I know Gluon is an easier interface, but will it be replacing the Symbol API in the future? I ask because it seems that the Gluon forward pass was slower for me than Symbol, so I would prefer to stick with Symbol for performance, but I also don’t want to be stuck with a legacy platform.



Hi @qheaden, Gluon API would be the recommended route if you’re getting started now.

Just to clarify, I think you’re actually deciding between Gluon API and the Module API. Under the hood Gluon still uses the NDArray API and Symbol API (depending on whether your hybridize your model).

With regards to performance in Gluon, the key is hybridization. When you first create a model with Gluon you’ll be using the NDArray API under the hood and you’ll get more flexibility and easier debugging at the expense of performance, which is what you’re seeing. But when you’re finished creating your network (e.g. net), you can call net.hybridize() to use Symbol API under the hood and get improved performance, similar to what you’d see when using Module API with Symbols.

Check out this tutorial, and you can find the Gluon Model Zoo here.


Thanks @thomelane! I think I know what my performance issue was with Gluon. I was calling hybridize(), but I didn’t realize that it builds the graph after the first forward pass. I was testing my model with a one-shot python script that would build everything, run the model, print the results, then exit. So it never got a chance to use the cache. In reality, I am going to build an API around this, so the cache would definitely be used.

I already have some models trained using the Symbol-based Model Zoo. Is there an easy way to load Symbol-based models using Gluon?

Thanks again.


I’m facing the similar problem.

For me, I feel use symbol/ndarray more intuitive and help me to understand ML/MxNet better. But it’s really hard to debug pure symbol codes. So I think maybe using Gluon and hybridize() is the correct way to go in the future.


Yes, you can integrate an existing symbol into Gluon. Check out SymbolBlock, as this can be used to wrap a Symbol in a Block (which are the building ‘blocks’ of Gluon).


Gluon’s definitely the way to go if you’re looking for improved debugging. Working with NDArrays (instead of Symbols) allows you to step through code and inspect values and shapes easily. Check out this video for an example of Gluon debugging.