Instructions to use rrivera1849/LUAR-MUD with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use rrivera1849/LUAR-MUD with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="rrivera1849/LUAR-MUD", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("rrivera1849/LUAR-MUD", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Support for latest transformers
Browse files- backbone/config.json +27 -0
- config.json +29 -2
- model.py +10 -7
backbone/config.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "old_models/paraphrase-distilroberta-base-v1/0_Transformer",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"RobertaModel"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"bos_token_id": 0,
|
| 8 |
+
"eos_token_id": 2,
|
| 9 |
+
"gradient_checkpointing": false,
|
| 10 |
+
"hidden_act": "gelu",
|
| 11 |
+
"hidden_dropout_prob": 0.1,
|
| 12 |
+
"hidden_size": 768,
|
| 13 |
+
"initializer_range": 0.02,
|
| 14 |
+
"intermediate_size": 3072,
|
| 15 |
+
"layer_norm_eps": 1e-05,
|
| 16 |
+
"max_position_embeddings": 514,
|
| 17 |
+
"model_type": "roberta",
|
| 18 |
+
"num_attention_heads": 12,
|
| 19 |
+
"num_hidden_layers": 6,
|
| 20 |
+
"output_hidden_states": true,
|
| 21 |
+
"pad_token_id": 1,
|
| 22 |
+
"position_embedding_type": "absolute",
|
| 23 |
+
"transformers_version": "4.7.0",
|
| 24 |
+
"type_vocab_size": 1,
|
| 25 |
+
"use_cache": true,
|
| 26 |
+
"vocab_size": 50265
|
| 27 |
+
}
|
config.json
CHANGED
|
@@ -13,5 +13,32 @@
|
|
| 13 |
"q_bucket_size": 512,
|
| 14 |
"torch_dtype": "float32",
|
| 15 |
"transformers_version": "4.33.2",
|
| 16 |
-
"use_memory_efficient_attention": false
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
"q_bucket_size": 512,
|
| 14 |
"torch_dtype": "float32",
|
| 15 |
"transformers_version": "4.33.2",
|
| 16 |
+
"use_memory_efficient_attention": false,
|
| 17 |
+
"backbone_config": {
|
| 18 |
+
"_name_or_path": "old_models/paraphrase-distilroberta-base-v1/0_Transformer",
|
| 19 |
+
"architectures": [
|
| 20 |
+
"RobertaModel"
|
| 21 |
+
],
|
| 22 |
+
"attention_probs_dropout_prob": 0.1,
|
| 23 |
+
"bos_token_id": 0,
|
| 24 |
+
"eos_token_id": 2,
|
| 25 |
+
"gradient_checkpointing": false,
|
| 26 |
+
"hidden_act": "gelu",
|
| 27 |
+
"hidden_dropout_prob": 0.1,
|
| 28 |
+
"hidden_size": 768,
|
| 29 |
+
"initializer_range": 0.02,
|
| 30 |
+
"intermediate_size": 3072,
|
| 31 |
+
"layer_norm_eps": 1e-05,
|
| 32 |
+
"max_position_embeddings": 514,
|
| 33 |
+
"model_type": "roberta",
|
| 34 |
+
"num_attention_heads": 12,
|
| 35 |
+
"num_hidden_layers": 6,
|
| 36 |
+
"output_hidden_states": true,
|
| 37 |
+
"pad_token_id": 1,
|
| 38 |
+
"position_embedding_type": "absolute",
|
| 39 |
+
"transformers_version": "4.7.0",
|
| 40 |
+
"type_vocab_size": 1,
|
| 41 |
+
"use_cache": true,
|
| 42 |
+
"vocab_size": 50265
|
| 43 |
+
}
|
| 44 |
+
}
|
model.py
CHANGED
|
@@ -8,7 +8,8 @@ import torch.nn as nn
|
|
| 8 |
import torch.nn.functional as F
|
| 9 |
from einops import rearrange, reduce, repeat
|
| 10 |
from torch.utils.checkpoint import checkpoint
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
from .config import LUARConfig
|
| 14 |
|
|
@@ -137,9 +138,11 @@ class LUAR(PreTrainedModel):
|
|
| 137 |
"""Defines the LUAR model.
|
| 138 |
"""
|
| 139 |
config_class = LUARConfig
|
| 140 |
-
|
|
|
|
| 141 |
def __init__(self, config):
|
| 142 |
super().__init__(config)
|
|
|
|
| 143 |
self.create_transformer(revision=config.upstream_transformer_revision)
|
| 144 |
self.attn_fn = SelfAttention(
|
| 145 |
config.use_memory_efficient_attention,
|
|
@@ -148,11 +151,11 @@ class LUAR(PreTrainedModel):
|
|
| 148 |
)
|
| 149 |
self.linear = nn.Linear(self.hidden_size, config.embedding_size)
|
| 150 |
|
| 151 |
-
def create_transformer(self, revision
|
| 152 |
-
"""Creates the Transformer backbone.
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
self.transformer = AutoModel.
|
| 156 |
self.hidden_size = self.transformer.config.hidden_size
|
| 157 |
self.num_attention_heads = self.transformer.config.num_attention_heads
|
| 158 |
self.dim_head = self.hidden_size // self.num_attention_heads
|
|
|
|
| 8 |
import torch.nn.functional as F
|
| 9 |
from einops import rearrange, reduce, repeat
|
| 10 |
from torch.utils.checkpoint import checkpoint
|
| 11 |
+
import os
|
| 12 |
+
from transformers import AutoConfig, AutoModel, PreTrainedModel
|
| 13 |
|
| 14 |
from .config import LUARConfig
|
| 15 |
|
|
|
|
| 138 |
"""Defines the LUAR model.
|
| 139 |
"""
|
| 140 |
config_class = LUARConfig
|
| 141 |
+
all_tied_weights_keys = {}
|
| 142 |
+
|
| 143 |
def __init__(self, config):
|
| 144 |
super().__init__(config)
|
| 145 |
+
self._luar_backbone_cfg = dict(config.backbone_config)
|
| 146 |
self.create_transformer(revision=config.upstream_transformer_revision)
|
| 147 |
self.attn_fn = SelfAttention(
|
| 148 |
config.use_memory_efficient_attention,
|
|
|
|
| 151 |
)
|
| 152 |
self.linear = nn.Linear(self.hidden_size, config.embedding_size)
|
| 153 |
|
| 154 |
+
def create_transformer(self, revision=None):
|
| 155 |
+
"""Creates the Transformer backbone (offline: backbone config embedded in LUAR config)."""
|
| 156 |
+
from transformers import AutoConfig
|
| 157 |
+
backbone_cfg = AutoConfig.for_model(**self._luar_backbone_cfg)
|
| 158 |
+
self.transformer = AutoModel.from_config(backbone_cfg)
|
| 159 |
self.hidden_size = self.transformer.config.hidden_size
|
| 160 |
self.num_attention_heads = self.transformer.config.num_attention_heads
|
| 161 |
self.dim_head = self.hidden_size // self.num_attention_heads
|