Can you provide what error you get?
I am able to run the below code fine. As I don’t have access to the rest of your code I just return the input and feature as it is.
import torch
import torch.nn as nn
from torch.autograd.function import Function


class CenterLoss(nn.Module):
    def __init__(self, num_classes=10, feat_dim=2, size_average=True):
        super(CenterLoss, self).__init__()
        self.centers = nn.Parameter(torch.randn(num_classes, feat_dim))

    def forward(self, label, feat):
        batch_size = feat.size(0)
        feat = feat.view(batch_size, -1)      
        return label, feat


loss = CenterLoss()
label = torch.ones(2)
feat = torch.ones(2)
print(loss(label, feat))

The output is
(tensor([1., 1.]), tensor([[1.],
        [1.]]))