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

Fix softmax behavior to not cast up the accumulator if no output dtype is specified #14759

Closed
wants to merge 6 commits into from

Conversation

nswamy
Copy link
Member

@nswamy nswamy commented Apr 22, 2019

Description

Softmax operator was recently changed to cast the accumulator type to higher precision data type(in #14098) than the input type regardless of the whether the dtype of the output is passed to the operator or not. This not only breaks backward compatibility but also the increases loss when training a rnn language model with float32 input data type. Details are #14722.

This PR changes the accumulator type only if the dtype has been passed and uses the dtype passed for accumulation.

@eric-haibin-lin

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • 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
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • 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

@nswamy nswamy added Bug Operator pr-awaiting-review PR is waiting for code review labels Apr 22, 2019
@@ -310,9 +311,9 @@ struct SoftmaxParam : public dmlc::Parameter<SoftmaxParam> {
}
};

static inline bool softmax_has_dtype_override(const nnvm::NodeAttrs& attrs) {
static inline int sofmtax_dtype_param(const nnvm::NodeAttrs &attrs) {
Copy link
Member

Choose a reason for hiding this comment

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

typo? softmax

shape.get<3>(), axis, static_cast<DType>(temperature));
}
});
int out_idx = sofmtax_dtype_param(attrs) != -1 ? 2 : 1;
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest we have an env var to trigger stable reduction instead of relying on dtype argument, including other ops like norm

Copy link
Member

Choose a reason for hiding this comment

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

@pinaraws
Copy link

@nswamy Please address comments

@pinaraws
Copy link

@mxnet-label-bot add[pr-awaiting-response]

@marcoabreu marcoabreu added the pr-awaiting-response PR is reviewed and waiting for contributor to respond label May 20, 2019
@pinaraws
Copy link

@mxnet-label-bot remove[pr-awaiting-review]

@marcoabreu marcoabreu removed the pr-awaiting-review PR is waiting for code review label May 20, 2019
@eric-haibin-lin
Copy link
Member

Fixed in #15037

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Operator pr-awaiting-response PR is reviewed and waiting for contributor to respond
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants