Upload 6 files
Browse files- config.json +2 -2
- enigma_module.py +25 -2
- model.safetensors +2 -2
- tokenizer.json +0 -0
- tokenizer_config.json +13 -0
config.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
{
|
| 2 |
"architectures": [
|
| 3 |
-
"
|
| 4 |
],
|
| 5 |
"auto_map": {
|
| 6 |
"AutoConfig": "enigma_module.EnigmaConfig",
|
| 7 |
-
"
|
| 8 |
},
|
| 9 |
"dtype": "float32",
|
| 10 |
"hidden_size": 128,
|
|
|
|
| 1 |
{
|
| 2 |
"architectures": [
|
| 3 |
+
"EnigmaForCausalLM"
|
| 4 |
],
|
| 5 |
"auto_map": {
|
| 6 |
"AutoConfig": "enigma_module.EnigmaConfig",
|
| 7 |
+
"AutoModelForCausalLM": "enigma_module.EnigmaForCausalLM"
|
| 8 |
},
|
| 9 |
"dtype": "float32",
|
| 10 |
"hidden_size": 128,
|
enigma_module.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import torch
|
| 2 |
import torch.nn as nn
|
| 3 |
from transformers import PreTrainedModel, PretrainedConfig
|
|
|
|
| 4 |
|
| 5 |
class EnigmaConfig(PretrainedConfig):
|
| 6 |
model_type = "enigma"
|
|
@@ -19,10 +20,32 @@ class EnigmaModel(PreTrainedModel):
|
|
| 19 |
self.linear = nn.Linear(config.hidden_size, config.hidden_size)
|
| 20 |
self.post_init()
|
| 21 |
|
| 22 |
-
def forward(self, input_ids):
|
| 23 |
x = self.embedding(input_ids)
|
| 24 |
return self.linear(x)
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
EnigmaConfig.register_for_auto_class()
|
| 28 |
EnigmaModel.register_for_auto_class("AutoModel")
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import torch.nn as nn
|
| 3 |
from transformers import PreTrainedModel, PretrainedConfig
|
| 4 |
+
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 5 |
|
| 6 |
class EnigmaConfig(PretrainedConfig):
|
| 7 |
model_type = "enigma"
|
|
|
|
| 20 |
self.linear = nn.Linear(config.hidden_size, config.hidden_size)
|
| 21 |
self.post_init()
|
| 22 |
|
| 23 |
+
def forward(self, input_ids, **kwargs):
|
| 24 |
x = self.embedding(input_ids)
|
| 25 |
return self.linear(x)
|
| 26 |
|
| 27 |
+
class EnigmaForCausalLM(PreTrainedModel):
|
| 28 |
+
config_class = EnigmaConfig
|
| 29 |
+
|
| 30 |
+
def __init__(self, config):
|
| 31 |
+
super().__init__(config)
|
| 32 |
+
self.model = EnigmaModel(config)
|
| 33 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 34 |
+
self.post_init()
|
| 35 |
+
|
| 36 |
+
def forward(self, input_ids, labels=None, **kwargs):
|
| 37 |
+
hidden_states = self.model(input_ids)
|
| 38 |
+
logits = self.lm_head(hidden_states)
|
| 39 |
+
loss = None
|
| 40 |
+
if labels is not None:
|
| 41 |
+
loss_fct = nn.CrossEntropyLoss()
|
| 42 |
+
loss = loss_fct(logits.view(-1, self.config.vocab_size), labels.view(-1))
|
| 43 |
+
return CausalLMOutputWithPast(loss=loss, logits=logits)
|
| 44 |
+
|
| 45 |
+
def prepare_inputs_for_generation(self, input_ids, **kwargs):
|
| 46 |
+
return {"input_ids": input_ids}
|
| 47 |
+
|
| 48 |
+
# Registrando para permitir AutoModel, AutoConfig e AutoModelForCausalLM
|
| 49 |
EnigmaConfig.register_for_auto_class()
|
| 50 |
EnigmaModel.register_for_auto_class("AutoModel")
|
| 51 |
+
EnigmaForCausalLM.register_for_auto_class("AutoModelForCausalLM")
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:72ba2e2671bd22265a6aa09c43682e31209e85aac91be3d872a4bb04e142d6df
|
| 3 |
+
size 5186432
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": "<|endoftext|>",
|
| 5 |
+
"eos_token": "<|endoftext|>",
|
| 6 |
+
"errors": "replace",
|
| 7 |
+
"is_local": false,
|
| 8 |
+
"local_files_only": false,
|
| 9 |
+
"model_max_length": 1024,
|
| 10 |
+
"pad_token": null,
|
| 11 |
+
"tokenizer_class": "GPT2Tokenizer",
|
| 12 |
+
"unk_token": "<|endoftext|>"
|
| 13 |
+
}
|