-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
[BatchNorm] Unexpected behaviour with track_running_stats #37823
Comments
Thanks for reporting this issue, @frgfm! And sorry to hear it's causing you trouble. I'm also surprised at this behavior -- I wonder if it was intended? |
Hi, author of @mruberry @frgfm The root cause of this is that |
@ssnl I figure it would be a nullity check under the hood, but thanks for the specifics. |
@ssnl I realize I might have misunderstood your suggestion. To clarify, what did you mean by
As I understand the values passed to My intuition was to pass the Let me know your thoughts on this, I may have completely missed your point earlier! |
@frgfm Oh good points. I must admit that I didn't think this through when I wrote the original reply. Here is the current behavior:
The problem with dynamic check of Really we want to change the second to last row in the above table to always Note that the last row corresponds to the behavior with So at the end of the day, we probably just want to change this line pytorch/torch/nn/modules/batchnorm.py Line 105 in 7be9796
to (self.running_mean is None and self.running_var is None) if self.track_running_stats else self.training (probably worth expanding into an if-block for readability, with comments.) |
@ssnl yes, I agree with the change in behaviour.
which is equivalent to
? I opened a PR with my suggestion above #38084, let me know what you think! |
…alse (#38084) Summary: This PR aims at tackling #37823 by: - ensuring that buffers will be used for normalization computation but won't be updated, when buffers are not None, and `track_running_stats=False` - adding a corresponding unittest to ensure expected behaviour Any feedback is welcome! _Note: we might want to update the docstrings of `BatchNorm*d`, feel free to share any suggestion!_ Pull Request resolved: #38084 Differential Revision: D22047871 Pulled By: ezyang fbshipit-source-id: 5acbcad9773e7901f26d625db71d43d7dc236d3e
Closed by #38084 |
🐛 Strange behaviour when changing track_running_stats after instantiation
When the
track_running_stats
is set to False after instantiation, the number of batches tracked is indeed not updated, but the running mean and var are.I understand that this attribute is not meant to be changed after instantiation. But here I was freezing BN stats in layers that had all their frozen parameters temporarily for a training. As you go through it,
model.eval()
andmodel.train()
are called often, which means that freezing the BN stats of frozen layers has to be done every epoch.To Reproduce
yields :
Expected behavior
Any forward through a BN layer would not have any influence on the BN stats if
track_running_stats
is set to ̀False` (even after instantiation).Environment
conda
The text was updated successfully, but these errors were encountered: