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

Conversation

jacquesqiao
Copy link
Member

@jacquesqiao jacquesqiao commented Jun 25, 2017

fix: #2534 #2565

Problem:

when training or infering with python v2 api, if trainer_count > 1 and call trainer.train or inferer.infer multiple times, the process will hang.

Reason:

when trainer_count > 1, paddle will use MultiGradientMachine and will start multiple worker threads to do the forward/backward work(thread number is trainer_count)

In v2 python API, trainer or inferer will call gradinet_machine.finish() after train/infer, this will stop the worker threads, when you call trianer.train or inferrer.infer the second time, there are no worker thread to handle the task, so it hangs there.

Fix:

Do not close worker threads when gradientMachine.finish() is called, close them in the destructor of gradientMachine.

@typhoonzero
Copy link
Contributor

Just to confirm, will swig call c++'s defunctor when a python object is released?

@@ -326,12 +332,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

@@ -171,6 +171,12 @@ MultiGradientMachine::MultiGradientMachine(const ModelConfig& config,
}
}

MultiGradientMachine::~MultiGradientMachine() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe in destructor, we should check whether MultiGradientMachine is finished or not?

If MultiGradientMachine is not finish, then invoke this->finish();

@jacquesqiao
Copy link
Member Author

Just to confirm, will swig call c++'s defunctor when a python object is released?

@typhoonzero not sure, I will check it.

@jacquesqiao jacquesqiao merged commit bf57345 into PaddlePaddle:develop Jun 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

python script hangs when trainer_count > 1 and call trainer.train() more than once.
3 participants