[Script] Add inference function for BERT classification #639
[Script] Add inference function for BERT classification #639
Conversation
Job PR-639/1 is complete. |
Codecov Report
@@ Coverage Diff @@
## master #639 +/- ##
==========================================
- Coverage 63.63% 63.46% -0.17%
==========================================
Files 141 141
Lines 12815 12849 +34
==========================================
Hits 8155 8155
- Misses 4660 4694 +34
|
Codecov Report
@@ Coverage Diff @@
## master #639 +/- ##
==========================================
- Coverage 63.23% 63.14% -0.09%
==========================================
Files 141 141
Lines 13013 13023 +10
==========================================
- Hits 8229 8224 -5
- Misses 4784 4799 +15
|
Do I need to deal with the codecov complaints? |
@TaoLv you can ignore it for now. I guess some aggregation of the reports may not be correct so I will look into that. |
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.
Thanks! A few comments;
scripts/bert/finetune_classifier.py
Outdated
toc = time.time() | ||
total_num = dev_batch_size * len(dev_data) | ||
logging.info('Time cost={:.2f} s throughput={:.2f} samples/s'.format( | ||
toc - tic, total_num / (toc - tic))) |
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.
lazy logging
logging.info('Time cost=%.2f s throughput=%.2f samples/s', toc - tic, total_num / (toc - tic))
Other logs should also consider lazy mode.
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.
Thank you for your review @kenjewu. Why do you think lazy logging is better here?
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.
If use lazy construction of the string, the logging string is not actually constructed unless logging actually happens. This will be more efficient
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.
Thanks @kenjewu , and doubt that does the code below need to do lazy logging?
logging.info('params saved in : {0}'.format(params_saved))
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.
not really, but this would: logging.info('params saved in : {0}', params_saved)
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.
Thank you @kenjewu, @szha, @pengxin99 . Now it's fixed.
…classification-inference
Job PR-639/3 is complete. |
Job PR-639/4 is complete. |
'--only_inference', | ||
action='store_true', | ||
help='whether to do inference only on dev data. ' | ||
'If true, will load params from --model_parameters.') |
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.
Can you add a test in gluon-nlp/scripts/tests/test_bert.py
?
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.
Not sure how to do that. It needs a params file to do inference.
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.
Ok. Let's revisit it later once we have some pre-trained model uploaded that can be used for inference
Job PR-639/2 is complete. |
Now inference log looks as following:
|
Job PR-639/6 is complete. |
LGTM. Ping @kenjewu @eric-haibin-lin for another round of review. |
@@ -325,8 +330,37 @@ def evaluate(dataloader_eval, metric): | |||
logging.info(metric_str, *metric_val) | |||
|
|||
|
|||
def log_train(batch_id, batch_num, metric, step_loss, log_interval, epoch_id, learning_rate): | |||
metric_nm, metric_val = metric.get() |
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.
Although this is just a small auxiliary function, it is more standard if you can add a function comment.
In addition, log_train
and log_inference
currently appear to be slightly different only when constructing a log string. Is it better to integrate as a function or to keep it so separated now?
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.
Thank you @kenjewu . Doc string is added for each function. I would like to keep the functions separated as is.
Job PR-639/7 is complete. |
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.
Comments addressed
* add inference function for finetune_classifier * fix some comments * lazy logging * log message functions * fix lint * add doc string
* add inference function for finetune_classifier * fix some comments * lazy logging * log message functions * fix lint * add doc string
* add inference function for finetune_classifier * fix some comments * lazy logging * log message functions * fix lint * add doc string
Description
(Brief description on what this PR is about)
Checklist
Essentials
Changes
Comments