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

standard update for sparse sgd_mom_update #9189

Merged
merged 12 commits into from
Jan 5, 2018
Merged

standard update for sparse sgd_mom_update #9189

merged 12 commits into from
Jan 5, 2018

Conversation

ZiyueHuang
Copy link
Member

@ZiyueHuang ZiyueHuang commented Dec 23, 2017

Description

#9177

cc @eric-haibin-lin

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

  • unittest

Comments

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

@eric-haibin-lin eric-haibin-lin self-assigned this Dec 27, 2017
@@ -464,16 +465,19 @@ class SGD(Optimizer):
----------
momentum : float, optional
The momentum value.
lazy_update : bool, optional
If True, standard updates are applied.
Copy link
Member

Choose a reason for hiding this comment

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

Clarify the default value, too

@@ -96,11 +147,15 @@ only the row slices whose indices appear in grad.indices are updated (for both w
.set_attr_parser(ParamParser<SGDMomParam>)
.set_attr<nnvm::FInferShape>("FInferShape", ElemwiseShape<3, 1>)
.set_attr<nnvm::FInferType>("FInferType", ElemwiseType<3, 1>)
.set_attr<FInferStorageType>("FInferStorageType", ElemwiseStorageType<3, 1, false, true, false>)
Copy link
Member

Choose a reason for hiding this comment

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

Also update the doc here, too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated

}
if (!dispatched && in_attrs->at(0) == kRowSparseStorage &&
in_attrs->at(1) == kRowSparseStorage &&
(in_attrs->at(2) == kRowSparseStorage || in_attrs->at(2) == kDefaultStorage)) {
Copy link
Member

Choose a reason for hiding this comment

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

Save in_attrs->at(2) in a local var to improve readability?

DType* mom_data = mom.dptr<DType>();
DType* out_data = out->dptr<DType>();
nnvm::dim_t num_rows = weight.shape_[0];
auto row_length = weight.shape_.ProdShape(1, weight.ndim());
Copy link
Member

Choose a reason for hiding this comment

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

let's not use auto


nnvm::dim_t* prefix_sum = reinterpret_cast<nnvm::dim_t*>(workspace.dptr_);
// mark row flags
Fill<false>(s, TBlob(prefix_sum, Shape1(num_rows), cpu::kDevMask), kWriteTo, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Fill uses memset which is single-thread. It's slow for large number of elements. Let's use Kernel<set_zero, cpu>::Launch

@@ -433,7 +433,8 @@ def _get_wd(self, index):
class SGD(Optimizer):
"""The SGD optimizer with momentum and weight decay.

The optimizer updates the weight by::
If any storage type of weight, state or grad is ``default``, \
**standard updates** are applied by::
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 we should reverse the order and mention lazy_update, since the users of optimizer don't know how state stypes are created:

If the storage types of weight and grad are both ``row_sparse``, and ``lazy_update`` is True,  **lazy updates** are applied by::
 
         for row in grad.indices:
            ...

Otherwise, **standard updates** are applied by:
          ...

: prefix_sum[i] > prefix_sum[i-1];

for (index_t j = 0; j < row_length; j++) {
const index_t data_i = i * row_length + j;
Copy link
Member

Choose a reason for hiding this comment

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

i * row_length can be cached and computed only once.
Same for (prefix_sum[i]-1) * row_length

Copy link
Member

@eric-haibin-lin eric-haibin-lin left a comment

Choose a reason for hiding this comment

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

LGTM in general

@@ -460,6 +461,99 @@ inline void SGDMomUpdateRspRspRspImpl(const SGDMomParam& param,
mom.data(), req, &out_blob);
}

template<int n_rsp, int n_rsp_dns>
Copy link
Member

Choose a reason for hiding this comment

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

Let's add some description on what the template params mean

@eric-haibin-lin eric-haibin-lin merged commit df9f79a into apache:master Jan 5, 2018
yuxiangw pushed a commit to yuxiangw/incubator-mxnet that referenced this pull request Jan 25, 2018
* standard sparse sgd mom update

* update

* update comments

* address comments

* revise

* more general infer stype

* fix

* fix

* add comments for stype inference func

* update
@ZiyueHuang ZiyueHuang deleted the std_sparse_sgd branch January 30, 2018 11:30
rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
* standard sparse sgd mom update

* update

* update comments

* address comments

* revise

* more general infer stype

* fix

* fix

* add comments for stype inference func

* update
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
* standard sparse sgd mom update

* update

* update comments

* address comments

* revise

* more general infer stype

* fix

* fix

* add comments for stype inference func

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

2 participants