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

Mistral Adapters #731

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 2 additions & 4 deletions src/adapters/__init__.py → src/adapters/__init__ 2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

__version__ = "1.0.0.dev0"
__version__ = "0.2.2"

from typing import TYPE_CHECKING

Expand Down Expand Up @@ -111,7 +111,6 @@
"models.mbart": ["MBartAdapterModel"],
"models.mistral": ["MistralAdapterModel"],
"models.mt5": ["MT5AdapterModel"],
"models.plbart": ["PLBartAdapterModel"],
"models.roberta": ["RobertaAdapterModel"],
"models.t5": ["T5AdapterModel"],
"models.vit": ["ViTAdapterModel"],
Expand Down Expand Up @@ -217,10 +216,9 @@
from .models.gpt2 import GPT2AdapterModel
from .models.gptj import GPTJAdapterModel
from .models.llama import LlamaAdapterModel
from .models.mbart import MBartAdapterModel
from .models.mistral import MistralAdapterModel
from .models.mbart import MBartAdapterModel
from .models.mt5 import MT5AdapterModel
from .models.plbart import PLBartAdapterModel
from .models.roberta import RobertaAdapterModel
from .models.t5 import T5AdapterModel
from .models.vit import ViTAdapterModel
Expand Down
11 changes: 2 additions & 9 deletions src/adapters/composition.py → src/adapters/composition 2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import itertools
import warnings
from collections.abc import Sequence
from typing import List, Optional, Set, Tuple, Union

Expand Down Expand Up @@ -92,7 +91,7 @@ def __init__(
self,
*average_adapters: List[Union[AdapterCompositionBlock, str]],
weights: Optional[List[float]] = None,
normalize_weights: bool = True,
normalize_weights: bool = True
):
super().__init__(*average_adapters)
if weights is not None:
Expand Down Expand Up @@ -129,7 +128,6 @@ def __init__(
"bart",
"mbart",
"mt5",
"plbart",
"gpt2",
"gptj",
"t5",
Expand All @@ -155,7 +153,7 @@ def validate_composition(adapter_composition: AdapterCompositionBlock, level=0,
f"Models of type {model_type} don't support adapter composition using {block_type.__name__}."
)
for child in adapter_composition:
if not type(child) in ALLOWED_NESTINGS[type(adapter_composition)]:
if type(child) not in ALLOWED_NESTINGS[type(adapter_composition)]:
raise ValueError(f"Adapter setup is invalid. Cannot nest {child} in {adapter_composition}")
# recursively validate children
validate_composition(child, level=level + 1)
Expand All @@ -181,11 +179,6 @@ def parse_composition(adapter_composition, level=0, model_type=None) -> AdapterC
else:
return adapter_composition
elif isinstance(adapter_composition, Sequence):
# Functionality of adapter-transformers v1.x
warnings.warn(
"Passing list objects for adapter activation is deprecated. Please use Stack or Fuse explicitly.",
category=FutureWarning,
)
# for backwards compatibility
if level == 1:
block_class = Fuse
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/configuration/adapter_fusion_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def load(cls, config: Union[dict, str], **kwargs):
dict: The resolved adapter fusion configuration dictionary.
"""
# currently storing AdapterFusion weights on AdapterHub is not supported.
config_dict = resolve_adapter_config(config, local_map=ADAPTERFUSION_CONFIG_MAP)
config_dict = resolve_adapter_config(config, local_map=ADAPTERFUSION_CONFIG_MAP, try_loading_from_hub=False)
# convert back to dict to allow attr overrides
if isinstance(config_dict, AdapterFusionConfig):
config_dict = config_dict.to_dict()
Expand Down
3 changes: 1 addition & 2 deletions src/adapters/configuration/model_adapters_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,5 @@ def build_full_config(adapter_config, model_config, save_id2label=False, **kwarg
config_dict["config"] = adapter_config.to_dict()
else:
config_dict["config"] = adapter_config
# add lib name before version to distinguish from adapter-transformers
config_dict["version"] = "adapters." + __version__
config_dict["version"] = __version__
return config_dict
151 changes: 0 additions & 151 deletions src/adapters/context.py

This file was deleted.

39 changes: 1 addition & 38 deletions src/adapters/head_utils.py → src/adapters/head_utils 2.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,27 +369,6 @@
},
"layers": ["lm_head"],
},
# PLBART
"PLBartForSequenceClassification": {
"config": {
"head_type": "classification",
"layers": 2,
"activation_function": "tanh",
},
"layers": [
None,
"classification_head.dense",
None,
None,
"classification_head.out_proj",
],
},
"PLBartForConditionalGeneration": {
"config": {
"head_type": "seq2seq_lm",
},
"layers": ["lm_head"],
},
# MT5
"MT5ForConditionalGeneration": {
"config": {
Expand Down Expand Up @@ -673,15 +652,7 @@
},
"layers": [None, "qa_outputs"],
},
"LlamaForTokenClassification": {
"config": {
"head_type": "tagging",
"layers": 1,
"activation_function": None,
},
"layers": [None, "score"],
},
# Mistral
#Mistral
"MistralForSequenceClassification": {
"config": {
"head_type": "classification",
Expand All @@ -698,14 +669,6 @@
},
"layers": ["lm_head"],
},
"MistralForTokenClassification": {
"config": {
"head_type": "tagging",
"layers": 1,
"activation_function": None,
},
"layers": [None, "score"],
},
# Electra
"ElectraForTokenClassification": {
"config": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,6 @@ def tie_weights(self):
self = getattr(self, self.base_model_prefix)
self._tie_encoder_decoder_weights(self.encoder, self.decoder, self.base_model_prefix)

super().tie_weights()

def _resize_token_embeddings(self, new_num_tokens, pad_to_multiple_of=None):
old_embeddings = self.get_input_embeddings()
new_embeddings = self._get_resized_embeddings(old_embeddings, new_num_tokens, pad_to_multiple_of)
Expand Down Expand Up @@ -527,7 +525,7 @@ def forward_head(
attention_mask=None,
return_dict=False,
context=None,
**kwargs,
**kwargs
):
"""
The forward pass through a prediction head configuration. There are three ways to specify the used prediction
Expand Down
Loading
Loading