Error in transcompliation from Python to C++ using TorchScript

Task:
Transcompiling Python (Pytorch) code to C++.
Problem:
The following error is reported when trying to load the serialised model in C++.

There were some warnings (shown below) when I was tracing the python code but I believe they’re not related to the current problem.


Additional Details:
The model I’m converting is shufflenetV2. I’m certain the problem lies not in tracing the python code as I’ve annotated them with decorators and sub-classed them with torch.jit.ScriptModule where required.

These are the steps I’ve followed (Loading a TorchScript Model in C++ — PyTorch Tutorials 2.2.0+cu121 documentation) , the error pops up at the last part of step 3 when trying to load the serialised model after building the LibTorch distribution.

Environment:
-Pytorch 1.0
-Linux Mint Sarah (ubuntu 16.10)
-Python 3.6.3

Any and all comments are welcome,
Thanking You in Advance.

TorchScript Code [Error-line marked (please scroll down)]:

op_version_set = 0
def forward(self,
input_1: Tensor) → Tensor:
input_2 = torch.convolution(input_1, getattr(self.conv1, “0”).weight, None, [2, 2], [1, 1], [1, 1], False, [0, 0], 1, False, False, True)
0 = torch.add(getattr(self.conv1, “1”).num_batches_tracked, CONSTANTS.c0, alpha=1)
input_3 = torch.batch_norm(input_2, getattr(self.conv1, “1”).weight, getattr(self.conv1, “1”).bias, getattr(self.conv1, “1”).running_mean, getattr(self.conv1, “1”).running_var, True, 0.10000000000000001, 1.0000000000000001e-05, True)
input_4 = torch.threshold
(input_3, 0., 0.)
input_5, _1 = torch.max_pool2d_with_indices(input_4, [3, 3], [2, 2], [1, 1], [1, 1], False)
input_6 = torch._convolution(input_5, getattr(getattr(self.features, “0”).banch1, “0”).weight, None, [2, 2], [1, 1], [1, 1], False, [0, 0], 24, False, False, True)
2 = torch.add(getattr(getattr(self.features, “0”).banch1, “1”).num_batches_tracked, CONSTANTS.c0, alpha=1)
input_7 = torch.batch_norm(input_6, getattr(getattr(self.features, “0”).banch1, “1”).weight, getattr(getattr(self.features, “0”).banch1, “1”).bias, getattr(getattr(self.features, “0”).banch1, “1”).running_mean, getattr(getattr(self.features, “0”).banch1, “1”).running_var, True, 0.10000000000000001, 1.0000000000000001e-05, True)
input_8 = torch._convolution(input_7, getattr(getattr(self.features, “0”).banch1, “2”).weight, None, [1, 1], [0, 0], [1, 1], False, [0, 0], 1, False, False, True)
3 = torch.add(getattr(getattr(self.features, “0”).banch1, “3”).num_batches_tracked, CONSTANTS.c0, alpha=1)
LINE 14
.
.
.
.
.
LINE 339
height_13 = ops.prim.NumToTensor(torch.size(CONSTANTS.c14, 2))
_199 = int(height_13)
_200 = int(height_13)
width_13 = ops.prim.NumToTensor(torch.size(CONSTANTS.c14, 3))
_201 = int(width_13)
_202 = int(width_13)
channels_per_group_13 = torch.div(self_33, CONSTANTS.c2)
_203 = [_198, 2, int(channels_per_group_13), _200, _202]
x_48 = torch.view(x_47, _203)
x_49 = torch.contiguous(torch.transpose(x_48, 1, 2))
x_50 = torch.view(x_49, [_197, -1, _199, _201])
_204 = torch.slice(x_50, 0, 0, 9223372036854775807, 1)
_205 = torch.slice(torch.slice(_204, 1, 0, 232, 1), 2, 0, 9223372036854775807, 1)
x1_11 = torch.slice(_205, 3, 0, 9223372036854775807, 1)
_206 = torch.slice(x_50, 0, 0, 9223372036854775807, 1)
_207 = torch.slice(_206, 1, 232, 9223372036854775807, 1)
_208 = torch.slice(_207, 2, 0, 9223372036854775807, 1)
x2_11 = torch.slice(_208, 3, 0, 9223372036854775807, 1)
input_111 = torch.convolution(x2_11, getattr(getattr(self.features, “13”).banch2, “0”).weight, None, [1, 1], [0, 0], [1, 1], False, [0, 0], 1, False, False, True)
209 = torch.add(getattr(getattr(self.features, “13”).banch2, “1”).num_batches_tracked, CONSTANTS.c0, alpha=1)
input_112 = torch.batch_norm(input_111, getattr(getattr(self.features, “13”).banch2, “1”).weight, getattr(getattr(self.features, “13”).banch2, “1”).bias, getattr(getattr(self.features, “13”).banch2, “1”).running_mean, getattr(getattr(self.features, “13”).banch2, “1”).running_var, True, 0.10000000000000001, 1.0000000000000001e-05, True)
input_113 = torch.threshold
(input_112, 0., 0.)
input_114 = torch._convolution(input_113, getattr(getattr(self.features, “13”).banch2, “3”).weight, None, [1, 1], [1, 1], [1, 1], False, [0, 0], 232, False, False, True)
210 = torch.add(getattr(getattr(self.features, “13”).banch2, “4”).num_batches_tracked, CONSTANTS.c0, alpha=1)
input_115 = torch.batch_norm(input_114, getattr(getattr(self.features, “13”).banch2, “4”).weight, getattr(getattr(self.features, “13”).banch2, “4”).bias, getattr(getattr(self.features, “13”).banch2, “4”).running_mean, getattr(getattr(self.features, “13”).banch2, “4”).running_var, True, 0.10000000000000001, 1.0000000000000001e-05, True)
input_116 = torch._convolution(input_115, getattr(getattr(self.features, “13”).banch2, “5”).weight, None, [1, 1], [0, 0], [1, 1], False, [0, 0], 1, False, False, True)
211 = torch.add(getattr(getattr(self.features, “13”).banch2, “6”).num_batches_tracked, CONSTANTS.c0, alpha=1)
input_117 = torch.batch_norm(input_116, getattr(getattr(self.features, “13”).banch2, “6”).weight, getattr(getattr(self.features, “13”).banch2, “6”).bias, getattr(getattr(self.features, “13”).banch2, “6”).running_mean, getattr(getattr(self.features, “13”).banch2, “6”).running_var, True, 0.10000000000000001, 1.0000000000000001e-05, True)
212 = [x1_11, torch.threshold(input_117, 0., 0.)]
x_51 = torch.cat(_212, 1)
batchsize_14 = ops.prim.NumToTensor(torch.size(CONSTANTS.c15, 0))
_213 = int(batchsize_14)
_214 = int(batchsize_14)
self_36 = ops.prim.NumToTensor(torch.size(CONSTANTS.c15, 1))
height_14 = ops.prim.NumToTensor(torch.size(CONSTANTS.c15, 2))
_215 = int(height_14)
_216 = int(height_14)
width_14 = ops.prim.NumToTensor(torch.size(CONSTANTS.c15, 3))
_217 = int(width_14)
_218 = int(width_14)
channels_per_group_14 = torch.div(self_36, CONSTANTS.c2)
_219 = [_214, 2, int(channels_per_group_14), _216, _218]
x_52 = torch.view(x_51, _219)
x_53 = torch.contiguous(torch.transpose(x_52, 1, 2))
x_54 = torch.view(x_53, [_213, -1, _215, _217])
_220 = torch.slice(x_54, 0, 0, 9223372036854775807, 1)
_221 = torch.slice(torch.slice(_220, 1, 0, 232, 1), 2, 0, 9223372036854775807, 1)
x1_12 = torch.slice(_221, 3, 0, 9223372036854775807, 1)
_222 = torch.slice(x_54, 0, 0, 9223372036854775807, 1)
_223 = torch.slice(_222, 1, 232, 9223372036854775807, 1)
_224 = torch.slice(_223, 2, 0, 9223372036854775807, 1)
x2_12 = torch.slice(_224, 3, 0, 9223372036854775807, 1)
input_118 = torch.convolution(x2_12, getattr(getattr(self.features, “14”).banch2, “0”).weight, None, [1, 1], [0, 0], [1, 1], False, [0, 0], 1, False, False, True)
225 = torch.add(getattr(getattr(self.features, “14”).banch2, “1”).num_batches_tracked, CONSTANTS.c0, alpha=1)
input_119 = torch.batch_norm(input_118, getattr(getattr(self.features, “14”).banch2, “1”).weight, getattr(getattr(self.features, “14”).banch2, “1”).bias, getattr(getattr(self.features, “14”).banch2, “1”).running_mean, getattr(getattr(self.features, “14”).banch2, “1”).running_var, True, 0.10000000000000001, 1.0000000000000001e-05, True)
input_120 = torch.threshold
(input_119, 0., 0.)
input_121 = torch._convolution(input_120, getattr(getattr(self.features, “14”).banch2, “3”).weight, None, [1, 1], [1, 1], [1, 1], False, [0, 0], 232, False, False, True)
226 = torch.add(getattr(getattr(self.features, “14”).banch2, “4”).num_batches_tracked, CONSTANTS.c0, alpha=1)
input_122 = torch.batch_norm(input_121, getattr(getattr(self.features, “14”).banch2, “4”).weight, getattr(getattr(self.features, “14”).banch2, “4”).bias, getattr(getattr(self.features, “14”).banch2, “4”).running_mean, getattr(getattr(self.features, “14”).banch2, “4”).running_var, True, 0.10000000000000001, 1.0000000000000001e-05, True)
input_123 = torch._convolution(input_122, getattr(getattr(self.features, “14”).banch2, “5”).weight, None, [1, 1], [0, 0], [1, 1], False, [0, 0], 1, False, False, True)
227 = torch.add(getattr(getattr(self.features, “14”).banch2, “6”).num_batches_tracked, CONSTANTS.c0, alpha=1)
input_124 = torch.batch_norm(input_123, getattr(getattr(self.features, “14”).banch2, “6”).weight, getattr(getattr(self.features, “14”).banch2, “6”).bias, getattr(getattr(self.features, “14”).banch2, “6”).running_mean, getattr(getattr(self.features, “14”).banch2, “6”).running_var, True, 0.10000000000000001, 1.0000000000000001e-05, True)
228 = [x1_12, torch.threshold(input_124, 0., 0.)]
x_55 = torch.cat(_228, 1)
batchsize_15 = ops.prim.NumToTensor(torch.size(CONSTANTS.c16, 0))
_229 = int(batchsize_15)
_230 = int(batchsize_15)
self_39 = ops.prim.NumToTensor(torch.size(CONSTANTS.c16, 1))
height_15 = ops.prim.NumToTensor(torch.size(CONSTANTS.c16, 2))
_231 = int(height_15)
_232 = int(height_15)
width_15 = ops.prim.NumToTensor(torch.size(CONSTANTS.c16, 3))
_233 = int(width_15)
_234 = int(width_15)
channels_per_group_15 = torch.div(self_39, CONSTANTS.c2)
_235 = [_230, 2, int(channels_per_group_15), _232, _234]
x_56 = torch.view(x_55, _235)
x_57 = torch.contiguous(torch.transpose(x_56, 1, 2))
x_58 = torch.view(x_57, [_229, -1, _231, _233])
_236 = torch.slice(x_58, 0, 0, 9223372036854775807, 1)
_237 = torch.slice(torch.slice(_236, 1, 0, 232, 1), 2, 0, 9223372036854775807, 1)
x1 = torch.slice(_237, 3, 0, 9223372036854775807, 1)
_238 = torch.slice(x_58, 0, 0, 9223372036854775807, 1)
_239 = torch.slice(_238, 1, 232, 9223372036854775807, 1)
_240 = torch.slice(_239, 2, 0, 9223372036854775807, 1)
x2 = torch.slice(_240, 3, 0, 9223372036854775807, 1)
input_125 = torch.convolution(x2, getattr(getattr(self.features, “15”).banch2, “0”).weight, None, [1, 1], [0, 0], [1, 1], False, [0, 0], 1, False, False, True)
241 = torch.add(getattr(getattr(self.features, “15”).banch2, “1”).num_batches_tracked, CONSTANTS.c0, alpha=1)
input_126 = torch.batch_norm(input_125, getattr(getattr(self.features, “15”).banch2, “1”).weight, getattr(getattr(self.features, “15”).banch2, “1”).bias, getattr(getattr(self.features, “15”).banch2, “1”).running_mean, getattr(getattr(self.features, “15”).banch2, “1”).running_var, True, 0.10000000000000001, 1.0000000000000001e-05, True)
input_127 = torch.threshold
(input_126, 0., 0.)
input_128 = torch._convolution(input_127, getattr(getattr(self.features, “15”).banch2, “3”).weight, None, [1, 1], [1, 1], [1, 1], False, [0, 0], 232, False, False, True)
242 = torch.add(getattr(getattr(self.features, “15”).banch2, “4”).num_batches_tracked, CONSTANTS.c0, alpha=1)
input_129 = torch.batch_norm(input_128, getattr(getattr(self.features, “15”).banch2, “4”).weight, getattr(getattr(self.features, “15”).banch2, “4”).bias, getattr(getattr(self.features, “15”).banch2, “4”).running_mean, getattr(getattr(self.features, “15”).banch2, “4”).running_var, True, 0.10000000000000001, 1.0000000000000001e-05, True)
input_130 = torch._convolution(input_129, getattr(getattr(self.features, “15”).banch2, “5”).weight, None, [1, 1], [0, 0], [1, 1], False, [0, 0], 1, False, False, True)
243 = torch.add(getattr(getattr(self.features, “15”).banch2, “6”).num_batches_tracked, CONSTANTS.c0, alpha=1)
input_131 = torch.batch_norm(input_130, getattr(getattr(self.features, “15”).banch2, “6”).weight, getattr(getattr(self.features, “15”).banch2, “6”).bias, getattr(getattr(self.features, “15”).banch2, “6”).running_mean, getattr(getattr(self.features, “15”).banch2, “6”).running_var, True, 0.10000000000000001, 1.0000000000000001e-05, True)
244 = [x1, torch.threshold(input_131, 0., 0.)]
x_59 = torch.cat(_244, 1)
batchsize = ops.prim.NumToTensor(torch.size(CONSTANTS.c17, 0))
_245 = int(batchsize)
_246 = int(batchsize)
self = ops.prim.NumToTensor(torch.size(CONSTANTS.c17, 1))
height = ops.prim.NumToTensor(torch.size(CONSTANTS.c17, 2))
_247 = int(height)
_248 = int(height)
width = ops.prim.NumToTensor(torch.size(CONSTANTS.c17, 3))
_249 = int(width)
_250 = int(width)
channels_per_group = torch.div(self, CONSTANTS.c2)
_251 = [_246, 2, int(channels_per_group), _248, _250]
x_60 = torch.view(x_59, _251)
x_61 = torch.contiguous(torch.transpose(x_60, 1, 2))
input_132 = torch.view(x_61, [_245, -1, _247, _249])
input_133 = torch._convolution(input_132, getattr(self.conv_last, “0”).weight, None, [1, 1], [0, 0], [1, 1], False, [0, 0], 1, False, False, True)
*

*~~~~~~~~~~~~~~~~~~~~~~~<--------- HERE

**
252 = torch.add(getattr(self.conv_last, “1”).num_batches_tracked, CONSTANTS.c0, alpha=1)
input_134 = torch.batch_norm(input_133, getattr(self.conv_last, “1”).weight, getattr(self.conv_last, “1”).bias, getattr(self.conv_last, “1”).running_mean, getattr(self.conv_last, “1”).running_var, True, 0.10000000000000001, 1.0000000000000001e-05, True)
input_135 = torch.threshold_(input_134, 0., 0.)
x = torch.adaptive_avg_pool2d(input_135, [1, 1])
input = torch.view(x, [-1, 1024])
_253 = torch.t(getattr(self.classifier, “0”).weight)
_254 = torch.addmm(getattr(self.classifier, “0”).bias, input, _253, beta=1, alpha=1)
return _254