Skip to content

Delay Compensated Asynchronous Stochastic Gradient Descent - #9551

Merged
maciekcc merged 29 commits into
tensorflow:masterfrom
just-a-jazz:asgd-dc
May 22, 2017
Merged

maciekcc merged 29 commits into
tensorflow:masterfrom
just-a-jazz:asgd-dc

Conversation

@just-a-jazz

Copy link
Copy Markdown

This adds the feature requested by #8744

@tensorflow-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@vrv

vrv commented May 1, 2017

Copy link
Copy Markdown

Thanks for this change!

  • There are very few comments explaining what's going on. Because this is a variation of a standard algorithm, it probably needs some more comments explaining what the equations are.

  • This is going to fail our linter because the lines are too long, indentation is not correct, etc. See Add Continuous Integration + Review Requirements to CONTRIBUTING.md #7443 (comment) for what needs to be done!

  • There are no tests; we need tests to make sure this is working correctly from a unit-testing perspective.

  • People would want proof that this implementation can be used to validate the results of the paper -- have you done any validation yourself? If so, can you provide some reproduction steps? For example, having something like in the mxnet pull request linked from the issue will be useful to show: 1) that it is working, 2) that it actually helps.

Thanks again!

@vrv
vrv requested review from mrry and vrv May 1, 2017 17:37
@vrv vrv self-assigned this May 1, 2017
@vrv vrv added the stat:awaiting response Status - Awaiting response from author label May 4, 2017
@vrv

vrv commented May 10, 2017

Copy link
Copy Markdown

ping for @alisidd !

@just-a-jazz

Copy link
Copy Markdown
Author

@vrv Hi, I'm still working on it, I should hopefully have a working version by tomorrow.

@tensorflow-jenkins

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

@just-a-jazz

Copy link
Copy Markdown
Author

@vrv I've made the requested changes, and I found quite a few problems with my implementations that required a few changes that I wasn't sure if I should be making, like an addition of an optional parameter to a method in the Optimizer class. It allows for multithreaded processing using one optimizer object. Regardless, I'm sure you can see what else I had to change.

Furthermore, I tested and validated the implementation using a modified version of mnist_softmax.py with 12 asynchronous workers, and a variance parameter of 5. I found there to be an improvement of around 1.5% in test accuracy over asynchronous stochastic gradient descent, similar to improvements found in the research paper.

@vrv

vrv commented May 12, 2017

Copy link
Copy Markdown

Thanks for making these changes -- though I think changing the public API of optimizers just for this one case suggests that the Optimizer interface is now doing too much.

I'm not too familiar with the optimizer interface personally, but one thought: the idea of delay compensated updates could theoretically apply to any gradient descent algorithm; instead of having this version descend from Optimizer, does it make sense to:

  1. Subclass Optimizer to be a DelayCompensatedOptimizer, where you add your specific modifications based on worker_index

  2. Make GradientDescentDC descend from it?

Let me know what you think!

(Also, I'd probably be verbose on the names here: DelayCompensatedGradientDescent; the term "DC" isn't standard enough for it to be abbreviated).

@vrv

vrv commented May 12, 2017

Copy link
Copy Markdown

Also there aren't any tests that actually exercise more than 1 worker, so it's hard to tell the context in which it's needed.

@jhseu in case he has any thoughts on optimizer interface

@just-a-jazz

just-a-jazz commented May 12, 2017 •

Copy link
Copy Markdown
Author

@vrv A whole class for adding the ability to address updates by the worker index would have usage if more algorithms were added similar to this one that depended on having that kind of information. I need that information because I need to store a separate var for each worker, and keep them separate throughout the optimization. I don't think most gradient descent algorithms need that kind of information though.

@vrv vrv added the API review API Review label May 13, 2017
@vrv

vrv commented May 15, 2017

Copy link
Copy Markdown

(I've assigned this the API review label so that the folks who look at API changes can assess whether this is something to accept.)

@rmlarsen

Copy link
Copy Markdown
Contributor

@tensorflow-jenkins test this please

@rmlarsen

Copy link
Copy Markdown
Contributor

@alisidd sorry it looks like you need to rebase again.

@just-a-jazz

Copy link
Copy Markdown
Author

@rmlarsen Should be good now

@vrv

vrv commented May 20, 2017

Copy link
Copy Markdown

No need to change the name! @tensorflow-jenkins test this please

@just-a-jazz

Copy link
Copy Markdown
Author

#10055 seems to have had the same problem when it was approved, not sure if I'm supposed to do something.

@vrv vrv added awaiting testing (then merge) and removed API review API Review stat:awaiting response Status - Awaiting response from author labels May 21, 2017
@vrv

vrv commented May 21, 2017

Copy link
Copy Markdown

@tensorflow-jenkins test this please

(it looks like no GPU kernels are registered, but perhaps that can be added as a future PR if someone wants. it's pretty straightforward to copy the existing code for other optimizers).

@maciekcc
maciekcc merged commit 375a392 into tensorflow:master May 22, 2017
@zhuhyc

zhuhyc commented Jun 28, 2017

Copy link
Copy Markdown

@alisidd @vrv
I add supporting GPU kernels base your code, when I execute a test,it runs on CPU normally, but it occurs an error on GPU

 python tensorflow/tensorflow/examples/tutorials/mnist/mnist_softmax_dc_asgd.py

the error is:

  **_2017-06-28 10:58:29.296340: E tensorflow/core/common_runtime/executor.cc:641] Executor failed to create kernel. Invalid argument: AttrValue must not have reference type value of float_ref
 for attr 'tensor_type'
; NodeDef: w/DelayCompensatedGradientDescent/_23 = _HostRecv[_start_time=0, client_terminated=false, recv_device="/job:localhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_103_w/DelayCompensatedGradientDescent", tensor_type=DT_FLOAT_REF, _device="/job:localhost/replica:0/task:0/gpu:0"](^w/DelayCompensatedGradientDescent/_22, ^DelayCompensatedGradientDescent/learning_rate, ^gradients/MatMul_grad/tuple/control_dependency_1, ^DelayCompensatedGradientDescent/lambda); Op<name=_HostRecv; signature= -> tensor:tensor_type; attr=tensor_type:type; attr=tensor_name:string; attr=send_device:string; attr=send_device_incarnation:int; attr=recv_device:string; attr=client_terminated:bool,default=false; is_stateful=true>
 [[Node: w/DelayCompensatedGradientDescent/_23 = _HostRecv[_start_time=0, client_terminated=false, recv_device="/job:localhost/replica:0/task:0/gpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_103_w/DelayCompensatedGradientDescent", tensor_type=DT_FLOAT_REF, _device="/job:localhost/replica:0/task:0/gpu:0"](^w/DelayCompensatedGradientDescent/_22, ^DelayCompensatedGradientDescent/learning_rate, ^gradients/MatMul_grad/tuple/control_dependency_1, ^DelayCompensatedGradientDescent/lambda)]]_**

the test code is here :
https://github.com/zhuhyc/tensorflow/blob/dc-asgd/tensorflow/examples/tutorials/mnist/mnist_softmax_dc_asgd.py

the patch is here:
https://github.com/zhuhyc/tensorflow/blob/dc-asgd/dc-asgd.patch
can you give me some suggestions to reslove this error?

@sesamesub

Copy link
Copy Markdown

I'm trying to learn more dcsgd and external optimizers for tf, I'm unsure how to implement this feature with the tf learn library examples.

@zhuhyc
Does your testcode work for CPUs? When I run the softmax example on docker nightly CPU build, I get the following result:

$ python mnist_softmax_dc_asgd.py

Traceback (most recent call last):
File "mnist_softmax_dc_asgd.py", line 84, in
tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "mnist_softmax_dc_asgd.py", line 64, in main
train_step = optimizer.minimize(cross_entropy,worker_index=0)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/opt/python/training/delay_compensated_gradient_descent.py", line 144, in minimize
name=name, worker_index=worker_index)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/opt/python/training/delay_compensated_gradient_descent.py", line 217, in apply_gradients
worker_index))
File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/opt/python/training/delay_compensated_gradient_descent.py", line 34, in update_op_asynchronous
return optimizer._apply_dense(g, self._v, index)
TypeError: _apply_dense() takes exactly 3 arguments (4 given)

@zhuhyc

zhuhyc commented Jun 29, 2017

Copy link
Copy Markdown

@sesamesub
Yes, it works for on CPUs correctly. My tf version is master branch and have applyed dc-asgd.patch
the patch is here:
https://github.com/zhuhyc/tensorflow/blob/dc-asgd/dc-asgd.patch
It looks like you don't apply the patch, please apply it and test again

@sesamesub

sesamesub commented Jul 7, 2017 via email

Copy link
Copy Markdown

@zhuhyc

zhuhyc commented Jul 10, 2017

Copy link
Copy Markdown

Ping to check status @alisidd

self._lambda = variance_parameter
self._num_workers = num_workers

def minimize(self, loss, global_step=None, var_list=None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hello -

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not use the minimize from the parent class? It seems this is copied exactly?

grads_and_vars,
global_step=None,
name=None,
worker_index=None):

@ry ry Aug 8, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also seems to be 95% copied from parent class?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@alisidd question for you above regarding subclassing.
cc @vrv

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

My preference was that delay-compensated-specific bits should not leak out to the parent class, which the original implementation did by adding worker_index to the public APIs. Where possible, it would be indeed nice to just reuse existing funtionality like in minimize(), but this function relies on extra state that is not available in the base APIs.

@MattX

MattX commented Nov 10, 2017 •

Copy link
Copy Markdown

It looks like this PR was removed from master (commit 47949be), with the message "Remove Delay Compensated Asynchronous Stochastic Gradient Descent (DCASGD). The implementation is broken in its current form."

What was wrong with the implementation? The message only references this PR and issue #8744, none of which seem to be mentioning problems.

@vrv

vrv commented Nov 10, 2017

Copy link
Copy Markdown

IIRC, it was lacking an _apply_dense() implementation, there were typos that caused failures when used, etc.

The commit is obviously in the history for somebody to re-use and fix, if they wanted, but they'd need to write more tests and probably refactor it to make it something that the team could accept to TensorFlow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.