Interesting idea!
I think you can try it, although I’m not sure, if your current similarity calculation is really useful.
Your criterion would yield a low loss, if the weights are just scaled with a constant, but represent the same transformation.
However, I’ve created a small example with some dummy data, which should give you a starter code for your experiments:
# Create simple model
class MyModel(nn.Module):
    def __init__(self):
        super(MyModel, self).__init__()
        self.fc1 = nn.Linear(2, 4)
        self.fc2 = nn.Linear(4, 1)
        
    def forward(self, x):
        x = F.relu(self.fc1(x))
        return F.sigmoid(self.fc2(x))

# Define similarity criterion
def weight_criterion(modelA, modelB):
    loss = 0
    for paramA, paramB in zip(modelA.parameters(), modelB.parameters()):
        loss += 1. / torch.sum(torch.abs(paramA.detach() - paramB))
    return loss

# Dummy data (negative input - 1, positive input - 0)
x = torch.cat((torch.randn(10, 2) - 1, torch.randn(10, 2) + 1), 0)
y = torch.cat((torch.full((10, ), 1), torch.full((10, ), 0)))

modelA = MyModel()
modelB = MyModel()

optimizerA = optim.SGD(modelA.parameters(), lr=1e-2)
optimizerB = optim.SGD(modelB.parameters(), lr=1e-2)

criterion = nn.BCELoss()

# Train modelA as the reference model
for epoch in range(20000):
    optimizerA.zero_grad()
    output = modelA(x)
    loss = criterion(output, y)
    loss.backward()
    optimizerA.step()
    print('Epoch {}, loss {}'.format(epoch, loss.item()))

# Train modelB with weight_loss
for epoch in range(20000):
    optimizerB.zero_grad()
    output = modelB(x)
    bce_loss = criterion(output, y)
    weight_loss = weight_criterion(modelA, modelB)
    loss = bce_loss + weight_loss
    loss.backward()
    optimizerB.step()
    print('Epoch {}, BCELoss {}, weight_loss {}'.format(
        epoch, bce_loss.item(), weight_loss.item()))

# Compare parameters of both models
for paramA, paramB in zip(modelA.parameters(), modelB.parameters()):
    print('A: {},\nB: {}'.format(
        paramA, paramB))

Let me know, if this is helpful and what you experienced in your experiments!