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

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

Open

Description

@Ajoo

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

Activity

  1. szha commented on Oct 25, 2017

    @szha
    Member

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

  2. solin319 commented on Oct 26, 2017

    @solin319
    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])
    
    
  3. analog-cbarber commented on Feb 23, 2018

    @analog-cbarber

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions