remosleandre commited on
Commit
8936391
1 Parent(s): 9d524af

[ADD] push config and model for hugging face

Browse files
Files changed (3) hide show
  1. config.json +12 -0
  2. model.py +1 -1
  3. model_hugging_face.py +65 -0
config.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "architecture",
3
+ "input_size": 9,
4
+ "hidden_size_1": 9,
5
+ "hidden_size_2": 9,
6
+ "hidden_size_3": 9,
7
+ "hidden_size_4": 9,
8
+ "hidden_size_5": 9,
9
+ "hidden_size_6": 9,
10
+ "hidden_size_7": 9,
11
+ "output_size": 9
12
+ }
model.py CHANGED
@@ -44,7 +44,7 @@ class Architecture(nn.Module):
44
 
45
  def load_model():
46
  model = Architecture()
47
- model.load_state_dict(torch.load('fine_tune_model_weights.pth'))
48
  return model
49
 
50
  def inference_model(model, input):
 
44
 
45
  def load_model():
46
  model = Architecture()
47
+ model.load_state_dict(torch.load('model_weights.pth'))
48
  return model
49
 
50
  def inference_model(model, input):
model_hugging_face.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PreTrainedModel, PretrainedConfig
2
+ import torch.nn as nn
3
+ import torch
4
+
5
+ class ArchitectureConfig(PretrainedConfig):
6
+ model_type = "architecture"
7
+
8
+ def __init__(self, **kwargs):
9
+ super().__init__(**kwargs)
10
+ self.input_size = kwargs.get("input_size", 9)
11
+ self.hidden_size_1 = kwargs.get("hidden_size_1", 9)
12
+ self.hidden_size_2 = kwargs.get("hidden_size_2", 9)
13
+ self.hidden_size_3 = kwargs.get("hidden_size_3", 9)
14
+ self.hidden_size_4 = kwargs.get("hidden_size_4", 9)
15
+ self.hidden_size_5 = kwargs.get("hidden_size_5", 9)
16
+ self.hidden_size_6 = kwargs.get("hidden_size_6", 9)
17
+ self.hidden_size_7 = kwargs.get("hidden_size_7", 9)
18
+ self.output_size = kwargs.get("output_size", 9)
19
+
20
+ class Architecture(PreTrainedModel):
21
+ config_class = ArchitectureConfig
22
+
23
+ def __init__(self, config: ArchitectureConfig):
24
+ super().__init__(config)
25
+ self.input_size = config.input_size
26
+ self.hidden_size_1 = config.hidden_size_1
27
+ self.hidden_size_2 = config.hidden_size_2
28
+ self.hidden_size_3 = config.hidden_size_3
29
+ self.hidden_size_4 = config.hidden_size_4
30
+ self.hidden_size_5 = config.hidden_size_5
31
+ self.hidden_size_6 = config.hidden_size_6
32
+ self.hidden_size_7 = config.hidden_size_7
33
+ self.output_size = config.output_size
34
+
35
+ self.fc1 = nn.Linear(self.input_size, self.hidden_size_1)
36
+ self.fc2 = nn.Linear(self.hidden_size_1, self.hidden_size_2)
37
+ self.fc3 = nn.Linear(self.hidden_size_2, self.hidden_size_3)
38
+ self.fc4 = nn.Linear(self.hidden_size_3, self.hidden_size_4)
39
+ self.fc5 = nn.Linear(self.hidden_size_4, self.hidden_size_5)
40
+ self.fc6 = nn.Linear(self.hidden_size_5, self.hidden_size_6)
41
+ self.fc7 = nn.Linear(self.hidden_size_6, self.hidden_size_7)
42
+ self.fc8 = nn.Linear(self.hidden_size_7, self.output_size)
43
+
44
+ self.relu = nn.ReLU()
45
+
46
+ def forward(self, x):
47
+ x1 = self.relu(self.fc1(x))
48
+ x2 = self.relu(self.fc2(x1))
49
+ x3 = self.relu(self.fc3(x2))
50
+ x4 = self.relu(self.fc4(x3))
51
+ x5 = self.relu(self.fc5(x4))
52
+ x6 = self.relu(self.fc6(x5))
53
+ x7 = self.relu(self.fc7(x6))
54
+ x8 = self.fc8(x7)
55
+ return x8
56
+
57
+ def inference(self, x):
58
+ return self.forward(x)
59
+
60
+ # Loading the model from saved weights
61
+ def load_model():
62
+ config = ArchitectureConfig()
63
+ model = Architecture(config)
64
+ model.load_state_dict(torch.load('model_weights.pth'))
65
+ return model