Skip to content

Instantly share code, notes, and snippets.

@zarzen
Created May 14, 2020
Embed
What would you like to do?
py shm
import posix_ipc
from torchvision import models
import pickle
import mmap
from model.index import get_model_module
def main():
""""""
m = models.resnet152(pretrained=True)
model_b = pickle.dumps(m)
model_size = len(model_b)
print('model size', model_size)
model_name = "resnet152-alter-0001"
mod = get_model_module(model_name)
data = mod.import_data(8)
outputs = m(data[0])
print('outputs: ', outputs.sum().item())
memory = posix_ipc.SharedMemory(model_name, posix_ipc.O_CREX, size=model_size)
memfile = mmap.mmap(memory.fd, memory.size)
memory.close_fd()
# write model bytes
memfile.seek(0)
memfile.write(model_b)
if __name__ == "__main__":
main()
import posix_ipc
from torchvision import models
import pickle
import mmap
from model.index import get_model_module
def main():
""""""
model_name = "resnet152-alter-0001"
model_size = 241757931
mod = get_model_module(model_name)
data = mod.import_data(8)
memory = posix_ipc.SharedMemory(model_name, size=model_size)
memfile = mmap.mmap(memory.fd, memory.size)
memory.close_fd()
memfile.seek(0)
m = pickle.load(memfile)
outputs = m(data[0])
print('output ', outputs.sum().item())
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment