Is Gluon going to replace Symbol?


#1

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.

Thanks!


#2

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.


#3

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.


#4

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.


#5

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).


#6

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.


#7

I understand that Gluon is much more flexible and more user friendly and you can even speed up by hybridizing the model, and after hybridizing your model would be almost 2x faster than before.

But the problem is that the symbolic graphs using symbol api is even 30% more faster than hybridized Gluon model, so why should we indulge in something which is slower? Moreover it is easy to make your own custom computation and backpropagate through it using symbol api, while in Gluon you have to make our own class using “block” or “hybrid block”.

I think the only use case of gluon is to use its imperative and flexible nature, through which we can do debugging for your model by changing the computation graph (which is not possible with symbol api) and then finally build our model using symbol api.

So its like using gluon for research and learning stuff, and symbol api for production.

PS: Plz correct me if I am wrong anywhere, I am just 18 years old and just started deep learning. I started using Mxnet when I found that doing research work in tensorflow is very difficult.