# Buggy code
def googlenet(pretrained=False, progress=True, **kwargs):
    r"""GoogLeNet (Inception v1) model architecture from
    `"Going Deeper with Convolutions" <http://arxiv.org/abs/1409.4842>`_.

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
        progress (bool): If True, displays a progress bar of the download to stderr
        aux_logits (bool): If True, adds two auxiliary branches that can improve training.
            Default: *False* when pretrained is True otherwise *True*
        transform_input (bool): If True, preprocesses the input according to the method with which it
            was trained on ImageNet. Default: *False*
    """
    if pretrained:
        if "transform_input" not in kwargs:
            kwargs["transform_input"] = True
        if "aux_logits" not in kwargs:
            kwargs["aux_logits"] = False
        if kwargs["aux_logits"]:
            warnings.warn(
                "auxiliary heads in the pretrained googlenet model are NOT pretrained, "
                "so make sure to train them"
            )
        original_aux_logits = kwargs["aux_logits"]
        kwargs["aux_logits"] = True
        kwargs["init_weights"] = False
        model = GoogLeNet(**kwargs)
        state_dict = load_state_dict_from_url(
            model_urls["googlenet"], progress=progress
        )
        model.load_state_dict(state_dict)
        if not original_aux_logits:
            model.aux_logits = False
            del model.aux1, model.aux2
        return model

    return GoogLeNet(**kwargs)


# 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 googlenet(pretrained=False, progress=True, **kwargs):
    r"""GoogLeNet (Inception v1) model architecture from
    `"Going Deeper with Convolutions" <http://arxiv.org/abs/1409.4842>`_.

    Args:
        pretrained (bool): If True, returns a model pre-trained on ImageNet
        progress (bool): If True, displays a progress bar of the download to stderr
        aux_logits (bool): If True, adds two auxiliary branches that can improve training.
            Default: *False* when pretrained is True otherwise *True*
        transform_input (bool): If True, preprocesses the input according to the method with which it
            was trained on ImageNet. Default: *False*
    """
    if pretrained:
        if "transform_input" not in kwargs:
            kwargs["transform_input"] = True
        if "aux_logits" not in kwargs:
            kwargs["aux_logits"] = False
        if kwargs["aux_logits"]:
            warnings.warn(
                "auxiliary heads in the pretrained googlenet model are NOT pretrained, "
                "so make sure to train them"
            )
        original_aux_logits = kwargs["aux_logits"]
        kwargs["aux_logits"] = True
        kwargs["init_weights"] = False
        model = GoogLeNet(**kwargs)
        state_dict = load_state_dict_from_url(
            model_urls["googlenet"], progress=progress
        )
        model.load_state_dict(state_dict)
        if not original_aux_logits:
            model.aux_logits = False
            model.aux1 = None
            model.aux2 = None
        return model

    return GoogLeNet(**kwargs)