Commit
·
c580b09
1
Parent(s):
8d84aef
update: first
Browse files- __pycache__/model.cpython-313.pyc +0 -0
- config.json/config.json +6 -0
- model.py +21 -0
- pytorch_model.bin/config.json +10 -0
- pytorch_model.bin/model.safetensors +3 -0
- train.py +18 -0
__pycache__/model.cpython-313.pyc
ADDED
|
Binary file (1.62 kB). View file
|
|
|
config.json/config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"input_dim": 4,
|
| 3 |
+
"model_type": "test_model",
|
| 4 |
+
"output_dim": 16,
|
| 5 |
+
"transformers_version": "4.54.1"
|
| 6 |
+
}
|
model.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import PreTrainedModel, PretrainedConfig
|
| 2 |
+
from torch import nn
|
| 3 |
+
|
| 4 |
+
class TestConfig(PretrainedConfig):
|
| 5 |
+
model_type = "test_model"
|
| 6 |
+
|
| 7 |
+
def __init__(self, input_dim=4, output_dim=16, **kwargs):
|
| 8 |
+
super().__init__(**kwargs)
|
| 9 |
+
self.input_dim = input_dim
|
| 10 |
+
self.output_dim = output_dim
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class TestModel(PreTrainedModel):
|
| 14 |
+
config_class = TestConfig
|
| 15 |
+
|
| 16 |
+
def __init__(self, config):
|
| 17 |
+
super().__init__(config)
|
| 18 |
+
self.layer = nn.Linear(config.input_dim, config.output_dim)
|
| 19 |
+
|
| 20 |
+
def forward(self, input):
|
| 21 |
+
return self.layer(input)
|
pytorch_model.bin/config.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"TestModel"
|
| 4 |
+
],
|
| 5 |
+
"input_dim": 4,
|
| 6 |
+
"model_type": "test_model",
|
| 7 |
+
"output_dim": 16,
|
| 8 |
+
"torch_dtype": "float32",
|
| 9 |
+
"transformers_version": "4.54.1"
|
| 10 |
+
}
|
pytorch_model.bin/model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4d309df6d7ad88e731d193ac5329b87ea597b1175a8b0ba7b33ba05d15821fb7
|
| 3 |
+
size 496
|
train.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from transformers import (WEIGHTS_NAME, CONFIG_NAME)
|
| 3 |
+
|
| 4 |
+
from model import (TestConfig, TestModel)
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
if __name__ == "__main__":
|
| 9 |
+
config = TestConfig()
|
| 10 |
+
model = TestModel(config)
|
| 11 |
+
|
| 12 |
+
x = torch.rand(16,4)
|
| 13 |
+
|
| 14 |
+
pred = model(x)
|
| 15 |
+
print(pred)
|
| 16 |
+
|
| 17 |
+
config.save_pretrained(CONFIG_NAME)
|
| 18 |
+
model.save_pretrained(WEIGHTS_NAME)
|