Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step size for parameter updater #3459

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions python/paddle/v2/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ def save_parameter_to_tar(self, f):
self.__parameters__.to_tar(f)
self.__parameter_updater__.restore()

def train(self, reader, num_passes=1, event_handler=None, feeding=None):
def train(self,
reader,
num_passes=1,
event_handler=None,
feeding=None,
step_size=1):
"""
Training method. Will train num_passes of input data.

Expand All @@ -119,6 +124,7 @@ def train(self, reader, num_passes=1, event_handler=None, feeding=None):
:param feeding: Feeding is a map of neural network input name and array
index that reader returns.
:type feeding: dict|list
:param step_size: the step size for parameter updater
:return:
"""
import py_paddle.swig_paddle as api
Expand Down Expand Up @@ -167,7 +173,8 @@ def train(self, reader, num_passes=1, event_handler=None, feeding=None):
batch_id=batch_id,
cost=cost,
evaluator=batch_evaluator))
self.__parameter_updater__.finishBatch(cost)
if batch_id >= step_size and batch_id % step_size == 0:
self.__parameter_updater__.finishBatch(cost)
Copy link
Contributor

@helinwang helinwang Aug 14, 2017

Choose a reason for hiding this comment

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

This is assuming the gradient is not reset to 0 and always accumulating new gradients across different steps, unless para->getBuf(PARAMETER_GRADIENT)->zeroMem(); is called.
I have checked the implementation inside NeuralNetwork.cpp, which does not reset the gradient across different steps, but each layer have access to the parameters and could potentially reset the gradient.
Just double check, did you verify with @jacquesqiao or @hedaoyuan about the correctness of this implementation?

batch_evaluator.finish()

self.__parameter_updater__.finishPass()
Expand Down