rahul003 closed pull request #8764: Gradient compression example and raise exception if kvstore type unsupported URL: https://github.com/apache/incubator-mxnet/pull/8764
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/example/gluon/word_language_model/train.py b/example/gluon/word_language_model/train.py index 0b504998be..b419277dcf 100644 --- a/example/gluon/word_language_model/train.py +++ b/example/gluon/word_language_model/train.py @@ -54,6 +54,11 @@ help='report interval') parser.add_argument('--save', type=str, default='model.params', help='path to save the final model') +parser.add_argument('--gctype', type=str, default='none', + help='type of gradient compression to use, \ + takes `2bit` or `none` for now.') +parser.add_argument('--gcthreshold', type=float, default=0.5, + help='threshold for 2bit gradient compression') args = parser.parse_args() @@ -90,10 +95,13 @@ def batchify(data, batch_size): model = model.RNNModel(args.model, ntokens, args.emsize, args.nhid, args.nlayers, args.dropout, args.tied) model.collect_params().initialize(mx.init.Xavier(), ctx=context) + +compression_params = None if args.gctype == 'none' else {'type': args.gctype, 'threshold': args.gcthreshold} trainer = gluon.Trainer(model.collect_params(), 'sgd', {'learning_rate': args.lr, 'momentum': 0, - 'wd': 0}) + 'wd': 0}, + compression_params=compression_params) loss = gluon.loss.SoftmaxCrossEntropyLoss() ############################################################################### diff --git a/python/mxnet/kvstore.py b/python/mxnet/kvstore.py index d068d06579..5d6fe2de0a 100644 --- a/python/mxnet/kvstore.py +++ b/python/mxnet/kvstore.py @@ -408,6 +408,8 @@ def set_gradient_compression(self, compression_params): Other keys in this dictionary are optional and specific to the type of gradient compression. """ + if (self.type() == 'device') or ('dist' in self.type()): + raise Exception('Gradient compression is not supported for this type of kvstore') ckeys, cvals = _ctype_dict(compression_params) check_call(_LIB.MXKVStoreSetGradientCompression(self.handle, mx_uint(len(compression_params)), ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services