Modify the existing Torchscript model

Hello,
I am trying to modify an existing Torchscript model for model compression. For example, I want to change several parameters of the aten:_convolution operators. To explain the question more clearly, suppose we traced a model in the following way:

net = torchvison.models.resnet18().cuda()
data = torch.ones(1, 3 , 224, 224)
traced = torch.jit.trace(net, data)

The question is can I modify the torchscript model by directly modifying the traced.graph so that the new model can be loaded and run in a different place? I also noticed that there is a ‘code’ variable in the ‘traced’, what is this variable for? Do I need to modify the ‘code’ variable at the same time?

Thanks ~

1 Like