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

rf.BatchNorm keeps updating statistics when used in eval mode in training #1625

Open
mnghiap opened this issue Sep 12, 2024 · 1 comment
Open

Comments

@mnghiap
Copy link

mnghiap commented Sep 12, 2024

Currently rf.BatchNorm decides whether to update the running statistics based on the rf.get_run_ctx().train_flag as in this line.

update_running_stats = self.running_mean is not None and rf.get_run_ctx().train_flag

However, there are cases where it should be used in eval mode during training (e.g. the teacher model in knowledge distillation), and in those cases it should not update the running statistics.

I suggest that we add something to allow rf.BatchNorm (and maybe other modules with similar issues, but I don't know yet) to run in eval mode even in training.

@albertz
Copy link
Member

albertz commented Sep 13, 2024

I was planning to add some context scope where we can overwrite the train_flag. So usage would be sth like:

with rf.get_run_ctx().set_train_flag_scope(False):
  ...

That should solve this, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants