Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Missing constant symbol (equivalent of tf.constant)? #8428

Open
Ajoo opened this issue Oct 25, 2017 · 3 comments
Open

Missing constant symbol (equivalent of tf.constant)? #8428

Ajoo opened this issue Oct 25, 2017 · 3 comments

Comments

@Ajoo
Copy link

Ajoo commented Oct 25, 2017

Hi, I just started using this framework for building something that is only marginally related to deep learning. As such, pardon me if this is simply due to my unfamiliarity or if this is an issue that doesn't arise often for deep learning applications.

Basically, I'm trying to do simple operations with symbols involving constant tensors but I cannot find an obvious way to do it. There's sym.ones and sym.zeros which create constant symbols of ones and zeros but there doesn't seem to be an easy way to create an arbitrary constant tensor symbol that I can use in operations such as sym.dot...

@szha
Copy link
Member

szha commented Oct 25, 2017

Yes, it would be nice to have a constant symbol similar to nd.array

@solin319
Copy link
Contributor

  1. define a var in symbol
weight = mx.symbol.Variable(name="weight", lr_mult=0)
  1. define a mixed initializer, init the weight by const ndarray
weight = mx.nd.ones((3))
initializer = mx.init.Mixed(['weight', '.*'], [mx.init.Constant(weight), xavier])

@analog-cbarber
Copy link

As a workaround, you can implement a constant CustomOp. It requires that you serialize the data through the CustomOpProp implementation somehow. One example of this can be seen here:
https://github.com/tqchen/mxnet-gan/blob/master/mxgan/custom_ops.py

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants