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

Suppress no-adapter warning when adapter_names is given #186

Merged
merged 1 commit into from
Jun 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/transformers/adapters/model_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,14 @@ def freeze_model(self, freeze=True):
param.requires_grad = not freeze
self.model_freezed = freeze

def pre_transformer_forward(self):
def pre_transformer_forward(self, **kwargs):
"""
This method should be called by every adapter-implementing model at the very beginning of the forward() method.
"""
# some warnings if we don't use available adapters
if not self.active_adapters and self.has_adapters():
logger.warning("There are adapters available but none are passed to model.forward")
active_adapters = self.active_adapters or kwargs.get("adapter_names", None)
if not active_adapters and self.has_adapters():
logger.warning("There are adapters available but none are activated for the forward pass.")

self.config.adapters.is_parallelized = False

Expand Down
4 changes: 2 additions & 2 deletions src/transformers/models/bart/modeling_bart.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ def forward(
)
use_cache = use_cache if use_cache is not None else self.config.use_cache
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
self.pre_transformer_forward()
self.pre_transformer_forward(**kwargs)

if encoder_outputs is None:
encoder_outputs = self.encoder(
Expand Down Expand Up @@ -1714,7 +1714,7 @@ def __init__(self, config):
self._init_adapter_modules()

def forward(self, *args, **kwargs):
self.pre_transformer_forward()
self.pre_transformer_forward(**kwargs)

return self.decoder(*args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion src/transformers/models/bert/modeling_bert.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ def forward(
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
)
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
self.pre_transformer_forward()
self.pre_transformer_forward(**kwargs)

if self.config.is_decoder:
use_cache = use_cache if use_cache is not None else self.config.use_cache
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/models/distilbert/modeling_distilbert.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def forward(
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
)
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
self.pre_transformer_forward()
self.pre_transformer_forward(**kwargs)

if input_ids is not None and inputs_embeds is not None:
raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/models/gpt2/modeling_gpt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def forward(
return_dict=None,
**kwargs
):
self.pre_transformer_forward()
self.pre_transformer_forward(**kwargs)

output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
output_hidden_states = (
Expand Down
4 changes: 2 additions & 2 deletions src/transformers/models/mbart/modeling_mbart.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ def forward(
)
use_cache = use_cache if use_cache is not None else self.config.use_cache
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
self.pre_transformer_forward()
self.pre_transformer_forward(**kwargs)

# different to other models, MBart automatically creates decoder_input_ids from
# input_ids if no decoder_input_ids are provided
Expand Down Expand Up @@ -1726,7 +1726,7 @@ def __init__(self, config):
self._init_adapter_modules()

def forward(self, *args, **kwargs):
self.pre_transformer_forward()
self.pre_transformer_forward(**kwargs)

return self.decoder(*args, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion src/transformers/models/roberta/modeling_roberta.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ def forward(
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
)
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
self.pre_transformer_forward()
self.pre_transformer_forward(**kwargs)

if self.config.is_decoder:
use_cache = use_cache if use_cache is not None else self.config.use_cache
Expand Down