Assuming you would like to get the length of torch.utils.data.Dataset then print(len(dataset)) should work:
class MyDataset(Dataset):
    def __init__(self):
        self.data = torch.randn(100, 1)
        
    def __getitem__(self, index):
        x = self.data[index]
        return x
    
    def __len__(self):
        return len(self.data)

dataset = MyDataset()
print(len(dataset))
> 100