Skip to content

trainer.test() #10453

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

Merged
merged 13 commits into from
May 11, 2018
Merged

trainer.test() #10453

merged 13 commits into from
May 11, 2018

Conversation

JiayiFeng
Copy link
Collaborator

@JiayiFeng JiayiFeng commented May 7, 2018

Fixes #10363

@JiayiFeng JiayiFeng changed the title [DRAFT] trainer.test() trainer.test() May 8, 2018
@JiayiFeng
Copy link
Collaborator Author

JiayiFeng commented May 8, 2018

Two problems I have encountered:

  1. The train_program may have multiple return values, we need a method to point out which one is the loss.

https://github.com/JiayiFeng/Paddle/blob/21be154df583ae8ba032379878018f90173da563/python/paddle/fluid/trainer.py#L77-L88

  1. In the test, we get metric results of every batch and accumulate them. However, if users return some variables which are not metrics and cannot be accumulated, what shall we do?

accumulated_loss += loss[0]
count += 1

return accumulated_loss / count
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we return Accuracy as well?

@daming-lu
Copy link
Contributor

daming-lu commented May 9, 2018

Based on our discussion, we define the 1st element in the returned tuple as loss. The rest are evaluation metrics. So a sample returned result would look like

(loss, accuracy, f1_score, ...)

@JiayiFeng
Copy link
Collaborator Author

After a discussion with @wangkuiyi and @daming-lu , we have reached two conclusions:

  1. All return values of inference_program are 'predictions'.

  2. train_program can return two kinds of variables: 'loss' and 'metric'. The first return value is the loss, and the others(if any) are metrics.

order in program
"""

return self._test_by_executor(reader, feed_order, self.test_outputs)
Copy link
Member

Choose a reason for hiding this comment

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

Why put all code into a separate function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe in the future, we need to support _test_by_parralle_executor. Here is a reserved interface for switching between multiple executors.

next_word = fluid.layers.data(name='nextw', shape=[1], dtype='int64')
# The declaration of 'next_word' must be after the invoking of inference_program,
# or the data input order of train program would be [next_word, firstw, secondw,
# thirdw, forthw], which is not correct.
predict_word = inference_program(is_sparse)
Copy link
Contributor

@jetfuel jetfuel May 10, 2018

Choose a reason for hiding this comment

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

I think we can also specify the feed order in the
trainer.train(....., feed_order=['firstw', 'secondw', 'thirdw', 'forthw', 'next_word'])

Copy link
Contributor

@jetfuel jetfuel left a comment

Choose a reason for hiding this comment

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

Otherwise, LGTM


def _test_by_executor(self, reader, feed_order, fetch_list):
with executor.scope_guard(self.scope):
feed_var_list = build_feed_var_list(self.test_program, feed_order)
Copy link
Contributor

Choose a reason for hiding this comment

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

Trainer. train takes in feed_order, Will it be possible to re-use the feed_order so we don't need to calculate it?

@jetfuel jetfuel merged commit ba57348 into PaddlePaddle:develop May 11, 2018
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.

4 participants