Skip to content

Instantly share code, notes, and snippets.

@dhruvbird
Created November 12, 2021 19:40
Show Gist options
  • Save dhruvbird/5f2cd7ed9a2a4caccc46f0e12f81ab6c to your computer and use it in GitHub Desktop.
Save dhruvbird/5f2cd7ed9a2a4caccc46f0e12f81ab6c to your computer and use it in GitHub Desktop.
View the bytecode of a PyTorch Lite Interpreter Model
import zipfile
bytecode_pkl = None
with zipfile.ZipFile('AddTensorsModelOptimized.ptl', 'r') as myzip:
bytecode_pkl = myzip.open("AddTensorsModelOptimized/bytecode.pkl")
from torch.utils import show_pickle
show_pickle.DumpUnpickler.dump(bytecode_pkl, None)
(5,
('__torch__.___torch_mangle_12.AddtensorsModel.forward',
(('instructions',
(('STOREN', 1, 3),
('DROPR', 1, 0),
('LOADC', 1, 0),
('MOVE', 2, 0),
('LOADC', 0, 0),
('OP', 0, 0),
('MOVE', 3, 0),
('LOADC', 0, 0),
('OP', 1, 0),
('RET', 0, 0))),
('operators', (('aten::add', 'Tensor'), ('aten::add', 'Tensor'))),
('constants',
(1,
torch._utils._rebuild_tensor_v2(pers.obj(('storage', torch.FloatStorage, '94800670686128.storage', 'cpu', 3),), 0, (3,), (1,), False, collections.OrderedDict()))),
('types', ()),
('register_size', 3)),
(('arguments',
((('name', 'self'),
('type', '__torch__.___torch_mangle_12.AddtensorsModel'),
('default_value', None)),
(('name', 'x'), ('type', 'Tensor'), ('default_value', None)),
(('name', 'y'), ('type', 'Tensor'), ('default_value', None)))),
('returns',
((('name', ''), ('type', 'Tensor'), ('default_value', None)),)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment