-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Feature/evaluator #5331
Merged
Merged
Feature/evaluator #5331
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
cf302bd
"add evaluator design doc"
dzhwinter debfb00
"add evaluator design doc"
dzhwinter 796eaf3
"add accuracy "
dzhwinter 83e6500
Merge remote-tracking branch 'origin/develop' into feature/evaluator
dzhwinter 233a305
"need to write math functors"
dzhwinter bdc832c
"add eval interface"
dzhwinter c09ad73
"add fit a line test"
dzhwinter 8d9b334
Merge remote-tracking branch 'origin/develop' into feature/evaluator
dzhwinter c4ac7fa
'add f1 test'
dzhwinter 7874399
Merge remote-tracking branch 'origin/develop' into feature/evaluator
dzhwinter 79a2ce4
"add small evaluation"
dzhwinter e34e129
Merge remote-tracking branch 'origin/develop' into feature/evaluator
dzhwinter b8f557f
"add elementwise_add more type"
dzhwinter 46c61b3
"add elementwise op support"
dzhwinter cfbc92e
"polish document"
dzhwinter 9e1799c
"fix based on comments"
dzhwinter 7c79243
"delete test evaluator"
dzhwinter fc117ec
Merge remote-tracking branch 'origin/develop' into feature/evaluator
dzhwinter 12858ba
"relauch ci"
dzhwinter 2f33f74
Merge remote-tracking branch 'origin/develop' into feature/evaluator
dzhwinter b32faa0
"fix import error"
dzhwinter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
## Evaluator Design | ||
|
||
### The Problem | ||
|
||
During training or serving, we provide the evaluation function to measure the model performance, e.g., accuracy, precision. In the operator based framework design, the data go through the network pipeline batch by batch. As a result, inside the operator, we only can calculate one minibatch metrics. We need to provide a mechanism to calculate the metrics for each N pass/batch the user wanted. | ||
|
||
### Evaluator Design | ||
Currently, every operation is expressed in the graph. we divide the evaluator process into three steps. | ||
|
||
1. Initialize the metric state and add it into the block. | ||
|
||
2. Calculate the statistic of the metric state in every mini-batch. The single operator is only responsible for calculating necessary statistics for one mini-batch. For example, accuracy operator only calculate a minibatch data if run once. | ||
|
||
|
||
3. Merge the mini-batch statistics to form the evaluation result for multiple mini-batches. When it comes to distributed training/Multi-GPU training, aggregate the value from different devices. | ||
|
||
### Implementation | ||
This design is shown in python API. | ||
Each metric operator need to caculate the metric statistic and return the batch aware states, Python side responsible for accumulate the states for each pass. | ||
|
||
|
||
```python | ||
class Evaluator(object): | ||
""" | ||
Evaluator Base class. | ||
""" | ||
def __init__(self, name, **kwargs): | ||
""" | ||
Different evaluator may has different metric states. E.g, Accuracy need two variables, total and right sample counts. | ||
Auc need four variables, `true_positives`, | ||
`true_negatives`, `false_positives` and `false_negatives`. So every evaluator should create its needed variables and append to main_program | ||
The initialization of Evaluator should be responsible for: | ||
create metric states and append to the main_program | ||
""" | ||
pass | ||
|
||
def _update_ops(self, input, label, **kwargs) | ||
""" | ||
Add mini-batch evaluator caculate operators to the main_program. | ||
Add increment operator to accumulate the metric states. | ||
""" | ||
|
||
|
||
def reset(self, executor, reset_program=None): | ||
""" | ||
Reset metric states at the begin of each pass/user specified batch number. | ||
Execute the reset_program to reset the states. | ||
""" | ||
|
||
|
||
def eval(self, executor, eval_program=None): | ||
""" | ||
Merge the mini-batch statistics to form the evaluation result for multiple mini-batches. | ||
Execute the eval_program and return the result. | ||
""" | ||
return eval_result | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw the code below, it seems that we need some detailed description of how to implement evaluator operators in C++, how to save state in C++ and update them in python side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I will add the detail.
Currently, we have two options.
option 1, just like the TensorFlow does, composing the low-level operators to compute metric. If the performance is a real bottleneck, rewrite them in the c++ side as a new operator.
option 2, we use c++ operator to calculate every mini-batch metric and maintain some states in Python side.
I'm not sure which is better now. I implement the option 2, how do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.