How to get the same results from a code before/after modularization

@InnovArul I used the following function (credit: Check if models have same weights) to compare the trained weights from the two codes layer-by-layer. The weights and biases were totally different even when the inputs are the same.

import torch 

def compare_weights(path_save1, path_save2):
    weights1 = torch.load(path_save1, map_location=torch.device('cpu'))
    weights2 = torch.load(path_save2, map_location=torch.device('cpu'))
    
    models_differ = 0
    for key_item1, key_item2 in zip(weights1.items(), weights2.items()):
        if torch.equal(key_item1[1], key_item2[1]):
            pass
        else:
            models_differ += 1
            if (key_item1[0] == key_item2[0]):
                print('Mismatch found at', key_item1[0])
            else:
                raise Exception 
    
    if models_differ == 0:
        print('Weights match perfectly!')