So I modify that code for the model that I use
VGG(
  (features): Sequential(
    (0): Conv2d(3, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (0_linear_quant): LinearQuant(sf=None, bits=8, overflow_rate=0.000, counter=20)
    (1): ReLU(inplace=True)
    (2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (2_linear_quant): LinearQuant(sf=None, bits=8, overflow_rate=0.000, counter=20)
    (3): ReLU(inplace=True)
    (4): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
    (5): Conv2d(64, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (5_linear_quant): LinearQuant(sf=None, bits=8, overflow_rate=0.000, counter=20)
    (6): ReLU(inplace=True)
    (7): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (7_linear_quant): LinearQuant(sf=None, bits=8, overflow_rate=0.000, counter=20)
    (8): ReLU(inplace=True)
    (9): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
    (10): Conv2d(128, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (10_linear_quant): LinearQuant(sf=None, bits=8, overflow_rate=0.000, counter=20)
    (11): ReLU(inplace=True)
    (12): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (12_linear_quant): LinearQuant(sf=None, bits=8, overflow_rate=0.000, counter=20)
    (13): ReLU(inplace=True)
    (14): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (14_linear_quant): LinearQuant(sf=None, bits=8, overflow_rate=0.000, counter=20)
    (15): ReLU(inplace=True)
    (16): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
    (17): Conv2d(256, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (17_linear_quant): LinearQuant(sf=None, bits=8, overflow_rate=0.000, counter=20)
    (18): ReLU(inplace=True)
    (19): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (19_linear_quant): LinearQuant(sf=None, bits=8, overflow_rate=0.000, counter=20)
    (20): ReLU(inplace=True)
    (21): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (21_linear_quant): LinearQuant(sf=None, bits=8, overflow_rate=0.000, counter=20)
    (22): ReLU(inplace=True)
    (23): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
    (24): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (24_linear_quant): LinearQuant(sf=None, bits=8, overflow_rate=0.000, counter=20)
    (25): ReLU(inplace=True)
    (26): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (26_linear_quant): LinearQuant(sf=None, bits=8, overflow_rate=0.000, counter=20)
    (27): ReLU(inplace=True)
    (28): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
    (28_linear_quant): LinearQuant(sf=None, bits=8, overflow_rate=0.000, counter=20)
    (29): ReLU(inplace=True)
    (30): MaxPool2d(kernel_size=2, stride=2, padding=0, dilation=1, ceil_mode=False)
  )
  (classifier): Sequential(
    (0): Linear(in_features=25088, out_features=4096, bias=True)
    (0_linear_quant): LinearQuant(sf=None, bits=8, overflow_rate=0.000, counter=20)
    (1): ReLU(inplace=True)
    (2): Dropout(p=0.5, inplace=False)
    (3): Linear(in_features=4096, out_features=4096, bias=True)
    (3_linear_quant): LinearQuant(sf=None, bits=8, overflow_rate=0.000, counter=20)
    (4): ReLU(inplace=True)
    (5): Dropout(p=0.5, inplace=False)
    (6): Linear(in_features=4096, out_features=1000, bias=True)
    (6_linear_quant): LinearQuant(sf=None, bits=8, overflow_rate=0.000, counter=20)
  )
)

This is the model that I use right now and this is from the GitHub below.

  
      
      GitHub
  
  
    

aaron-xichen/pytorch-playground 1

Base pretrained models and datasets in pytorch (MNIST, SVHN, CIFAR10, CIFAR100, STL10, AlexNet, VGG16, VGG19, ResNet, Inception, SqueezeNet) - aaron-xichen/pytorch-playground


  
  
    
    
  
  


and right now, when I change the code as this
    for idx, (data, target) in enumerate(tqdm.tqdm(ds, total=n_sample)):
        n_passed += len(data)
        data =  Variable(torch.FloatTensor(data)).cuda()
        indx_target = torch.LongTensor(target)
        for name, module in model.module.named_children():
            for name, module in module.named_children():
                for name, module in module.named_children():
                    module.register_forward_hook(get_hook(name))
        #h1 = model.module.model._modules["features"]._modules.get("0_linear_quant").register_forward_hook(get_activation('0_linear_quant'))
        #h2 = model.module.model._modules["features"]._modules.get("0").register_forward_hook(get_ofmap('fea0'))

        output = model(data)
        bs = output.size(0)

        keys = list(act_in.keys())
        for key_out, key_in in zip(keys[:-1], keys[1:]):
            print('Comparing output of {} to input of {}'.format(key_out, key_in))
            print((act_out[key_out] == act_in[key_in]).all())

Error is like this
Comparing output of 0 to input of 0_linear_quant
tensor(True, device='cuda:0')
Comparing output of 0_linear_quant to input of 1
tensor(True, device='cuda:0')
Comparing output of 1 to input of 2
tensor(True, device='cuda:0')
Comparing output of 2 to input of 2_linear_quant
Traceback (most recent call last):
  File "/home/sunyoung/research/quantization/quant/bin/quantize", line 33, in <module>
    sys.exit(load_entry_point('pytorch-playground', 'console_scripts', 'quantize')())
  File "/home/sunyoung/research/quantization/pytorch-playground/quantize.py", line 107, in main
    misc.eval_model(model_raw, val_ds_tmp, ngpu=1, n_sample=args.n_sample, is_imagenet=is_imagenet)
  File "/home/sunyoung/research/quantization/pytorch-playground/utee/misc.py", line 230, in eval_model
    print((act_out[key_out] == act_in[key_in]).all())
RuntimeError: The size of tensor a (4096) must match the size of tensor b (224) at non-singleton dimension 3

I don’t know why this happen because when I execute inference code without that, it doesn’t have problem.