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] Set the priority of EvalHook to "LOW" to avoid a bug of IterBasedRunner #488

Merged
merged 2 commits into from
Oct 20, 2021
Merged

[Fix] Set the priority of EvalHook to "LOW" to avoid a bug of IterBasedRunner #488

merged 2 commits into from
Oct 20, 2021

Conversation

okotaku
Copy link
Collaborator

@okotaku okotaku commented Oct 15, 2021

Motivation

If the priority of EvalHook is higher than IterTimerHook, it will cause KeyError: 'data_time' (open-mmlab/mmsegmentation#758, open-mmlab/mmcv#1261).
Since the time key will add to the output of log_buffer after IterTimeHook, the TextLoggerHook will print the time and data_time at the same time.

This PR is based on open-mmlab/mmsegmentation#766 open-mmlab/mmdetection#5882 .

This PR will be useful for models that uses IterBasedRunner.

Modification

Set the priority of EvalHook to LOW.

BC-breaking (Optional)

Does the modification introduce changes that break the backward compatibility of the downstream repositories?
No

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here and update the documentation.

Checklist

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects, like MMDet or MMSeg.
  • CLA has been signed and all committers have signed the CLA in this PR.

@CLAassistant
Copy link

CLAassistant commented Oct 15, 2021

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Oct 15, 2021

Codecov Report

Merging #488 (968e54e) into master (10e8495) will increase coverage by 0.54%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #488      +/-   ##
==========================================
+ Coverage   77.96%   78.51%   +0.54%     
==========================================
  Files         102      102              
  Lines        5619     5612       -7     
  Branches      923      915       -8     
==========================================
+ Hits         4381     4406      +25     
+ Misses       1111     1087      -24     
+ Partials      127      119       -8     
Flag Coverage Δ
unittests 78.51% <0.00%> (+0.54%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmcls/apis/train.py 22.72% <0.00%> (ø)
mmcls/models/utils/attention.py 98.72% <0.00%> (-1.28%) ⬇️
mmcls/models/heads/vision_transformer_head.py 93.18% <0.00%> (+1.28%) ⬆️
mmcls/models/backbones/vision_transformer.py 93.79% <0.00%> (+16.25%) ⬆️
mmcls/utils/logger.py 100.00% <0.00%> (+25.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 10e8495...968e54e. Read the comment docs.

@mzr1996
Copy link
Member

mzr1996 commented Oct 15, 2021

Usually classification tasks use EpochBasedRunner instead of IterBasedRunner, and they won't meet this problem.
So are you trying using IterBasedRunner?

@okotaku
Copy link
Collaborator Author

okotaku commented Oct 15, 2021

Yes, I encountered this error when I used the IterBasedRunner.
After reflecting the fix in this PR, this error has been resolved.

@@ -151,7 +151,8 @@ def train_model(model,
eval_cfg = cfg.get('evaluation', {})
eval_cfg['by_epoch'] = cfg.runner['type'] != 'IterBasedRunner'
eval_hook = DistEvalHook if distributed else EvalHook
runner.register_hook(eval_hook(val_dataloader, **eval_cfg))
runner.register_hook(
Copy link
Member

Choose a reason for hiding this comment

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

Please add a comment here to describe why the priority needs to be set as 'LOW'

Copy link
Member

@mzr1996 mzr1996 Oct 18, 2021

Choose a reason for hiding this comment

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

For example,

# `EvalHook` needs to be executed after `IterTimerHook`.
# Otherwise, it will cause a bug if use `IterBasedRunner`.
# Refers to https://github.com/open-mmlab/mmcv/issues/1261

Copy link
Member

@mzr1996 mzr1996 left a comment

Choose a reason for hiding this comment

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

LGTM

@mzr1996 mzr1996 changed the title Set the priority of EvalHook to LOW. [Fix] Set the priority of EvalHook to "LOW" to avoid a bug of IterBasedRunner Oct 20, 2021
@mzr1996 mzr1996 merged commit f68f17e into open-mmlab:master Oct 20, 2021
mzr1996 pushed a commit to mzr1996/mmpretrain that referenced this pull request Nov 24, 2022
…BasedRunner` (open-mmlab#488)

* Set the priority of EvalHook to LOW.

* add a comment
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.

3 participants