Upload BasicLinear
Browse files- config.json +15 -0
- custom_config.py +18 -0
- custom_net.py +21 -0
- model.safetensors +3 -0
config.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"BasicLinear"
|
| 4 |
+
],
|
| 5 |
+
"auto_map": {
|
| 6 |
+
"AutoConfig": "custom_config.LinearConfig",
|
| 7 |
+
"AutoModel": "custom_net.BasicLinear"
|
| 8 |
+
},
|
| 9 |
+
"bias": true,
|
| 10 |
+
"dtype": "float32",
|
| 11 |
+
"in_features": 10,
|
| 12 |
+
"model_type": "linear",
|
| 13 |
+
"out_features": 1,
|
| 14 |
+
"transformers_version": "4.57.1"
|
| 15 |
+
}
|
custom_config.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import PretrainedConfig
|
| 2 |
+
|
| 3 |
+
class LinearConfig(PretrainedConfig):
|
| 4 |
+
model_type = 'linear'
|
| 5 |
+
|
| 6 |
+
def __init__(self,
|
| 7 |
+
in_features=10,
|
| 8 |
+
out_features=1,
|
| 9 |
+
bias=True,
|
| 10 |
+
**kwargs):
|
| 11 |
+
|
| 12 |
+
self.in_features = in_features
|
| 13 |
+
self.out_features = out_features
|
| 14 |
+
self.bias = bias
|
| 15 |
+
|
| 16 |
+
super().__init__(**kwargs)
|
| 17 |
+
|
| 18 |
+
|
custom_net.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import PreTrainedModel
|
| 2 |
+
from .custom_config import LinearConfig
|
| 3 |
+
import torch.nn as nn
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
class BasicLinear(PreTrainedModel):
|
| 7 |
+
config_class = LinearConfig
|
| 8 |
+
|
| 9 |
+
def __init__(self, config):
|
| 10 |
+
super().__init__(config)
|
| 11 |
+
self.weight = nn.Parameter(torch.randn(config.out_features, config.in_features) * 0.01)
|
| 12 |
+
if config.bias:
|
| 13 |
+
self.bias = nn.Parameter(torch.zeros(config.out_features))
|
| 14 |
+
else:
|
| 15 |
+
self.bias = None
|
| 16 |
+
|
| 17 |
+
def forward(self, x):
|
| 18 |
+
out = x @ self.weight.T
|
| 19 |
+
if self.bias is not None:
|
| 20 |
+
out = out + self.bias
|
| 21 |
+
return out
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3a8c05d6ab9216b2c052c8ceed97cca88520c4538ab3cded2a4f54e0255e791b
|
| 3 |
+
size 204
|