I guess this counts shared parameters multiple times, doesn’t it?
import torch
from models.modelparts import count_parameters
class tstModel(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.p = torch.nn.Parameter(
            torch.randn(1, 1, 1, requires_grad=True)
                .expand(-1, 5, -1)
        )
print(count_parameters(tstModel()))

prints 5
If I understand correctly, expand just creates tensor with 5 views to the same parameter, so the right answer should be 1.
But I don’t know how to fix that.