Upload model
Browse files- config.json +7 -0
- configuration_fc.py +12 -0
- model_fc.py +15 -0
config.json
CHANGED
@@ -1,5 +1,12 @@
|
|
1 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
"model_type": "fc_layer",
|
3 |
"num_nodes": 10,
|
|
|
4 |
"transformers_version": "4.28.1"
|
5 |
}
|
|
|
1 |
{
|
2 |
+
"architectures": [
|
3 |
+
"FCModel"
|
4 |
+
],
|
5 |
+
"auto_map": {
|
6 |
+
"AutoModel": "model_fc.FCModel"
|
7 |
+
},
|
8 |
"model_type": "fc_layer",
|
9 |
"num_nodes": 10,
|
10 |
+
"torch_dtype": "float32",
|
11 |
"transformers_version": "4.28.1"
|
12 |
}
|
configuration_fc.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import PretrainedConfig
|
2 |
+
from typing import List
|
3 |
+
|
4 |
+
class FCConfig(PretrainedConfig):
|
5 |
+
model_type = "fc_layer" # For registration auto class
|
6 |
+
|
7 |
+
def __init__(self, num_nodes=10, **kwargs):
|
8 |
+
## Must include keyword arguments
|
9 |
+
## Note: Must need a default value for hyperparameters
|
10 |
+
self.num_nodes = num_nodes
|
11 |
+
super().__init__(**kwargs)
|
12 |
+
|
model_fc.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import PreTrainedModel
|
2 |
+
from .configuration_fc import FCConfig
|
3 |
+
from torch.nn import Linear
|
4 |
+
|
5 |
+
class FCModel(PreTrainedModel):
|
6 |
+
config_class = FCConfig
|
7 |
+
|
8 |
+
def __init__(self, config):
|
9 |
+
super().__init__(config)
|
10 |
+
self.model = Linear(in_features=10, out_features=config.num_nodes)
|
11 |
+
|
12 |
+
def forward(self, tensor):
|
13 |
+
# Use as forward similar to forward in torch
|
14 |
+
return self.model.forward(tensor)
|
15 |
+
|