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

#246 Fix issue where training was not kept consistent #249

Merged
merged 4 commits into from
Dec 28, 2022

Conversation

Dref360
Copy link
Member

@Dref360 Dref360 commented Dec 11, 2022

Summary:

Fixes #246

Features:

import torch
from transformers import BertForSequenceClassification
from baal.bayesian.dropout import patch_module,unpatch_module

pretrained_weights = 'bert-base-uncased'
use_cuda = torch.cuda.is_available()

model = BertForSequenceClassification.from_pretrained(pretrained_model_name_or_path=pretrained_weights)
print(f"Droputs enabled: {model.dropout.training}, model= {model.training}") # False here
 
>>> Droputs enabled: False, model= False

model = patch_module(model,inplace=False)
print(f"Droputs enabled: {model.dropout.training}, model= {model.training}") # True here

>>> Droputs enabled: False, model= False

model = unpatch_module(model,inplace=False)
print(f"Droputs enabled: {model.dropout.training}, model= {model.training}") # Should be False here but this is true??

>>> Droputs enabled: False, model= False

Checklist:

  • Your code is documented (To validate this, add your module to tests/documentation_test.py).
  • Your code is tested with unit tests.
  • You moved your Issue to the PR state.

@Dref360 Dref360 merged commit 5b93236 into master Dec 28, 2022
@Dref360 Dref360 deleted the BAAL-246/training_state branch December 28, 2022 16:56
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.

unpatch_module does not seem to be working
1 participant