Skip to content

Commit

Permalink
Simplify XAdapterModel implementations (#641)
Browse files Browse the repository at this point in the history
This PR includes some refactorings of all AdapterModel classes:
- moves prediction head adding methods to base mixin & remove from all
model classes
- convert `head_types` to list, use single mapping in base mixin
  • Loading branch information
calpt committed Feb 17, 2024
1 parent 26ea2c6 commit 29cbdd7
Show file tree
Hide file tree
Showing 27 changed files with 955 additions and 2,224 deletions.
16 changes: 16 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# https://www.sphinx-doc.org/en/main/usage/configuration.html
import os
import sys
import re


# -- Path setup --------------------------------------------------------------
Expand Down Expand Up @@ -87,6 +88,21 @@
smv_remote_whitelist = None


def skip_head_member(app, what, name, obj, skip, options):
if type(obj).__name__ == "function" and "inherited-members" in options and (m := re.match(r"add\_(.*)\_head$", name)):
cls_name = options["inherited-members"].replace("PreTrainedModel", "AdapterModel").replace("PretrainedModel", "AdapterModel")
cls = vars(sys.modules["adapters"])[cls_name]
# HACK: currently parses head type from name
head_type_str = m.group(1).replace("qa", "question_answering")
if head_type_str in cls.head_types:
return False
else:
return True

return skip


def setup(app):
app.connect('autodoc-skip-member', skip_head_member)
app.add_config_value("recommonmark_config", {"enable_eval_rst": True}, True)
app.add_css_file("custom.css")
1 change: 1 addition & 0 deletions src/adapters/heads/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from .base import *
from .dependency_parsing import *
from .language_modeling import BertStyleMaskedLMHead, CausalLMHead, Seq2SeqLMHead
from .model_mixin import ModelWithFlexibleHeadsAdaptersMixin
491 changes: 2 additions & 489 deletions src/adapters/heads/base.py

Large diffs are not rendered by default.

Loading

0 comments on commit 29cbdd7

Please sign in to comment.