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

Add constant parameter #9893

Merged
merged 4 commits into from
Feb 28, 2018
Merged

Add constant parameter #9893

merged 4 commits into from
Feb 28, 2018

Conversation

piiswrong
Copy link
Contributor

Description

(Brief description on what this PR is about)

Checklist

Essentials

  • Passed code style checking (make lint)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@piiswrong piiswrong requested a review from szha as a code owner February 27, 2018 02:03
self.const = self.params.get_constant('const', self.value)

def hybrid_forward(self, F, x, const):
return x + const
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be x + self.const?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const is the parameter, and block handles it.

@@ -548,6 +588,45 @@ def get(self, name, **kwargs):
setattr(param, k, v)
return param

def get_constant(self, name, value=None):
Copy link
Member

@szha szha Feb 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When developing for a language model with weight drop, we took the approach of adding a new type of Parameter. While using the new WeightDropParameter, we found it quite difficult as user to properly change the type of parameter in the ParameterDict. Since dropout-on-parameter is a common use case too, should we be open to adding a getter function for such parameter as well? Or should we consider a different pattern?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I've met some similar problems implementing the weight normalization, which also transforms the parameters.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the pattern here is that we need parameter transformation, and it can be done through overriding the data() (and maybe grad()) method. This currently requires inheriting the Parameter class, and there is no existing method in casting the parameter type. So in this case, what's needed is a way to cast the parameter.

One alternative is to provide a place to plug in transformation functions in data() and grad().

@piiswrong piiswrong merged commit 8940fb3 into apache:master Feb 28, 2018
rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
* add constant parameter

* Update parameter.py

* Update parameter.py

* Update gluon.md
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
* add constant parameter

* Update parameter.py

* Update parameter.py

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

Successfully merging this pull request may close these issues.

3 participants