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

fix MultiGradientMachine train and infer #2595

Merged
merged 2 commits into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
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
22 changes: 15 additions & 7 deletions paddle/gserver/gradientmachines/MultiGradientMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,21 @@ MultiGradientMachine::MultiGradientMachine(const ModelConfig& config,

outArgStream_ = HPPL_STREAM_1;

start();
}

void MultiGradientMachine::start() {
for (auto& thread : threads_) {
thread->start();
}
}

void MultiGradientMachine::finish() {
for (auto& thread : threads_) {
thread->stop();
}
}

std::vector<const std::vector<ParameterPtr>*>
MultiGradientMachine::getSlaveParameters() {
std::vector<const std::vector<ParameterPtr>*> vec;
Expand Down Expand Up @@ -326,12 +336,6 @@ void MultiGradientMachine::onPassEnd() {
}
}

void MultiGradientMachine::finish() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why remove finish?

Copy link
Member Author

Choose a reason for hiding this comment

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

After move thread->stop() to destructor, finish() seems has no use.

Copy link
Member Author

Choose a reason for hiding this comment

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

Have add finish back

for (auto& thread : threads_) {
thread->stop();
}
}

Evaluator* MultiGradientMachine::makeEvaluator() const {
return threads_[0]->getGradientMachine()->makeEvaluator();
}
Expand Down Expand Up @@ -445,14 +449,18 @@ TrainerThread::TrainerThread(const ModelConfig& config,

gradStream_ = HPPL_STREAM_2;
valueStream_ = HPPL_STREAM_3;
stopping_ = false;
stopping_ = true;
updateCounter_ = 0;
parameterUpdated_ = false;
}

TrainerThread::~TrainerThread() { stop(); }

void TrainerThread::start() {
if (!stopping_) return;

stopping_ = false;

gradientMachine_->start();

computeThread_.reset(new std::thread([this]() { computeThread(); }));
Expand Down
6 changes: 4 additions & 2 deletions paddle/gserver/gradientmachines/MultiGradientMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ class MultiGradientMachine : public GradientMachine {

explicit MultiGradientMachine(const ModelConfig& config, bool useGpu);

virtual void start();

virtual void finish();

virtual void prefetch(const std::vector<Argument>& inArgs);

virtual void forward(const std::vector<Argument>& inArgs,
Expand All @@ -193,8 +197,6 @@ class MultiGradientMachine : public GradientMachine {

virtual void onPassEnd();

virtual void finish();

virtual Evaluator* makeEvaluator() const;

virtual void eval(Evaluator* evaluator) const;
Expand Down