# Buggy code
def __init__(
    self,
    num_classes=1000,
    aux_logits=True,
    transform_input=False,
    init_weights=True,
    blocks=None,
):
    super(GoogLeNet, self).__init__()
    if blocks is None:
        blocks = [BasicConv2d, Inception, InceptionAux]
    assert len(blocks) == 3
    conv_block = blocks[0]
    inception_block = blocks[1]
    inception_aux_block = blocks[2]

    self.aux_logits = aux_logits
    self.transform_input = transform_input

    self.conv1 = conv_block(3, 64, kernel_size=7, stride=2, padding=3)
    self.maxpool1 = nn.MaxPool2d(3, stride=2, ceil_mode=True)
    self.conv2 = conv_block(64, 64, kernel_size=1)
    self.conv3 = conv_block(64, 192, kernel_size=3, padding=1)
    self.maxpool2 = nn.MaxPool2d(3, stride=2, ceil_mode=True)

    self.inception3a = inception_block(192, 64, 96, 128, 16, 32, 32)
    self.inception3b = inception_block(256, 128, 128, 192, 32, 96, 64)
    self.maxpool3 = nn.MaxPool2d(3, stride=2, ceil_mode=True)

    self.inception4a = inception_block(480, 192, 96, 208, 16, 48, 64)
    self.inception4b = inception_block(512, 160, 112, 224, 24, 64, 64)
    self.inception4c = inception_block(512, 128, 128, 256, 24, 64, 64)
    self.inception4d = inception_block(512, 112, 144, 288, 32, 64, 64)
    self.inception4e = inception_block(528, 256, 160, 320, 32, 128, 128)
    self.maxpool4 = nn.MaxPool2d(2, stride=2, ceil_mode=True)

    self.inception5a = inception_block(832, 256, 160, 320, 32, 128, 128)
    self.inception5b = inception_block(832, 384, 192, 384, 48, 128, 128)

    if aux_logits:
        self.aux1 = inception_aux_block(512, num_classes)
        self.aux2 = inception_aux_block(528, num_classes)

    self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
    self.dropout = nn.Dropout(0.2)
    self.fc = nn.Linear(1024, num_classes)

    if init_weights:
        self._initialize_weights()


# Traceback (RuntimeError)
Traceback (most recent call last):
File "quantize_resnet.py", line 181, in <module>
main()
File "quantize_resnet.py", line 138, in main
m = torch.jit.script(model.float().eval())
File "/data/users/jerryzh/anaconda3/envs/py3/lib/python3.7/site-packages/torch/jit/__init__.py", line 1267, in script
return torch.jit._recursive.create_script_module(obj, torch.jit._recursive.infer_methods_to_compile)
File "/data/users/jerryzh/anaconda3/envs/py3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 305, in create_script_module
return create_script_module_impl(nn_module, concrete_type, stubs_fn)
File "/data/users/jerryzh/anaconda3/envs/py3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 352, in create_script_module_impl
create_methods_from_stubs(concrete_type, stubs)
File "/data/users/jerryzh/anaconda3/envs/py3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 279, in create_methods_from_stubs
concrete_type._create_methods(defs, rcbs, defaults)
File "/data/users/jerryzh/anaconda3/envs/py3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 578, in compile_unbound_method
create_methods_from_stubs(concrete_type, (stub,))
File "/data/users/jerryzh/anaconda3/envs/py3/lib/python3.7/site-packages/torch/jit/_recursive.py", line 279, in create_methods_from_stubs
concrete_type._create_methods(defs, rcbs, defaults)
RuntimeError:
Module 'GoogLeNet' has no attribute 'aux1' :
File "/data/users/jerryzh/anaconda3/envs/py3/lib/python3.7/site-packages/torchvision-0.6.0a0+b2e9565-py3.7-linux-x86_64.egg/torchvision/models/googlenet.py", line 156
aux_defined = self.training and self.aux_logits
if aux_defined:
aux1 = self.aux1(x)
~~~~~~~~~ <--- HERE
else:
aux1 = None
'GoogLeNet._forward' is being compiled since it was called from 'GoogLeNet.forward'
File "/data/users/jerryzh/anaconda3/envs/py3/lib/python3.7/site-packages/torchvision-0.6.0a0+b2e9565-py3.7-linux-x86_64.egg/torchvision/models/googlenet.py", line 200
# type: (Tensor) -> GoogLeNetOutputs
x = self._transform_input(x)
x, aux1, aux2 = self._forward(x)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
aux_defined = self.training and self.aux_logits
if torch.jit.is_scripting():

# Fixed code
def __init__(
    self,
    num_classes=1000,
    aux_logits=True,
    transform_input=False,
    init_weights=True,
    blocks=None,
):
    super(GoogLeNet, self).__init__()
    if blocks is None:
        blocks = [BasicConv2d, Inception, InceptionAux]
    assert len(blocks) == 3
    conv_block = blocks[0]
    inception_block = blocks[1]
    inception_aux_block = blocks[2]

    self.aux_logits = aux_logits
    self.transform_input = transform_input

    self.conv1 = conv_block(3, 64, kernel_size=7, stride=2, padding=3)
    self.maxpool1 = nn.MaxPool2d(3, stride=2, ceil_mode=True)
    self.conv2 = conv_block(64, 64, kernel_size=1)
    self.conv3 = conv_block(64, 192, kernel_size=3, padding=1)
    self.maxpool2 = nn.MaxPool2d(3, stride=2, ceil_mode=True)

    self.inception3a = inception_block(192, 64, 96, 128, 16, 32, 32)
    self.inception3b = inception_block(256, 128, 128, 192, 32, 96, 64)
    self.maxpool3 = nn.MaxPool2d(3, stride=2, ceil_mode=True)

    self.inception4a = inception_block(480, 192, 96, 208, 16, 48, 64)
    self.inception4b = inception_block(512, 160, 112, 224, 24, 64, 64)
    self.inception4c = inception_block(512, 128, 128, 256, 24, 64, 64)
    self.inception4d = inception_block(512, 112, 144, 288, 32, 64, 64)
    self.inception4e = inception_block(528, 256, 160, 320, 32, 128, 128)
    self.maxpool4 = nn.MaxPool2d(2, stride=2, ceil_mode=True)

    self.inception5a = inception_block(832, 256, 160, 320, 32, 128, 128)
    self.inception5b = inception_block(832, 384, 192, 384, 48, 128, 128)

    if aux_logits:
        self.aux1 = inception_aux_block(512, num_classes)
        self.aux2 = inception_aux_block(528, num_classes)
    else:
        self.aux1 = None
        self.aux2 = None

    self.avgpool = nn.AdaptiveAvgPool2d((1, 1))
    self.dropout = nn.Dropout(0.2)
    self.fc = nn.Linear(1024, num_classes)

    if init_weights:
        self._initialize_weights()