What is the difference between Symbol and Gluon? Why are there two modules, mx.symbol and mx.sym?

Q1: I don’t know why there are two different api. After read this topic, I think gluon is a new api which supports dynamic graph, it’s easy to debug but slow, right?
Q2: Why there are two similar module: mx.symbol and mx.sym? What’s the difference?
Q3: In addition to the official api, is there any better tutorial on the symbol interface? I only find many gluon tutorials. Thank you very much

hi,

Q1: There are two different APIs because we want users to have the best of both worlds:

  • an imperative API - Gluon that is very user friendly and allows for quick prototyping, easy debugging and natural control flow for people familiar with python programming.
  • a symbolic API for creating static graphs with low level optimizations on operators and allows for support in multiple languages, cross-compatibility with other frameworks (via ONNX) and as a backend for other high level APIs like keras.

Furthermore gluon performance in terms of speed doesn’t drop off too much compared to symbol. And you can also hybridize gluon blocks so that they get converted to symbol. See this tutorial for more info about hybrid:

http://d2l.ai/chapter_computational-performance/hybridize.html

https://gluon.mxnet.io/chapter07_distributed-learning/hybridize.html

Q2: There’s no difference between mx.symbol and mx.sym. mx.sym is just an alternate module name for mx.symbol. Similar to the way mx.nd is a n alternate module name for mx.ndarray. if you import either mx.sym or mx.symbol, you’ll get the same libraries. See example below

>>> import mxnet
>>> mxnet.sym == mxnet.symbol
True
>>> mxnet.sym is mxnet.symbol
True
>>>

Q3: If you’re just starting out, would strongly nudge you towards trying out gluon for your use cases. However, here’s a getting started tutorial with symbol as well: https://mxnet.incubator.apache.org/versions/master/tutorials/basic/symbol.html.

2 Likes

Here’s some more example codes for symbol.

The symbol tutorial is broken - https://mxnet.incubator.apache.org/versions/master/tutorials/basic/symbol.html

Thanks for pointing this out.

Would strongly encourage you to use gluon as you can hybridize you gluon code after you’re done tinkering and get the benefits of optimizations from symbol.

However, here’s an example from the github repo with symbol.