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 T5EncoderModel adapter integration #376

Merged
merged 1 commit into from
Jul 5, 2022
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
8 changes: 4 additions & 4 deletions src/transformers/adapters/mixins/t5.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class T5ModelAdaptersMixin(EmbeddingAdaptersMixin, InvertibleAdaptersMixin, Mode
"""Adds adapters to the T5Model class."""

def iter_layers(self) -> Iterable[Tuple[int, nn.Module]]:
global_i = 0
if hasattr(self, "encoder"):
global_i = len(self.encoder.block)
for i, layer in enumerate(self.encoder.block):
yield i, layer
for i, layer in enumerate(self.decoder.block, start=len(self.encoder.block)):
yield i, layer
else:
for i, layer in enumerate(self.decoder.block):
if hasattr(self, "decoder"):
for i, layer in enumerate(self.decoder.block, start=global_i):
yield i, layer

def _init_adapter_modules(self):
Expand Down
3 changes: 3 additions & 0 deletions src/transformers/models/t5/modeling_t5.py
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,8 @@ def __init__(self, config: T5Config):
self.model_parallel = False
self.device_map = None

self._init_adapter_modules()

@add_start_docstrings(PARALLELIZE_DOCSTRING)
def parallelize(self, device_map=None):
self.device_map = (
Expand Down Expand Up @@ -1870,6 +1872,7 @@ class PreTrainedModel

@add_start_docstrings_to_model_forward(T5_ENCODER_INPUTS_DOCSTRING)
@replace_return_docstrings(output_type=BaseModelOutput, config_class=_CONFIG_FOR_DOC)
@ForwardContext.wrap
def forward(
self,
input_ids: Optional[torch.LongTensor] = None,
Expand Down