This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MXNET-72] Improve sparse.adam_update (#10062)
* Bump 1.1 (#192) * bump * also update base.h * revert website changes * Update index.html * update news.md (#191) * Update NEWS.md * Update README.md * refactor regression ops to nnvm interface (#9540) * refactor regression ops * fix err for instantiation of minus_sign * remove useless header file init_op.h * replace with macro and address other comments * update * minor revise docs * add mae test * Update KEYS * Update NEWS.md * fixed links that were missng ndarray folder path (#9618) * Fixed 4 broken links (#9698) * Fixed 4 broken links * fixed pylint for long line disable and 1 broken link * Update NEWS.md * Update NOTICE (#9706) * revert acc changes (#9731) * Revert "avoid per-batch blocking in metric (#9636)" This reverts commit 3fe694e. * Revert "proper flatten in acc (#9619)" This reverts commit ed823b2. * Revert "use nd for accuracy calculation (#9583)" This reverts commit f5f1b91. * keep doc change * PGP keys add liuyizhi AT apache.org (#9728) * Add my key (#9736) * [REVIEW REQUIRED] Revert PR #9484 & add additional dependency licenses to LICENSE file (#9701) * Revert "[Review Required] Fixing Licenses: Cleaning up the Top Level LICENSE file (#9484)" This reverts commit 8930d96. * Some more LICENSE fixes * Adding some more packages to the LICENSE file * Adding dependencies of dependencies * update navbar model zoo link (#9749) * update navbar model zoo link * update * initial commit * clean up * refactor * fix test
- Loading branch information
1 parent
88f2bd0
commit f0f745d
Showing
5 changed files
with
196 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
import time | ||
import mxnet as mx | ||
from mxnet.ndarray.sparse import adam_update | ||
import numpy as np | ||
import argparse | ||
|
||
mx.random.seed(0) | ||
np.random.seed(0) | ||
|
||
parser = argparse.ArgumentParser(description='Benchmark adam updater') | ||
parser.add_argument('--dim-in', type=int, default=240000, help='weight.shape[0]') | ||
parser.add_argument('--dim-out', type=int, default=512, help='weight.shape[1]') | ||
parser.add_argument('--nnr', type=int, default=5000, help='grad.indices.shape[0]') | ||
parser.add_argument('--repeat', type=int, default=1000, help='num repeat') | ||
parser.add_argument('--dense-grad', action='store_true', | ||
help='if set to true, both gradient and weight are dense.') | ||
parser.add_argument('--dense-state', action='store_true', | ||
help='if set to true, states are dense, indicating standard update') | ||
parser.add_argument('--cpu', action='store_true') | ||
|
||
|
||
args = parser.parse_args() | ||
dim_in = args.dim_in | ||
dim_out = args.dim_out | ||
nnr = args.nnr | ||
ctx = mx.cpu() if args.cpu else mx.gpu() | ||
|
||
ones = mx.nd.ones((dim_in, dim_out), ctx=ctx) | ||
|
||
if not args.dense_grad: | ||
weight = ones.tostype('row_sparse') | ||
indices = np.arange(dim_in) | ||
np.random.shuffle(indices) | ||
indices = np.unique(indices[:nnr]) | ||
indices = mx.nd.array(indices, ctx=ctx) | ||
grad = mx.nd.sparse.retain(weight, indices) | ||
else: | ||
weight = ones.copy() | ||
grad = ones.copy() | ||
|
||
if args.dense_state: | ||
mean = ones.copy() | ||
else: | ||
mean = ones.tostype('row_sparse') | ||
|
||
var = mean.copy() | ||
|
||
# warmup | ||
for i in range(10): | ||
adam_update(weight, grad, mean, var, out=weight, lr=1, wd=0, beta1=0.9, | ||
beta2=0.99, rescale_grad=0.5, epsilon=1e-8) | ||
weight.wait_to_read() | ||
|
||
# measure speed | ||
a = time.time() | ||
for i in range(args.repeat): | ||
adam_update(weight, grad, mean, var, out=weight, lr=1, wd=0, beta1=0.9, | ||
beta2=0.99, rescale_grad=0.5, epsilon=1e-8) | ||
weight.wait_to_read() | ||
b = time.time() | ||
print(b - a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters